js/src/jit-test/tests/arrow-functions/syntax-errors.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/jit-test/tests/arrow-functions/syntax-errors.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,38 @@
     1.4 +// Check that we correctly throw SyntaxErrors for various syntactic near-misses.
     1.5 +
     1.6 +load(libdir + "asserts.js");
     1.7 +
     1.8 +var mistakes = [
     1.9 +    "((a)) => expr",
    1.10 +    "a + b => a",
    1.11 +    "'' + a => a",
    1.12 +    "...x",
    1.13 +    "[x] => x",
    1.14 +    "([x] => x)",
    1.15 +    "{p: p} => p",
    1.16 +    "({p: p} => p)",
    1.17 +    "{p} => p",
    1.18 +    "(...x => expr)",
    1.19 +    "1 || a => a",
    1.20 +    "'use strict' => {}",
    1.21 +    "package => {'use strict';}",    // tricky: FutureReservedWord in strict mode code only
    1.22 +    "'use strict'; arguments => 0",  // names banned in strict mode code
    1.23 +    "'use strict'; eval => 0",
    1.24 +    "a => {'use strict'; with (a) return x; }",
    1.25 +    "a => yield a",
    1.26 +    "a => { yield a; }",
    1.27 +    "a => { { let x; yield a; } }",
    1.28 +    "(a = yield 0) => a",
    1.29 +    "for (;;) a => { break; };",
    1.30 +    "for (;;) a => { continue; };",
    1.31 +    "...rest) =>",
    1.32 +    "2 + ...rest) =>"
    1.33 +];
    1.34 +
    1.35 +for (var s of mistakes)
    1.36 +    assertThrowsInstanceOf(function () { Function(s); }, SyntaxError);
    1.37 +
    1.38 +// Check that the tricky case is not an error in non-strict-mode code.
    1.39 +var f = package => 0;
    1.40 +assertEq(f(1), 0);
    1.41 +

mercurial