summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/fields/error.js
blob: 4c164b2bbcf1c1c8f5f68c6583b7dc44f365431c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
load(libdir + 'asserts.js');

let source = `class C {
    x =
}`;
assertErrorMessage(() => Function(source), SyntaxError, /./);

source = `class C {
    -2;
    -2 = 2;
}`;
assertErrorMessage(() => Function(source), SyntaxError, /./);

source = `class C {
    x += 2;
}`;
assertErrorMessage(() => Function(source), SyntaxError, /./);

source = `class C {
    #2;
}`;
assertErrorMessage(() => Function(source), SyntaxError, /./);

source = `class C {
    #["h" + "i"];
}`;
assertErrorMessage(() => Function(source), SyntaxError, /./);

source = `class C {
    #"hi";
}`;
assertErrorMessage(() => Function(source), SyntaxError, /./);

source = `class C {
    constructor;
}`;
assertErrorMessage(() => Function(source), SyntaxError, /./);

source = `class C {
    "constructor";
}`;
assertErrorMessage(() => Function(source), SyntaxError, /./);

source = `class C {
    x = arguments;
}`;
assertErrorMessage(() => Function(source), SyntaxError, /./);

source = `class C {
    x = super();
}`;
assertErrorMessage(() => Function(source), SyntaxError, /./);

source = `function f() {
class C {
    #"should still throw error during lazy parse";
}
}`;
assertErrorMessage(() => Function(source), SyntaxError, /./);

source = `#outside;`;
assertErrorMessage(() => eval(source), SyntaxError, /./);

source = `class C {
    x = super();
}`;
assertErrorMessage(() => Function(source), SyntaxError, /./);

source = `class C {
    x = sper();
}`;
eval(source);


// The following test cases fail to parse because ASI does not happen if the
// next token might be valid, even if it leads to a SyntaxError further down
// the road.

source = `class C {
    x = 0
    ["computedMethodName"](){}
}`;
assertThrowsInstanceOf(() => Function(source), SyntaxError);

source = `class C {
    x = 0
    *f(){}
}`;
assertThrowsInstanceOf(() => Function(source), SyntaxError);


// The following test cases fail to parse because ASI doesn't happen without a
// newline.

source = `class C { x y }`;
assertThrowsInstanceOf(() => Function(source), SyntaxError);

source = `class C { if var }  // identifiers that look like keywords`;
assertThrowsInstanceOf(() => Function(source), SyntaxError);

source = `class C { x = 1 y }`;
assertThrowsInstanceOf(() => Function(source), SyntaxError);

source = `class C { x async f() {} }`;
assertThrowsInstanceOf(() => Function(source), SyntaxError);

source = `class C { x static f() {} }`;
assertThrowsInstanceOf(() => Function(source), SyntaxError);

source = `class C { field1 static field2 }`;
assertThrowsInstanceOf(() => Function(source), SyntaxError);

source = `class C { x get f() {} }`;
assertThrowsInstanceOf(() => Function(source), SyntaxError);

if (typeof reportCompare === 'function') reportCompare(true, true);