js/src/tests/js1_8_1/extensions/strict-warning.js

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

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

mercurial