|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 |
|
3 /* |
|
4 * Any copyright is dedicated to the Public Domain. |
|
5 * http://creativecommons.org/licenses/publicdomain/ |
|
6 */ |
|
7 |
|
8 function isSyntaxError(code) { |
|
9 try { |
|
10 eval(code); |
|
11 return false; |
|
12 } catch (exception) { |
|
13 if (SyntaxError.prototype.isPrototypeOf(exception)) |
|
14 return true; |
|
15 throw exception; |
|
16 }; |
|
17 }; |
|
18 |
|
19 /* |
|
20 * Duplicate parameter names must be tolerated (as per ES3), unless |
|
21 * the parameter list uses destructuring, in which case we claim the |
|
22 * user has opted in to a modicum of sanity, and we forbid duplicate |
|
23 * parameter names. |
|
24 */ |
|
25 assertEq(isSyntaxError("function f(x,x){}"), false); |
|
26 |
|
27 assertEq(isSyntaxError("function f(x,[x]){})"), true); |
|
28 assertEq(isSyntaxError("function f(x,{y:x}){})"), true); |
|
29 assertEq(isSyntaxError("function f(x,{x}){})"), true); |
|
30 |
|
31 assertEq(isSyntaxError("function f([x],x){})"), true); |
|
32 assertEq(isSyntaxError("function f({y:x},x){})"), true); |
|
33 assertEq(isSyntaxError("function f({x},x){})"), true); |
|
34 |
|
35 assertEq(isSyntaxError("function f([x,x]){}"), true); |
|
36 assertEq(isSyntaxError("function f({x,x}){}"), true); |
|
37 assertEq(isSyntaxError("function f({y:x,z:x}){}"), true); |
|
38 |
|
39 assertEq(isSyntaxError("function f(x,x,[y]){}"), true); |
|
40 assertEq(isSyntaxError("function f(x,x,{y}){}"), true); |
|
41 assertEq(isSyntaxError("function f([y],x,x){}"), true); |
|
42 assertEq(isSyntaxError("function f({y},x,x){}"), true); |
|
43 |
|
44 assertEq(isSyntaxError("function f(a,b,c,d,e,f,g,h,b,[y]){}"), true); |
|
45 assertEq(isSyntaxError("function f([y],a,b,c,d,e,f,g,h,a){}"), true); |
|
46 assertEq(isSyntaxError("function f([a],b,c,d,e,f,g,h,i,a){}"), true); |
|
47 assertEq(isSyntaxError("function f(a,b,c,d,e,f,g,h,i,[a]){}"), true); |
|
48 assertEq(isSyntaxError("function f(a,b,c,d,e,f,g,h,i,[a]){}"), true); |
|
49 |
|
50 reportCompare(true, true); |