]>
Commit | Line | Data |
---|---|---|
ed1e77d3 A |
1 | function testSyntax(script) { |
2 | try { | |
3 | eval(script); | |
4 | } catch (error) { | |
5 | if (error instanceof SyntaxError) | |
6 | throw new Error("Bad error: " + String(error)); | |
7 | } | |
8 | } | |
9 | ||
10 | function testSyntaxError(script, message) { | |
11 | var error = null; | |
12 | try { | |
13 | eval(script); | |
14 | } catch (e) { | |
15 | error = e; | |
16 | } | |
17 | if (!error) | |
18 | throw new Error("Expected syntax error not thrown"); | |
19 | ||
20 | if (String(error) !== message) | |
21 | throw new Error("Bad error: " + String(error)); | |
22 | } | |
23 | ||
24 | testSyntax("var cocoa"); | |
25 | testSyntax("var c\u006fcoa"); | |
26 | ||
27 | testSyntaxError(String.raw`var var`, String.raw`SyntaxError: Cannot use the keyword 'var' as a variable name.`); | |
28 | testSyntaxError(String.raw`var v\u0061r`, String.raw`SyntaxError: Cannot use the keyword 'v\u0061r' as a variable name.`); | |
29 | testSyntaxError(String.raw`var v\u{0061}r`, String.raw`SyntaxError: Cannot use the keyword 'v\u{0061}r' as a variable name.`); | |
30 | ||
31 | testSyntaxError(String.raw`var var = 2000000;`, String.raw`SyntaxError: Cannot use the keyword 'var' as a variable name.`); | |
32 | testSyntaxError(String.raw`var v\u0061r = 2000000;`, String.raw`SyntaxError: Cannot use the keyword 'v\u0061r' as a variable name.`); | |
33 | testSyntaxError(String.raw`var v\u{0061}r = 2000000`, String.raw`SyntaxError: Cannot use the keyword 'v\u{0061}r' as a variable name.`); | |
34 | ||
35 | testSyntaxError(String.raw`var {var} = obj)`, String.raw`SyntaxError: Cannot use abbreviated destructuring syntax for keyword 'var'.`); | |
36 | testSyntaxError(String.raw`var {v\u0061r} = obj`, String.raw`SyntaxError: Cannot use abbreviated destructuring syntax for keyword 'var'.`); | |
37 | testSyntaxError(String.raw`var {v\u{0061}r} = obj`, String.raw`SyntaxError: Cannot use abbreviated destructuring syntax for keyword 'var'.`); | |
38 | ||
39 | testSyntaxError(String.raw`var {var:var} = obj)`, String.raw`SyntaxError: Cannot use the keyword 'var' as a variable name.`); | |
40 | testSyntaxError(String.raw`var {var:v\u0061r} = obj`, String.raw`SyntaxError: Cannot use the keyword 'v\u0061r' as a variable name.`); | |
41 | testSyntaxError(String.raw`var {var:v\u{0061}r} = obj`, String.raw`SyntaxError: Cannot use the keyword 'v\u{0061}r' as a variable name.`); | |
42 | ||
43 | testSyntaxError(String.raw`var [var] = obj`, String.raw`SyntaxError: Cannot use the keyword 'var' as a variable name.`); | |
44 | testSyntaxError(String.raw`var [v\u0061r] = obj`, String.raw`SyntaxError: Cannot use the keyword 'v\u0061r' as a variable name.`); | |
45 | testSyntaxError(String.raw`var [v\u{0061}r] = obj`, String.raw`SyntaxError: Cannot use the keyword 'v\u{0061}r' as a variable name.`); | |
46 | ||
47 | testSyntaxError(String.raw`[var] = obj`, String.raw`SyntaxError: Unexpected keyword 'var'`); | |
48 | testSyntaxError(String.raw`[v\u0061r] = obj`, String.raw`SyntaxError: Unexpected keyword 'v\u0061r'`); | |
49 | testSyntaxError(String.raw`[v\u{0061}r] = obj`, String.raw`SyntaxError: Unexpected keyword 'v\u{0061}r'`); | |
50 | ||
51 | testSyntaxError(String.raw`function var() { }`, String.raw`SyntaxError: Cannot use the keyword 'var' as a function name.`); | |
52 | testSyntaxError(String.raw`function v\u0061r() { }`, String.raw`SyntaxError: Cannot use the keyword 'v\u0061r' as a function name.`); | |
53 | testSyntaxError(String.raw`function v\u{0061}r() { }`, String.raw`SyntaxError: Cannot use the keyword 'v\u{0061}r' as a function name.`); | |
54 | ||
55 | testSyntaxError(String.raw`function a(var) { }`, String.raw`SyntaxError: Cannot use the keyword 'var' as a variable name.`); | |
56 | testSyntaxError(String.raw`function a(v\u0061r) { }`, String.raw`SyntaxError: Cannot use the keyword 'v\u0061r' as a variable name.`); | |
57 | testSyntaxError(String.raw`function a(v\u{0061}r) { }`, String.raw`SyntaxError: Cannot use the keyword 'v\u{0061}r' as a variable name.`); | |
58 | ||
59 | testSyntaxError(String.raw`function a({var}) { }`, String.raw`SyntaxError: Cannot use abbreviated destructuring syntax for keyword 'var'.`); | |
60 | testSyntaxError(String.raw`function a({v\u0061r}) { }`, String.raw`SyntaxError: Cannot use abbreviated destructuring syntax for keyword 'var'.`); | |
61 | testSyntaxError(String.raw`function a({v\u{0061}r}) { }`, String.raw`SyntaxError: Cannot use abbreviated destructuring syntax for keyword 'var'.`); | |
62 | ||
63 | testSyntaxError(String.raw`function a({var:var}) { }`, String.raw`SyntaxError: Cannot use the keyword 'var' as a variable name.`); | |
64 | testSyntaxError(String.raw`function a({var:v\u0061r}) { }`, String.raw`SyntaxError: Cannot use the keyword 'v\u0061r' as a variable name.`); | |
65 | testSyntaxError(String.raw`function a({var:v\u{0061}r}) { }`, String.raw`SyntaxError: Cannot use the keyword 'v\u{0061}r' as a variable name.`); | |
66 | ||
67 | testSyntaxError(String.raw`function a([var]) { }`, String.raw`SyntaxError: Cannot use the keyword 'var' as a variable name.`); | |
68 | testSyntaxError(String.raw`function a([v\u0061r]) { }`, String.raw`SyntaxError: Cannot use the keyword 'v\u0061r' as a variable name.`); | |
69 | testSyntaxError(String.raw`function a([v\u{0061}r]) { }`, String.raw`SyntaxError: Cannot use the keyword 'v\u{0061}r' as a variable name.`); | |
70 | ||
71 | testSyntaxError(String.raw`(function var() { })`, String.raw`SyntaxError: Cannot use the keyword 'var' as a function name.`); | |
72 | testSyntaxError(String.raw`(function v\u0061r() { })`, String.raw`SyntaxError: Cannot use the keyword 'v\u0061r' as a function name.`); | |
73 | testSyntaxError(String.raw`(function v\u{0061}r() { })`, String.raw`SyntaxError: Cannot use the keyword 'v\u{0061}r' as a function name.`); | |
74 | ||
75 | testSyntaxError(String.raw`(function a(var) { })`, String.raw`SyntaxError: Cannot use the keyword 'var' as a variable name.`); | |
76 | testSyntaxError(String.raw`(function a(v\u0061r) { })`, String.raw`SyntaxError: Cannot use the keyword 'v\u0061r' as a variable name.`); | |
77 | testSyntaxError(String.raw`(function a(v\u{0061}r) { })`, String.raw`SyntaxError: Cannot use the keyword 'v\u{0061}r' as a variable name.`); | |
78 | ||
79 | testSyntaxError(String.raw`(function a({var}) { })`, String.raw`SyntaxError: Cannot use abbreviated destructuring syntax for keyword 'var'.`); | |
80 | testSyntaxError(String.raw`(function a({v\u0061r}) { })`, String.raw`SyntaxError: Cannot use abbreviated destructuring syntax for keyword 'var'.`); | |
81 | testSyntaxError(String.raw`(function a({v\u{0061}r}) { })`, String.raw`SyntaxError: Cannot use abbreviated destructuring syntax for keyword 'var'.`); | |
82 | ||
83 | testSyntaxError(String.raw`(function a({var:var}) { })`, String.raw`SyntaxError: Cannot use the keyword 'var' as a variable name.`); | |
84 | testSyntaxError(String.raw`(function a({var:v\u0061r}) { })`, String.raw`SyntaxError: Cannot use the keyword 'v\u0061r' as a variable name.`); | |
85 | testSyntaxError(String.raw`(function a({var:v\u{0061}r}) { })`, String.raw`SyntaxError: Cannot use the keyword 'v\u{0061}r' as a variable name.`); | |
86 | ||
87 | testSyntaxError(String.raw`(function a([var]) { })`, String.raw`SyntaxError: Cannot use the keyword 'var' as a variable name.`); | |
88 | testSyntaxError(String.raw`(function a([v\u0061r]) { })`, String.raw`SyntaxError: Cannot use the keyword 'v\u0061r' as a variable name.`); | |
89 | testSyntaxError(String.raw`(function a([v\u{0061}r]) { })`, String.raw`SyntaxError: Cannot use the keyword 'v\u{0061}r' as a variable name.`); | |
90 | ||
91 | testSyntaxError(String.raw`(function a([{var}]) { })`, String.raw`SyntaxError: Cannot use abbreviated destructuring syntax for keyword 'var'.`); | |
92 | testSyntaxError(String.raw`(function a([{v\u0061r}]) { })`, String.raw`SyntaxError: Cannot use abbreviated destructuring syntax for keyword 'var'.`); | |
93 | testSyntaxError(String.raw`(function a([{v\u{0061}r}]) { })`, String.raw`SyntaxError: Cannot use abbreviated destructuring syntax for keyword 'var'.`); | |
94 | ||
95 | testSyntaxError(String.raw`(function a([{var:var}]) { })`, String.raw`SyntaxError: Cannot use the keyword 'var' as a variable name.`); | |
96 | testSyntaxError(String.raw`(function a([{var:v\u0061r}]) { })`, String.raw`SyntaxError: Cannot use the keyword 'v\u0061r' as a variable name.`); | |
97 | testSyntaxError(String.raw`(function a([{var:v\u{0061}r}]) { })`, String.raw`SyntaxError: Cannot use the keyword 'v\u{0061}r' as a variable name.`); | |
98 | ||
99 | testSyntaxError(String.raw`(function a([[var]]) { })`, String.raw`SyntaxError: Cannot use the keyword 'var' as a variable name.`); | |
100 | testSyntaxError(String.raw`(function a([[v\u0061r]]) { })`, String.raw`SyntaxError: Cannot use the keyword 'v\u0061r' as a variable name.`); | |
101 | testSyntaxError(String.raw`(function a([[v\u{0061}r]]) { })`, String.raw`SyntaxError: Cannot use the keyword 'v\u{0061}r' as a variable name.`); | |
102 | ||
103 | testSyntaxError(String.raw`(function a({ hello: {var}}) { })`, String.raw`SyntaxError: Cannot use abbreviated destructuring syntax for keyword 'var'.`); | |
104 | testSyntaxError(String.raw`(function a({ hello: {v\u0061r}}) { })`, String.raw`SyntaxError: Cannot use abbreviated destructuring syntax for keyword 'var'.`); | |
105 | testSyntaxError(String.raw`(function a({ hello: {v\u{0061}r}}) { })`, String.raw`SyntaxError: Cannot use abbreviated destructuring syntax for keyword 'var'.`); | |
106 | ||
107 | testSyntaxError(String.raw`(function a({ hello: {var:var}}) { })`, String.raw`SyntaxError: Cannot use the keyword 'var' as a variable name.`); | |
108 | testSyntaxError(String.raw`(function a({ hello: {var:v\u0061r}}) { })`, String.raw`SyntaxError: Cannot use the keyword 'v\u0061r' as a variable name.`); | |
109 | testSyntaxError(String.raw`(function a({ hello: {var:v\u{0061}r}}) { })`, String.raw`SyntaxError: Cannot use the keyword 'v\u{0061}r' as a variable name.`); | |
110 | ||
111 | testSyntaxError(String.raw`(function a({ hello: [var]}) { })`, String.raw`SyntaxError: Cannot use the keyword 'var' as a variable name.`); | |
112 | testSyntaxError(String.raw`(function a({ hello: [v\u0061r]}) { })`, String.raw`SyntaxError: Cannot use the keyword 'v\u0061r' as a variable name.`); | |
113 | testSyntaxError(String.raw`(function a({ hello: [v\u{0061}r]}) { })`, String.raw`SyntaxError: Cannot use the keyword 'v\u{0061}r' as a variable name.`); | |
114 | ||
115 | testSyntaxError(String.raw`(function a({ 0: {var} }) { })`, String.raw`SyntaxError: Cannot use abbreviated destructuring syntax for keyword 'var'.`); | |
116 | testSyntaxError(String.raw`(function a({ 0: {v\u0061r}}) { })`, String.raw`SyntaxError: Cannot use abbreviated destructuring syntax for keyword 'var'.`); | |
117 | testSyntaxError(String.raw`(function a({ 0: {v\u{0061}r}}) { })`, String.raw`SyntaxError: Cannot use abbreviated destructuring syntax for keyword 'var'.`); | |
118 | ||
119 | testSyntaxError(String.raw`(function a({ 0: {var:var}}) { })`, String.raw`SyntaxError: Cannot use the keyword 'var' as a variable name.`); | |
120 | testSyntaxError(String.raw`(function a({ 0: {var:v\u0061r}}) { })`, String.raw`SyntaxError: Cannot use the keyword 'v\u0061r' as a variable name.`); | |
121 | testSyntaxError(String.raw`(function a({ 0: {var:v\u{0061}r}}) { })`, String.raw`SyntaxError: Cannot use the keyword 'v\u{0061}r' as a variable name.`); | |
122 | ||
123 | testSyntaxError(String.raw`(function a({ 0: {value:var}}) { })`, String.raw`SyntaxError: Cannot use the keyword 'var' as a variable name.`); | |
124 | testSyntaxError(String.raw`(function a({ 0: {value:v\u0061r}}) { })`, String.raw`SyntaxError: Cannot use the keyword 'v\u0061r' as a variable name.`); | |
125 | testSyntaxError(String.raw`(function a({ 0: {value:v\u{0061}r}}) { })`, String.raw`SyntaxError: Cannot use the keyword 'v\u{0061}r' as a variable name.`); | |
126 | ||
127 | testSyntaxError(String.raw`(function a({ 0: [var]}) { })`, String.raw`SyntaxError: Cannot use the keyword 'var' as a variable name.`); | |
128 | testSyntaxError(String.raw`(function a({ 0: [v\u0061r]}) { })`, String.raw`SyntaxError: Cannot use the keyword 'v\u0061r' as a variable name.`); | |
129 | testSyntaxError(String.raw`(function a({ 0: [v\u{0061}r]}) { })`, String.raw`SyntaxError: Cannot use the keyword 'v\u{0061}r' as a variable name.`); | |
130 | ||
131 | testSyntaxError(String.raw`try { } catch(var) { }`, String.raw`SyntaxError: Cannot use the keyword 'var' as a catch variable name.`); | |
132 | testSyntaxError(String.raw`try { } catch(v\u0061r) { }`, String.raw`SyntaxError: Cannot use the keyword 'v\u0061r' as a catch variable name.`); | |
133 | testSyntaxError(String.raw`try { } catch(v\u{0061}r) { }`, String.raw`SyntaxError: Cannot use the keyword 'v\u{0061}r' as a catch variable name.`); | |
134 | ||
135 | testSyntaxError(String.raw`class var { }`, String.raw`SyntaxError: Cannot use the keyword 'var' as a class name.`); | |
136 | testSyntaxError(String.raw`class v\u0061r { }`, String.raw`SyntaxError: Cannot use the keyword 'v\u0061r' as a class name.`); | |
137 | testSyntaxError(String.raw`class v\u{0061}r { }`, String.raw`SyntaxError: Cannot use the keyword 'v\u{0061}r' as a class name.`); | |
138 | ||
139 | // Allowed in non-keyword aware context. | |
140 | testSyntax(String.raw`({ v\u0061r: 'Cocoa' })`); | |
141 | testSyntax(String.raw`({ v\u{0061}r: 'Cocoa' })`); |