js/src/tests/ecma_5/strict/rebind-eval-should-fail-in-strict-mode.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/ecma_5/strict/rebind-eval-should-fail-in-strict-mode.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,39 @@
     1.4 +/*
     1.5 + * Any copyright is dedicated to the Public Domain.
     1.6 + * http://creativecommons.org/licenses/publicdomain/
     1.7 + */
     1.8 +
     1.9 +var BadSyntaxStrings = [
    1.10 +    "function foo1() { \"use strict\"; try {} catch (eval) {} }",
    1.11 +    "function foo2() { \"use strict\"; let eval = 9; foo(); }",
    1.12 +    "function foo3() { \"use strict\"; for (let eval = 3;;) { foo(); }}",
    1.13 +    "function foo4() { \"use strict\"; for (let eval in {a:1}) { foo(); }}",
    1.14 +    "function foo5() { \"use strict\"; for (let eval of [1, 2, 3]) { foo(); }}",
    1.15 +    "function foo6() { \"use strict\"; var eval = 12; }",
    1.16 +    "function foo7() { \"use strict\"; for (var eval = 3;;) { foo(); }}",
    1.17 +    "function foo8() { \"use strict\"; for (var eval in {a:1}) { foo(); }}",
    1.18 +    "function foo9() { \"use strict\"; for (var eval of [1, 2, 3]) { foo(); }}",
    1.19 +    "function foo10() { \"use strict\"; const eval = 12; }",
    1.20 +    "function foo11() { \"use strict\"; for (const eval = 3;;) { foo(); }}",
    1.21 +    "function foo12() { \"use strict\"; return [eval for (eval of [1, 2, 3])]; }",
    1.22 +    "function foo13() { \"use strict\"; return [eval for (eval in {a:3})]; }",
    1.23 +    "function foo14() { \"use strict\"; return (eval for (eval of [1, 2, 3])); }",
    1.24 +    "function foo15() { \"use strict\"; return (eval for (eval in {a:3})); }"
    1.25 +];
    1.26 +
    1.27 +function testString(s, i) {
    1.28 +    var gotSyntaxError = -1;
    1.29 +    try {
    1.30 +        eval(s);
    1.31 +    } catch(err) {
    1.32 +        if (err instanceof SyntaxError)
    1.33 +            gotSyntaxError = i;
    1.34 +    }
    1.35 +
    1.36 +    assertEq(gotSyntaxError, i);
    1.37 +}
    1.38 +
    1.39 +for (var i = 0; i < BadSyntaxStrings.length; i++)
    1.40 +    testString(BadSyntaxStrings[i], i);
    1.41 +
    1.42 +reportCompare(true, true);

mercurial