@@ -118,9 +118,11 @@ Scope::Scope(Zone* zone, Scope* outer_scope, ScopeType scope_type)
118118 DCHECK (!is_script_scope ());
119119 SetDefaults ();
120120 set_language_mode (outer_scope->language_mode ());
121- set_private_name_lookup_skips_outer_class (
122- outer_scope->is_class_scope () &&
123- outer_scope->AsClassScope ()->IsParsingHeritage ());
121+ if (outer_scope->is_class_scope () &&
122+ outer_scope->AsClassScope ()->IsParsingHeritage ()) {
123+ set_private_name_lookup_skips_outer_class (true );
124+ outer_scope->GetClosureScope ()->RecordNeedsPrivateNameContextChainRecalc ();
125+ }
124126 outer_scope_->AddInnerScope (this );
125127}
126128
@@ -180,6 +182,9 @@ DeclarationScope::DeclarationScope(Zone* zone, Scope* outer_scope,
180182 params_(4 , zone) {
181183 DCHECK (!is_script_scope ());
182184 SetDefaults ();
185+ if (V8_UNLIKELY (private_name_lookup_skips_outer_class ())) {
186+ RecordNeedsPrivateNameContextChainRecalc ();
187+ }
183188}
184189
185190ModuleScope::ModuleScope (DeclarationScope* script_scope,
@@ -305,18 +310,14 @@ DeclarationScope::DeclarationScope(Zone* zone, ScopeType scope_type,
305310 DCHECK (IsClassConstructor (function_kind ()));
306311 set_class_scope_has_private_brand (true );
307312 }
313+ if (V8_UNLIKELY (private_name_lookup_skips_outer_class ())) {
314+ RecordNeedsPrivateNameContextChainRecalc ();
315+ }
308316}
309317
310318Scope::Scope (Zone* zone, const AstRawString* catch_variable_name,
311319 MaybeAssignedFlag maybe_assigned, Handle<ScopeInfo> scope_info)
312- : outer_scope_(nullptr ),
313- variables_(zone),
314- scope_info_(scope_info),
315- scope_type_(CATCH_SCOPE ) {
316- SetDefaults ();
317- #ifdef DEBUG
318- already_resolved_ = true ;
319- #endif
320+ : Scope(zone, CATCH_SCOPE , nullptr , scope_info) {
320321 // Cache the catch variable, even though it's also available via the
321322 // scope_info, as the parser expects that a catch scope always has the catch
322323 // variable as first and only variable.
@@ -326,7 +327,6 @@ Scope::Scope(Zone* zone, const AstRawString* catch_variable_name,
326327 kCreatedInitialized , maybe_assigned, &was_added);
327328 DCHECK (was_added);
328329 AllocateHeapSlot (variable);
329- set_is_hoisted_in_context (scope_info->is_hoisted_in_context ());
330330}
331331
332332void DeclarationScope::SetDefaults () {
@@ -454,9 +454,14 @@ Scope* Scope::DeserializeScopeChain(
454454 eval_scope->set_start_position (position);
455455 eval_scope->set_end_position (position);
456456 eval_scope->set_eval_position (position);
457-
458457 if (current_scope != nullptr ) {
458+ eval_scope->set_private_name_lookup_skips_outer_class (
459+ current_scope->private_name_lookup_skips_outer_class ());
460+ current_scope->set_private_name_lookup_skips_outer_class (false );
459461 eval_scope->AddInnerScope (current_scope);
462+ } else if (parse_info != nullptr ) {
463+ eval_scope->set_private_name_lookup_skips_outer_class (
464+ parse_info->flags ().private_name_lookup_skips_outer_class ());
460465 }
461466 current_scope = eval_scope;
462467 if (innermost_scope == nullptr ) innermost_scope = current_scope;
@@ -940,6 +945,7 @@ Scope* Scope::FinalizeBlockScope() {
940945 scope->outer_scope_ = outer_scope ();
941946 if (private_name_lookup_skips_outer_class ()) {
942947 scope->set_private_name_lookup_skips_outer_class (true );
948+ scope->GetClosureScope ()->RecordNeedsPrivateNameContextChainRecalc ();
943949 }
944950 if (scope->is_function_scope ()) {
945951 scope->set_is_hoisted_in_context (false );
@@ -997,12 +1003,14 @@ void Scope::Snapshot::Reparent(DeclarationScope* new_parent) {
9971003 for (; inner_scope->sibling () != top_inner_scope_;
9981004 inner_scope = inner_scope->sibling ()) {
9991005 inner_scope->outer_scope_ = new_parent;
1006+ inner_scope->set_private_name_lookup_skips_outer_class (false );
10001007 if (inner_scope->inner_scope_calls_eval ()) {
10011008 new_parent->set_inner_scope_calls_eval (true );
10021009 }
10031010 DCHECK_NE (inner_scope, new_parent);
10041011 }
10051012 inner_scope->outer_scope_ = new_parent;
1013+ inner_scope->set_private_name_lookup_skips_outer_class (false );
10061014 if (inner_scope->inner_scope_calls_eval ()) {
10071015 new_parent->set_inner_scope_calls_eval (true );
10081016 }
@@ -1454,7 +1462,12 @@ bool DeclarationScope::AllocateVariables(ParseInfo* info) {
14541462 }
14551463
14561464 // Don't allocate variables of preparsed scopes.
1457- if (!was_lazily_parsed ()) AllocateVariablesRecursively ();
1465+ if (!was_lazily_parsed ()) {
1466+ AllocateVariablesRecursively ();
1467+ if (needs_private_name_context_chain_recalc ()) {
1468+ RecalcPrivateNameContextChain ();
1469+ }
1470+ }
14581471
14591472 return true ;
14601473}
@@ -2924,10 +2937,6 @@ void DeclarationScope::AllocateScopeInfos(ParseInfo* parse_info,
29242937 }
29252938 }
29262939
2927- if (scope->needs_private_name_context_chain_recalc ()) {
2928- scope->RecalcPrivateNameContextChain ();
2929- }
2930-
29312940 Tagged<WeakFixedArray> infos = script->infos ();
29322941 std::unordered_map<int , Handle<ScopeInfo>> scope_infos_to_reuse;
29332942 if (infos->ulength ().value () != 0 ) {
0 commit comments