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: 12.6.3-1.js 24 ECMA Section: 12.6.3 The for...in Statement 25 Description: 26 The production IterationStatement : for ( LeftHandSideExpression in Expression ) 27 Statement is evaluated as follows: 28 29 1. Evaluate the Expression. 30 2. Call GetValue(Result(1)). 31 3. Call ToObject(Result(2)). 32 4. Let C be "normal completion". 33 5. Get the name of the next property of Result(3) that doesn't have the 34 DontEnum attribute. If there is no such property, go to step 14. 35 6. Evaluate the LeftHandSideExpression (it may be evaluated repeatedly). 36 7. Call PutValue(Result(6), Result(5)). PutValue( V, W ): 37 1. If Type(V) is not Reference, generate a runtime error. 38 2. Call GetBase(V). 39 3. If Result(2) is null, go to step 6. 40 4. Call the [[Put]] method of Result(2), passing GetPropertyName(V) 41 for the property name and W for the value. 42 5. Return. 43 6. Call the [[Put]] method for the global object, passing 44 GetPropertyName(V) for the property name and W for the value. 45 7. Return. 46 8. Evaluate Statement. 47 9. If Result(8) is a value completion, change C to be "normal completion 48 after value V" where V is the value carried by Result(8). 49 10. If Result(8) is a break completion, go to step 14. 50 11. If Result(8) is a continue completion, go to step 5. 51 12. If Result(8) is a return completion, return Result(8). 52 13. Go to step 5. 53 14. Return C. 54 55 Author: christine (at) netscape.com 56 Date: 11 september 1997 57 */ 58 var SECTION = "12.6.3-4"; 59 var VERSION = "ECMA_1"; 60 startTest(); 61 var TITLE = "The for..in statment"; 62 var BUGNUMBER="http://scopus.mcom.com/bugsplat/show_bug.cgi?id=344855"; 63 64 writeHeaderToLog( SECTION + " "+ TITLE); 65 66 var testcases = new Array(); 67 68 // for ( LeftHandSideExpression in Expression ) 69 // LeftHandSideExpression:NewExpression:MemberExpression 70 71 var o = new MyObject(); 72 var result = 0; 73 74 for ( MyObject in o ) { 75 result += o[MyObject]; 76 } 77 78 testcases[testcases.length] = new TestCase( SECTION, 79 "for ( MyObject in o ) { result += o[MyObject] }", 80 6, 81 result ); 82 83 var result = 0; 84 85 for ( value in o ) { 86 result += o[value]; 87 } 88 89 testcases[testcases.length] = new TestCase( SECTION, 90 "for ( value in o ) { result += o[value]", 91 6, 92 result ); 93 94 var value = "value"; 95 var result = 0; 96 for ( value in o ) { 97 result += o[value]; 98 } 99 100 testcases[testcases.length] = new TestCase( SECTION, 101 "value = \"value\"; for ( value in o ) { result += o[value]", 102 6, 103 result ); 104 105 var value = 0; 106 var result = 0; 107 for ( value in o ) { 108 result += o[value]; 109 } 110 111 testcases[testcases.length] = new TestCase( SECTION, 112 "value = 0; for ( value in o ) { result += o[value]", 113 6, 114 result ); 115 116 // this causes a segv 117 118 var ob = { 0:"hello" }; 119 var result = 0; 120 for ( ob[0] in o ) { 121 result += o[ob[0]]; 122 } 123 testcases[testcases.length] = new TestCase( SECTION, 124 "ob = { 0:\"hello\" }; for ( ob[0] in o ) { result += o[ob[0]]", 125 6, 126 result ); 127 128 var result = 0; 129 for ( ob["0"] in o ) { 130 result += o[ob["0"]]; 131 } 132 testcases[testcases.length] = new TestCase( SECTION, 133 "value = 0; for ( ob[\"0\"] in o ) { result += o[o[\"0\"]]", 134 6, 135 result ); 136 137 var result = 0; 138 var ob = { value:"hello" }; 139 for ( ob[value] in o ) { 140 result += o[ob[value]]; 141 } 142 testcases[testcases.length] = new TestCase( SECTION, 143 "ob = { 0:\"hello\" }; for ( ob[value] in o ) { result += o[ob[value]]", 144 6, 145 result ); 146 147 var result = 0; 148 for ( ob["value"] in o ) { 149 result += o[ob["value"]]; 150 } 151 testcases[testcases.length] = new TestCase( SECTION, 152 "value = 0; for ( ob[\"value\"] in o ) { result += o[ob[\"value\"]]", 153 6, 154 result ); 155 156 var result = 0; 157 for ( ob.value in o ) { 158 result += o[ob.value]; 159 } 160 testcases[testcases.length] = new TestCase( SECTION, 161 "value = 0; for ( ob.value in o ) { result += o[ob.value]", 162 6, 163 result ); 164 165 // LeftHandSideExpression:NewExpression:MemberExpression [ Expression ] 166 // LeftHandSideExpression:NewExpression:MemberExpression . Identifier 167 // LeftHandSideExpression:NewExpression:new MemberExpression Arguments 168 // LeftHandSideExpression:NewExpression:PrimaryExpression:( Expression ) 169 // LeftHandSideExpression:CallExpression:MemberExpression Arguments 170 // LeftHandSideExpression:CallExpression Arguments 171 // LeftHandSideExpression:CallExpression [ Expression ] 172 // LeftHandSideExpression:CallExpression . Identifier 173 174 test(); 175 176 function test() { 177 for ( tc=0; tc < testcases.length; tc++ ) { 178 testcases[tc].passed = writeTestCaseResult( 179 testcases[tc].expect, 180 testcases[tc].actual, 181 testcases[tc].description +" = "+ 182 testcases[tc].actual ); 183 184 testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value "; 185 } 186 stopTest(); 187 return ( testcases ); 188 } 189 function MyObject() { 190 this.value = 2; 191 this[0] = 4; 192 return this; 193 } 194