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/eval/redeclared-arguments-in-param-expression-eval.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | js/src/tests/non262/eval/redeclared-arguments-in-param-expression-eval.js | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/js/src/tests/non262/eval/redeclared-arguments-in-param-expression-eval.js b/js/src/tests/non262/eval/redeclared-arguments-in-param-expression-eval.js new file mode 100644 index 0000000000..58d94d6f70 --- /dev/null +++ b/js/src/tests/non262/eval/redeclared-arguments-in-param-expression-eval.js @@ -0,0 +1,87 @@ +// Ensure there's no predefined |arguments| binding. +assertEq("arguments" in this, false); + +// Declare |arguments| when no pre-existing (and explicit) |arguments| bindings are present. +function f1(p = eval("var arguments")) {} +assertThrowsInstanceOf(f1, SyntaxError); + +// Declare |arguments| when the function body contains an |arguments| var-binding. +function f2(p = eval("var arguments")) { + var arguments; +} +assertThrowsInstanceOf(f2, SyntaxError); + +// Declare |arguments| when the function body contains an |arguments| function declaration. +// +// <https://tc39.es/ecma262/#sec-functiondeclarationinstantiation> doesn't create the +// implicit |arguments| binding when no parameter expressions are present. This case +// may be special-cased in implementations and therefore should be tested specifically. +function f3(p = eval("var arguments")) { + function arguments() {} +} +assertThrowsInstanceOf(f3, SyntaxError); + +// Declare |arguments| when the function body contains an |arguments| lexical binding. +// +// <https://tc39.es/ecma262/#sec-functiondeclarationinstantiation> doesn't create the +// implicit |arguments| binding when no parameter expressions are present. This case +// may be special-cased in implementations and therefore should be tested specifically. +function f4(p = eval("var arguments")) { + let arguments; +} +assertThrowsInstanceOf(f4, SyntaxError); + +// Declare |arguments| when a following parameter is named |arguments|. +function f5(p = eval("var arguments"), arguments) {} +assertThrowsInstanceOf(f5, SyntaxError); + +// Declare |arguments| when a preceding parameter is named |arguments|. +function f6(arguments, p = eval("var arguments")) {} +assertThrowsInstanceOf(f6, SyntaxError); + + +// Repeat the same kind of tests for arrow function. + +// Declare |arguments| when no pre-existing |arguments| bindings are present. +var a1 = (p = eval("var arguments = 'param'")) => { + assertEq(arguments, "param"); +}; +a1(); + +// Declare |arguments| when the function body contains an |arguments| var-binding. +var a2 = (p = eval("var arguments = 'param'"), q = () => arguments) => { + var arguments = "local"; + assertEq(arguments, "local"); + assertEq(q(), "param"); +}; +a2(); + +// Declare |arguments| when the function body contains an |arguments| function declaration. +var a3 = (p = eval("var arguments = 'param'"), q = () => arguments) => { + function arguments() {} + assertEq(typeof arguments, "function"); + assertEq(q(), "param"); +}; +a3(); + +// Declare |arguments| when the function body contains an |arguments| lexical binding. +var a4 = (p = eval("var arguments = 'param'"), q = () => arguments) => { + let arguments = "local"; + assertEq(arguments, "local"); + assertEq(q(), "param"); +}; +a4(); + +// Declare |arguments| when a following parameter is named |arguments|. +var a5 = (p = eval("var arguments"), arguments) => {}; +assertThrowsInstanceOf(a5, SyntaxError); + +// Declare |arguments| when a preceding parameter is named |arguments|. +var a6 = (arguments, p = eval("var arguments")) => {}; +assertThrowsInstanceOf(a6, SyntaxError); + +// None of the direct eval calls introduced a global |arguments| binding. +assertEq("arguments" in this, false); + +if (typeof reportCompare === "function") + reportCompare(true, true); |