diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/tests/non262/misc/future-reserved-words.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-upstream.tar.xz firefox-esr-upstream.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/non262/misc/future-reserved-words.js')
-rw-r--r-- | js/src/tests/non262/misc/future-reserved-words.js | 493 |
1 files changed, 493 insertions, 0 deletions
diff --git a/js/src/tests/non262/misc/future-reserved-words.js b/js/src/tests/non262/misc/future-reserved-words.js new file mode 100644 index 0000000000..43b1b2f607 --- /dev/null +++ b/js/src/tests/non262/misc/future-reserved-words.js @@ -0,0 +1,493 @@ +/* + * Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/licenses/publicdomain/ + */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 497869; +var summary = "Implement FutureReservedWords per-spec"; + +print(BUGNUMBER + ": " + summary); + +/************** + * BEGIN TEST * + **************/ + +var futureReservedWords = + [ + "class", + // "const", // Mozilla extension enabled even for versionless code + "enum", + "export", + "extends", + "import", + "super", + ]; + +var strictFutureReservedWords = + [ + "implements", + "interface", + "let", // enabled: this file doesn't execute as JS1.7 + "package", + "private", + "protected", + "public", + "static", + "yield", // enabled: this file doesn't execute as JS1.7 + ]; + +function testWord(word, expectNormal, expectStrict) +{ + var actual, status; + + // USE AS LHS FOR ASSIGNMENT + + actual = ""; + status = summary + ": " + word + ": normal assignment"; + try + { + eval(word + " = 'foo';"); + actual = "no error"; + } + catch(e) + { + actual = e.name; + status += ", " + e.name + ": " + e.message + " "; + } + assertEq(actual, expectNormal, status); + + actual = ""; + status = summary + ": " + word + ": strict assignment"; + try + { + eval("'use strict'; " + word + " = 'foo';"); + actual = "no error"; + } + catch(e) + { + actual = e.name; + status += ", " + e.name + ": " + e.message + " "; + } + assertEq(actual, expectStrict, status); + + // USE AS DESTRUCTURING SHORTHAND + + actual = ""; + status = summary + ": " + word + ": destructuring shorthand"; + try + { + eval("({ " + word + " } = 'foo');"); + actual = "no error"; + } + catch(e) + { + actual = e.name; + status += ", " + e.name + ": " + e.message + " "; + } + assertEq(actual, expectNormal, status); + + actual = ""; + status = summary + ": " + word + ": strict destructuring shorthand"; + try + { + eval("'use strict'; ({ " + word + " } = 'foo');"); + actual = "no error"; + } + catch(e) + { + actual = e.name; + status += ", " + e.name + ": " + e.message + " "; + } + assertEq(actual, expectStrict, status); + + // USE IN VARIABLE DECLARATION + + actual = ""; + status = summary + ": " + word + ": normal var"; + try + { + eval("var " + word + ";"); + actual = "no error"; + } + catch (e) + { + actual = e.name; + status += ", " + e.name + ": " + e.message + " "; + } + assertEq(actual, expectNormal, status); + + actual = ""; + status = summary + ": " + word + ": strict var"; + try + { + eval("'use strict'; var " + word + ";"); + actual = "no error"; + } + catch (e) + { + actual = e.name; + status += ", " + e.name + ": " + e.message + " "; + } + assertEq(actual, expectStrict, status); + + // USE IN FOR-IN VARIABLE DECLARATION + + actual = ""; + status = summary + ": " + word + ": normal for-in var"; + try + { + eval("for (var " + word + " in {});"); + actual = "no error"; + } + catch (e) + { + actual = e.name; + status += ", " + e.name + ": " + e.message + " "; + } + assertEq(actual, expectNormal, status); + + actual = ""; + status = summary + ": " + word + ": strict for-in var"; + try + { + eval("'use strict'; for (var " + word + " in {});"); + actual = "no error"; + } + catch (e) + { + actual = e.name; + status += ", " + e.name + ": " + e.message + " "; + } + assertEq(actual, expectStrict, status); + + // USE AS CATCH IDENTIFIER + + actual = ""; + status = summary + ": " + word + ": normal var"; + try + { + eval("try { } catch (" + word + ") { }"); + actual = "no error"; + } + catch (e) + { + actual = e.name; + status += ", " + e.name + ": " + e.message + " "; + } + assertEq(actual, expectNormal, status); + + actual = ""; + status = summary + ": " + word + ": strict var"; + try + { + eval("'use strict'; try { } catch (" + word + ") { }"); + actual = "no error"; + } + catch (e) + { + actual = e.name; + status += ", " + e.name + ": " + e.message + " "; + } + assertEq(actual, expectStrict, status); + + // USE AS LABEL + + actual = ""; + status = summary + ": " + word + ": normal label"; + try + { + eval(word + ": while (false);"); + actual = "no error"; + } + catch (e) + { + actual = e.name; + status += ", " + e.name + ": " + e.message + " "; + } + assertEq(actual, expectNormal, status); + + actual = ""; + status = summary + ": " + word + ": strict label"; + try + { + eval("'use strict'; " + word + ": while (false);"); + actual = "no error"; + } + catch (e) + { + actual = e.name; + status += ", " + e.name + ": " + e.message + " "; + } + assertEq(actual, expectStrict, status); + + // USE AS ARGUMENT NAME IN FUNCTION DECLARATION + + actual = ""; + status = summary + ": " + word + ": normal function argument"; + try + { + eval("function foo(" + word + ") { }"); + actual = "no error"; + } + catch (e) + { + actual = e.name; + status += ", " + e.name + ": " + e.message + " "; + } + assertEq(actual, expectNormal, status); + + actual = ""; + status = summary + ": " + word + ": strict function argument"; + try + { + eval("'use strict'; function foo(" + word + ") { }"); + actual = "no error"; + } + catch (e) + { + actual = e.name; + status += ", " + e.name + ": " + e.message + " "; + } + assertEq(actual, expectStrict, status); + + actual = ""; + status = summary + ": " + word + ": function argument retroactively strict"; + try + { + eval("function foo(" + word + ") { 'use strict'; }"); + actual = "no error"; + } + catch (e) + { + actual = e.name; + status += ", " + e.name + ": " + e.message + " "; + } + assertEq(actual, expectStrict, status); + + // USE AS ARGUMENT NAME IN FUNCTION EXPRESSION + + actual = ""; + status = summary + ": " + word + ": normal function expression argument"; + try + { + eval("var s = (function foo(" + word + ") { });"); + actual = "no error"; + } + catch (e) + { + actual = e.name; + status += ", " + e.name + ": " + e.message + " "; + } + assertEq(actual, expectNormal, status); + + actual = ""; + status = summary + ": " + word + ": strict function expression argument"; + try + { + eval("'use strict'; var s = (function foo(" + word + ") { });"); + actual = "no error"; + } + catch (e) + { + actual = e.name; + status += ", " + e.name + ": " + e.message + " "; + } + assertEq(actual, expectStrict, status); + + actual = ""; + status = summary + ": " + word + ": function expression argument retroactively strict"; + try + { + eval("var s = (function foo(" + word + ") { 'use strict'; });"); + actual = "no error"; + } + catch (e) + { + actual = e.name; + status += ", " + e.name + ": " + e.message + " "; + } + assertEq(actual, expectStrict, status); + + // USE AS ARGUMENT NAME WITH FUNCTION CONSTRUCTOR + + actual = ""; + status = summary + ": " + word + ": argument with normal Function"; + try + { + Function(word, "return 17"); + actual = "no error"; + } + catch (e) + { + actual = e.name; + status += ", " + e.name + ": " + e.message + " "; + } + assertEq(actual, expectNormal, status); + + actual = ""; + status = summary + ": " + word + ": argument with strict Function"; + try + { + Function(word, "'use strict'; return 17"); + actual = "no error"; + } + catch (e) + { + actual = e.name; + status += ", " + e.name + ": " + e.message + " "; + } + assertEq(actual, expectStrict, status); + + // USE AS ARGUMENT NAME IN PROPERTY SETTER + + actual = ""; + status = summary + ": " + word + ": normal property setter argument"; + try + { + eval("var o = { set x(" + word + ") { } };"); + actual = "no error"; + } + catch (e) + { + actual = e.name; + status += ", " + e.name + ": " + e.message + " "; + } + assertEq(actual, expectNormal, status); + + actual = ""; + status = summary + ": " + word + ": strict property setter argument"; + try + { + eval("'use strict'; var o = { set x(" + word + ") { } };"); + actual = "no error"; + } + catch (e) + { + actual = e.name; + status += ", " + e.name + ": " + e.message + " "; + } + assertEq(actual, expectStrict, status); + + actual = ""; + status = summary + ": " + word + ": property setter argument retroactively strict"; + try + { + eval("var o = { set x(" + word + ") { 'use strict'; } };"); + actual = "no error"; + } + catch (e) + { + actual = e.name; + status += ", " + e.name + ": " + e.message + " "; + } + assertEq(actual, expectStrict, status); + + // USE AS FUNCTION NAME IN FUNCTION DECLARATION + + actual = ""; + status = summary + ": " + word + ": normal function name"; + try + { + eval("function " + word + "() { }"); + actual = "no error"; + } + catch (e) + { + actual = e.name; + status += ", " + e.name + ": " + e.message + " "; + } + assertEq(actual, expectNormal, status); + + actual = ""; + status = summary + ": " + word + ": strict function name"; + try + { + eval("'use strict'; function " + word + "() { }"); + actual = "no error"; + } + catch (e) + { + actual = e.name; + status += ", " + e.name + ": " + e.message + " "; + } + assertEq(actual, expectStrict, status); + + actual = ""; + status = summary + ": " + word + ": function name retroactively strict"; + try + { + eval("function " + word + "() { 'use strict'; }"); + actual = "no error"; + } + catch (e) + { + actual = e.name; + status += ", " + e.name + ": " + e.message + " "; + } + assertEq(actual, expectStrict, status); + + // USE AS FUNCTION NAME IN FUNCTION EXPRESSION + + actual = ""; + status = summary + ": " + word + ": normal function expression name"; + try + { + eval("var s = (function " + word + "() { });"); + actual = "no error"; + } + catch (e) + { + actual = e.name; + status += ", " + e.name + ": " + e.message + " "; + } + assertEq(actual, expectNormal, status); + + actual = ""; + status = summary + ": " + word + ": strict function expression name"; + try + { + eval("'use strict'; var s = (function " + word + "() { });"); + actual = "no error"; + } + catch (e) + { + actual = e.name; + status += ", " + e.name + ": " + e.message + " "; + } + assertEq(actual, expectStrict, status); + + actual = ""; + status = summary + ": " + word + ": function expression name retroactively strict"; + try + { + eval("var s = (function " + word + "() { 'use strict'; });"); + actual = "no error"; + } + catch (e) + { + actual = e.name; + status += ", " + e.name + ": " + e.message + " "; + } + assertEq(actual, expectStrict, status); +} + +function testFutureReservedWord(word) +{ + testWord(word, "SyntaxError", "SyntaxError"); +} + +function testStrictFutureReservedWord(word) +{ + testWord(word, "no error", "SyntaxError"); +} + +futureReservedWords.forEach(testFutureReservedWord); +strictFutureReservedWords.forEach(testStrictFutureReservedWord); + +/******************************************************************************/ + +if (typeof reportCompare === "function") + reportCompare(true, true); + +print("All tests passed!"); |