Bug 1096378 - Disallow duplicated parameter in method definition. r=jorendorff

This commit is contained in:
Tooru Fujisawa 2015-02-04 01:25:33 +09:00
parent 09771b2a17
commit 3a46343337
2 changed files with 20 additions and 1 deletions

View File

@ -1624,7 +1624,7 @@ Parser<ParseHandler>::functionArguments(FunctionSyntaxKind kind, FunctionType ty
bool hasDefaults = false; bool hasDefaults = false;
Node duplicatedArg = null(); Node duplicatedArg = null();
Node list = null(); Node list = null();
bool disallowDuplicateArgs = kind == Arrow; bool disallowDuplicateArgs = kind == Arrow || kind == Method;
if (type == Getter) { if (type == Getter) {
report(ParseError, false, null(), JSMSG_ACCESSOR_WRONG_ARGS, "getter", "no", "s"); report(ParseError, false, null(), JSMSG_ACCESSOR_WRONG_ARGS, "getter", "no", "s");

View File

@ -0,0 +1,19 @@
// Make sure duplicated name is allowed in non-strict.
function f0(a) {
}
// SyntaxError should be thrown if method definition has duplicated name.
assertThrowsInstanceOf(() => eval(`
({
m1(a, a) {
}
});
`), SyntaxError);
assertThrowsInstanceOf(() => eval(`
({
m2(a, ...a) {
}
});
`), SyntaxError);
reportCompare(0, 0, 'ok');