Commit 34e45c84 authored by Toon Verwaest's avatar Toon Verwaest Committed by Commit Bot

[parser] Don't create a separate list for preparser params

Instead directly declare the parameters as they are "added to the list".

Change-Id: I3245b5834157eb9f443ceb5da47db231a237d673
Reviewed-on: https://chromium-review.googlesource.com/c/1270815Reviewed-by: 's avatarMarja Hölttä <marja@chromium.org>
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56481}
parent 62e99653
......@@ -3834,8 +3834,7 @@ void ParserBase<Impl>::ParseFormalParameterList(FormalParametersT* parameters,
}
}
impl()->DeclareFormalParameters(parameters->scope, parameters->params,
parameters->is_simple);
impl()->DeclareFormalParameters(parameters);
}
template <typename Impl>
......
......@@ -760,8 +760,7 @@ FunctionLiteral* Parser::DoParseFunction(Isolate* isolate, ParseInfo* info,
// BindingIdentifier
ParseFormalParameter(&formals, &ok);
if (ok) {
DeclareFormalParameters(formals.scope, formals.params,
formals.is_simple);
DeclareFormalParameters(&formals);
}
}
}
......@@ -2388,8 +2387,7 @@ void Parser::DeclareArrowFunctionFormalParameters(
return;
}
DeclareFormalParameters(parameters->scope, parameters->params,
parameters->is_simple);
DeclareFormalParameters(parameters);
DCHECK_EQ(parameters->is_simple, parameters->scope->has_simple_parameters());
}
......@@ -2979,7 +2977,7 @@ ZonePtrList<Statement>* Parser::ParseFunction(
kNoSourcePosition, is_rest);
}
DCHECK_EQ(arguments_length, formals.num_parameters());
DeclareFormalParameters(formals.scope, formals.params, formals.is_simple);
DeclareFormalParameters(&formals);
} else {
// For a regular function, the function arguments are parsed from source.
DCHECK_NULL(arguments_for_wrapped_function);
......
......@@ -920,11 +920,11 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
}
V8_INLINE void DeclareFormalParameters(
DeclarationScope* scope,
const base::ThreadedList<ParserFormalParameters::Parameter>& parameters,
bool is_simple) {
const ParserFormalParameters* parameters) {
bool is_simple = parameters->is_simple;
DeclarationScope* scope = parameters->scope;
if (!is_simple) scope->SetHasNonSimpleParameters();
for (auto parameter : parameters) {
for (auto parameter : parameters->params) {
bool is_optional = parameter->initializer != nullptr;
// If the parameter list is simple, declare the parameters normally with
// their names. If the parameter list is not simple, declare a temporary
......
......@@ -841,23 +841,8 @@ class PreParserFactory {
struct PreParserFormalParameters : FormalParametersBase {
struct Parameter : public ZoneObject {
using VariableZoneThreadedListType =
ZoneThreadedList<VariableProxy, VariableProxy::PreParserNext>;
Parameter(VariableZoneThreadedListType* variables, bool is_rest)
: variables_(variables), is_rest(is_rest) {}
Parameter** next() { return &next_parameter; }
Parameter* const* next() const { return &next_parameter; }
VariableZoneThreadedListType* variables_;
Parameter* next_parameter = nullptr;
bool is_rest : 1;
};
explicit PreParserFormalParameters(DeclarationScope* scope)
: FormalParametersBase(scope) {}
base::ThreadedList<Parameter> params;
};
......@@ -1665,48 +1650,39 @@ class PreParser : public ParserBase<PreParser> {
}
V8_INLINE void AddFormalParameter(PreParserFormalParameters* parameters,
const PreParserExpression& pattern,
PreParserExpression& pattern,
const PreParserExpression& initializer,
int initializer_end_position,
bool is_rest) {
parameters->params.Add(new (zone()) PreParserFormalParameters::Parameter(
pattern.variables_, is_rest));
DeclarationScope* scope = parameters->scope;
if (pattern.variables_ == nullptr) {
scope->DeclareParameterName(ast_value_factory()->empty_string(), is_rest,
ast_value_factory(), false, true);
} else {
// We declare the parameter name for all names, but only create a
// parameter entry for the first one.
auto it = pattern.variables_->begin();
if (scope->LookupLocal(it->raw_name()) != nullptr) {
classifier()->RecordDuplicateFormalParameterError(
Scanner::Location::invalid());
}
scope->DeclareParameterName(it->raw_name(), is_rest, ast_value_factory(),
true, true);
for (++it; it != pattern.variables_->end(); ++it) {
if (scope->LookupLocal(it->raw_name()) != nullptr) {
classifier()->RecordDuplicateFormalParameterError(
Scanner::Location::invalid());
}
scope->DeclareParameterName(it->raw_name(), is_rest,
ast_value_factory(), true, false);
}
}
parameters->UpdateArityAndFunctionLength(!initializer.IsNull(), is_rest);
}
V8_INLINE void DeclareFormalParameters(
DeclarationScope* scope,
const base::ThreadedList<PreParserFormalParameters::Parameter>&
parameters,
bool is_simple) {
if (!is_simple) scope->SetHasNonSimpleParameters();
for (auto parameter : parameters) {
DCHECK_IMPLIES(is_simple, parameter->variables_ != nullptr);
DCHECK_IMPLIES(is_simple, parameter->variables_->LengthForTest() == 1);
if (parameter->variables_ == nullptr) {
// No names were declared; declare a dummy one here to up the
// parameter count.
scope->DeclareParameterName(ast_value_factory()->empty_string(),
parameter->is_rest, ast_value_factory(),
false, true);
} else {
// Make sure each parameter is added only once even if it's a
// destructuring parameter which contains multiple names.
bool add_parameter = true;
for (auto variable : (*parameter->variables_)) {
// Find duplicates in simple and complex parameter lists.
if (scope->LookupLocal(variable->raw_name())) {
classifier()->RecordDuplicateFormalParameterError(
Scanner::Location::invalid());
}
// We declare the parameter name for all names, but only create a
// parameter entry for the first one.
scope->DeclareParameterName(variable->raw_name(), parameter->is_rest,
ast_value_factory(), true, add_parameter);
add_parameter = false;
}
}
}
const PreParserFormalParameters* parameters) {
if (!parameters->is_simple) parameters->scope->SetHasNonSimpleParameters();
}
V8_INLINE void DeclareArrowFunctionFormalParameters(
......
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