2 * Any copyright is dedicated to the Public Domain.
3 * http://creativecommons.org/licenses/publicdomain/
6 //-----------------------------------------------------------------------------
7 var BUGNUMBER = 497869;
8 var summary = "Implement FutureReservedWords per-spec";
10 print(BUGNUMBER + ": " + summary);
16 var futureReservedWords =
19 // "const", // Mozilla extension enabled even for versionless code
27 var strictFutureReservedWords =
31 "let", // enabled: this file doesn't execute as JS1.7
37 "yield", // enabled: this file doesn't execute as JS1.7
40 function testWord(word, expectNormal, expectStrict)
44 // USE AS LHS FOR ASSIGNMENT
46 if (expectNormal !== "skip")
49 status = summary + ": " + word + ": normal assignment";
52 eval(word + " = 'foo';");
58 status += ", " + e.name + ": " + e.message + " ";
60 reportCompare(expectNormal, actual, status);
64 status = summary + ": " + word + ": strict assignment";
67 eval("'use strict'; " + word + " = 'foo';");
73 status += ", " + e.name + ": " + e.message + " ";
75 reportCompare(expectStrict, actual, status);
77 // USE IN VARIABLE DECLARATION
79 if (expectNormal !== "skip")
82 status = summary + ": " + word + ": normal var";
85 eval("var " + word + ";");
91 status += ", " + e.name + ": " + e.message + " ";
93 reportCompare(expectNormal, actual, status);
97 status = summary + ": " + word + ": strict var";
100 eval("'use strict'; var " + word + ";");
106 status += ", " + e.name + ": " + e.message + " ";
108 reportCompare(expectStrict, actual, status);
110 // USE IN FOR-IN VARIABLE DECLARATION
112 if (expectNormal !== "skip")
115 status = summary + ": " + word + ": normal for-in var";
118 eval("for (var " + word + " in {});");
124 status += ", " + e.name + ": " + e.message + " ";
126 reportCompare(expectNormal, actual, status);
130 status = summary + ": " + word + ": strict for-in var";
133 eval("'use strict'; for (var " + word + " in {});");
139 status += ", " + e.name + ": " + e.message + " ";
141 reportCompare(expectStrict, actual, status);
143 // USE AS CATCH IDENTIFIER
145 if (expectNormal !== "skip")
148 status = summary + ": " + word + ": normal var";
151 eval("try { } catch (" + word + ") { }");
157 status += ", " + e.name + ": " + e.message + " ";
159 reportCompare(expectNormal, actual, status);
163 status = summary + ": " + word + ": strict var";
166 eval("'use strict'; try { } catch (" + word + ") { }");
172 status += ", " + e.name + ": " + e.message + " ";
174 reportCompare(expectStrict, actual, status);
178 if (expectNormal !== "skip")
181 status = summary + ": " + word + ": normal label";
184 eval(word + ": while (false);");
190 status += ", " + e.name + ": " + e.message + " ";
192 reportCompare(expectNormal, actual, status);
196 status = summary + ": " + word + ": strict label";
199 eval("'use strict'; " + word + ": while (false);");
205 status += ", " + e.name + ": " + e.message + " ";
207 reportCompare(expectStrict, actual, status);
209 // USE AS ARGUMENT NAME IN FUNCTION DECLARATION
211 if (expectNormal !== "skip")
214 status = summary + ": " + word + ": normal function argument";
217 eval("function foo(" + word + ") { }");
223 status += ", " + e.name + ": " + e.message + " ";
225 reportCompare(expectNormal, actual, status);
229 status = summary + ": " + word + ": strict function argument";
232 eval("'use strict'; function foo(" + word + ") { }");
238 status += ", " + e.name + ": " + e.message + " ";
240 reportCompare(expectStrict, actual, status);
243 status = summary + ": " + word + ": function argument retroactively strict";
246 eval("function foo(" + word + ") { 'use strict'; }");
252 status += ", " + e.name + ": " + e.message + " ";
254 reportCompare(expectStrict, actual, status);
256 // USE AS ARGUMENT NAME IN FUNCTION EXPRESSION
258 if (expectNormal !== "skip")
261 status = summary + ": " + word + ": normal function expression argument";
264 eval("var s = (function foo(" + word + ") { });");
270 status += ", " + e.name + ": " + e.message + " ";
272 reportCompare(expectNormal, actual, status);
276 status = summary + ": " + word + ": strict function expression argument";
279 eval("'use strict'; var s = (function foo(" + word + ") { });");
285 status += ", " + e.name + ": " + e.message + " ";
287 reportCompare(expectStrict, actual, status);
290 status = summary + ": " + word + ": function expression argument retroactively strict";
293 eval("var s = (function foo(" + word + ") { 'use strict'; });");
299 status += ", " + e.name + ": " + e.message + " ";
301 reportCompare(expectStrict, actual, status);
303 // USE AS ARGUMENT NAME WITH FUNCTION CONSTRUCTOR
305 if (expectNormal !== "skip")
308 status = summary + ": " + word + ": argument with normal Function";
311 Function(word, "return 17");
317 status += ", " + e.name + ": " + e.message + " ";
319 reportCompare(expectNormal, actual, status);
323 status = summary + ": " + word + ": argument with strict Function";
326 Function(word, "'use strict'; return 17");
332 status += ", " + e.name + ": " + e.message + " ";
334 reportCompare(expectStrict, actual, status);
336 // USE AS ARGUMENT NAME IN PROPERTY SETTER
338 if (expectNormal !== "skip")
341 status = summary + ": " + word + ": normal property setter argument";
344 eval("var o = { set x(" + word + ") { } };");
350 status += ", " + e.name + ": " + e.message + " ";
352 reportCompare(expectNormal, actual, status);
356 status = summary + ": " + word + ": strict property setter argument";
359 eval("'use strict'; var o = { set x(" + word + ") { } };");
365 status += ", " + e.name + ": " + e.message + " ";
367 reportCompare(expectStrict, actual, status);
370 status = summary + ": " + word + ": property setter argument retroactively strict";
373 eval("var o = { set x(" + word + ") { 'use strict'; } };");
379 status += ", " + e.name + ": " + e.message + " ";
381 reportCompare(expectStrict, actual, status);
383 // USE AS FUNCTION NAME IN FUNCTION DECLARATION
385 if (expectNormal !== "skip")
388 status = summary + ": " + word + ": normal function name";
391 eval("function " + word + "() { }");
397 status += ", " + e.name + ": " + e.message + " ";
399 reportCompare(expectNormal, actual, status);
403 status = summary + ": " + word + ": strict function name";
406 eval("'use strict'; function " + word + "() { }");
412 status += ", " + e.name + ": " + e.message + " ";
414 reportCompare(expectStrict, actual, status);
417 status = summary + ": " + word + ": function name retroactively strict";
420 eval("function " + word + "() { 'use strict'; }");
426 status += ", " + e.name + ": " + e.message + " ";
428 reportCompare(expectStrict, actual, status);
430 // USE AS FUNCTION NAME IN FUNCTION EXPRESSION
432 if (expectNormal !== "skip")
435 status = summary + ": " + word + ": normal function expression name";
438 eval("var s = (function " + word + "() { });");
444 status += ", " + e.name + ": " + e.message + " ";
446 reportCompare(expectNormal, actual, status);
450 status = summary + ": " + word + ": strict function expression name";
453 eval("'use strict'; var s = (function " + word + "() { });");
459 status += ", " + e.name + ": " + e.message + " ";
461 reportCompare(expectStrict, actual, status);
464 status = summary + ": " + word + ": function expression name retroactively strict";
467 eval("var s = (function " + word + "() { 'use strict'; });");
473 status += ", " + e.name + ": " + e.message + " ";
475 reportCompare(expectStrict, actual, status);
478 function testFutureReservedWord(word)
481 * NON-STANDARD DEVIATION: At one point in history SpiderMonkey unreserved
482 * most of the reserved words in ES3, including those words which are
483 * FutureReservedWords in ES5. It's too late this release cycle to expect
484 * "SyntaxError" for the normal code cases, so for now we "skip" testing
485 * these words in normal code. (We don't test for "no error" because that
486 * would be contrary to the spec, and this test is not in an extensions/
489 testWord(word, "skip", "SyntaxError");
492 function testStrictFutureReservedWord(word)
494 testWord(word, "no error", "SyntaxError");
497 futureReservedWords.forEach(testFutureReservedWord);
498 strictFutureReservedWords.forEach(testStrictFutureReservedWord);
500 /******************************************************************************/
502 if (typeof reportCompare === "function")
503 reportCompare(true, true);
505 print("All tests passed!");