michael@0: // Turn on strict mode and warnings-as-errors mode. michael@0: if (options().split().indexOf('strict') == -1) michael@0: options('strict'); michael@0: if (options().split().indexOf('werror') == -1) michael@0: options('werror'); michael@0: michael@0: function expectSyntaxError(stmt) { michael@0: print(stmt); michael@0: var result = 'no error'; michael@0: try { michael@0: Function(stmt); michael@0: } catch (exc) { michael@0: result = exc.constructor.name; michael@0: } michael@0: assertEq(result, 'SyntaxError'); michael@0: } michael@0: michael@0: function test(expr) { michael@0: // Without extra parentheses, expect an error. michael@0: expectSyntaxError('if (' + expr + ') {};'); michael@0: michael@0: // Extra parentheses silence the warning/error. michael@0: Function('if ((' + expr + ')) {};'); michael@0: } michael@0: michael@0: // Overparenthesized assignment in a condition should not be a strict error. michael@0: test('a = 0'); michael@0: test('a = (f(), g)'); michael@0: test('a = b || c > d'); michael@0: expectSyntaxError('if (a == 0);'); michael@0: reportCompare('passed', 'passed', 'Overparenthesized assignment in a condition should not be a strict error.'); michael@0: