Debian Codegraph @

js/src/tests/non262/statements/for-in-with-assignment-syntax.js

raw
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5 const validSyntax = [
6 "var x",
7 ];
8
9 const destructuring = [
10 "[]",
11 "[,]",
12 "[a]",
13 "[a = 0]",
14 "[...a]",
15 "[...[]]",
16 "[...[a]]",
17 "{}",
18 "{p: x}",
19 "{p: x = 0}",
20 "{x}",
21 "{x = 0}",
22 ];
23
24 const invalidSyntax = [
25 ...destructuring.map(binding => `var ${binding}`),
26 "let x",
27 ...destructuring.map(binding => `let ${binding}`),
28 "const x",
29 ...destructuring.map(binding => `const ${binding}`),
30 "x",
31 ...destructuring.map(binding => `${binding}`),
32 "o.p",
33 "o[0]",
34 "f()",
35 ];
36
37 for (let valid of validSyntax) {
38 Function(`for (${valid} = 0 in {});`);
39 assertThrowsInstanceOf(() => Function(`"use strict"; for (${valid} = 0 in {});`),
40 SyntaxError);
41 }
42
43 for (let invalid of invalidSyntax) {
44 assertThrowsInstanceOf(() => Function(`for (${invalid} = 0 in {});`), SyntaxError);
45 }
46
47 // Invalid syntax, needs method context to parse.
48 assertThrowsInstanceOf(() => Function(`({ m() { for (super.p = 0 in {}); } })`), SyntaxError);
49 assertThrowsInstanceOf(() => Function(`({ m() { for (super[0] = 0 in {}); } })`), SyntaxError);
50
51 assertThrowsInstanceOf(() => Function(`for (0 = 0 in {});`), SyntaxError);
52 assertThrowsInstanceOf(() => Function(`for (i++ = 0 in {});`), SyntaxError);
53 assertThrowsInstanceOf(() => Function(`for (new F() = 0 in {});`), SyntaxError);
54 assertThrowsInstanceOf(() => Function(`function f() { for (new.target = 0 in {}); }`), SyntaxError);
55 assertThrowsInstanceOf(() => Function(`class C extends D { constructor() { for (super() = 0 in {}); } }`), SyntaxError);
56
57 // Same as above, only this time don't make it look like we actually parse a for-in statement.
58 assertThrowsInstanceOf(() => Function(`for (0 = 0 #####`), SyntaxError);
59 assertThrowsInstanceOf(() => Function(`for (i++ = 0 #####`), SyntaxError);
60 assertThrowsInstanceOf(() => Function(`for (new F() = 0 #####`), SyntaxError);
61 assertThrowsInstanceOf(() => Function(`function f() { for (new.target = 0 #####`), SyntaxError);
62 assertThrowsInstanceOf(() => Function(`class C extends D { constructor() { for (super() = 0 #####`), SyntaxError);
63
64
65 if (typeof reportCompare === "function")
66 reportCompare(true, true);