michael@0: /* michael@0: * Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/licenses/publicdomain/ michael@0: */ michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: var BUGNUMBER = 497869; michael@0: var summary = "Implement FutureReservedWords per-spec"; michael@0: michael@0: print(BUGNUMBER + ": " + summary); michael@0: michael@0: /************** michael@0: * BEGIN TEST * michael@0: **************/ michael@0: michael@0: var futureReservedWords = michael@0: [ michael@0: "class", michael@0: // "const", // Mozilla extension enabled even for versionless code michael@0: "enum", michael@0: "export", michael@0: "extends", michael@0: "import", michael@0: "super", michael@0: ]; michael@0: michael@0: var strictFutureReservedWords = michael@0: [ michael@0: "implements", michael@0: "interface", michael@0: "let", // enabled: this file doesn't execute as JS1.7 michael@0: "package", michael@0: "private", michael@0: "protected", michael@0: "public", michael@0: "static", michael@0: "yield", // enabled: this file doesn't execute as JS1.7 michael@0: ]; michael@0: michael@0: function testWord(word, expectNormal, expectStrict) michael@0: { michael@0: var actual, status; michael@0: michael@0: // USE AS LHS FOR ASSIGNMENT michael@0: michael@0: actual = ""; michael@0: status = summary + ": " + word + ": normal assignment"; michael@0: try michael@0: { michael@0: eval(word + " = 'foo';"); michael@0: actual = "no error"; michael@0: } michael@0: catch(e) michael@0: { michael@0: actual = e.name; michael@0: status += ", " + e.name + ": " + e.message + " "; michael@0: } michael@0: reportCompare(expectNormal, actual, status); michael@0: michael@0: actual = ""; michael@0: status = summary + ": " + word + ": strict assignment"; michael@0: try michael@0: { michael@0: eval("'use strict'; " + word + " = 'foo';"); michael@0: actual = "no error"; michael@0: } michael@0: catch(e) michael@0: { michael@0: actual = e.name; michael@0: status += ", " + e.name + ": " + e.message + " "; michael@0: } michael@0: reportCompare(expectStrict, actual, status); michael@0: michael@0: // USE IN VARIABLE DECLARATION michael@0: michael@0: actual = ""; michael@0: status = summary + ": " + word + ": normal var"; michael@0: try michael@0: { michael@0: eval("var " + word + ";"); michael@0: actual = "no error"; michael@0: } michael@0: catch (e) michael@0: { michael@0: actual = e.name; michael@0: status += ", " + e.name + ": " + e.message + " "; michael@0: } michael@0: reportCompare(expectNormal, actual, status); michael@0: michael@0: actual = ""; michael@0: status = summary + ": " + word + ": strict var"; michael@0: try michael@0: { michael@0: eval("'use strict'; var " + word + ";"); michael@0: actual = "no error"; michael@0: } michael@0: catch (e) michael@0: { michael@0: actual = e.name; michael@0: status += ", " + e.name + ": " + e.message + " "; michael@0: } michael@0: reportCompare(expectStrict, actual, status); michael@0: michael@0: // USE IN FOR-IN VARIABLE DECLARATION michael@0: michael@0: actual = ""; michael@0: status = summary + ": " + word + ": normal for-in var"; michael@0: try michael@0: { michael@0: eval("for (var " + word + " in {});"); michael@0: actual = "no error"; michael@0: } michael@0: catch (e) michael@0: { michael@0: actual = e.name; michael@0: status += ", " + e.name + ": " + e.message + " "; michael@0: } michael@0: reportCompare(expectNormal, actual, status); michael@0: michael@0: actual = ""; michael@0: status = summary + ": " + word + ": strict for-in var"; michael@0: try michael@0: { michael@0: eval("'use strict'; for (var " + word + " in {});"); michael@0: actual = "no error"; michael@0: } michael@0: catch (e) michael@0: { michael@0: actual = e.name; michael@0: status += ", " + e.name + ": " + e.message + " "; michael@0: } michael@0: reportCompare(expectStrict, actual, status); michael@0: michael@0: // USE AS CATCH IDENTIFIER michael@0: michael@0: actual = ""; michael@0: status = summary + ": " + word + ": normal var"; michael@0: try michael@0: { michael@0: eval("try { } catch (" + word + ") { }"); michael@0: actual = "no error"; michael@0: } michael@0: catch (e) michael@0: { michael@0: actual = e.name; michael@0: status += ", " + e.name + ": " + e.message + " "; michael@0: } michael@0: reportCompare(expectNormal, actual, status); michael@0: michael@0: actual = ""; michael@0: status = summary + ": " + word + ": strict var"; michael@0: try michael@0: { michael@0: eval("'use strict'; try { } catch (" + word + ") { }"); michael@0: actual = "no error"; michael@0: } michael@0: catch (e) michael@0: { michael@0: actual = e.name; michael@0: status += ", " + e.name + ": " + e.message + " "; michael@0: } michael@0: reportCompare(expectStrict, actual, status); michael@0: michael@0: // USE AS LABEL michael@0: michael@0: actual = ""; michael@0: status = summary + ": " + word + ": normal label"; michael@0: try michael@0: { michael@0: eval(word + ": while (false);"); michael@0: actual = "no error"; michael@0: } michael@0: catch (e) michael@0: { michael@0: actual = e.name; michael@0: status += ", " + e.name + ": " + e.message + " "; michael@0: } michael@0: reportCompare(expectNormal, actual, status); michael@0: michael@0: actual = ""; michael@0: status = summary + ": " + word + ": strict label"; michael@0: try michael@0: { michael@0: eval("'use strict'; " + word + ": while (false);"); michael@0: actual = "no error"; michael@0: } michael@0: catch (e) michael@0: { michael@0: actual = e.name; michael@0: status += ", " + e.name + ": " + e.message + " "; michael@0: } michael@0: reportCompare(expectStrict, actual, status); michael@0: michael@0: // USE AS ARGUMENT NAME IN FUNCTION DECLARATION michael@0: michael@0: actual = ""; michael@0: status = summary + ": " + word + ": normal function argument"; michael@0: try michael@0: { michael@0: eval("function foo(" + word + ") { }"); michael@0: actual = "no error"; michael@0: } michael@0: catch (e) michael@0: { michael@0: actual = e.name; michael@0: status += ", " + e.name + ": " + e.message + " "; michael@0: } michael@0: reportCompare(expectNormal, actual, status); michael@0: michael@0: actual = ""; michael@0: status = summary + ": " + word + ": strict function argument"; michael@0: try michael@0: { michael@0: eval("'use strict'; function foo(" + word + ") { }"); michael@0: actual = "no error"; michael@0: } michael@0: catch (e) michael@0: { michael@0: actual = e.name; michael@0: status += ", " + e.name + ": " + e.message + " "; michael@0: } michael@0: reportCompare(expectStrict, actual, status); michael@0: michael@0: actual = ""; michael@0: status = summary + ": " + word + ": function argument retroactively strict"; michael@0: try michael@0: { michael@0: eval("function foo(" + word + ") { 'use strict'; }"); michael@0: actual = "no error"; michael@0: } michael@0: catch (e) michael@0: { michael@0: actual = e.name; michael@0: status += ", " + e.name + ": " + e.message + " "; michael@0: } michael@0: reportCompare(expectStrict, actual, status); michael@0: michael@0: // USE AS ARGUMENT NAME IN FUNCTION EXPRESSION michael@0: michael@0: actual = ""; michael@0: status = summary + ": " + word + ": normal function expression argument"; michael@0: try michael@0: { michael@0: eval("var s = (function foo(" + word + ") { });"); michael@0: actual = "no error"; michael@0: } michael@0: catch (e) michael@0: { michael@0: actual = e.name; michael@0: status += ", " + e.name + ": " + e.message + " "; michael@0: } michael@0: reportCompare(expectNormal, actual, status); michael@0: michael@0: actual = ""; michael@0: status = summary + ": " + word + ": strict function expression argument"; michael@0: try michael@0: { michael@0: eval("'use strict'; var s = (function foo(" + word + ") { });"); michael@0: actual = "no error"; michael@0: } michael@0: catch (e) michael@0: { michael@0: actual = e.name; michael@0: status += ", " + e.name + ": " + e.message + " "; michael@0: } michael@0: reportCompare(expectStrict, actual, status); michael@0: michael@0: actual = ""; michael@0: status = summary + ": " + word + ": function expression argument retroactively strict"; michael@0: try michael@0: { michael@0: eval("var s = (function foo(" + word + ") { 'use strict'; });"); michael@0: actual = "no error"; michael@0: } michael@0: catch (e) michael@0: { michael@0: actual = e.name; michael@0: status += ", " + e.name + ": " + e.message + " "; michael@0: } michael@0: reportCompare(expectStrict, actual, status); michael@0: michael@0: // USE AS ARGUMENT NAME WITH FUNCTION CONSTRUCTOR michael@0: michael@0: actual = ""; michael@0: status = summary + ": " + word + ": argument with normal Function"; michael@0: try michael@0: { michael@0: Function(word, "return 17"); michael@0: actual = "no error"; michael@0: } michael@0: catch (e) michael@0: { michael@0: actual = e.name; michael@0: status += ", " + e.name + ": " + e.message + " "; michael@0: } michael@0: reportCompare(expectNormal, actual, status); michael@0: michael@0: actual = ""; michael@0: status = summary + ": " + word + ": argument with strict Function"; michael@0: try michael@0: { michael@0: Function(word, "'use strict'; return 17"); michael@0: actual = "no error"; michael@0: } michael@0: catch (e) michael@0: { michael@0: actual = e.name; michael@0: status += ", " + e.name + ": " + e.message + " "; michael@0: } michael@0: reportCompare(expectStrict, actual, status); michael@0: michael@0: // USE AS ARGUMENT NAME IN PROPERTY SETTER michael@0: michael@0: actual = ""; michael@0: status = summary + ": " + word + ": normal property setter argument"; michael@0: try michael@0: { michael@0: eval("var o = { set x(" + word + ") { } };"); michael@0: actual = "no error"; michael@0: } michael@0: catch (e) michael@0: { michael@0: actual = e.name; michael@0: status += ", " + e.name + ": " + e.message + " "; michael@0: } michael@0: reportCompare(expectNormal, actual, status); michael@0: michael@0: actual = ""; michael@0: status = summary + ": " + word + ": strict property setter argument"; michael@0: try michael@0: { michael@0: eval("'use strict'; var o = { set x(" + word + ") { } };"); michael@0: actual = "no error"; michael@0: } michael@0: catch (e) michael@0: { michael@0: actual = e.name; michael@0: status += ", " + e.name + ": " + e.message + " "; michael@0: } michael@0: reportCompare(expectStrict, actual, status); michael@0: michael@0: actual = ""; michael@0: status = summary + ": " + word + ": property setter argument retroactively strict"; michael@0: try michael@0: { michael@0: eval("var o = { set x(" + word + ") { 'use strict'; } };"); michael@0: actual = "no error"; michael@0: } michael@0: catch (e) michael@0: { michael@0: actual = e.name; michael@0: status += ", " + e.name + ": " + e.message + " "; michael@0: } michael@0: reportCompare(expectStrict, actual, status); michael@0: michael@0: // USE AS FUNCTION NAME IN FUNCTION DECLARATION michael@0: michael@0: actual = ""; michael@0: status = summary + ": " + word + ": normal function name"; michael@0: try michael@0: { michael@0: eval("function " + word + "() { }"); michael@0: actual = "no error"; michael@0: } michael@0: catch (e) michael@0: { michael@0: actual = e.name; michael@0: status += ", " + e.name + ": " + e.message + " "; michael@0: } michael@0: reportCompare(expectNormal, actual, status); michael@0: michael@0: actual = ""; michael@0: status = summary + ": " + word + ": strict function name"; michael@0: try michael@0: { michael@0: eval("'use strict'; function " + word + "() { }"); michael@0: actual = "no error"; michael@0: } michael@0: catch (e) michael@0: { michael@0: actual = e.name; michael@0: status += ", " + e.name + ": " + e.message + " "; michael@0: } michael@0: reportCompare(expectStrict, actual, status); michael@0: michael@0: actual = ""; michael@0: status = summary + ": " + word + ": function name retroactively strict"; michael@0: try michael@0: { michael@0: eval("function " + word + "() { 'use strict'; }"); michael@0: actual = "no error"; michael@0: } michael@0: catch (e) michael@0: { michael@0: actual = e.name; michael@0: status += ", " + e.name + ": " + e.message + " "; michael@0: } michael@0: reportCompare(expectStrict, actual, status); michael@0: michael@0: // USE AS FUNCTION NAME IN FUNCTION EXPRESSION michael@0: michael@0: actual = ""; michael@0: status = summary + ": " + word + ": normal function expression name"; michael@0: try michael@0: { michael@0: eval("var s = (function " + word + "() { });"); michael@0: actual = "no error"; michael@0: } michael@0: catch (e) michael@0: { michael@0: actual = e.name; michael@0: status += ", " + e.name + ": " + e.message + " "; michael@0: } michael@0: reportCompare(expectNormal, actual, status); michael@0: michael@0: actual = ""; michael@0: status = summary + ": " + word + ": strict function expression name"; michael@0: try michael@0: { michael@0: eval("'use strict'; var s = (function " + word + "() { });"); michael@0: actual = "no error"; michael@0: } michael@0: catch (e) michael@0: { michael@0: actual = e.name; michael@0: status += ", " + e.name + ": " + e.message + " "; michael@0: } michael@0: reportCompare(expectStrict, actual, status); michael@0: michael@0: actual = ""; michael@0: status = summary + ": " + word + ": function expression name retroactively strict"; michael@0: try michael@0: { michael@0: eval("var s = (function " + word + "() { 'use strict'; });"); michael@0: actual = "no error"; michael@0: } michael@0: catch (e) michael@0: { michael@0: actual = e.name; michael@0: status += ", " + e.name + ": " + e.message + " "; michael@0: } michael@0: reportCompare(expectStrict, actual, status); michael@0: } michael@0: michael@0: function testFutureReservedWord(word) michael@0: { michael@0: testWord(word, "SyntaxError", "SyntaxError"); michael@0: } michael@0: michael@0: function testStrictFutureReservedWord(word) michael@0: { michael@0: testWord(word, "no error", "SyntaxError"); michael@0: } michael@0: michael@0: futureReservedWords.forEach(testFutureReservedWord); michael@0: strictFutureReservedWords.forEach(testStrictFutureReservedWord); michael@0: michael@0: /******************************************************************************/ michael@0: michael@0: if (typeof reportCompare === "function") michael@0: reportCompare(true, true); michael@0: michael@0: print("All tests passed!");