Skip to content

Commit 6a4cd97

Browse files
LeszekSwirskiCommit Bot
authored and
Commit Bot
committed
Merged: [parser] Fix AST func reindexing for function fields
AST reindexing has to skip visiting fields that are already in the member initializer, as they will have already been visited when visiting said initializer. This is the case for private fields and fields with computed names. However, the reindexer was incorrectly assuming that all properties with a FunctionLiteral value are methods (and thus not fields, and can safely be visited). This is not the case for fields with function expression values. Now, we correctly use the class property's "kind" when making this visitation decision. (cherry picked from commit a769ea7) Bug: chromium:1132111 Tbr: [email protected] No-Try: true No-Presubmit: true No-Tree-Checks: true Change-Id: I33ac5664bb5334e964d351de1ba7e2c57f3398f8 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2465056 Commit-Queue: Adam Klein <[email protected]> Reviewed-by: Adam Klein <[email protected]> Cr-Commit-Position: refs/branch-heads/8.6@{#24} Cr-Branched-From: a64aed2-refs/heads/8.6.395@{#1} Cr-Branched-From: a626bc0-refs/heads/master@{#69472}
1 parent 7dc5718 commit 6a4cd97

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

src/ast/ast-function-literal-id-reindexer.cc

+5-4
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ void AstFunctionLiteralIdReindexer::VisitClassLiteral(ClassLiteral* expr) {
5454
// Private fields have their key and value present in
5555
// instance_members_initializer_function, so they will
5656
// already have been visited.
57-
if (prop->value()->IsFunctionLiteral()) {
58-
Visit(prop->value());
59-
} else {
57+
if (prop->kind() == ClassLiteralProperty::Kind::FIELD) {
6058
CheckVisited(prop->value());
59+
} else {
60+
Visit(prop->value());
6161
}
6262
}
6363
ZonePtrList<ClassLiteral::Property>* props = expr->public_members();
@@ -67,7 +67,8 @@ void AstFunctionLiteralIdReindexer::VisitClassLiteral(ClassLiteral* expr) {
6767
// Public fields with computed names have their key
6868
// and value present in instance_members_initializer_function, so they will
6969
// already have been visited.
70-
if (prop->is_computed_name() && !prop->value()->IsFunctionLiteral()) {
70+
if (prop->is_computed_name() &&
71+
prop->kind() == ClassLiteralProperty::Kind::FIELD) {
7172
if (!prop->key()->IsLiteral()) {
7273
CheckVisited(prop->key());
7374
}
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2020 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+
// Public function field with computed name
6+
eval(`
7+
buggy = ((bug = new class { [0] = x => 1337.0; }) => bug);
8+
`);
9+
10+
// Public method with computed name
11+
eval(`
12+
buggy = ((bug = new class { [0](x) { return 1337.0}; }) => bug);
13+
`);
14+
15+
// Private function field with computed name
16+
eval(`
17+
buggy = ((bug = new class { #foo = x => 1337.0; }) => bug);
18+
`);
19+
20+
// Private method with computed name
21+
eval(`
22+
buggy = ((bug = new class { #foo(x) { return 1337.0; } }) => bug);
23+
`);

0 commit comments

Comments
 (0)