Skip to content

Commit 0d75c4e

Browse files
verwaestV8 LUCI CQ
authored andcommitted
[parser] Don't handle this var management in reparsed scopes
The variable is already properly allocated, so we shouldn't try to reallocate it. Notable this would be wrong in the case where we reparse a class body for one of its initializers. The function in which the class body actually lives might not have required a context, but computed property names might have referred to its receiver. When we reparse the class that function might not be on the outer scope chain of the class (since it didn't require a context). Bug: 371237564 Change-Id: I54ccbc86eb9abdcd558d395f7896d1a23a110b50 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/5937959 Reviewed-by: Marja Hölttä <[email protected]> Commit-Queue: Toon Verwaest <[email protected]> Commit-Queue: Marja Hölttä <[email protected]> Auto-Submit: Toon Verwaest <[email protected]> Reviewed-by: Joyee Cheung <[email protected]> Cr-Commit-Position: refs/heads/main@{#96677}
1 parent a1a2b74 commit 0d75c4e

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

src/ast/scopes.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ class V8_EXPORT_PRIVATE Scope : public NON_EXPORTED_BASE(ZoneObject) {
113113
ClassScope* AsClassScope();
114114
const ClassScope* AsClassScope() const;
115115

116+
bool is_reparsed() const { return !scope_info_.is_null(); }
117+
116118
class Snapshot final {
117119
public:
118120
inline explicit Snapshot(Scope* scope);
@@ -1413,8 +1415,6 @@ class V8_EXPORT_PRIVATE ClassScope : public Scope {
14131415
IsStaticFlag is_static_flag, bool* was_added);
14141416
Variable* RedeclareSyntheticContextVariable(const AstRawString* name);
14151417

1416-
bool is_reparsed() const { return !scope_info_.is_null(); }
1417-
14181418
// Try resolving all unresolved private names found in the current scope.
14191419
// Called from DeclarationScope::AllocateVariables() when reparsing a
14201420
// method to generate code or when eval() is called to access private names.

src/parsing/parser-base.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,8 +1241,10 @@ class ParserBase {
12411241
// Needs to be called if the reference needs to be available from the current
12421242
// point. It causes the receiver to be context allocated if necessary.
12431243
// Returns the receiver variable that we're referencing.
1244-
V8_INLINE Variable* UseThis() {
1245-
DeclarationScope* closure_scope = scope()->GetClosureScope();
1244+
V8_INLINE void UseThis() {
1245+
Scope* scope = this->scope();
1246+
if (scope->is_reparsed()) return;
1247+
DeclarationScope* closure_scope = scope->GetClosureScope();
12461248
DeclarationScope* receiver_scope = closure_scope->GetReceiverScope();
12471249
Variable* var = receiver_scope->receiver();
12481250
var->set_is_used();
@@ -1255,7 +1257,6 @@ class ParserBase {
12551257
closure_scope->set_has_this_reference();
12561258
var->ForceContextAllocation();
12571259
}
1258-
return var;
12591260
}
12601261

12611262
V8_INLINE IdentifierT ParseAndClassifyIdentifier(Token::Value token);
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
function test(val) {
6+
function func() {
7+
class Class extends func {
8+
static {
9+
super.m();
10+
}
11+
// An instance initializer between two static initializers is
12+
// needed to trigger the regression.
13+
[this] = val;
14+
static 1;
15+
}
16+
}
17+
func();
18+
}
19+
assertThrows(test);

0 commit comments

Comments
 (0)