Commit 9f73f5a3 authored by Shu-yu Guo's avatar Shu-yu Guo Committed by Commit Bot

[class] Fix ClassScope::LookupPrivateName to walk scope chain

private name was not found in the current scope. Outer private names
were sometimes coincidentally correctly resolved if the innermost
ClassScope does not need to allocate a context and does not have a
ScopeInfo.

ClassScope: :LookupPrivateName was not walking the scope chain when a
Change-Id: I18937e6cdf2ad4ae15825b11762fbec7a1358145
Bug: v8:9635
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1761547Reviewed-by: 's avatarSathya Gunasekaran  <gsathya@chromium.org>
Commit-Queue: Shu-yu Guo <syg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63295}
parent 489e7deb
......@@ -2469,7 +2469,9 @@ Variable* ClassScope::LookupPrivateName(VariableProxy* proxy) {
if (var == nullptr && !class_scope->scope_info_.is_null()) {
var = class_scope->LookupPrivateNameInScopeInfo(proxy->raw_name());
}
return var;
if (var != nullptr) {
return var;
}
}
return nullptr;
}
......
// This file was procedurally generated from the following sources:
// - src/class-elements/private-field-on-nested-class.case
// - src/class-elements/default/cls-expr.template
/*---
description: PrivateName CallExpression usage (private field) (field definitions in a class expression)
esid: prod-FieldDefinition
features: [class-fields-private, class-fields-public, class]
flags: [generated]
info: |
Updated Productions
CallExpression[Yield, Await]:
CoverCallExpressionAndAsyncArrowHead[?Yield, ?Await]
SuperCall[?Yield, ?Await]
CallExpression[?Yield, ?Await]Arguments[?Yield, ?Await]
CallExpression[?Yield, ?Await][Expression[+In, ?Yield, ?Await]]
CallExpression[?Yield, ?Await].IdentifierName
CallExpression[?Yield, ?Await]TemplateLiteral[?Yield, ?Await]
CallExpression[?Yield, ?Await].PrivateName
---*/
var C = class {
#outer = 'test262';
B_withoutPrivateField = class {
method(o) {
return o.#outer;
}
}
B_withPrivateField = class {
#inner = 42;
method(o) {
return o.#outer;
}
}
}
let c = new C();
let innerB1 = new c.B_withoutPrivateField();
assert.sameValue(innerB1.method(c), 'test262');
let innerB2 = new c.B_withPrivateField();
assert.sameValue(innerB2.method(c), 'test262');
// This file was procedurally generated from the following sources:
// - src/class-elements/private-field-on-nested-class.case
// - src/class-elements/default/cls-decl.template
/*---
description: PrivateName CallExpression usage (private field) (field definitions in a class declaration)
esid: prod-FieldDefinition
features: [class-fields-private, class-fields-public, class]
flags: [generated]
info: |
Updated Productions
CallExpression[Yield, Await]:
CoverCallExpressionAndAsyncArrowHead[?Yield, ?Await]
SuperCall[?Yield, ?Await]
CallExpression[?Yield, ?Await]Arguments[?Yield, ?Await]
CallExpression[?Yield, ?Await][Expression[+In, ?Yield, ?Await]]
CallExpression[?Yield, ?Await].IdentifierName
CallExpression[?Yield, ?Await]TemplateLiteral[?Yield, ?Await]
CallExpression[?Yield, ?Await].PrivateName
---*/
class C {
#outer = 'test262';
B_withoutPrivateField = class {
method(o) {
return o.#outer;
}
}
B_withPrivateField = class {
#inner = 42;
method(o) {
return o.#outer;
}
}
}
let c = new C();
let innerB1 = new c.B_withoutPrivateField();
assert.sameValue(innerB1.method(c), 'test262');
let innerB2 = new c.B_withPrivateField();
assert.sameValue(innerB2.method(c), 'test262');
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