Improve error message for duplicate parameters

Duplicate parameters are banned both overall in strict mode and also
in arrow functions. Our error message for both cases blamed strict
mode, which is confusing. This patch fixes the message to point to
arrow functions as a possible source as well.

R=wingo, adamk
LOG=N

Review URL: https://codereview.chromium.org/1236863008

Cr-Commit-Position: refs/heads/master@{#29662}
This commit is contained in:
littledan 2015-07-14 14:58:49 -07:00 committed by Commit bot
parent 9d6ab46aef
commit 5c036cd772
7 changed files with 18 additions and 11 deletions

View File

@ -157,8 +157,7 @@ class ExpressionClassifier {
if (!is_valid_formal_parameter_list_without_duplicates()) return;
invalid_productions_ |= DistinctFormalParametersProduction;
duplicate_formal_parameter_error_.location = loc;
duplicate_formal_parameter_error_.message =
MessageTemplate::kStrictParamDupe;
duplicate_formal_parameter_error_.message = MessageTemplate::kParamDupe;
duplicate_formal_parameter_error_.arg = nullptr;
}

View File

@ -297,8 +297,6 @@ class CallSite {
T(ConstructorIsGenerator, "Class constructor may not be a generator") \
T(DerivedConstructorReturn, \
"Derived constructors may only return object or undefined") \
T(DuplicateArrawFunFormalParam, \
"Arrow function may not have duplicate parameter names") \
T(DuplicateConstructor, "A class may only have one constructor") \
T(DuplicateExport, "Duplicate export of '%'") \
T(DuplicateProto, \
@ -335,6 +333,7 @@ class CallSite {
T(ParamAfterRest, "Rest parameter must be last formal parameter") \
T(BadSetterRestParameter, \
"Setter function argument must not be a rest parameter") \
T(ParamDupe, "Duplicate parameter name not allowed in this context") \
T(ParenthesisInArgString, "Function arg string contains parenthesis") \
T(SingleFunctionLiteral, "Single function literal required") \
T(SloppyLexical, \
@ -346,8 +345,6 @@ class CallSite {
"In strict mode code, functions can only be declared at top level or " \
"immediately within another function.") \
T(StrictOctalLiteral, "Octal literals are not allowed in strict mode.") \
T(StrictParamDupe, \
"Strict mode function may not have duplicate parameter names") \
T(StrictWith, "Strict mode code may not include a with statement") \
T(StrongArguments, \
"In strong mode, 'arguments' is deprecated, use '...args' instead") \

View File

@ -2057,7 +2057,7 @@ Variable* Parser::Declare(Declaration* declaration,
if (declaration_kind == DeclarationDescriptor::NORMAL) {
ParserTraits::ReportMessage(MessageTemplate::kVarRedeclaration, name);
} else {
ParserTraits::ReportMessage(MessageTemplate::kStrictParamDupe);
ParserTraits::ReportMessage(MessageTemplate::kParamDupe);
}
*ok = false;
return nullptr;

View File

@ -0,0 +1,7 @@
// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-arrow-functions
(b, a, a, d) => a

View File

@ -0,0 +1,4 @@
*%(basename)s:7: SyntaxError: Duplicate parameter name not allowed in this context
(b, a, a, d) => a
^
SyntaxError: Duplicate parameter name not allowed in this context

View File

@ -1,4 +1,4 @@
*%(basename)s:6: SyntaxError: Strict mode function may not have duplicate parameter names
*%(basename)s:6: SyntaxError: Duplicate parameter name not allowed in this context
function foo(b, a, a, d) { return a }
^
SyntaxError: Strict mode function may not have duplicate parameter names
SyntaxError: Duplicate parameter name not allowed in this context

View File

@ -69,8 +69,8 @@ PASS (function (){'use strict'; try{}catch(eval){}}) threw exception SyntaxError
PASS (function(){(function (){'use strict'; try{}catch(eval){}})}) threw exception SyntaxError: Unexpected eval or arguments in strict mode.
PASS (function (){'use strict'; try{}catch(arguments){}}) threw exception SyntaxError: Unexpected eval or arguments in strict mode.
PASS (function(){(function (){'use strict'; try{}catch(arguments){}})}) threw exception SyntaxError: Unexpected eval or arguments in strict mode.
PASS (function (a, a){'use strict';}) threw exception SyntaxError: Strict mode function may not have duplicate parameter names.
PASS (function(){(function (a, a){'use strict';})}) threw exception SyntaxError: Strict mode function may not have duplicate parameter names.
PASS (function (a, a){'use strict';}) threw exception SyntaxError: Duplicate parameter name not allowed in this context.
PASS (function(){(function (a, a){'use strict';})}) threw exception SyntaxError: Duplicate parameter name not allowed in this context.
PASS (function (a){'use strict'; delete a;})() threw exception SyntaxError: Delete of an unqualified identifier in strict mode..
PASS (function(){(function (a){'use strict'; delete a;})()}) threw exception SyntaxError: Delete of an unqualified identifier in strict mode..
PASS (function (){'use strict'; var a; delete a;})() threw exception SyntaxError: Delete of an unqualified identifier in strict mode..