summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/syntax/non-simple-with-strict-directive.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/tests/non262/syntax/non-simple-with-strict-directive.js
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/non262/syntax/non-simple-with-strict-directive.js')
-rw-r--r--js/src/tests/non262/syntax/non-simple-with-strict-directive.js140
1 files changed, 140 insertions, 0 deletions
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);