|
1 /* |
|
2 * Any copyright is dedicated to the Public Domain. |
|
3 * http://creativecommons.org/licenses/publicdomain/ |
|
4 */ |
|
5 |
|
6 var BadSyntaxStrings = [ |
|
7 "function foo1() { \"use strict\"; try {} catch (eval) {} }", |
|
8 "function foo2() { \"use strict\"; let eval = 9; foo(); }", |
|
9 "function foo3() { \"use strict\"; for (let eval = 3;;) { foo(); }}", |
|
10 "function foo4() { \"use strict\"; for (let eval in {a:1}) { foo(); }}", |
|
11 "function foo5() { \"use strict\"; for (let eval of [1, 2, 3]) { foo(); }}", |
|
12 "function foo6() { \"use strict\"; var eval = 12; }", |
|
13 "function foo7() { \"use strict\"; for (var eval = 3;;) { foo(); }}", |
|
14 "function foo8() { \"use strict\"; for (var eval in {a:1}) { foo(); }}", |
|
15 "function foo9() { \"use strict\"; for (var eval of [1, 2, 3]) { foo(); }}", |
|
16 "function foo10() { \"use strict\"; const eval = 12; }", |
|
17 "function foo11() { \"use strict\"; for (const eval = 3;;) { foo(); }}", |
|
18 "function foo12() { \"use strict\"; return [eval for (eval of [1, 2, 3])]; }", |
|
19 "function foo13() { \"use strict\"; return [eval for (eval in {a:3})]; }", |
|
20 "function foo14() { \"use strict\"; return (eval for (eval of [1, 2, 3])); }", |
|
21 "function foo15() { \"use strict\"; return (eval for (eval in {a:3})); }" |
|
22 ]; |
|
23 |
|
24 function testString(s, i) { |
|
25 var gotSyntaxError = -1; |
|
26 try { |
|
27 eval(s); |
|
28 } catch(err) { |
|
29 if (err instanceof SyntaxError) |
|
30 gotSyntaxError = i; |
|
31 } |
|
32 |
|
33 assertEq(gotSyntaxError, i); |
|
34 } |
|
35 |
|
36 for (var i = 0; i < BadSyntaxStrings.length; i++) |
|
37 testString(BadSyntaxStrings[i], i); |
|
38 |
|
39 reportCompare(true, true); |