]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/ecma_2/Statements/forin-001.js
2 * File Name: forin-001.js
4 * Description: The forin-001 statement
6 * Verify that the property name is assigned to the property on the left
7 * hand side of the for...in expression.
9 * Author: christine@netscape.com
10 * Date: 28 August 1998
12 var SECTION
= "forin-001";
13 var VERSION
= "ECMA_2";
14 var TITLE
= "The for...in statement";
15 var BUGNUMBER
="330890";
16 var BUGNUMBER
="http://scopus.mcom.com/bugsplat/show_bug.cgi?id=344855";
19 writeHeaderToLog( SECTION
+ " "+ TITLE
);
22 var testcases
= new Array();
24 ForIn_1( { length:4, company:"netscape", year:2000, 0:"zero" } );
25 ForIn_2( { length:4, company:"netscape", year:2000, 0:"zero" } );
26 ForIn_3( { length:4, company:"netscape", year:2000, 0:"zero" } );
28 // ForIn_6({ length:4, company:"netscape", year:2000, 0:"zero" });
29 // ForIn_7({ length:4, company:"netscape", year:2000, 0:"zero" });
30 ForIn_8({ length:4, company:"netscape", year:2000, 0:"zero" });
35 * Verify that the left side argument is evaluated with every iteration.
36 * Verify that the name of each property of the object is assigned to a
40 function ForIn_1( object
) {
41 PropertyArray
= new Array();
42 ValueArray
= new Array();
44 for ( PropertyArray
[PropertyArray
.length
] in object
) {
45 ValueArray
[ValueArray
.length
] =
46 object
[PropertyArray
[PropertyArray
.length
-1]];
49 for ( var i
= 0; i
< PropertyArray
.length
; i
++ ) {
50 testcases
[tc
++] = new TestCase(
52 "object[" + PropertyArray
[i
] +"]",
53 object
[PropertyArray
[i
]],
58 testcases
[tc
++] = new TestCase(
66 * Similar to ForIn_1, except it should increment the counter variable
67 * every time the left hand expression is evaluated.
69 function ForIn_2( object
) {
70 PropertyArray
= new Array();
71 ValueArray
= new Array();
74 for ( PropertyArray
[i
++] in object
) {
75 ValueArray
[ValueArray
.length
] =
76 object
[PropertyArray
[PropertyArray
.length
-1]];
79 for ( i
= 0; i
< PropertyArray
.length
; i
++ ) {
80 testcases
[tc
++] = new TestCase(
82 "object[" + PropertyArray
[i
] +"]",
83 object
[PropertyArray
[i
]],
88 testcases
[tc
++] = new TestCase(
96 * Break out of a for...in loop
100 function ForIn_3( object
) {
101 var checkBreak
= "pass";
102 var properties
= new Array();
103 var values
= new Array();
105 for ( properties
[properties
.length
] in object
) {
106 values
[values
.length
] = object
[properties
[properties
.length
-1]];
111 testcases
[tc
++] = new TestCase(
113 "check break out of for...in",
117 testcases
[tc
++] = new TestCase(
123 testcases
[tc
++] = new TestCase(
125 "object["+properties
[0]+"]",
127 object
[properties
[0]] );
131 * Break out of a labeled for...in loop.
133 function ForIn_4( object
) {
139 var property
= new Array();
144 for ( property
[i
++] in object
) {
152 testcases
[tc
++] = new TestCase(
154 "verify labeled statement is only executed once",
158 testcases
[tc
++] = new TestCase(
160 "verify statements in for loop are evaluated",
164 testcases
[tc
++] = new TestCase(
166 "verify break out of labeled for...in loop",
170 testcases
[tc
++] = new TestCase(
172 "verify break out of labeled block",
178 * Labeled break out of a labeled for...in loop.
180 function ForIn_5 (object
) {
186 var property
= new Array();
190 for ( property
[i
++] in object
) {
198 testcases
[tc
++] = new TestCase(
200 "verify labeled statement is only executed once",
204 testcases
[tc
++] = new TestCase(
206 "verify statements in for loop are evaluated",
210 testcases
[tc
++] = new TestCase(
212 "verify break out of labeled for...in loop",
216 testcases
[tc
++] = new TestCase(
218 "verify break out of labeled block",
224 * Labeled continue from a labeled for...in loop
226 function ForIn_7( object
) {
232 var property
= new Array();
235 for ( property
[i
++] in object
) {
241 testcases
[tc
++] = new TestCase(
243 "verify statements in for loop are evaluated",
247 testcases
[tc
++] = new TestCase(
249 "verify break out of labeled for...in loop",
253 testcases
[tc
++] = new TestCase(
255 "verify break out of labeled block",
262 * continue in a for...in loop
265 function ForIn_8( object
) {
266 var checkBreak
= "pass";
267 var properties
= new Array();
268 var values
= new Array();
270 for ( properties
[properties
.length
] in object
) {
271 values
[values
.length
] = object
[properties
[properties
.length
-1]];
276 testcases
[tc
++] = new TestCase(
278 "check break out of for...in",
282 testcases
[tc
++] = new TestCase(
288 testcases
[tc
++] = new TestCase(
290 "object["+properties
[0]+"]",
292 object
[properties
[0]] );