michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: michael@0: /* michael@0: * Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/licenses/publicdomain/ michael@0: */ michael@0: michael@0: function isSyntaxError(code) { michael@0: try { michael@0: eval(code); michael@0: return false; michael@0: } catch (exception) { michael@0: if (SyntaxError.prototype.isPrototypeOf(exception)) michael@0: return true; michael@0: throw exception; michael@0: }; michael@0: }; michael@0: michael@0: /* michael@0: * Duplicate parameter names must be tolerated (as per ES3), unless michael@0: * the parameter list uses destructuring, in which case we claim the michael@0: * user has opted in to a modicum of sanity, and we forbid duplicate michael@0: * parameter names. michael@0: */ michael@0: assertEq(isSyntaxError("function f(x,x){}"), false); michael@0: michael@0: assertEq(isSyntaxError("function f(x,[x]){})"), true); michael@0: assertEq(isSyntaxError("function f(x,{y:x}){})"), true); michael@0: assertEq(isSyntaxError("function f(x,{x}){})"), true); michael@0: michael@0: assertEq(isSyntaxError("function f([x],x){})"), true); michael@0: assertEq(isSyntaxError("function f({y:x},x){})"), true); michael@0: assertEq(isSyntaxError("function f({x},x){})"), true); michael@0: michael@0: assertEq(isSyntaxError("function f([x,x]){}"), true); michael@0: assertEq(isSyntaxError("function f({x,x}){}"), true); michael@0: assertEq(isSyntaxError("function f({y:x,z:x}){}"), true); michael@0: michael@0: assertEq(isSyntaxError("function f(x,x,[y]){}"), true); michael@0: assertEq(isSyntaxError("function f(x,x,{y}){}"), true); michael@0: assertEq(isSyntaxError("function f([y],x,x){}"), true); michael@0: assertEq(isSyntaxError("function f({y},x,x){}"), true); michael@0: michael@0: assertEq(isSyntaxError("function f(a,b,c,d,e,f,g,h,b,[y]){}"), true); michael@0: assertEq(isSyntaxError("function f([y],a,b,c,d,e,f,g,h,a){}"), true); michael@0: assertEq(isSyntaxError("function f([a],b,c,d,e,f,g,h,i,a){}"), true); michael@0: assertEq(isSyntaxError("function f(a,b,c,d,e,f,g,h,i,[a]){}"), true); michael@0: assertEq(isSyntaxError("function f(a,b,c,d,e,f,g,h,i,[a]){}"), true); michael@0: michael@0: reportCompare(true, true);