Debian Codegraph @

js/src/tests/non262/lexical/regress-336376-01.js

raw
1 /* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 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 var BUGNUMBER = "336376";
8 var summary = "Tests reserved words in contexts in which they are not reserved";
9 var actual, expect;
10
11 printBugNumber(BUGNUMBER);
12 printStatus(summary);
13
14 /**************
15 * TEST SETUP *
16 **************/
17
18 //
19 // New tests go in Tester.prototype._tests. A test is called with a single
20 // argument, the keyword to test in the syntax tested by that test. Tests
21 // should not return anything, and they should signal failure by throwing an
22 // explanatory exception and success by not throwing one.
23 //
24 // If you define a new test, make sure to name it using an informative string
25 // for ease of use if any keywords ever manually define the array of tests they
26 // should pass, and add it as a string to ALL_TESTS.
27 //
28
29 // all tests
30 const ALL_TESTS =
31 [
32 "CONTEXT_OBJECT_LITERAL_PROPERTY",
33 "CONTEXT_OBJECT_PROPERTY_DOT_REFERENCE",
34 "CONTEXT_OBJECT_PROPERTY_DOT_REFERENCE_IS_FUNCTION",
35 "CONTEXT_OBJECT_PROPERTY_DOT_GET",
36 "CONTEXT_OBJECT_PROPERTY_DOT_SET",
37 ];
38
39 function r(keyword, tests)
40 {
41 /**
42 * @param keyword
43 * the keyword as a string
44 * @param tests
45 * array of test numbers against it, or leave undefined to run all tests
46 * against it
47 */
48 function Reserved(keyword, tests)
49 {
50 this.keyword = keyword;
51 if (tests)
52 this.tests = tests;
53 else
54 this.tests = ALL_TESTS;
55 }
56 Reserved.prototype =
57 {
58 toString:
59 function()
60 {
61 return "'" + this.keyword + "' being run against tests " +
62 this.tests;
63 }
64 };
65 return new Reserved(keyword, tests);
66 }
67
68 // ECMA-262, 3rd. ed. keywords -- see 7.5.2
69 const ECMA_262_3_KEYWORD =
70 [
71 r("break"),
72 r("case"),
73 r("catch"),
74 r("continue"),
75 r("default"),
76 r("delete"),
77 r("do"),
78 r("else"),
79 r("finally"),
80 r("for"),
81 r("function"),
82 r("if"),
83 r("in"),
84 r("instanceof"),
85 r("new"),
86 r("return"),
87 r("switch"),
88 r("this"),
89 r("throw"),
90 r("try"),
91 r("typeof"),
92 r("var"),
93 r("void"),
94 r("while"),
95 r("with"),
96 ];
97
98 // ECMA-262, 3rd. ed. future reserved keywords -- see 7.5.3
99 const ECMA_262_3_FUTURERESERVEDKEYWORD =
100 [
101 r("abstract"),
102 r("boolean"),
103 r("byte"),
104 r("char"),
105 r("class"),
106 r("const"),
107 r("debugger"),
108 r("double"),
109 r("enum"),
110 r("export"),
111 r("extends"),
112 r("final"),
113 r("float"),
114 r("goto"),
115 r("implements"),
116 r("import"),
117 r("int"),
118 r("interface"),
119 r("long"),
120 r("native"),
121 r("package"),
122 r("private"),
123 r("protected"),
124 r("public"),
125 r("short"),
126 r("static"),
127 r("super"),
128 r("synchronized"),
129 r("throws"),
130 r("transient"),
131 r("volatile"),
132 ];
133
134 // like reserved words, but not quite reserved words
135 const PSEUDO_RESERVED =
136 [
137 r("true"),
138 r("false"),
139 r("null"),
140 ];
141
142 // new-in-ES4 reserved words -- fill this as each is implemented
143 const ECMA_262_4_RESERVED_WORDS =
144 [
145 r("let")
146 ];
147
148
149
150 /**
151 * @param keyword
152 * string containing the tested keyword
153 * @param test
154 * the number of the failing test
155 * @param error
156 * the exception thrown when running the test
157 */
158 function Failure(keyword, test, error)
159 {
160 this.keyword = keyword;
161 this.test = test;
162 this.error = error;
163 }
164 Failure.prototype =
165 {
166 toString:
167 function()
168 {
169 return "*** FAILURE on '" + this.keyword + "'!\n" +
170 "* test: " + this.test + "\n" +
171 "* error: " + this.error + "\n";
172 }
173 };
174
175 function Tester()
176 {
177 this._failedTests = [];
178 }
179 Tester.prototype =
180 {
181 testReservedWords:
182 function(reservedArray)
183 {
184 var rv;
185 for (var i = 0, sz = reservedArray.length; i < sz; i++)
186 {
187 var res = reservedArray[i];
188 if (!res)
189 continue;
190
191 var tests = res.tests;
192 for (var j = 0, sz2 = tests.length; j < sz2; j++)
193 {
194 var test = tests[j];
195 if (!test)
196 continue;
197
198 try
199 {
200 this._tests[test](res.keyword);
201 }
202 catch (e)
203 {
204 this._failedTests.push(new Failure(res.keyword, test, e));
205 }
206 }
207 }
208 },
209 flushErrors:
210 function ()
211 {
212 if (this._failedTests.length > 0) {
213 var except = "*************************\n" +
214 "* FAILURES ENCOUNTERED! *\n" +
215 "*************************\n";
216 for (var i = 0, sz = this._failedTests.length; i < sz; i++)
217 except += this._failedTests[i];
218 throw except;
219 }
220 },
221 _tests:
222 {
223 CONTEXT_OBJECT_LITERAL_PROPERTY:
224 function(keyword)
225 {
226 try
227 {
228 eval("var o = { " + keyword + ": 17 };\n" +
229 "if (o['" + keyword + "'] != 17)\n" +
230 "throw \"o['" + keyword + "'] == 17\";");
231 }
232 catch (e)
233 {
234 throw e;
235 }
236 },
237 CONTEXT_OBJECT_PROPERTY_DOT_REFERENCE:
238 function(keyword)
239 {
240 try
241 {
242 eval("var o = { \"" + keyword + "\": 17, baz: null };\n" +
243 "if (o." + keyword + " != 17)\n" +
244 "throw \"o." + keyword + " == 17\";");
245 }
246 catch (e)
247 {
248 throw e;
249 }
250 },
251 CONTEXT_OBJECT_PROPERTY_DOT_REFERENCE_IS_FUNCTION:
252 function(keyword)
253 {
254 try
255 {
256 eval("var o = { '" + keyword + "': function() { return 17; }, baz: null };\n" +
257 "if (o." + keyword + "() != 17)\n" +
258 "throw \"o." + keyword + " == 17\";");
259 }
260 catch (e)
261 {
262 throw e;
263 }
264 },
265 CONTEXT_OBJECT_PROPERTY_DOT_GET:
266 function(keyword)
267 {
268 try
269 {
270 var o = {};
271 eval("o['" + keyword + "'] = 17;\n" +
272 "if (o." + keyword + " != 17)\n" +
273 "throw \"'o." + keyword + " != 17' failed!\";");
274 }
275 catch (e)
276 {
277 throw e;
278 }
279 },
280 CONTEXT_OBJECT_PROPERTY_DOT_SET:
281 function(keyword)
282 {
283 try
284 {
285 var o = {};
286 eval("o." + keyword + " = 17;\n" +
287 "if (o['" + keyword + "'] != 17)\n" +
288 "throw \"'o." + keyword + " = 17' failed!\";");
289 }
290 catch (e)
291 {
292 throw e;
293 }
294 },
295 }
296 };
297
298
299 /***************
300 * BEGIN TESTS *
301 ***************/
302
303 var failed = false;
304
305 try
306 {
307 var tester = new Tester();
308 tester.testReservedWords(ECMA_262_3_KEYWORD);
309 tester.testReservedWords(ECMA_262_3_FUTURERESERVEDKEYWORD);
310 tester.testReservedWords(PSEUDO_RESERVED);
311 tester.testReservedWords(ECMA_262_4_RESERVED_WORDS);
312 tester.flushErrors();
313 }
314 catch (e)
315 {
316 failed = e;
317 }
318
319 expect = false;
320 actual = failed;
321
322 reportCompare(expect, actual, summary);