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 --- .../statements/for-in-with-assignment-syntax.js | 66 ++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 js/src/tests/non262/statements/for-in-with-assignment-syntax.js (limited to 'js/src/tests/non262/statements/for-in-with-assignment-syntax.js') diff --git a/js/src/tests/non262/statements/for-in-with-assignment-syntax.js b/js/src/tests/non262/statements/for-in-with-assignment-syntax.js new file mode 100644 index 0000000000..7540b4bd1b --- /dev/null +++ b/js/src/tests/non262/statements/for-in-with-assignment-syntax.js @@ -0,0 +1,66 @@ +/* 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 validSyntax = [ + "var x", +]; + +const destructuring = [ + "[]", + "[,]", + "[a]", + "[a = 0]", + "[...a]", + "[...[]]", + "[...[a]]", + "{}", + "{p: x}", + "{p: x = 0}", + "{x}", + "{x = 0}", +]; + +const invalidSyntax = [ + ...destructuring.map(binding => `var ${binding}`), + "let x", + ...destructuring.map(binding => `let ${binding}`), + "const x", + ...destructuring.map(binding => `const ${binding}`), + "x", + ...destructuring.map(binding => `${binding}`), + "o.p", + "o[0]", + "f()", +]; + +for (let valid of validSyntax) { + Function(`for (${valid} = 0 in {});`); + assertThrowsInstanceOf(() => Function(`"use strict"; for (${valid} = 0 in {});`), + SyntaxError); +} + +for (let invalid of invalidSyntax) { + assertThrowsInstanceOf(() => Function(`for (${invalid} = 0 in {});`), SyntaxError); +} + +// Invalid syntax, needs method context to parse. +assertThrowsInstanceOf(() => Function(`({ m() { for (super.p = 0 in {}); } })`), SyntaxError); +assertThrowsInstanceOf(() => Function(`({ m() { for (super[0] = 0 in {}); } })`), SyntaxError); + +assertThrowsInstanceOf(() => Function(`for (0 = 0 in {});`), SyntaxError); +assertThrowsInstanceOf(() => Function(`for (i++ = 0 in {});`), SyntaxError); +assertThrowsInstanceOf(() => Function(`for (new F() = 0 in {});`), SyntaxError); +assertThrowsInstanceOf(() => Function(`function f() { for (new.target = 0 in {}); }`), SyntaxError); +assertThrowsInstanceOf(() => Function(`class C extends D { constructor() { for (super() = 0 in {}); } }`), SyntaxError); + +// Same as above, only this time don't make it look like we actually parse a for-in statement. +assertThrowsInstanceOf(() => Function(`for (0 = 0 #####`), SyntaxError); +assertThrowsInstanceOf(() => Function(`for (i++ = 0 #####`), SyntaxError); +assertThrowsInstanceOf(() => Function(`for (new F() = 0 #####`), SyntaxError); +assertThrowsInstanceOf(() => Function(`function f() { for (new.target = 0 #####`), SyntaxError); +assertThrowsInstanceOf(() => Function(`class C extends D { constructor() { for (super() = 0 #####`), SyntaxError); + + +if (typeof reportCompare === "function") + reportCompare(true, true); -- cgit v1.2.3