* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / Microsoft.JScript / Test / Mozilla / ecma_3 / Statements / regress-131348.js
1 /* ***** BEGIN LICENSE BLOCK *****
2  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3  *
4  * The contents of this file are subject to the Mozilla Public License Version
5  * 1.1 (the "License"); you may not use this file except in compliance with
6  * the License. You may obtain a copy of the License at
7  * http://www.mozilla.org/MPL/
8  *
9  * Software distributed under the License is distributed on an "AS IS" basis,
10  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11  * for the specific language governing rights and limitations under the
12  * License.
13  *
14  * The Original Code is JavaScript Engine testing utilities.
15  *
16  * The Initial Developer of the Original Code is
17  * Netscape Communications Corp.
18  * Portions created by the Initial Developer are Copyright (C) 2002
19  * the Initial Developer. All Rights Reserved.
20  *
21  * Contributor(s):
22  *   pschwartau@netscape.com
23  *
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.
35  *
36  * ***** END LICENSE BLOCK *****
37  *
38  *
39  * Date:    10 Apr 2002
40  * Revised: 14 July 2002
41  *
42  * SUMMARY: JS should NOT error on |for(i in undefined)|, |for(i in null)|
43  *
44  * ECMA-262 3rd Edition Final spec says such statements SHOULD error. See:
45  *
46  *               Section 12.6.4  The for-in Statement
47  *               Section 9.9     ToObject
48  *
49  *
50  * But SpiderMonkey has decided NOT to follow this; it's a bug in the spec.
51  * See http://bugzilla.mozilla.org/show_bug.cgi?id=131348
52  *
53  * Update: Rhino has also decided not to follow the spec on this
54  * See http://bugzilla.mozilla.org/show_bug.cgi?id=136893
55  */
56 //-----------------------------------------------------------------------------
57 var UBound = 0;
58 var bug = 131348;
59 var summary = 'JS should not error on |for(i in undefined)|, |for(i in null)|';
60 var TEST_PASSED = 'No error';
61 var TEST_FAILED = 'An error was generated!!!';
62 var status = '';
63 var statusitems = [];
64 var actual = '';
65 var actualvalues = [];
66 var expect= '';
67 var expectedvalues = [];
68
69
70
71 status = inSection(1);
72 expect = TEST_PASSED;
73 actual = TEST_PASSED;
74 try
75 {
76   for (var i in undefined)
77   {
78     writeLineToLog(i);
79   }
80 }
81 catch(e)
82 {
83   actual = TEST_FAILED;
84 }
85 addThis();
86
87
88
89 status = inSection(2);
90 expect = TEST_PASSED;
91 actual = TEST_PASSED;
92 try
93 {
94   for (var i in null)
95   {
96     writeLineToLog(i);
97   }
98 }
99 catch(e)
100 {
101   actual = TEST_FAILED;
102 }
103 addThis();
104
105
106
107 status = inSection(3);
108 expect = TEST_PASSED;
109 actual = TEST_PASSED;
110 /*
111  * Variable names that cannot be looked up generate ReferenceErrors; however,
112  * property names like obj.ZZZ that cannot be looked up are set to |undefined|
113  *
114  * Therefore, this should indirectly test | for (var i in undefined) |
115  */
116 try
117 {
118   for (var i in this.ZZZ)
119   {
120     writeLineToLog(i);
121   }
122 }
123 catch(e)
124 {
125   actual = TEST_FAILED;
126 }
127 addThis();
128
129
130
131 status = inSection(4);
132 expect = TEST_PASSED;
133 actual = TEST_PASSED;
134 /*
135  * The result of an unsuccessful regexp match is the null value
136  * Therefore, this should indirectly test | for (var i in null) |
137  */
138 try
139 {
140   for (var i in 'bbb'.match(/aaa/))
141   {
142     writeLineToLog(i);
143   }
144 }
145 catch(e)
146 {
147   actual = TEST_FAILED;
148 }
149 addThis();
150
151
152
153
154 //-----------------------------------------------------------------------------
155 test();
156 //-----------------------------------------------------------------------------
157
158
159
160 function addThis()
161 {
162   statusitems[UBound] = status;
163   actualvalues[UBound] = actual;
164   expectedvalues[UBound] = expect;
165   UBound++;
166 }
167
168
169 function test()
170 {
171   enterFunc('test');
172   printBugNumber(bug);
173   printStatus(summary);
174  
175   for (var i=0; i<UBound; i++)
176   {
177     reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
178   }
179
180   exitFunc ('test');
181 }