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

     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');
     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 }
    18 function test(expr) {
    19     // Without extra parentheses, expect an error.
    20     expectSyntaxError('if (' + expr + ') {};');
    22     // Extra parentheses silence the warning/error.
    23     Function('if ((' + expr + ')) {};');
    24 }
    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.');

mercurial