]> git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/ecma/Array/15.4.5.1-1.js
JavaScriptCore-466.1.6.tar.gz
[apple/javascriptcore.git] / tests / mozilla / ecma / Array / 15.4.5.1-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/
5 *
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.
10 *
11 * The Original Code is Mozilla Communicator client code, released March
12 * 31, 1998.
13 *
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
17 * Rights Reserved.
18 *
19 * Contributor(s):
20 *
21 */
22 /**
23 File Name: 15.4.5.1-1.js
24 ECMA Section: [[ Put]] (P, V)
25 Description:
26 Array objects use a variation of the [[Put]] method used for other native
27 ECMAScript objects (section 8.6.2.2).
28
29 Assume A is an Array object and P is a string.
30
31 When the [[Put]] method of A is called with property P and value V, the
32 following steps are taken:
33
34 1. Call the [[CanPut]] method of A with name P.
35 2. If Result(1) is false, return.
36 3. If A doesn't have a property with name P, go to step 7.
37 4. If P is "length", go to step 12.
38 5. Set the value of property P of A to V.
39 6. Go to step 8.
40 7. Create a property with name P, set its value to V and give it empty
41 attributes.
42 8. If P is not an array index, return.
43 9. If A itself has a property (not an inherited property) named "length",
44 andToUint32(P) is less than the value of the length property of A, then
45 return.
46 10. Change (or set) the value of the length property of A to ToUint32(P)+1.
47 11. Return.
48 12. Compute ToUint32(V).
49 13. For every integer k that is less than the value of the length property
50 of A but not less than Result(12), if A itself has a property (not an
51 inherited property) named ToString(k), then delete that property.
52 14. Set the value of property P of A to Result(12).
53 15. Return.
54 Author: christine@netscape.com
55 Date: 12 november 1997
56 */
57
58 var SECTION = "15.4.5.1-1";
59 var VERSION = "ECMA_1";
60 startTest();
61 var TITLE = "Array [[Put]] (P, V)";
62
63 writeHeaderToLog( SECTION + " "+ TITLE);
64
65 var testcases = getTestCases();
66 test();
67
68 function getTestCases() {
69 var array = new Array();
70
71 var item = 0;
72
73 // P is "length"
74
75 array[item++] = new TestCase( SECTION,
76 "var A = new Array(); A.length = 1000; A.length",
77 1000,
78 eval("var A = new Array(); A.length = 1000; A.length") );
79
80 // A has Property P, and P is not length or an array index
81 array[item++] = new TestCase( SECTION,
82 "var A = new Array(1000); A.name = 'name of this array'; A.name",
83 'name of this array',
84 eval("var A = new Array(1000); A.name = 'name of this array'; A.name") );
85
86 array[item++] = new TestCase( SECTION,
87 "var A = new Array(1000); A.name = 'name of this array'; A.length",
88 1000,
89 eval("var A = new Array(1000); A.name = 'name of this array'; A.length") );
90
91
92 // A has Property P, P is not length, P is an array index, and ToUint32(p) is less than the
93 // value of length
94
95 array[item++] = new TestCase( SECTION,
96 "var A = new Array(1000); A[123] = 'hola'; A[123]",
97 'hola',
98 eval("var A = new Array(1000); A[123] = 'hola'; A[123]") );
99
100 array[item++] = new TestCase( SECTION,
101 "var A = new Array(1000); A[123] = 'hola'; A.length",
102 1000,
103 eval("var A = new Array(1000); A[123] = 'hola'; A.length") );
104
105
106 for ( var i = 0X0020, TEST_STRING = "var A = new Array( " ; i < 0x00ff; i++ ) {
107 TEST_STRING += "\'\\"+ String.fromCharCode( i ) +"\'";
108 if ( i < 0x00FF - 1 ) {
109 TEST_STRING += ",";
110 } else {
111 TEST_STRING += ");"
112 }
113 }
114
115 var LENGTH = 0x00ff - 0x0020;
116
117 array[item++] = new TestCase( SECTION,
118 TEST_STRING +" A[150] = 'hello'; A[150]",
119 'hello',
120 eval( TEST_STRING + " A[150] = 'hello'; A[150]" ) );
121
122 array[item++] = new TestCase( SECTION,
123 TEST_STRING +" A[150] = 'hello'; A[150]",
124 LENGTH,
125 eval( TEST_STRING + " A[150] = 'hello'; A.length" ) );
126
127 // A has Property P, P is not length, P is an array index, and ToUint32(p) is not less than the
128 // value of length
129
130 array[item++] = new TestCase( SECTION,
131 "var A = new Array(); A[123] = true; A.length",
132 124,
133 eval("var A = new Array(); A[123] = true; A.length") );
134
135 array[item++] = new TestCase( SECTION,
136 "var A = new Array(0,1,2,3,4,5,6,7,8,9,10); A[15] ='15'; A.length",
137 16,
138 eval("var A = new Array(0,1,2,3,4,5,6,7,8,9,10); A[15] ='15'; A.length") );
139
140 for ( var i = 0; i < A.length; i++, item++ ) {
141 array[item] = new TestCase( SECTION,
142 "var A = new Array(0,1,2,3,4,5,6,7,8,9,10); A[15] ='15'; A[" +i +"]",
143 (i <= 10) ? i : ( i == 15 ? '15' : void 0 ),
144 A[i] );
145 }
146 // P is not an array index, and P is not "length"
147
148 array[item++] = new TestCase( SECTION,
149 "var A = new Array(); A.join.length = 4; A.join.length",
150 1,
151 eval("var A = new Array(); A.join.length = 4; A.join.length") );
152
153 array[item++] = new TestCase( SECTION,
154 "var A = new Array(); A.join.length = 4; A.length",
155 0,
156 eval("var A = new Array(); A.join.length = 4; A.length") );
157
158 return array;
159 }
160 function test() {
161 for ( tc=0; tc < testcases.length; tc++ ) {
162 testcases[tc].passed = writeTestCaseResult(
163 testcases[tc].expect,
164 testcases[tc].actual,
165 testcases[tc].description +" = "+
166 testcases[tc].actual );
167
168 testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
169 }
170 stopTest();
171 return ( testcases );
172 }