js/src/jit-test/tests/arrow-functions/syntax-errors.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.

michael@0 1 // Check that we correctly throw SyntaxErrors for various syntactic near-misses.
michael@0 2
michael@0 3 load(libdir + "asserts.js");
michael@0 4
michael@0 5 var mistakes = [
michael@0 6 "((a)) => expr",
michael@0 7 "a + b => a",
michael@0 8 "'' + a => a",
michael@0 9 "...x",
michael@0 10 "[x] => x",
michael@0 11 "([x] => x)",
michael@0 12 "{p: p} => p",
michael@0 13 "({p: p} => p)",
michael@0 14 "{p} => p",
michael@0 15 "(...x => expr)",
michael@0 16 "1 || a => a",
michael@0 17 "'use strict' => {}",
michael@0 18 "package => {'use strict';}", // tricky: FutureReservedWord in strict mode code only
michael@0 19 "'use strict'; arguments => 0", // names banned in strict mode code
michael@0 20 "'use strict'; eval => 0",
michael@0 21 "a => {'use strict'; with (a) return x; }",
michael@0 22 "a => yield a",
michael@0 23 "a => { yield a; }",
michael@0 24 "a => { { let x; yield a; } }",
michael@0 25 "(a = yield 0) => a",
michael@0 26 "for (;;) a => { break; };",
michael@0 27 "for (;;) a => { continue; };",
michael@0 28 "...rest) =>",
michael@0 29 "2 + ...rest) =>"
michael@0 30 ];
michael@0 31
michael@0 32 for (var s of mistakes)
michael@0 33 assertThrowsInstanceOf(function () { Function(s); }, SyntaxError);
michael@0 34
michael@0 35 // Check that the tricky case is not an error in non-strict-mode code.
michael@0 36 var f = package => 0;
michael@0 37 assertEq(f(1), 0);
michael@0 38

mercurial