js/src/tests/js1_8/regress/regress-499524.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/js1_8/regress/regress-499524.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,50 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +
     1.6 +/*
     1.7 + * Any copyright is dedicated to the Public Domain.
     1.8 + * http://creativecommons.org/licenses/publicdomain/
     1.9 + */
    1.10 +
    1.11 +function isSyntaxError(code) {
    1.12 +  try {
    1.13 +    eval(code);
    1.14 +    return false;
    1.15 +  } catch (exception) {
    1.16 +    if (SyntaxError.prototype.isPrototypeOf(exception))
    1.17 +      return true;
    1.18 +    throw exception;
    1.19 +  };
    1.20 +};
    1.21 +
    1.22 +/* 
    1.23 + * Duplicate parameter names must be tolerated (as per ES3), unless
    1.24 + * the parameter list uses destructuring, in which case we claim the
    1.25 + * user has opted in to a modicum of sanity, and we forbid duplicate
    1.26 + * parameter names.
    1.27 + */
    1.28 +assertEq(isSyntaxError("function f(x,x){}"),                false);
    1.29 +
    1.30 +assertEq(isSyntaxError("function f(x,[x]){})"),             true);
    1.31 +assertEq(isSyntaxError("function f(x,{y:x}){})"),           true);
    1.32 +assertEq(isSyntaxError("function f(x,{x}){})"),             true);
    1.33 +
    1.34 +assertEq(isSyntaxError("function f([x],x){})"),             true);
    1.35 +assertEq(isSyntaxError("function f({y:x},x){})"),           true);
    1.36 +assertEq(isSyntaxError("function f({x},x){})"),             true);
    1.37 +
    1.38 +assertEq(isSyntaxError("function f([x,x]){}"),              true);
    1.39 +assertEq(isSyntaxError("function f({x,x}){}"),              true);
    1.40 +assertEq(isSyntaxError("function f({y:x,z:x}){}"),          true);
    1.41 +
    1.42 +assertEq(isSyntaxError("function f(x,x,[y]){}"),            true);
    1.43 +assertEq(isSyntaxError("function f(x,x,{y}){}"),            true);
    1.44 +assertEq(isSyntaxError("function f([y],x,x){}"),            true);
    1.45 +assertEq(isSyntaxError("function f({y},x,x){}"),            true);
    1.46 +
    1.47 +assertEq(isSyntaxError("function f(a,b,c,d,e,f,g,h,b,[y]){}"),  true);
    1.48 +assertEq(isSyntaxError("function f([y],a,b,c,d,e,f,g,h,a){}"),  true);
    1.49 +assertEq(isSyntaxError("function f([a],b,c,d,e,f,g,h,i,a){}"),  true);
    1.50 +assertEq(isSyntaxError("function f(a,b,c,d,e,f,g,h,i,[a]){}"),  true);
    1.51 +assertEq(isSyntaxError("function f(a,b,c,d,e,f,g,h,i,[a]){}"),  true);
    1.52 +
    1.53 +reportCompare(true, true);

mercurial