|
1 // Turn on strict mode and warnings-as-errors mode. |
|
2 if (options().split().indexOf('strict') == -1) |
|
3 options('strict'); |
|
4 if (options().split().indexOf('werror') == -1) |
|
5 options('werror'); |
|
6 |
|
7 function expectSyntaxError(stmt) { |
|
8 print(stmt); |
|
9 var result = 'no error'; |
|
10 try { |
|
11 Function(stmt); |
|
12 } catch (exc) { |
|
13 result = exc.constructor.name; |
|
14 } |
|
15 assertEq(result, 'SyntaxError'); |
|
16 } |
|
17 |
|
18 function test(expr) { |
|
19 // Without extra parentheses, expect an error. |
|
20 expectSyntaxError('if (' + expr + ') {};'); |
|
21 |
|
22 // Extra parentheses silence the warning/error. |
|
23 Function('if ((' + expr + ')) {};'); |
|
24 } |
|
25 |
|
26 // Overparenthesized assignment in a condition should not be a strict error. |
|
27 test('a = 0'); |
|
28 test('a = (f(), g)'); |
|
29 test('a = b || c > d'); |
|
30 expectSyntaxError('if (a == 0);'); |
|
31 reportCompare('passed', 'passed', 'Overparenthesized assignment in a condition should not be a strict error.'); |
|
32 |