1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma/Statements/12.6.3-4.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,168 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 + 1.10 +/** 1.11 + File Name: 12.6.3-1.js 1.12 + ECMA Section: 12.6.3 The for...in Statement 1.13 + Description: 1.14 + The production IterationStatement : for ( LeftHandSideExpression in Expression ) 1.15 + Statement is evaluated as follows: 1.16 + 1.17 + 1. Evaluate the Expression. 1.18 + 2. Call GetValue(Result(1)). 1.19 + 3. Call ToObject(Result(2)). 1.20 + 4. Let C be "normal completion". 1.21 + 5. Get the name of the next property of Result(3) that doesn't have the 1.22 + DontEnum attribute. If there is no such property, go to step 14. 1.23 + 6. Evaluate the LeftHandSideExpression (it may be evaluated repeatedly). 1.24 + 7. Call PutValue(Result(6), Result(5)). PutValue( V, W ): 1.25 + 1. If Type(V) is not Reference, generate a runtime error. 1.26 + 2. Call GetBase(V). 1.27 + 3. If Result(2) is null, go to step 6. 1.28 + 4. Call the [[Put]] method of Result(2), passing GetPropertyName(V) 1.29 + for the property name and W for the value. 1.30 + 5. Return. 1.31 + 6. Call the [[Put]] method for the global object, passing 1.32 + GetPropertyName(V) for the property name and W for the value. 1.33 + 7. Return. 1.34 + 8. Evaluate Statement. 1.35 + 9. If Result(8) is a value completion, change C to be "normal completion 1.36 + after value V" where V is the value carried by Result(8). 1.37 + 10. If Result(8) is a break completion, go to step 14. 1.38 + 11. If Result(8) is a continue completion, go to step 5. 1.39 + 12. If Result(8) is a return completion, return Result(8). 1.40 + 13. Go to step 5. 1.41 + 14. Return C. 1.42 + 1.43 + Author: christine@netscape.com 1.44 + Date: 11 september 1997 1.45 +*/ 1.46 +var SECTION = "12.6.3-4"; 1.47 +var VERSION = "ECMA_1"; 1.48 +startTest(); 1.49 +var TITLE = "The for..in statement"; 1.50 +var BUGNUMBER="http://scopus.mcom.com/bugsplat/show_bug.cgi?id=344855"; 1.51 + 1.52 +writeHeaderToLog( SECTION + " "+ TITLE); 1.53 + 1.54 +// for ( LeftHandSideExpression in Expression ) 1.55 +// LeftHandSideExpression:NewExpression:MemberExpression 1.56 + 1.57 +var o = new MyObject(); 1.58 +var result = 0; 1.59 + 1.60 +for ( MyObject in o ) { 1.61 + result += o[MyObject]; 1.62 +} 1.63 + 1.64 +new TestCase( SECTION, 1.65 + "for ( MyObject in o ) { result += o[MyObject] }", 1.66 + 6, 1.67 + result ); 1.68 + 1.69 +var result = 0; 1.70 + 1.71 +for ( value in o ) { 1.72 + result += o[value]; 1.73 +} 1.74 + 1.75 +new TestCase( SECTION, 1.76 + "for ( value in o ) { result += o[value]", 1.77 + 6, 1.78 + result ); 1.79 + 1.80 +var value = "value"; 1.81 +var result = 0; 1.82 +for ( value in o ) { 1.83 + result += o[value]; 1.84 +} 1.85 + 1.86 +new TestCase( SECTION, 1.87 + "value = \"value\"; for ( value in o ) { result += o[value]", 1.88 + 6, 1.89 + result ); 1.90 + 1.91 +var value = 0; 1.92 +var result = 0; 1.93 +for ( value in o ) { 1.94 + result += o[value]; 1.95 +} 1.96 + 1.97 +new TestCase( SECTION, 1.98 + "value = 0; for ( value in o ) { result += o[value]", 1.99 + 6, 1.100 + result ); 1.101 + 1.102 +// this causes a segv 1.103 + 1.104 +var ob = { 0:"hello" }; 1.105 +var result = 0; 1.106 +for ( ob[0] in o ) { 1.107 + result += o[ob[0]]; 1.108 +} 1.109 + 1.110 +new TestCase( SECTION, 1.111 + "ob = { 0:\"hello\" }; for ( ob[0] in o ) { result += o[ob[0]]", 1.112 + 6, 1.113 + result ); 1.114 + 1.115 +var result = 0; 1.116 +for ( ob["0"] in o ) { 1.117 + result += o[ob["0"]]; 1.118 +} 1.119 + 1.120 +new TestCase( SECTION, 1.121 + "value = 0; for ( ob[\"0\"] in o ) { result += o[o[\"0\"]]", 1.122 + 6, 1.123 + result ); 1.124 + 1.125 +var result = 0; 1.126 +var ob = { value:"hello" }; 1.127 +for ( ob[value] in o ) { 1.128 + result += o[ob[value]]; 1.129 +} 1.130 + 1.131 +new TestCase( SECTION, 1.132 + "ob = { 0:\"hello\" }; for ( ob[value] in o ) { result += o[ob[value]]", 1.133 + 6, 1.134 + result ); 1.135 + 1.136 +var result = 0; 1.137 +for ( ob["value"] in o ) { 1.138 + result += o[ob["value"]]; 1.139 +} 1.140 + 1.141 +new TestCase( SECTION, 1.142 + "value = 0; for ( ob[\"value\"] in o ) { result += o[ob[\"value\"]]", 1.143 + 6, 1.144 + result ); 1.145 + 1.146 +var result = 0; 1.147 +for ( ob.value in o ) { 1.148 + result += o[ob.value]; 1.149 +} 1.150 + 1.151 +new TestCase( SECTION, 1.152 + "value = 0; for ( ob.value in o ) { result += o[ob.value]", 1.153 + 6, 1.154 + result ); 1.155 + 1.156 +// LeftHandSideExpression:NewExpression:MemberExpression [ Expression ] 1.157 +// LeftHandSideExpression:NewExpression:MemberExpression . Identifier 1.158 +// LeftHandSideExpression:NewExpression:new MemberExpression Arguments 1.159 +// LeftHandSideExpression:NewExpression:PrimaryExpression:( Expression ) 1.160 +// LeftHandSideExpression:CallExpression:MemberExpression Arguments 1.161 +// LeftHandSideExpression:CallExpression Arguments 1.162 +// LeftHandSideExpression:CallExpression [ Expression ] 1.163 +// LeftHandSideExpression:CallExpression . Identifier 1.164 + 1.165 +test(); 1.166 + 1.167 +function MyObject() { 1.168 + this.value = 2; 1.169 + this[0] = 4; 1.170 + return this; 1.171 +}