Commit 2963f1b2 authored by Toon Verwaest's avatar Toon Verwaest Committed by Commit Bot

[parser] Simplify ParseFunctionBody

- Merge is_simple branches at the top
- Remove block around inner_body parsing. Always merge fully at the end.
- Remove conditional inner block adding to outer body. Simply add it to the
  inner body making merge push it to the parent.

Change-Id: I1f062918a7abac354b949136463517bd0440984f
Reviewed-on: https://chromium-review.googlesource.com/c/1386111
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58390}
parent 71180e54
......@@ -3820,9 +3820,13 @@ void ParserBase<Impl>::ParseFunctionBody(
const FormalParametersT& parameters, FunctionKind kind,
FunctionLiteral::FunctionType function_type, FunctionBodyType body_type) {
if (IsResumableFunction(kind)) impl()->PrepareGeneratorVariables();
DeclarationScope* function_scope = parameters.scope;
DeclarationScope* inner_scope = function_scope;
// Building the parameter initialization block declares the parameters.
// TODO(verwaest): Rely on ArrowHeadParsingScope instead.
if (!parameters.is_simple) {
if (V8_UNLIKELY(!parameters.is_simple)) {
if (has_error()) return;
BlockT init_block = impl()->BuildParameterInitializationBlock(parameters);
if (IsAsyncFunction(kind) && !IsAsyncGeneratorFunction(kind)) {
......@@ -3830,20 +3834,13 @@ void ParserBase<Impl>::ParseFunctionBody(
}
body->Add(init_block);
if (has_error()) return;
}
DeclarationScope* function_scope = scope()->AsDeclarationScope();
bool allow_duplicate_parameters = false;
BlockT inner_block = impl()->NullBlock();
{
StatementListT inner_body(pointer_buffer());
DeclarationScope* inner_scope = function_scope;
if (!parameters.is_simple) {
inner_scope = NewVarblockScope();
inner_scope->set_start_position(scanner()->location().beg_pos);
}
StatementListT inner_body(pointer_buffer());
{
BlockState block_state(&scope_, inner_scope);
......@@ -3887,7 +3884,9 @@ void ParserBase<Impl>::ParseFunctionBody(
scope()->set_end_position(end_position());
if (parameters.is_simple) {
bool allow_duplicate_parameters = false;
if (V8_LIKELY(parameters.is_simple)) {
DCHECK_EQ(inner_scope, function_scope);
if (is_sloppy(function_scope->language_mode())) {
impl()->InsertSloppyBlockFunctionVarBindings(function_scope);
......@@ -3907,8 +3906,9 @@ void ParserBase<Impl>::ParseFunctionBody(
inner_scope->set_end_position(end_position());
if (inner_scope->FinalizeBlockScope() != nullptr) {
inner_block = factory()->NewBlock(true, inner_body);
BlockT inner_block = factory()->NewBlock(true, inner_body);
inner_body.Rewind();
inner_body.Add(inner_block);
inner_block->set_scope(inner_scope);
const AstRawString* conflict = inner_scope->FindVariableDeclaredIn(
function_scope, VariableMode::kLastLexicalVariableMode);
......@@ -3919,10 +3919,6 @@ void ParserBase<Impl>::ParseFunctionBody(
impl()->InsertShadowingVarBindingInitializers(inner_block);
}
}
inner_body.MergeInto(body);
}
if (!impl()->IsNull(inner_block)) body->Add(inner_block);
ValidateFormalParameters(language_mode(), parameters,
allow_duplicate_parameters);
......@@ -3935,6 +3931,8 @@ void ParserBase<Impl>::ParseFunctionBody(
}
impl()->DeclareFunctionNameVar(function_name, function_type, function_scope);
inner_body.MergeInto(body);
}
template <typename Impl>
......
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