Commit b64e13b0 authored by dslomov's avatar dslomov Committed by Commit bot

[destructuring] Refactor duplicate parameter name detection.

Pushed the detection logic down to ParseAndClassifyIdentifier in
preparation to having patterns in parameter positions.

R=arv@chromium.org,rossberg@chromium.org,wingo@igalia.com
BUG=v8:811
LOG=N

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

Cr-Commit-Position: refs/heads/master@{#28876}
parent 08a09d1b
......@@ -782,6 +782,7 @@ source_set("v8_base") {
"src/elements.h",
"src/execution.cc",
"src/execution.h",
"src/expression-classifier.h",
"src/extensions/externalize-string-extension.cc",
"src/extensions/externalize-string-extension.h",
"src/extensions/free-buffer-extension.cc",
......
This diff is collapsed.
......@@ -3805,11 +3805,9 @@ void ParserTraits::DeclareArrowFunctionParameters(
parser_->scope_->RemoveUnresolved(expr->AsVariableProxy());
bool is_rest = false;
bool is_duplicate = DeclareFormalParameter(scope, raw_name, is_rest);
if (is_duplicate && !duplicate_loc->IsValid()) {
*duplicate_loc = param_location;
}
ExpressionClassifier classifier;
DeclareFormalParameter(scope, raw_name, &classifier, is_rest);
*duplicate_loc = classifier.duplicate_formal_parameter_error().location;
}
......
......@@ -754,19 +754,9 @@ class ParserTraits {
V8_INLINE Scope* NewScope(Scope* parent_scope, ScopeType scope_type,
FunctionKind kind = kNormalFunction);
bool DeclareFormalParameter(Scope* scope, const AstRawString* name,
bool is_rest) {
bool is_duplicate = false;
Variable* var = scope->DeclareParameter(name, VAR, is_rest, &is_duplicate);
if (is_sloppy(scope->language_mode())) {
// TODO(sigurds) Mark every parameter as maybe assigned. This is a
// conservative approximation necessary to account for parameters
// that are assigned via the arguments array.
var->set_maybe_assigned();
}
return is_duplicate;
}
V8_INLINE void DeclareFormalParameter(Scope* scope, const AstRawString* name,
ExpressionClassifier* classifier,
bool is_rest);
void DeclareArrowFunctionParameters(Scope* scope, Expression* expr,
const Scanner::Location& params_loc,
Scanner::Location* duplicate_loc,
......@@ -1282,6 +1272,25 @@ Expression* ParserTraits::SpreadCallNew(
Expression* function, ZoneList<v8::internal::Expression*>* args, int pos) {
return parser_->SpreadCallNew(function, args, pos);
}
void ParserTraits::DeclareFormalParameter(Scope* scope,
const AstRawString* name,
ExpressionClassifier* classifier,
bool is_rest) {
bool is_duplicate = false;
Variable* var = scope->DeclareParameter(name, VAR, is_rest, &is_duplicate);
if (is_sloppy(scope->language_mode())) {
// TODO(sigurds) Mark every parameter as maybe assigned. This is a
// conservative approximation necessary to account for parameters
// that are assigned via the arguments array.
var->set_maybe_assigned();
}
if (is_duplicate) {
classifier->RecordDuplicateFormalParameterError(
parser_->scanner()->location());
}
}
} } // namespace v8::internal
#endif // V8_PARSER_H_
......@@ -1033,18 +1033,15 @@ PreParser::Expression PreParser::ParseFunctionLiteral(
PreParserFactory factory(NULL);
FunctionState function_state(&function_state_, &scope_, function_scope, kind,
&factory);
ExpressionClassifier formals_classifier;
DuplicateFinder duplicate_finder(scanner()->unicode_cache());
ExpressionClassifier formals_classifier(&duplicate_finder);
bool has_rest = false;
Expect(Token::LPAREN, CHECK_OK);
int start_position = scanner()->location().beg_pos;
function_scope->set_start_position(start_position);
int num_parameters;
{
DuplicateFinder duplicate_finder(scanner()->unicode_cache());
num_parameters = ParseFormalParameterList(&duplicate_finder, &has_rest,
&formals_classifier, CHECK_OK);
}
int num_parameters = ParseFormalParameterList(nullptr, &has_rest,
&formals_classifier, CHECK_OK);
Expect(Token::RPAREN, CHECK_OK);
int formals_end_position = scanner()->location().end_pos;
......
This diff is collapsed.
......@@ -616,6 +616,7 @@
'../../src/elements.h',
'../../src/execution.cc',
'../../src/execution.h',
'../../src/expression-classifier.h',
'../../src/extensions/externalize-string-extension.cc',
'../../src/extensions/externalize-string-extension.h',
'../../src/extensions/free-buffer-extension.cc',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment