From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- .../syntax/non-simple-with-strict-directive.js | 140 +++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 js/src/tests/non262/syntax/non-simple-with-strict-directive.js (limited to 'js/src/tests/non262/syntax/non-simple-with-strict-directive.js') diff --git a/js/src/tests/non262/syntax/non-simple-with-strict-directive.js b/js/src/tests/non262/syntax/non-simple-with-strict-directive.js new file mode 100644 index 0000000000..a0e5366879 --- /dev/null +++ b/js/src/tests/non262/syntax/non-simple-with-strict-directive.js @@ -0,0 +1,140 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +const testCases = [ + // Array destructuring. + "[]", + "[a]", + "x, [a]", + "[a], x", + + // Array destructuring with defaults. + "[a = 0]", + "x, [a = 0]", + "[a = 0], x", + + // Array destructuring with rest binding identifier. + "[...a]", + "x, [...a]", + "[...a], x", + + // Array destructuring with rest binding pattern. + "[...[a]]", + "x, [...[a]]", + "[...[a]], x", + + // Object destructuring. + "{}", + "{p: o}", + "x, {p: o}", + "{p: o}, x", + + // Object destructuring with defaults. + "{p: o = 0}", + "x, {p: o = 0}", + "{p: o = 0}, x", + + // Object destructuring with shorthand identifier form. + "{o}", + "x, {o}", + "{o}, x", + + // Object destructuring with CoverInitName. + "{o = 0}", + "x, {o = 0}", + "{o = 0}, x", + + // Default parameter. + "d = 0", + "x, d = 0", + "d = 0, x", + + // Rest parameter. + "...rest", + "x, ...rest", + + // Rest parameter with array destructuring. + "...[]", + "...[a]", + "x, ...[]", + "x, ...[a]", + + // Rest parameter with object destructuring. + "...{}", + "...{p: o}", + "x, ...{}", + "x, ...{p: o}", + + // All non-simple cases combined. + "x, d = 123, [a], {p: 0}, ...rest", +]; + +const GeneratorFunction = function*(){}.constructor; + +const functionDefinitions = [ + // FunctionDeclaration + parameters => `function f(${parameters}) { "use strict"; }`, + + // FunctionExpression + parameters => `void function(${parameters}) { "use strict"; };`, + parameters => `void function f(${parameters}) { "use strict"; };`, + + // Function constructor + parameters => `Function('${parameters}', '"use strict";')`, + + // GeneratorDeclaration + parameters => `function* g(${parameters}) { "use strict"; }`, + + // GeneratorExpression + parameters => `void function*(${parameters}) { "use strict"; };`, + parameters => `void function* g(${parameters}) { "use strict"; };`, + + // GeneratorFunction constructor + parameters => `GeneratorFunction('${parameters}', '"use strict";')`, + + // MethodDefinition + parameters => `({ m(${parameters}) { "use strict"; } });`, + parameters => `(class { m(${parameters}) { "use strict"; } });`, + parameters => `class C { m(${parameters}) { "use strict"; } }`, + + // MethodDefinition (constructors) + parameters => `(class { constructor(${parameters}) { "use strict"; } });`, + parameters => `class C { constructor(${parameters}) { "use strict"; } }`, + + // MethodDefinition (getter) + parameters => `({ get m(${parameters}) { "use strict"; } });`, + parameters => `(class { get m(${parameters}) { "use strict"; } });`, + parameters => `class C { get m(${parameters}) { "use strict"; } }`, + + // MethodDefinition (setter) + parameters => `({ set m(${parameters}) { "use strict"; } });`, + parameters => `(class { set m(${parameters}) { "use strict"; } });`, + parameters => `class C { set m(${parameters}) { "use strict"; } }`, + + // GeneratorMethod + parameters => `({ *m(${parameters}) { "use strict"; } });`, + parameters => `(class { *m(${parameters}) { "use strict"; } });`, + parameters => `class C { *m(${parameters}) { "use strict"; } }`, + + // ArrowFunction + parameters => `(${parameters}) => { "use strict"; };`, +]; + +for (let nonSimpleParameters of testCases) { + for (let def of functionDefinitions) { + // Non-strict script code. + assertThrowsInstanceOf(() => eval(` + ${def(nonSimpleParameters)} + `), SyntaxError, def(nonSimpleParameters)); + + // Strict script code. + assertThrowsInstanceOf(() => eval(` + "use strict"; + ${def(nonSimpleParameters)} + `), SyntaxError, `"use strict"; ${def(nonSimpleParameters)}`); + } +} + +if (typeof reportCompare === 'function') + reportCompare(0, 0); -- cgit v1.2.3