diff --git a/src/ast/scopes.cc b/src/ast/scopes.cc index ba6969f603..4a2efe19d3 100644 --- a/src/ast/scopes.cc +++ b/src/ast/scopes.cc @@ -505,10 +505,8 @@ Scope* Scope::DeserializeScopeChain(IsolateT* isolate, Zone* zone, : ScopeInfo(); } - if (deserialization_mode == DeserializationMode::kIncludingVariables && - script_scope->scope_info_.is_null()) { - script_scope->SetScriptScopeInfo( - ReadOnlyRoots(isolate).global_this_binding_scope_info_handle()); + if (deserialization_mode == DeserializationMode::kIncludingVariables) { + SetScriptScopeInfo(isolate, script_scope); } if (innermost_scope == nullptr) return script_scope; @@ -516,6 +514,24 @@ Scope* Scope::DeserializeScopeChain(IsolateT* isolate, Zone* zone, return innermost_scope; } +template +void Scope::SetScriptScopeInfo(IsolateT* isolate, + DeclarationScope* script_scope) { + if (script_scope->scope_info_.is_null()) { + script_scope->SetScriptScopeInfo( + ReadOnlyRoots(isolate).global_this_binding_scope_info_handle()); + } +} + +template EXPORT_TEMPLATE_DEFINE( + V8_EXPORT_PRIVATE) void Scope::SetScriptScopeInfo(Isolate* isolate, + DeclarationScope* + script_scope); +template EXPORT_TEMPLATE_DEFINE( + V8_EXPORT_PRIVATE) void Scope::SetScriptScopeInfo(LocalIsolate* isolate, + DeclarationScope* + script_scope); + template EXPORT_TEMPLATE_DEFINE(V8_EXPORT_PRIVATE) Scope* Scope::DeserializeScopeChain( Isolate* isolate, Zone* zone, ScopeInfo scope_info, diff --git a/src/ast/scopes.h b/src/ast/scopes.h index 3b9d13db4d..6b3d33ed87 100644 --- a/src/ast/scopes.h +++ b/src/ast/scopes.h @@ -171,6 +171,11 @@ class V8_EXPORT_PRIVATE Scope : public NON_EXPORTED_BASE(ZoneObject) { AstValueFactory* ast_value_factory, DeserializationMode deserialization_mode); + template + EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) + static void SetScriptScopeInfo(IsolateT* isolate, + DeclarationScope* script_scope); + // Checks if the block scope is redundant, i.e. it does not contain any // block scoped declarations. In that case it is removed from the scope // tree and its children are reparented. diff --git a/src/parsing/parser.cc b/src/parsing/parser.cc index f8e6100fc4..6ee70886a9 100644 --- a/src/parsing/parser.cc +++ b/src/parsing/parser.cc @@ -836,6 +836,7 @@ void Parser::ParseFunction(Isolate* isolate, ParseInfo* info, int end_position = shared_info->EndPosition(); MaybeHandle deserialize_start_scope = maybe_outer_scope_info; + bool needs_script_scope_finalization = false; // If the function is a class member initializer and there isn't a // scope mismatch, we will only deserialize up to the outer scope of // the class scope, and regenerate the class scope during reparsing. @@ -851,12 +852,20 @@ void Parser::ParseFunction(Isolate* isolate, ParseInfo* info, deserialize_start_scope = handle(outer_scope_info->OuterScopeInfo(), isolate); } else { + // If the class scope doesn't have an outer scope to deserialize, we need + // to finalize the script scope without using + // Scope::DeserializeScopeChain(). deserialize_start_scope = MaybeHandle(); + needs_script_scope_finalization = true; } } DeserializeScopeChain(isolate, info, deserialize_start_scope, Scope::DeserializationMode::kIncludingVariables); + if (needs_script_scope_finalization) { + DCHECK_EQ(original_scope_, info->script_scope()); + Scope::SetScriptScopeInfo(isolate, info->script_scope()); + } DCHECK_EQ(factory()->zone(), info->zone()); Handle