Commit 09534392 authored by Toon Verwaest's avatar Toon Verwaest Committed by Commit Bot

Reland "[parser] Simplify ParseFunctionBody"

This is a reland of 2963f1b2

Original change's description:
> [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: Igor Sheludko <ishell@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#58390}

Change-Id: I145f0cb1eda1dca4dd047b55e54b2b1bb704ecf8
Reviewed-on: https://chromium-review.googlesource.com/c/1397662Reviewed-by: 's avatarToon Verwaest <verwaest@chromium.org>
Commit-Queue: Maya Lekova <mslekova@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58567}
parent d575bdd8
......@@ -3817,9 +3817,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)) {
......@@ -3827,20 +3831,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);
......@@ -3884,7 +3881,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);
......@@ -3904,8 +3903,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);
......@@ -3916,10 +3916,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);
......@@ -3932,6 +3928,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