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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/js1_8_1/extensions/strict-warning.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,32 @@
     1.4 +// Turn on strict mode and warnings-as-errors mode.
     1.5 +if (options().split().indexOf('strict') == -1)
     1.6 +    options('strict');
     1.7 +if (options().split().indexOf('werror') == -1)
     1.8 +    options('werror');
     1.9 +
    1.10 +function expectSyntaxError(stmt) {
    1.11 +    print(stmt);
    1.12 +    var result = 'no error';
    1.13 +    try {
    1.14 +        Function(stmt);
    1.15 +    } catch (exc) {
    1.16 +        result = exc.constructor.name;
    1.17 +    }
    1.18 +    assertEq(result, 'SyntaxError');
    1.19 +}
    1.20 +
    1.21 +function test(expr) {
    1.22 +    // Without extra parentheses, expect an error.
    1.23 +    expectSyntaxError('if (' + expr + ') {};');
    1.24 +
    1.25 +    // Extra parentheses silence the warning/error.
    1.26 +    Function('if ((' + expr + ')) {};');
    1.27 +}
    1.28 +
    1.29 +// Overparenthesized assignment in a condition should not be a strict error.
    1.30 +test('a = 0');
    1.31 +test('a = (f(), g)');
    1.32 +test('a = b || c > d');
    1.33 +expectSyntaxError('if (a == 0);');
    1.34 +reportCompare('passed', 'passed', 'Overparenthesized assignment in a condition should not be a strict error.');
    1.35 +

mercurial