]>
git.saurik.com Git - apple/javascriptcore.git/blob - 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/
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.5.1-1.js
24 ECMA Section: [[ Put]] (P, V)
26 Array objects use a variation of the [[Put]] method used for other native
27 ECMAScript objects (section 8.6.2.2).
29 Assume A is an Array object and P is a string.
31 When the [[Put]] method of A is called with property P and value V, the
32 following steps are taken:
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.
40 7. Create a property with name P, set its value to V and give it empty
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
46 10. Change (or set) the value of the length property of A to ToUint32(P)+1.
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).
54 Author: christine@netscape.com
55 Date: 12 november 1997
58 var SECTION
= "15.4.5.1-1";
59 var VERSION
= "ECMA_1";
61 var TITLE
= "Array [[Put]] (P, V)";
63 writeHeaderToLog( SECTION
+ " "+ TITLE
);
65 var testcases
= getTestCases();
68 function getTestCases() {
69 var array
= new Array();
75 array
[item
++] = new TestCase( SECTION
,
76 "var A = new Array(); A.length = 1000; A.length",
78 eval("var A = new Array(); A.length = 1000; A.length") );
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",
84 eval("var A = new Array(1000); A.name = 'name of this array'; A.name") );
86 array
[item
++] = new TestCase( SECTION
,
87 "var A = new Array(1000); A.name = 'name of this array'; A.length",
89 eval("var A = new Array(1000); A.name = 'name of this array'; A.length") );
92 // A has Property P, P is not length, P is an array index, and ToUint32(p) is less than the
95 array
[item
++] = new TestCase( SECTION
,
96 "var A = new Array(1000); A[123] = 'hola'; A[123]",
98 eval("var A = new Array(1000); A[123] = 'hola'; A[123]") );
100 array
[item
++] = new TestCase( SECTION
,
101 "var A = new Array(1000); A[123] = 'hola'; A.length",
103 eval("var A = new Array(1000); A[123] = 'hola'; A.length") );
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 ) {
115 var LENGTH
= 0x00ff - 0x0020;
117 array
[item
++] = new TestCase( SECTION
,
118 TEST_STRING
+" A[150] = 'hello'; A[150]",
120 eval( TEST_STRING
+ " A[150] = 'hello'; A[150]" ) );
122 array
[item
++] = new TestCase( SECTION
,
123 TEST_STRING
+" A[150] = 'hello'; A[150]",
125 eval( TEST_STRING
+ " A[150] = 'hello'; A.length" ) );
127 // A has Property P, P is not length, P is an array index, and ToUint32(p) is not less than the
130 array
[item
++] = new TestCase( SECTION
,
131 "var A = new Array(); A[123] = true; A.length",
133 eval("var A = new Array(); A[123] = true; A.length") );
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",
138 eval("var A = new Array(0,1,2,3,4,5,6,7,8,9,10); A[15] ='15'; A.length") );
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 ),
146 // P is not an array index, and P is not "length"
148 array
[item
++] = new TestCase( SECTION
,
149 "var A = new Array(); A.join.length = 4; A.join.length",
151 eval("var A = new Array(); A.join.length = 4; A.join.length") );
153 array
[item
++] = new TestCase( SECTION
,
154 "var A = new Array(); A.join.length = 4; A.length",
156 eval("var A = new Array(); A.join.length = 4; A.length") );
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
);
168 testcases
[tc
].reason
+= ( testcases
[tc
].passed
) ? "" : "wrong value ";
171 return ( testcases
);