Skip to content

Commit f3a13e2

Browse files
verwaestV8 LUCI CQ
authored andcommitted
[parser] hidden non-catch scopes can safely cause reuse
Bug: 352414652 Change-Id: If1c804f653bc0cfcb741b9816c0dbd4d51a1f6ee Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/5713608 Commit-Queue: Leszek Swirski <[email protected]> Auto-Submit: Toon Verwaest <[email protected]> Reviewed-by: Leszek Swirski <[email protected]> Cr-Commit-Position: refs/heads/main@{#95055}
1 parent 332ebb2 commit f3a13e2

3 files changed

Lines changed: 19 additions & 2 deletions

File tree

src/ast/scopes.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2693,7 +2693,7 @@ void Scope::AllocateScopeInfosRecursively(
26932693
// next outer scope that needs a context.
26942694
next_outer_scope = scope_info_;
26952695
DCHECK(!scope_info_.is_null());
2696-
DCHECK(!is_hidden());
2696+
DCHECK(!is_hidden_catch_scope());
26972697
CHECK_EQ(scope_info_->scope_type(), scope_type_);
26982698
CHECK_EQ(scope_info_->ContextLength(), num_heap_slots_);
26992699
#ifdef DEBUG
@@ -2704,7 +2704,7 @@ void Scope::AllocateScopeInfosRecursively(
27042704
#ifdef DEBUG
27052705
// Mark this ID as being used. Skip hidden scopes because they are
27062706
// synthetic, unreusable, but hard to make unique.
2707-
if (v8_flags.reuse_scope_infos && !is_hidden()) {
2707+
if (v8_flags.reuse_scope_infos && !is_hidden_catch_scope()) {
27082708
scope_infos_to_reuse[UniqueIdInScript()] = {};
27092709
}
27102710
#endif

src/ast/scopes.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,10 @@ class V8_EXPORT_PRIVATE Scope : public NON_EXPORTED_BASE(ZoneObject) {
339339
bool is_hidden() const { return is_hidden_; }
340340
void set_is_hidden() { is_hidden_ = true; }
341341

342+
bool is_hidden_catch_scope() const {
343+
return is_hidden() && scope_type() == CATCH_SCOPE;
344+
}
345+
342346
void ForceContextAllocationForParameters() {
343347
DCHECK(!already_resolved_);
344348
force_context_allocation_for_parameters_ = true;

test/mjsunit/regress-352414652.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2024 the V8 project authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
// Flags: --allow-natives-syntax --reuse-scope-infos
6+
7+
function __f_11() {
8+
for (let i = __f_26 = function() { return i }; i < 1; ++i) {
9+
}
10+
}
11+
__f_11();
12+
%ForceFlush(__f_11);
13+
__f_11();

0 commit comments

Comments
 (0)