1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma_3/Statements/regress-131348.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,150 @@ 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 + * Date: 10 Apr 2002 1.12 + * Revised: 14 July 2002 1.13 + * 1.14 + * SUMMARY: JS should NOT error on |for(i in undefined)|, |for(i in null)| 1.15 + * 1.16 + * ECMA-262 3rd Edition Final spec says such statements SHOULD error. See: 1.17 + * 1.18 + * Section 12.6.4 The for-in Statement 1.19 + * Section 9.9 ToObject 1.20 + * 1.21 + * 1.22 + * But SpiderMonkey has decided NOT to follow this; it's a bug in the spec. 1.23 + * See http://bugzilla.mozilla.org/show_bug.cgi?id=131348 1.24 + * 1.25 + * Update: Rhino has also decided not to follow the spec on this 1.26 + * See http://bugzilla.mozilla.org/show_bug.cgi?id=136893 1.27 + */ 1.28 +//----------------------------------------------------------------------------- 1.29 +var UBound = 0; 1.30 +var BUGNUMBER = 131348; 1.31 +var summary = 'JS should not error on |for(i in undefined)|, |for(i in null)|'; 1.32 +var TEST_PASSED = 'No error'; 1.33 +var TEST_FAILED = 'An error was generated!!!'; 1.34 +var status = ''; 1.35 +var statusitems = []; 1.36 +var actual = ''; 1.37 +var actualvalues = []; 1.38 +var expect= ''; 1.39 +var expectedvalues = []; 1.40 + 1.41 + 1.42 + 1.43 +status = inSection(1); 1.44 +expect = TEST_PASSED; 1.45 +actual = TEST_PASSED; 1.46 +try 1.47 +{ 1.48 + for (var i in undefined) 1.49 + { 1.50 + print(i); 1.51 + } 1.52 +} 1.53 +catch(e) 1.54 +{ 1.55 + actual = TEST_FAILED; 1.56 +} 1.57 +addThis(); 1.58 + 1.59 + 1.60 + 1.61 +status = inSection(2); 1.62 +expect = TEST_PASSED; 1.63 +actual = TEST_PASSED; 1.64 +try 1.65 +{ 1.66 + for (var i in null) 1.67 + { 1.68 + print(i); 1.69 + } 1.70 +} 1.71 +catch(e) 1.72 +{ 1.73 + actual = TEST_FAILED; 1.74 +} 1.75 +addThis(); 1.76 + 1.77 + 1.78 + 1.79 +status = inSection(3); 1.80 +expect = TEST_PASSED; 1.81 +actual = TEST_PASSED; 1.82 +/* 1.83 + * Variable names that cannot be looked up generate ReferenceErrors; however, 1.84 + * property names like obj.ZZZ that cannot be looked up are set to |undefined| 1.85 + * 1.86 + * Therefore, this should indirectly test | for (var i in undefined) | 1.87 + */ 1.88 +try 1.89 +{ 1.90 + for (var i in this.ZZZ) 1.91 + { 1.92 + print(i); 1.93 + } 1.94 +} 1.95 +catch(e) 1.96 +{ 1.97 + actual = TEST_FAILED; 1.98 +} 1.99 +addThis(); 1.100 + 1.101 + 1.102 + 1.103 +status = inSection(4); 1.104 +expect = TEST_PASSED; 1.105 +actual = TEST_PASSED; 1.106 +/* 1.107 + * The result of an unsuccessful regexp match is the null value 1.108 + * Therefore, this should indirectly test | for (var i in null) | 1.109 + */ 1.110 +try 1.111 +{ 1.112 + for (var i in 'bbb'.match(/aaa/)) 1.113 + { 1.114 + print(i); 1.115 + } 1.116 +} 1.117 +catch(e) 1.118 +{ 1.119 + actual = TEST_FAILED; 1.120 +} 1.121 +addThis(); 1.122 + 1.123 + 1.124 + 1.125 + 1.126 +//----------------------------------------------------------------------------- 1.127 +test(); 1.128 +//----------------------------------------------------------------------------- 1.129 + 1.130 + 1.131 + 1.132 +function addThis() 1.133 +{ 1.134 + statusitems[UBound] = status; 1.135 + actualvalues[UBound] = actual; 1.136 + expectedvalues[UBound] = expect; 1.137 + UBound++; 1.138 +} 1.139 + 1.140 + 1.141 +function test() 1.142 +{ 1.143 + enterFunc('test'); 1.144 + printBugNumber(BUGNUMBER); 1.145 + printStatus(summary); 1.146 + 1.147 + for (var i=0; i<UBound; i++) 1.148 + { 1.149 + reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]); 1.150 + } 1.151 + 1.152 + exitFunc ('test'); 1.153 +}