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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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