From 7786487bbe0c5ee43a287dfb820582cf9267d12f Mon Sep 17 00:00:00 2001 From: Tooru Fujisawa Date: Tue, 3 Feb 2015 14:59:32 +0900 Subject: [PATCH] Bug 1096377 - Disallow duplicated parameter in arrow functions. r=jorendorff --- js/src/frontend/Parser.cpp | 2 +- .../tests/ecma_6/Function/arrow-has-duplicated.js | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 js/src/tests/ecma_6/Function/arrow-has-duplicated.js diff --git a/js/src/frontend/Parser.cpp b/js/src/frontend/Parser.cpp index 23a196dcb2ac..864c967cf391 100644 --- a/js/src/frontend/Parser.cpp +++ b/js/src/frontend/Parser.cpp @@ -1624,7 +1624,7 @@ Parser::functionArguments(FunctionSyntaxKind kind, FunctionType ty bool hasDefaults = false; Node duplicatedArg = null(); Node list = null(); - bool disallowDuplicateArgs = false; + bool disallowDuplicateArgs = kind == Arrow; if (type == Getter) { report(ParseError, false, null(), JSMSG_ACCESSOR_WRONG_ARGS, "getter", "no", "s"); diff --git a/js/src/tests/ecma_6/Function/arrow-has-duplicated.js b/js/src/tests/ecma_6/Function/arrow-has-duplicated.js new file mode 100644 index 000000000000..19096ebf885a --- /dev/null +++ b/js/src/tests/ecma_6/Function/arrow-has-duplicated.js @@ -0,0 +1,15 @@ +// Make sure duplicated name is allowed in non-strict. +function f0(a, a) { +} + +// SyntaxError should be thrown if arrow function has duplicated name. +assertThrowsInstanceOf(() => eval(` +(a, a) => { +}; +`), SyntaxError); +assertThrowsInstanceOf(() => eval(` +(a, ...a) => { +}; +`), SyntaxError); + +reportCompare(0, 0, 'ok');