Debian Codegraph @

rhino/testsrc/tests/ecma_3/Statements/regress-131348.js

raw symbols SCIP
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 /*
7 *
8 * Date: 10 Apr 2002
9 * Revised: 14 July 2002
10 *
11 * SUMMARY: JS should NOT error on |for(i in undefined)|, |for(i in null)|
12 *
13 * ECMA-262 3rd Edition Final spec says such statements SHOULD error. See:
14 *
15 * Section 12.6.4 The for-in Statement
16 * Section 9.9 ToObject
17 *
18 *
19 * But SpiderMonkey has decided NOT to follow this; it's a bug in the spec.
20 * See http://bugzilla.mozilla.org/show_bug.cgi?id=131348
21 *
22 * Update: Rhino has also decided not to follow the spec on this
23 * See http://bugzilla.mozilla.org/show_bug.cgi?id=136893
24 */
25 //-----------------------------------------------------------------------------
26 var gTestfile = 'regress-131348.js';
27 var UBound = 0;
28 var BUGNUMBER = 131348;
29 var summary = 'JS should not error on |for(i in undefined)|, |for(i in null)|';
30 var TEST_PASSED = 'No error';
31 var TEST_FAILED = 'An error was generated!!!';
32 var status = '';
33 var statusitems = [];
34 var actual = '';
35 var actualvalues = [];
36 var expect= '';
37 var expectedvalues = [];
38
39
40
41 status = inSection(1);
42 expect = TEST_PASSED;
43 actual = TEST_PASSED;
44 try
45 {
46 for (var i in undefined)
47 {
48 print(i);
49 }
50 }
51 catch(e)
52 {
53 actual = TEST_FAILED;
54 }
55 addThis();
56
57
58
59 status = inSection(2);
60 expect = TEST_PASSED;
61 actual = TEST_PASSED;
62 try
63 {
64 for (var i in null)
65 {
66 print(i);
67 }
68 }
69 catch(e)
70 {
71 actual = TEST_FAILED;
72 }
73 addThis();
74
75
76
77 status = inSection(3);
78 expect = TEST_PASSED;
79 actual = TEST_PASSED;
80 /*
81 * Variable names that cannot be looked up generate ReferenceErrors; however,
82 * property names like obj.ZZZ that cannot be looked up are set to |undefined|
83 *
84 * Therefore, this should indirectly test | for (var i in undefined) |
85 */
86 try
87 {
88 for (var i in this.ZZZ)
89 {
90 print(i);
91 }
92 }
93 catch(e)
94 {
95 actual = TEST_FAILED;
96 }
97 addThis();
98
99
100
101 status = inSection(4);
102 expect = TEST_PASSED;
103 actual = TEST_PASSED;
104 /*
105 * The result of an unsuccessful regexp match is the null value
106 * Therefore, this should indirectly test | for (var i in null) |
107 */
108 try
109 {
110 for (var i in 'bbb'.match(/aaa/))
111 {
112 print(i);
113 }
114 }
115 catch(e)
116 {
117 actual = TEST_FAILED;
118 }
119 addThis();
120
121
122
123
124 //-----------------------------------------------------------------------------
125 test();
126 //-----------------------------------------------------------------------------
127
128
129
130 function addThis()
131 {
132 statusitems[UBound] = status;
133 actualvalues[UBound] = actual;
134 expectedvalues[UBound] = expect;
135 UBound++;
136 }
137
138
139 function test()
140 {
141 enterFunc('test');
142 printBugNumber(BUGNUMBER);
143 printStatus(summary);
144
145 for (var i=0; i<UBound; i++)
146 {
147 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
148 }
149
150 exitFunc ('test');
151 }