Commit a769ea7a authored by Leszek Swirski's avatar Leszek Swirski Committed by Commit Bot

[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.

Fixed: chromium:1132111
Change-Id: Ia53d1fe713453e361b818dfb0b5f88a90cecdf21
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2440519
Auto-Submit: Leszek Swirski <leszeks@chromium.org>
Commit-Queue: Sathya Gunasekaran  <gsathya@chromium.org>
Reviewed-by: 's avatarSathya Gunasekaran  <gsathya@chromium.org>
Cr-Commit-Position: refs/heads/master@{#70247}
parent 98a9f051
......@@ -54,10 +54,10 @@ void AstFunctionLiteralIdReindexer::VisitClassLiteral(ClassLiteral* expr) {
// Private fields have their key and value present in
// instance_members_initializer_function, so they will
// already have been visited.
if (prop->value()->IsFunctionLiteral()) {
Visit(prop->value());
} else {
if (prop->kind() == ClassLiteralProperty::Kind::FIELD) {
CheckVisited(prop->value());
} else {
Visit(prop->value());
}
}
ZonePtrList<ClassLiteral::Property>* props = expr->public_members();
......@@ -67,7 +67,8 @@ void AstFunctionLiteralIdReindexer::VisitClassLiteral(ClassLiteral* expr) {
// Public fields with computed names have their key
// and value present in instance_members_initializer_function, so they will
// already have been visited.
if (prop->is_computed_name() && !prop->value()->IsFunctionLiteral()) {
if (prop->is_computed_name() &&
prop->kind() == ClassLiteralProperty::Kind::FIELD) {
if (!prop->key()->IsLiteral()) {
CheckVisited(prop->key());
}
......
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Public function field with computed name
eval(`
buggy = ((bug = new class { [0] = x => 1337.0; }) => bug);
`);
// Public method with computed name
eval(`
buggy = ((bug = new class { [0](x) { return 1337.0}; }) => bug);
`);
// Private function field with computed name
eval(`
buggy = ((bug = new class { #foo = x => 1337.0; }) => bug);
`);
// Private method with computed name
eval(`
buggy = ((bug = new class { #foo(x) { return 1337.0; } }) => bug);
`);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment