]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/ecma/Array/15.4.4.4-2.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
73 var SECTION
= "15.4.4.4-1";
74 var VERSION
= "ECMA_1";
76 var testcases
= new Array();
78 writeHeaderToLog( SECTION
+ " Array.prototype.reverse()");
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") );
97 function CheckItems( R
, A
) {
98 for ( var i
= 0; i
< R
.length
; i
++ ) {
99 testcases
[testcases
.length
] = new TestCase(
107 for ( tc
=0; tc
< testcases
.length
; tc
++ ) {
108 testcases
[tc
].passed
= writeTestCaseResult(
109 testcases
[tc
].expect
,
110 testcases
[tc
].actual
,
111 testcases
[tc
].description
+" = "+ testcases
[tc
].actual
);
112 testcases
[tc
].reason
+= ( testcases
[tc
].passed
) ? "" : "wrong value ";
115 return ( testcases
);
117 function Object_1( value
) {
118 this.array
= value
.split(",");
119 this.length
= this.array
.length
;
120 for ( var i
= 0; i
< this.length
; i
++ ) {
121 this[i
] = eval(this.array
[i
]);
123 this.join
= Array
.prototype.reverse
;
124 this.getClass
= Object
.prototype.toString
;
126 function Reverse( array
) {
127 var r2
= array
.length
;
129 var r3
= Math
.floor( r2
/2 );
134 for ( k
= 0; k
< r3
; k
++ ) {
136 // var r7 = String( k );
138 var r8
= String( r6
);
149 function Iterate( array
) {
150 for ( var i
= 0; i
< array
.length
; i
++ ) {
151 // print( i+": "+ array[String(i)] );
155 function Object_1( value
) {
156 this.array
= value
.split(",");
157 this.length
= this.array
.length
;
158 for ( var i
= 0; i
< this.length
; i
++ ) {
159 this[i
] = this.array
[i
];
161 this.reverse
= Array
.prototype.reverse
;
162 this.getClass
= Object
.prototype.toString
;