| description( |
| "This test checks that the following expressions or statements are valid ECMASCRIPT code or should throw parse error" |
| ); |
| |
| function runTest(_a, expectSyntaxError) |
| { |
| var error; |
| |
| if (typeof _a != "string") |
| testFailed("runTest expects string argument: " + _a); |
| try { |
| eval(_a); |
| } catch (e) { |
| error = e; |
| } |
| |
| if (expectSyntaxError) { |
| if (error && error instanceof SyntaxError) |
| testPassed('Invalid: "' + _a + '"'); |
| else if (error) |
| testFailed('Invalid: "' + _a + '" should throw SyntaxError but got ' + (error.name || error)); |
| else |
| testFailed('Invalid: "' + _a + '" but did not throw'); |
| } else { |
| if (!error) |
| testPassed('Valid: "' + _a + '"'); |
| else if (!(error instanceof SyntaxError)) |
| testPassed('Valid: "' + _a + '" with ' + (error.name || error)); |
| else |
| testFailed('Valid: "' + _a + '" should NOT throw but got ' + (error.name || error)); |
| } |
| } |
| |
| function valid(_a) |
| { |
| // Test both the grammar and the syntax checker |
| runTest(_a, false); |
| runTest("function f() { " + _a + " }", false); |
| } |
| |
| function invalid(_a) |
| { |
| // Test both the grammar and the syntax checker |
| runTest(_a, true); |
| runTest("function f() { " + _a + " }", true); |
| } |
| |
| // known issue: |
| // some statements requires statement as argument, and |
| // it seems the End-Of-File terminator is converted to semicolon |
| // "a:[EOF]" is not parse error, while "{ a: }" is parse error |
| // "if (a)[EOF]" is not parse error, while "{ if (a) }" is parse error |
| // known issues of bison parser: |
| // accepts: 'function f() { return 6 + }' (only inside a function declaration) |
| // some comma expressions: see reparsing-semicolon-insertion.js |
| |
| debug ("Unary operators and member access"); |
| |
| valid (""); |
| invalid("(a"); |
| invalid("a[5"); |
| invalid("a[5 + 6"); |
| invalid("a."); |
| invalid("()"); |
| invalid("a.'l'"); |
| valid ("a: +~!new a"); |
| invalid("new -a"); |
| valid ("new (-1)") |
| valid ("a: b: c: new f(x++)++") |
| valid ("(a)++"); |
| valid ("(1--).x"); |
| invalid("a-- ++"); |
| invalid("(a:) --b"); |
| valid ("++ -- ++ a"); |
| valid ("++ new new a ++"); |
| valid ("delete void 0"); |
| invalid("delete the void"); |
| invalid("(a++"); |
| valid ("++a--"); |
| valid ("++((a))--"); |
| valid ("(a.x++)++"); |
| invalid("1: null"); |
| invalid("+-!~"); |
| invalid("+-!~(("); |
| invalid("a)"); |
| invalid("a]"); |
| invalid(".l"); |
| invalid("1.l"); |
| valid ("1 .l"); |
| |
| debug ("Octal numbers"); |
| |
| valid ("'use strict'; 0"); |
| valid ("0"); |
| invalid("'use strict'; 00"); |
| valid ("00"); |
| invalid("'use strict'; 08"); |
| valid ("08"); |
| invalid("'use strict'; 09"); |
| valid ("09"); |
| |
| debug ("Binary and conditional operators"); |
| |
| valid ("a + + typeof this"); |
| invalid("a + * b"); |
| invalid("a ? b"); |
| invalid("a ? b :"); |
| invalid("%a"); |
| invalid("a-"); |
| valid ("a = b ? b = c : d = e"); |
| valid ("s: a[1].l ? b.l['s'] ? c++ : d : true"); |
| valid ("a ? b + 1 ? c + 3 * d.l : d[5][6] : e"); |
| valid ("a in b instanceof delete -c"); |
| invalid("a in instanceof b.l"); |
| valid ("- - true % 5"); |
| invalid("- false = 3"); |
| valid ("a: b: c: (1 + null) = 3"); |
| valid ("a[2] = b.l += c /= 4 * 7 ^ !6"); |
| invalid("a + typeof b += c in d"); |
| invalid("typeof a &= typeof b"); |
| valid ("a: ((typeof (a))) >>>= a || b.l && c"); |
| valid ("a: b: c[a /= f[a %= b]].l[c[x] = 7] -= a ? b <<= f : g"); |
| valid ("-void+x['y'].l == x.l != 5 - f[7]"); |
| |
| debug ("Function calls (and new with arguments)"); |
| |
| valid ("a()()()"); |
| valid ("s: l: a[2](4 == 6, 5 = 6)(f[4], 6)"); |
| valid ("s: eval(a.apply(), b.call(c[5] - f[7]))"); |
| invalid("a("); |
| invalid("a(5"); |
| invalid("a(5,"); |
| invalid("a(5,)"); |
| invalid("a(5,6"); |
| valid ("a(b[7], c <d> e.l, new a() > b)"); |
| invalid("a(b[5)"); |
| invalid("a(b.)"); |
| valid ("~new new a(1)(i++)(c[l])"); |
| invalid("a(*a)"); |
| valid ("((((a))((b)()).l))()"); |
| valid ("(a)[b + (c) / (d())].l--"); |
| valid ("new (5)"); |
| invalid("new a(5"); |
| valid ("new (f + 5)(6, (g)() - 'l'() - true(false))"); |
| invalid("a(.length)"); |
| |
| debug ("function declaration and expression"); |
| |
| valid ("function f() {}"); |
| valid ("function f(a,b) {}"); |
| invalid("function () {}"); |
| invalid("function f(a b) {}"); |
| invalid("function f(a,) {}"); |
| invalid("function f(a,"); |
| invalid("function f(a, 1) {}"); |
| valid ("function g(arguments, eval) {}"); |
| valid ("function f() {} + function g() {}"); |
| invalid("(function a{})"); |
| invalid("(function this(){})"); |
| valid ("(delete new function f(){} + function(a,b){}(5)(6))"); |
| valid ("6 - function (m) { function g() {} }"); |
| invalid("function l() {"); |
| invalid("function l++(){}"); |
| |
| debug ("Array and object literal, comma operator"); |
| |
| // Note these are tested elsewhere, no need to repeat those tests here |
| valid ("[] in [5,6] * [,5,] / [,,5,,] || [a,] && new [,b] % [,,]"); |
| invalid("[5,"); |
| invalid("[,"); |
| invalid("(a,)"); |
| valid ("1 + {get get(){}, set set(a){}, get1:4, set1:get-set, }"); |
| invalid("1 + {a"); |
| invalid("1 + {a:"); |
| invalid("1 + {get l("); |
| invalid(",a"); |
| valid ("(4,(5,a(3,4))),f[4,a-6]"); |
| invalid("(,f)"); |
| invalid("a,,b"); |
| invalid("a ? b, c : d"); |
| |
| debug ("simple statements"); |
| |
| valid ("{ }"); |
| invalid("{ { }"); |
| valid ("{ ; ; ; }"); |
| valid ("a: { ; }"); |
| invalid("{ a: }"); |
| valid ("{} f; { 6 + f() }"); |
| valid ("{ a[5],6; {} ++b-new (-5)() } c().l++"); |
| valid ("{ l1: l2: l3: { this } a = 32 ; { i++ ; { { { } } ++i } } }"); |
| valid ("if (a) ;"); |
| invalid("{ if (a) }"); |
| invalid("if a {}"); |
| invalid("if (a"); |
| invalid("if (a { }"); |
| valid ("x: s: if (a) ; else b"); |
| invalid("else {}"); |
| valid ("if (a) if (b) y; else {} else ;"); |
| invalid("if (a) {} else x; else"); |
| invalid("if (a) { else }"); |
| valid ("if (a.l + new b()) 4 + 5 - f()"); |
| valid ("if (a) with (x) ; else with (y) ;"); |
| invalid("with a.b { }"); |
| valid ("while (a() - new b) ;"); |
| invalid("while a {}"); |
| valid ("do ; while(0) i++"); // Is this REALLY valid? (Firefox also accepts this) |
| valid ("do if (a) x; else y; while(z)"); |
| invalid("do g; while 4"); |
| invalid("do g; while ((4)"); |
| valid ("{ { do do do ; while(0) while(0) while(0) } }"); |
| valid ("do while (0) if (a) {} else y; while(0)"); |
| valid ("if (a) while (b) if (c) with(d) {} else e; else f"); |
| invalid("break ; break your_limits ; continue ; continue living ; debugger"); |
| invalid("debugger X"); |
| invalid("break 0.2"); |
| invalid("continue a++"); |
| invalid("continue (my_friend)"); |
| valid ("while (1) break"); |
| valid ("do if (a) with (b) continue; else debugger; while (false)"); |
| invalid("do if (a) while (false) else debugger"); |
| invalid("while if (a) ;"); |
| valid ("if (a) function f() {} else function g() {}"); |
| valid ("if (a()) while(0) function f() {} else function g() {}"); |
| invalid("if (a()) function f() { else function g() }"); |
| invalid("if (a) if (b) ; else function f {}"); |
| invalid("if (a) if (b) ; else function (){}"); |
| valid ("throw a"); |
| valid ("throw a + b in void c"); |
| invalid("throw"); |
| |
| debug ("var and const statements"); |
| |
| valid ("var a, b = null"); |
| valid ("const a = 5, b = 10, c = 20"); |
| invalid("var"); |
| invalid("var = 7"); |
| invalid("var c (6)"); |
| valid ("if (a) var a,b; else { const b = 1, c = 2; }"); |
| invalid("if (a) var a,b; else { const b, c }"); |
| invalid("var 5 = 6"); |
| valid ("while (0) var a, b, c=6, d, e, f=5*6, g=f*h, h"); |
| invalid("var a = if (b) { c }"); |
| invalid("var a = var b"); |
| invalid("const a = b += c, a, a, a = (b - f())"); |
| invalid("var a %= b | 5"); |
| invalid("var (a) = 5"); |
| invalid("var a = (4, b = 6"); |
| invalid("const 'l' = 3"); |
| invalid("var var = 3"); |
| valid ("var varr = 3 in 1"); |
| valid ("const a = void 7 - typeof 8, b = 8"); |
| invalid("const a, a, a = void 7 - typeof 8, a = 8"); |
| valid ("const x_x = 6 /= 7 ? e : f"); |
| invalid("var a = ?"); |
| invalid("const a = *7"); |
| invalid("var a = :)"); |
| valid ("var a = a in b in c instanceof d"); |
| invalid("var a = b ? c, b"); |
| invalid("const a = b : c"); |
| valid("const a = 7; eval(''); a++"); |
| valid("const a = 7; eval(''); a--"); |
| valid("const a = 7; with({}) a++"); |
| valid("const a = 7; with({}) a--"); |
| valid("const a = 7; eval(''); a+=1"); |
| valid("const a = 7; eval(''); a-=1"); |
| valid("const a = 7; with({}) a+=1"); |
| valid("const a = 7; with({}) a-=1"); |
| valid("const a = 7; eval(''); a=1"); |
| valid("const a = 7; eval(''); a=1"); |
| valid("const a = 7; with({}) a=1"); |
| valid("const a = 7; with({}) a=1"); |
| |
| |
| debug ("for statement"); |
| |
| valid ("for ( ; ; ) { break }"); |
| valid ("for ( a ; ; ) { break }"); |
| valid ("for ( ; a ; ) { break }"); |
| valid ("for ( ; ; a ) { break }"); |
| valid ("for ( a ; a ; ) break"); |
| valid ("for ( a ; ; a ) break"); |
| valid ("for ( ; a ; a ) break"); |
| invalid("for () { }"); |
| invalid("for ( a ) { }"); |
| invalid("for ( ; ) ;"); |
| invalid("for a ; b ; c { }"); |
| invalid("for (a ; { }"); |
| invalid("for ( a ; ) ;"); |
| invalid("for ( ; a ) break"); |
| valid ("for (var a, b ; ; ) { break } "); |
| valid ("for (var a = b, b = a ; ; ) break"); |
| valid ("for (var a = b, c, d, b = a ; x in b ; ) { break }"); |
| valid ("for (var a = b, c, d ; ; 1 in a()) break"); |
| invalid("for ( ; var a ; ) break"); |
| invalid("for (const x; ; ) break"); |
| invalid("for (const x = 20, y; ; ) break"); |
| valid ("for (const x = 20; ; ) break"); |
| valid ("for (const x of []) break"); |
| valid ("for (const x in {}) break"); |
| invalid("for (const x = 20, x = 30; ; ) { const x = 20; break; }"); |
| valid ("for (const x = 20; ; ) { const x = 20; break; }"); |
| valid ("for (const x of []) { const x = 20; break; }"); |
| valid ("for (const x in {}) { const x = 20; break; }"); |
| invalid("for (const let = 10; ; ) { break; }"); |
| invalid("for (const let in {}) { break; }"); |
| invalid("for (const let of []) { break; }"); |
| invalid("for (let let = 10; ; ) { break; }"); |
| invalid("for (let let in {}) { break; }"); |
| invalid("for (let let of []) { break; }"); |
| invalid("for ( %a ; ; ) { }"); |
| valid ("for (a in b) break"); |
| valid ("for (a() in b) break"); |
| valid ("for (a().l[4] in b) break"); |
| valid ("for (new a in b in c in d) break"); |
| valid ("for (new new new a in b) break"); |
| invalid("for (delete new a() in b) break"); |
| invalid("for (a * a in b) break"); |
| valid ("for ((a * a) in b) break"); |
| invalid("for (a++ in b) break"); |
| valid ("for ((a++) in b) break"); |
| invalid("for (++a in b) break"); |
| valid ("for ((++a) in b) break"); |
| invalid("for (a, b in c) break"); |
| invalid("for (a,b in c ;;) break"); |
| valid ("for (a,(b in c) ;;) break"); |
| valid ("for ((a, b) in c) break"); |
| invalid("for (a ? b : c in c) break"); |
| valid ("for ((a ? b : c) in c) break"); |
| valid ("for (var a in b in c) break"); |
| valid("for (var a = 5 += 6 in b) break"); |
| valid("for (var a = debug('should not be hit') in b) break"); |
| invalid("for (var a += 5 in b) break"); |
| invalid("for (var a = in b) break"); |
| invalid("for (var a, b in b) break"); |
| invalid("for (var a = -6, b in b) break"); |
| invalid("for (var a, b = 8 in b) break"); |
| valid("for (var a = (b in c) in d) break"); |
| invalid("for (var a = (b in c in d) break"); |
| invalid("for (var (a) in b) { }"); |
| valid ("for (var a = 7, b = c < d >= d ; f()[6]++ ; --i()[1]++ ) {}"); |
| |
| debug ("try statement"); |
| |
| invalid("try { break } catch(e) {}"); |
| valid ("try {} finally { c++ }"); |
| valid ("try { with (x) { } } catch(e) {} finally { if (a) ; }"); |
| invalid("try {}"); |
| invalid("catch(e) {}"); |
| invalid("finally {}"); |
| invalid("try a; catch(e) {}"); |
| invalid("try {} catch(e) a()"); |
| invalid("try {} finally a()"); |
| invalid("try {} catch(e)"); |
| invalid("try {} finally"); |
| invalid("try {} finally {} catch(e) {}"); |
| invalid("try {} catch (...) {}"); |
| invalid("try {} catch {}"); |
| valid ("if (a) try {} finally {} else b;"); |
| valid ("if (--a()) do with(1) try {} catch(ke) { f() ; g() } while (a in b) else {}"); |
| invalid("if (a) try {} else b; catch (e) { }"); |
| invalid("try { finally {}"); |
| |
| debug ("switch statement"); |
| |
| valid ("switch (a) {}"); |
| invalid("switch () {}"); |
| invalid("case 5:"); |
| invalid("default:"); |
| invalid("switch (a) b;"); |
| invalid("switch (a) case 3: b;"); |
| valid ("switch (f()) { case 5 * f(): default: case '6' - 9: ++i }"); |
| invalid("switch (true) { default: case 6: default: }"); |
| invalid("switch (l) { f(); }"); |
| invalid("switch (l) { case 1: ; a: case 5: }"); |
| valid ("switch (g() - h[5].l) { case 1 + 6: a: b: c: ++f }"); |
| invalid("switch (g) { case 1: a: }"); |
| invalid("switch (g) { case 1: a: default: }"); |
| invalid("switch g { case 1: l() }"); |
| invalid("switch (g) { case 1:"); |
| valid ("switch (l) { case a = b ? c : d : }"); |
| valid ("switch (sw) { case a ? b - 7[1] ? [c,,] : d = 6 : { } : }"); |
| invalid("switch (l) { case b ? c : }"); |
| valid ("switch (l) { case 1: a: with(g) switch (g) { case 2: default: } default: }"); |
| invalid("switch (4 - ) { }"); |
| invalid("switch (l) { default case: 5; }"); |
| |
| invalid("L: L: ;"); |
| invalid("L: L1: L: ;"); |
| invalid("L: L1: L2: L3: L4: L: ;"); |
| |
| invalid("for(var a,b 'this shouldn\'t be allowed' false ; ) ;"); |
| invalid("for(var a,b '"); |
| |
| valid("function __proto__(){}") |
| valid("(function __proto__(){})") |
| valid("'use strict'; function __proto__(){}") |
| valid("'use strict'; (function __proto__(){})") |
| |
| valid("'use strict'; function f1(a) { function f2(b) { return b; } return f2(a); } f1(5);") |
| valid("'use strict'; function f1(a) { function f2(b) { function f3(c) { return c; } return f3(b); } return f2(a); } f1(5);") |
| invalid("'use strict'; function f1(a) { if (a) { function f2(b) { return b; } return f2(a); } else return a; } f1(5);") |
| invalid("'use strict'; function f1(a) { function f2(b) { if (b) { function f3(c) { return c; } return f3(b); } else return b; } return f2(a); } f1(5);") |
| |
| valid("var str = \"'use strict'; function f1(a) { function f2(b) { return b; } return f2(a); } return f1(arguments[0]);\"; var foo = new Function(str); foo(5);") |
| valid("var str = \"'use strict'; function f1(a) { function f2(b) { function f3(c) { return c; } return f3(b); } return f2(a); } return f1(arguments[0]);\"; var foo = new Function(str); foo(5);") |
| invalid("var str = \"'use strict'; function f1(a) { if (a) { function f2(b) { return b; } return f2(a); } else return a; } return f1(arguments[0]);\"; var foo = new Function(str); foo(5);", SyntaxError, undefined) |
| invalid("var str = \"'use strict'; function f1(a) { function f2(b) { if (b) { function f3(c) { return c; } return f3(b); } else return b; } return f2(a); } return f1(arguments[0]);\"; var foo = new Function(str); foo(5);", SyntaxError, undefined) |
| |
| valid("if (0) $foo; ") |
| valid("if (0) _foo; ") |
| valid("if (0) foo$; ") |
| valid("if (0) foo_; ") |
| valid("if (0) obj.$foo; ") |
| valid("if (0) obj._foo; ") |
| valid("if (0) obj.foo$; ") |
| valid("if (0) obj.foo_; ") |
| valid("if (0) obj.foo\\u03bb; ") |
| valid("if (0) new a(b+c).d = 5"); |
| valid("if (0) new a(b+c) = 5"); |
| valid("([1 || 1].a = 1)"); |
| valid("({a: 1 || 1}.a = 1)"); |
| |
| invalid("var a.b = c"); |
| invalid("var a.b;"); |
| |
| valid("for (of of of){}") |
| valid("for (of; of; of){}") |
| valid("for (var of of of){}") |
| valid("for (var of; of; of){}") |
| invalid("for (var of.of of of){}") |
| invalid("for (var of[of] of of){}") |
| valid("for (of.of of of){}") |
| valid("for (of[of] of of){}") |
| valid("for (var [of] of of){}") |
| valid("for (var {of} of of){}") |
| valid("for (of in of){}") |
| valid("for (var of in of){}") |
| invalid("for (var of.of in of){}") |
| valid("for (of.of in of){}") |
| valid("for (of[of] in of){}") |
| invalid("for (var of[of] in of){}") |
| valid("for (var [of] in of){}") |
| valid("for (var {of} in of){}") |
| valid("for ([of] in of){}") |
| valid("for ({of} in of){}") |
| invalid("for (var of = x of of){}") |
| invalid("for (var {of} = x of of){}") |
| invalid("for (var [of] = x of of){}") |
| |
| |
| invalid("for (of of of of){}") |
| invalid("for (of of; of; of){}") |
| invalid("for (of of []; of; of){}") |
| invalid("for (of of){}") |
| invalid("for (var of of){}") |
| invalid("for (of of in of){}") |
| invalid("for (of in){}") |
| invalid("for (var of in){}") |
| |
| debug("spread operator") |
| valid("foo(...bar)") |
| valid("o.foo(...bar)") |
| valid("o[foo](...bar)") |
| valid("new foo(...bar)") |
| valid("new o.foo(...bar)") |
| valid("new o[foo](...bar)") |
| invalid("foo(...)") |
| invalid("o.foo(...)") |
| invalid("o[foo](...)") |
| invalid("foo(bar...)") |
| invalid("o.foo(bar...)") |
| invalid("o[foo](bar...)") |
| invalid("foo(a,...bar)") |
| invalid("o.foo(a,...bar)") |
| invalid("o[foo](a,...bar)") |
| invalid("foo(...bar, a)") |
| invalid("o.foo(...bar, a)") |
| invalid("o[foo](...bar, a)") |
| valid("[...bar]") |
| valid("[a, ...bar]") |
| valid("[...bar, a]") |
| valid("[...bar,,,,]") |
| valid("[,,,,...bar]") |
| valid("({1: x})") |
| valid("({1: x}=1)") |
| valid("({1: x}=null)") |
| valid("({1: x})") |
| valid("({1: x}=1)") |
| valid("({1: x}=null)") |
| valid("({a: b}=null)") |
| valid("'use strict'; ({1: x})") |
| valid("'use strict'; ({1: x}=1)") |
| valid("'use strict'; ({1: x}=null)") |
| valid("'use strict'; ({a: b}=null)") |
| valid("var {1:x}=1") |
| valid("var {x}=1") |
| valid("var {x, y}=1") |
| valid("var [x]=1") |
| valid("var [x, y]=1") |
| valid("[x]=1") |
| valid("var [x]=1") |
| valid("({[x]: 1})") |
| valid("delete ({a}=1)") |
| valid("delete ({a:a}=1)") |
| valid("({a}=1)()") |
| valid("({a:a}=1)()") |
| valid("({a}=1)=1") |
| valid("({a:a}=1)=1") |
| valid("({a}=1=1)") |
| valid("({a:a}=1=1)") |
| invalid("var {x}") |
| invalid("var {x, y}") |
| invalid("var {x} = 20, {x, y}") |
| invalid("var {foo:bar, bar:baz}") |
| invalid("var [x]") |
| invalid("var [x, y]") |
| invalid("var [x] = [], [x, y]") |
| valid("({get x(){}})") |
| valid("({set x(x){}})") |
| invalid("({get x(a){}})") |
| invalid("({get x(a,b){}})") |
| invalid("({set x(){}})") |
| invalid("({set x(a,b){}})") |
| valid("({get [x](){}})") |
| invalid("({get [x (){}})") |
| invalid("({set [x](){}})") |
| valid("({set [x](x){}})") |
| invalid("({set [x (x){}})") |
| invalid("({[...x]: 1})") |
| invalid("function f({a, a}) {}"); |
| invalid("function f({a}, a) {}"); |
| invalid("function f([b, b]) {}"); |
| invalid("function f([b], b) {}"); |
| invalid("function f({a: {b}}, b) {}"); |
| valid("function f(a, b = 20) {}"); |
| valid("function f(a = 20, b = a) {}"); |
| valid("function f({a = 20} = {a: 40}, b = a) {}"); |
| valid("function f([a,b,c] = [1,2,3]) {}"); |
| invalid("function f(a, a=20) {}"); |
| invalid("function f({a} = 20, a=20) {}"); |
| invalid("function f([a,b,a] = [1,2,3]) {}"); |
| invalid("function f([a,b,c] = [1,2,3], a) {}"); |
| invalid("function f([a,b,c] = [1,2,3], {a}) {}"); |
| valid("( function(){ return this || eval('this'); }().x = 'y' )"); |
| invalid("function(){ return this || eval('this'); }().x = 'y'"); |
| invalid("1 % +"); |
| invalid("1 % -"); |
| invalid("1 % typeof"); |
| invalid("1 % void"); |
| invalid("1 % !"); |
| invalid("1 % ~"); |
| invalid("1 % delete"); |
| invalid("1 % ++"); |
| invalid("1 % --"); |
| invalid("1 % \n++"); |
| invalid("1 % \n--"); |
| |
| debug("Rest parameter"); |
| valid("function foo(...a) { }"); |
| valid("function foo(a, ...b) { }"); |
| valid("function foo(a = 20, ...b) { }"); |
| valid("function foo(a, b, c, d, e, f, g, ...h) { }"); |
| invalid("function foo(a, ...b, c) { }") |
| invalid("function foo(a, ...b, ) { }") |
| invalid("function foo(a, ...a) { }"); |
| invalid("function foo(...a, ...b) { }"); |
| invalid("function foo(...b, ...b) { }"); |
| invalid("function foo(...b ...b) { }"); |
| invalid("function foo(a, a, ...b) { }"); |
| invalid("function foo(...{b}) { }"); |
| invalid("function foo(...[b]) { }"); |
| invalid("function foo(...123) { }"); |
| invalid("function foo(...123abc) { }"); |
| valid("function foo(...abc123) { }"); |
| valid("function foo(...let) { }"); |
| invalid("'use strict'; function foo(...let) { }"); |
| valid("function foo(...yield) { }"); |
| invalid("'use strict'; function foo(...yield) { }"); |
| invalid("function foo(...if) { }"); |
| |
| |
| |
| try { eval("a.b.c = {};"); } catch(e1) { e=e1; shouldBe("e.line", "1") } |
| foo = 'FAIL'; |
| bar = 'PASS'; |
| try { |
| eval("foo = 'PASS'; a.b.c = {}; bar = 'FAIL';"); |
| } catch(e) { |
| shouldBe("foo", "'PASS'"); |
| shouldBe("bar", "'PASS'"); |
| } |