Debian Codegraph @

rhino/testsrc/tests/ecma/Array/15.4.4.4-2.js

raw symbols SCIP
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 gTestfile = '15.4.4.4-2.js';
7
8 /**
9 File Name: 15.4.4.3-1.js
10 ECMA Section: 15.4.4.3-1 Array.prototype.reverse()
11 Description:
12
13 The elements of the array are rearranged so as to reverse their order.
14 This object is returned as the result of the call.
15
16 1. Call the [[Get]] method of this object with argument "length".
17 2. Call ToUint32(Result(1)).
18 3. Compute floor(Result(2)/2).
19 4. Let k be 0.
20 5. If k equals Result(3), return this object.
21 6. Compute Result(2)k1.
22 7. Call ToString(k).
23 8. ToString(Result(6)).
24 9. Call the [[Get]] method of this object with argument Result(7).
25 10. Call the [[Get]] method of this object with argument Result(8).
26 11. If this object has a property named by Result(8), go to step 12; but
27 if this object has no property named by Result(8), then go to either
28 step 12 or step 14, depending on the implementation.
29 12. Call the [[Put]] method of this object with arguments Result(7) and
30 Result(10).
31 13. Go to step 15.
32 14. Call the [[Delete]] method on this object, providing Result(7) as the
33 name of the property to delete.
34 15. If this object has a property named by Result(7), go to step 16; but if
35 this object has no property named by Result(7), then go to either step 16
36 or step 18, depending on the implementation.
37 16. Call the [[Put]] method of this object with arguments Result(8) and
38 Result(9).
39 17. Go to step 19.
40 18. Call the [[Delete]] method on this object, providing Result(8) as the
41 name of the property to delete.
42 19. Increase k by 1.
43 20. Go to step 5.
44
45 Note that the reverse function is intentionally generic; it does not require
46 that its this value be an Array object. Therefore it can be transferred to other
47 kinds of objects for use as a method. Whether the reverse function can be applied
48 successfully to a host object is implementation dependent.
49
50 Note: Array.prototype.reverse allows some flexibility in implementation
51 regarding array indices that have not been populated. This test covers the
52 cases in which unpopulated indices are not deleted, since the JavaScript
53 implementation does not delete uninitialzed indices.
54
55 Author: [email protected]
56 Date: 7 october 1997
57 */
58
59 var SECTION = "15.4.4.4-1";
60 var VERSION = "ECMA_1";
61 startTest();
62
63 writeHeaderToLog( SECTION + " Array.prototype.reverse()");
64
65 var ARR_PROTOTYPE = Array.prototype;
66
67 new TestCase( SECTION, "Array.prototype.reverse.length", 0, Array.prototype.reverse.length );
68 new TestCase( SECTION, "delete Array.prototype.reverse.length", false, delete Array.prototype.reverse.length );
69 new TestCase( SECTION, "delete Array.prototype.reverse.length; Array.prototype.reverse.length", 0, eval("delete Array.prototype.reverse.length; Array.prototype.reverse.length") );
70
71 // length of array is 0
72 new TestCase( SECTION,
73 "var A = new Array(); A.reverse(); A.length",
74 0,
75 eval("var A = new Array(); A.reverse(); A.length") );
76
77 test();
78
79 function CheckItems( R, A ) {
80 for ( var i = 0; i < R.length; i++ ) {
81 new TestCase(
82 SECTION,
83 "A["+i+ "]",
84 R[i],
85 A[i] );
86 }
87 }
88 test();
89
90 function Object_1( value ) {
91 this.array = value.split(",");
92 this.length = this.array.length;
93 for ( var i = 0; i < this.length; i++ ) {
94 this[i] = eval(this.array[i]);
95 }
96 this.join = Array.prototype.reverse;
97 this.getClass = Object.prototype.toString;
98 }
99 function Reverse( array ) {
100 var r2 = array.length;
101 var k = 0;
102 var r3 = Math.floor( r2/2 );
103 if ( r3 == k ) {
104 return array;
105 }
106
107 for ( k = 0; k < r3; k++ ) {
108 var r6 = r2 - k - 1;
109 // var r7 = String( k );
110 var r7 = k;
111 var r8 = String( r6 );
112
113 var r9 = array[r7];
114 var r10 = array[r8];
115
116 array[r7] = r10;
117 array[r8] = r9;
118 }
119
120 return array;
121 }
122 function Iterate( array ) {
123 for ( var i = 0; i < array.length; i++ ) {
124 // print( i+": "+ array[String(i)] );
125 }
126 }
127
128 function Object_1( value ) {
129 this.array = value.split(",");
130 this.length = this.array.length;
131 for ( var i = 0; i < this.length; i++ ) {
132 this[i] = this.array[i];
133 }
134 this.reverse = Array.prototype.reverse;
135 this.getClass = Object.prototype.toString;
136 }