Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / src / tests / ecma_3 / Statements / regress-121744.js
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4  *
5  * The contents of this file are subject to the Mozilla Public License Version
6  * 1.1 (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  * http://www.mozilla.org/MPL/
9  *
10  * Software distributed under the License is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12  * for the specific language governing rights and limitations under the
13  * License.
14  *
15  * The Original Code is JavaScript Engine testing utilities.
16  *
17  * The Initial Developer of the Original Code is
18  * Netscape Communications Corp.
19  * Portions created by the Initial Developer are Copyright (C) 2002
20  * the Initial Developer. All Rights Reserved.
21  *
22  * Contributor(s):
23  *   pschwartau@netscape.com
24  *
25  * Alternatively, the contents of this file may be used under the terms of
26  * either the GNU General Public License Version 2 or later (the "GPL"), or
27  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28  * in which case the provisions of the GPL or the LGPL are applicable instead
29  * of those above. If you wish to allow use of your version of this file only
30  * under the terms of either the GPL or the LGPL, and not to allow others to
31  * use your version of this file under the terms of the MPL, indicate your
32  * decision by deleting the provisions above and replace them with the notice
33  * and other provisions required by the GPL or the LGPL. If you do not delete
34  * the provisions above, a recipient may use your version of this file under
35  * the terms of any one of the MPL, the GPL or the LGPL.
36  *
37  * ***** END LICENSE BLOCK ***** */
38
39 /*
40  *
41  * Date:    30 Jan 2002
42  * Revised: 10 Apr 2002
43  * Revised: 14 July 2002
44  *
45  * SUMMARY: JS should error on |for(i in undefined)|, |for(i in null)|
46  * See http://bugzilla.mozilla.org/show_bug.cgi?id=121744
47  *
48  * ECMA-262 3rd Edition Final spec says such statements should error. See:
49  *
50  *               Section 12.6.4  The for-in Statement
51  *               Section 9.9     ToObject
52  *
53  *
54  * BUT: SpiderMonkey has decided NOT to follow this; it's a bug in the spec.
55  * See http://bugzilla.mozilla.org/show_bug.cgi?id=131348
56  *
57  * UPDATE: Rhino has also decided not to follow the spec on this.
58  * See http://bugzilla.mozilla.org/show_bug.cgi?id=136893
59  *
60
61  |--------------------------------------------------------------------|
62  |                                                                    |
63  | So for now, adding an early return for this test so it won't run.  |
64  |                                                                    |
65  |--------------------------------------------------------------------|
66
67  *
68  */
69 //-----------------------------------------------------------------------------
70 var UBound = 0;
71 var BUGNUMBER = 121744;
72 var summary = 'JS should error on |for(i in undefined)|, |for(i in null)|';
73 var TEST_PASSED = 'TypeError';
74 var TEST_FAILED = 'Generated an error, but NOT a TypeError!';
75 var TEST_FAILED_BADLY = 'Did not generate ANY error!!!';
76 var status = '';
77 var statusitems = [];
78 var actual = '';
79 var actualvalues = [];
80 var expect= '';
81 var expectedvalues = [];
82
83 /*
84  * AS OF 14 JULY 2002, DON'T RUN THIS TEST IN EITHER RHINO OR SPIDERMONKEY -
85  */
86 quit();
87
88
89 status = inSection(1);
90 expect = TEST_PASSED;
91 actual = TEST_FAILED_BADLY;
92 /*
93  * OK, this should generate a TypeError
94  */
95 try
96 {
97   for (var i in undefined)
98   {
99     print(i);
100   }
101 }
102 catch(e)
103 {
104   if (e instanceof TypeError)
105     actual = TEST_PASSED;
106   else
107     actual = TEST_FAILED;
108 }
109 addThis();
110
111
112
113 status = inSection(2);
114 expect = TEST_PASSED;
115 actual = TEST_FAILED_BADLY;
116 /*
117  * OK, this should generate a TypeError
118  */
119 try
120 {
121   for (var i in null)
122   {
123     print(i);
124   }
125 }
126 catch(e)
127 {
128   if (e instanceof TypeError)
129     actual = TEST_PASSED;
130   else
131     actual = TEST_FAILED;
132 }
133 addThis();
134
135
136
137 status = inSection(3);
138 expect = TEST_PASSED;
139 actual = TEST_FAILED_BADLY;
140 /*
141  * Variable names that cannot be looked up generate ReferenceErrors; however,
142  * property names like obj.ZZZ that cannot be looked up are set to |undefined|
143  *
144  * Therefore, this should indirectly test | for (var i in undefined) |
145  */
146 try
147 {
148   for (var i in this.ZZZ)
149   {
150     print(i);
151   }
152 }
153 catch(e)
154 {
155   if(e instanceof TypeError)
156     actual = TEST_PASSED;
157   else
158     actual = TEST_FAILED;
159 }
160 addThis();
161
162
163
164 status = inSection(4);
165 expect = TEST_PASSED;
166 actual = TEST_FAILED_BADLY;
167 /*
168  * The result of an unsuccessful regexp match is the null value
169  * Therefore, this should indirectly test | for (var i in null) |
170  */
171 try
172 {
173   for (var i in 'bbb'.match(/aaa/))
174   {
175     print(i);
176   }
177 }
178 catch(e)
179 {
180   if(e instanceof TypeError)
181     actual = TEST_PASSED;
182   else
183     actual = TEST_FAILED;
184 }
185 addThis();
186
187
188
189 //-----------------------------------------------------------------------------
190 test();
191 //-----------------------------------------------------------------------------
192
193
194
195 function addThis()
196 {
197   statusitems[UBound] = status;
198   actualvalues[UBound] = actual;
199   expectedvalues[UBound] = expect;
200   UBound++;
201 }
202
203
204 function test()
205 {
206   enterFunc('test');
207   printBugNumber(BUGNUMBER);
208   printStatus(summary);
209
210   for (var i=0; i<UBound; i++)
211   {
212     reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
213   }
214
215   exitFunc ('test');
216 }