1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is JavaScript Engine testing utilities.
17 * The Initial Developer of the Original Code is
18 * Netscape Communication Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
40 * File Name: forin-001.js
42 * Description: The forin-001 statement
44 * Verify that the property name is assigned to the property on the left
45 * hand side of the for...in expression.
47 * Author: christine@netscape.com
48 * Date: 28 August 1998
50 var SECTION = "forin-001";
51 var VERSION = "ECMA_2";
52 var TITLE = "The for...in statement";
53 var BUGNUMBER="330890";
54 var BUGNUMBER="http://scopus.mcom.com/bugsplat/show_bug.cgi?id=344855";
57 writeHeaderToLog( SECTION + " "+ TITLE);
59 ForIn_1( { length:4, company:"netscape", year:2000, 0:"zero" } );
60 ForIn_2( { length:4, company:"netscape", year:2000, 0:"zero" } );
61 ForIn_3( { length:4, company:"netscape", year:2000, 0:"zero" } );
63 // ForIn_6({ length:4, company:"netscape", year:2000, 0:"zero" });
64 // ForIn_7({ length:4, company:"netscape", year:2000, 0:"zero" });
65 ForIn_8({ length:4, company:"netscape", year:2000, 0:"zero" });
70 * Verify that the left side argument is evaluated with every iteration.
71 * Verify that the name of each property of the object is assigned to a
75 function ForIn_1( object ) {
76 PropertyArray = new Array();
77 ValueArray = new Array();
79 for ( PropertyArray[PropertyArray.length] in object ) {
80 ValueArray[ValueArray.length] =
81 object[PropertyArray[PropertyArray.length-1]];
84 for ( var i = 0; i < PropertyArray.length; i++ ) {
87 "object[" + PropertyArray[i] +"]",
88 object[PropertyArray[i]],
101 * Similar to ForIn_1, except it should increment the counter variable
102 * every time the left hand expression is evaluated.
104 function ForIn_2( object ) {
105 PropertyArray = new Array();
106 ValueArray = new Array();
109 for ( PropertyArray[i++] in object ) {
110 ValueArray[ValueArray.length] =
111 object[PropertyArray[PropertyArray.length-1]];
114 for ( i = 0; i < PropertyArray.length; i++ ) {
117 "object[" + PropertyArray[i] +"]",
118 object[PropertyArray[i]],
126 PropertyArray.length,
131 * Break out of a for...in loop
135 function ForIn_3( object ) {
136 var checkBreak = "pass";
137 var properties = new Array();
138 var values = new Array();
140 for ( properties[properties.length] in object ) {
141 values[values.length] = object[properties[properties.length-1]];
148 "check break out of for...in",
160 "object["+properties[0]+"]",
162 object[properties[0]] );
166 * Break out of a labeled for...in loop.
168 function ForIn_4( object ) {
174 var property = new Array();
179 for ( property[i++] in object ) {
189 "verify labeled statement is only executed once",
195 "verify statements in for loop are evaluated",
201 "verify break out of labeled for...in loop",
207 "verify break out of labeled block",
213 * Labeled break out of a labeled for...in loop.
215 function ForIn_5 (object) {
221 var property = new Array();
225 for ( property[i++] in object ) {
235 "verify labeled statement is only executed once",
241 "verify statements in for loop are evaluated",
247 "verify break out of labeled for...in loop",
253 "verify break out of labeled block",
259 * Labeled continue from a labeled for...in loop
261 function ForIn_7( object ) {
267 var property = new Array();
270 for ( property[i++] in object ) {
278 "verify statements in for loop are evaluated",
284 "verify break out of labeled for...in loop",
290 "verify break out of labeled block",
297 * continue in a for...in loop
300 function ForIn_8( object ) {
301 var checkBreak = "pass";
302 var properties = new Array();
303 var values = new Array();
305 for ( properties[properties.length] in object ) {
306 values[values.length] = object[properties[properties.length-1]];
313 "check break out of for...in",
325 "object["+properties[0]+"]",
327 object[properties[0]] );