]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/ecma/Array/15.4.4.4-1.js
1 /* The contents of this file are subject to the Netscape Public
2 * License Version 1.1 (the "License"); you may not use this file
3 * except in compliance with the License. You may obtain a copy of
4 * the License at http://www.mozilla.org/NPL/
6 * Software distributed under the License is distributed on an "AS
7 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
8 * implied. See the License for the specific language governing
9 * rights and limitations under the License.
11 * The Original Code is Mozilla Communicator client code, released March
14 * The Initial Developer of the Original Code is Netscape Communications
15 * Corporation. Portions created by Netscape are
16 * Copyright (C) 1998 Netscape Communications Corporation. All
23 File Name: 15.4.4.3-1.js
24 ECMA Section: 15.4.4.3-1 Array.prototype.reverse()
27 The elements of the array are rearranged so as to reverse their order.
28 This object is returned as the result of the call.
30 1. Call the [[Get]] method of this object with argument "length".
31 2. Call ToUint32(Result(1)).
32 3. Compute floor(Result(2)/2).
34 5. If k equals Result(3), return this object.
35 6. Compute Result(2)k1.
37 8. ToString(Result(6)).
38 9. Call the [[Get]] method of this object with argument Result(7).
39 10. Call the [[Get]] method of this object with argument Result(8).
40 11. If this object has a property named by Result(8), go to step 12; but
41 if this object has no property named by Result(8), then go to either
42 step 12 or step 14, depending on the implementation.
43 12. Call the [[Put]] method of this object with arguments Result(7) and
46 14. Call the [[Delete]] method on this object, providing Result(7) as the
47 name of the property to delete.
48 15. If this object has a property named by Result(7), go to step 16; but if
49 this object has no property named by Result(7), then go to either step 16
50 or step 18, depending on the implementation.
51 16. Call the [[Put]] method of this object with arguments Result(8) and
54 18. Call the [[Delete]] method on this object, providing Result(8) as the
55 name of the property to delete.
59 Note that the reverse function is intentionally generic; it does not require
60 that its this value be an Array object. Therefore it can be transferred to other
61 kinds of objects for use as a method. Whether the reverse function can be applied
62 successfully to a host object is implementation dependent.
64 Note: Array.prototype.reverse allows some flexibility in implementation
65 regarding array indices that have not been populated. This test covers the
66 cases in which unpopulated indices are not deleted, since the JavaScript
67 implementation does not delete uninitialzed indices.
69 Author: christine@netscape.com
72 var SECTION
= "15.4.4.4-1";
73 var VERSION
= "ECMA_1";
75 var BUGNUMBER
="123724";
77 writeHeaderToLog( SECTION
+ " Array.prototype.reverse()");
79 var testcases
= new Array();
83 function getTestCases() {
84 var ARR_PROTOTYPE
= Array
.prototype;
86 testcases
[testcases
.length
] = new TestCase( SECTION
, "Array.prototype.reverse.length", 0, Array
.prototype.reverse
.length
);
87 testcases
[testcases
.length
] = new TestCase( SECTION
, "delete Array.prototype.reverse.length", false, delete Array
.prototype.reverse
.length
);
88 testcases
[testcases
.length
] = new TestCase( SECTION
, "delete Array.prototype.reverse.length; Array.prototype.reverse.length", 0, eval("delete Array.prototype.reverse.length; Array.prototype.reverse.length") );
90 // length of array is 0
91 testcases
[testcases
.length
] = new TestCase( SECTION
,
92 "var A = new Array(); A.reverse(); A.length",
94 eval("var A = new Array(); A.reverse(); A.length") );
96 // length of array is 1
97 var A
= new Array(true);
100 testcases
[testcases
.length
] = new TestCase( SECTION
,
101 "var A = new Array(true); A.reverse(); A.length",
103 eval("var A = new Array(true); A.reverse(); A.length") );
106 // length of array is 2
107 var S
= "var A = new Array( true,false )";
111 testcases
[testcases
.length
] = new TestCase(
113 S
+"; A.reverse(); A.length",
115 eval( S
+ "; A.reverse(); A.length") );
119 // length of array is 3
120 var S
= "var A = new Array( true,false,null )";
124 testcases
[testcases
.length
] = new TestCase( SECTION
,
125 S
+"; A.reverse(); A.length",
127 eval( S
+ "; A.reverse(); A.length") );
130 // length of array is 4
131 var S
= "var A = new Array( true,false,null,void 0 )";
135 testcases
[testcases
.length
] = new TestCase( SECTION
,
136 S
+"; A.reverse(); A.length",
138 eval( S
+ "; A.reverse(); A.length") );
142 // some array indexes have not been set
143 var S
= "var A = new Array(); A[8] = 'hi', A[3] = 'yo'";
147 testcases
[testcases
.length
] = new TestCase( SECTION
,
148 S
+"; A.reverse(); A.length",
150 eval( S
+ "; A.reverse(); A.length") );
154 var OBJECT_OBJECT
= new Object();
155 var FUNCTION_OBJECT
= new Function( 'return this' );
156 var BOOLEAN_OBJECT
= new Boolean
;
157 var DATE_OBJECT
= new Date(0);
158 var STRING_OBJECT
= new String('howdy');
159 var NUMBER_OBJECT
= new Number(Math
.PI
);
160 var ARRAY_OBJECT
= new Array(1000);
162 var args
= "null, void 0, Math.pow(2,32), 1.234e-32, OBJECT_OBJECT, BOOLEAN_OBJECT, FUNCTION_OBJECT, DATE_OBJECT, STRING_OBJECT,"+
163 "ARRAY_OBJECT, NUMBER_OBJECT, Math, true, false, 123, '90210'";
165 var S
= "var A = new Array("+args
+")";
169 testcases
[testcases
.length
] = new TestCase( SECTION
,
170 S
+"; A.reverse(); A.length",
172 eval( S
+ "; A.reverse(); A.length") );
177 for (var i
= 0; i
< limit
; i
++ ) {
179 if ( i
+ 1 < limit
) {
184 var S
= "var A = new Array("+args
+")";
188 testcases
[testcases
.length
] = new TestCase( SECTION
,
189 S
+"; A.reverse(); A.length",
191 eval( S
+ "; A.reverse(); A.length") );
194 var S
= "var MYOBJECT = new Object_1( \"void 0, 1, null, 2, \'\'\" )";
196 var R
= Reverse( A
);
198 testcases
[testcases
.length
] = new TestCase( SECTION
,
199 S
+"; A.reverse(); A.length",
201 eval( S
+ "; A.reverse(); A.length") );
204 return ( testcases
);
206 function CheckItems( R
, A
) {
207 for ( var i
= 0; i
< R
.length
; i
++ ) {
208 testcases
[testcases
.length
] = new TestCase(
216 for ( tc
=0; tc
< testcases
.length
; tc
++ ) {
217 testcases
[tc
].passed
= writeTestCaseResult(
218 testcases
[tc
].expect
,
219 testcases
[tc
].actual
,
220 testcases
[tc
].description
+" = "+ testcases
[tc
].actual
);
221 testcases
[tc
].reason
+= ( testcases
[tc
].passed
) ? "" : "wrong value ";
224 return ( testcases
);
226 function Object_1( value
) {
227 this.array
= value
.split(",");
228 this.length
= this.array
.length
;
229 for ( var i
= 0; i
< this.length
; i
++ ) {
230 this[i
] = eval(this.array
[i
]);
232 this.join
= Array
.prototype.reverse
;
233 this.getClass
= Object
.prototype.toString
;
235 function Reverse( array
) {
236 var r2
= array
.length
;
238 var r3
= Math
.floor( r2
/2 );
243 for ( k
= 0; k
< r3
; k
++ ) {
245 // var r7 = String( k );
247 var r8
= String( r6
);
258 function Iterate( array
) {
259 for ( var i
= 0; i
< array
.length
; i
++ ) {
260 // print( i+": "+ array[String(i)] );
264 function Object_1( value
) {
265 this.array
= value
.split(",");
266 this.length
= this.array
.length
;
267 for ( var i
= 0; i
< this.length
; i
++ ) {
268 this[i
] = this.array
[i
];
270 this.reverse
= Array
.prototype.reverse
;
271 this.getClass
= Object
.prototype.toString
;