[optional-chaining] Disallow optional chaining with private names.

Bug: chromium:1014458
Change-Id: I9e5e83da4452e9953218335353047f41c18f68fe
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1864333
Commit-Queue: Joshua Litt <joshualitt@chromium.org>
Reviewed-by: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#64428}
This commit is contained in:
Joshua Litt 2019-10-21 06:53:18 -07:00 committed by Commit Bot
parent dd29ce3ee3
commit d6f911368b
2 changed files with 8 additions and 1 deletions

View File

@ -3277,7 +3277,13 @@ ParserBase<Impl>::ParseLeftHandSideContinuation(ExpressionT result) {
if (is_optional) {
DCHECK_EQ(scanner()->current_token(), Token::QUESTION_PERIOD);
int pos = position();
ExpressionT key = ParsePropertyOrPrivatePropertyName();
Token::Value next = Next();
if (V8_UNLIKELY(!Token::IsPropertyName(next))) {
ReportUnexpectedToken(next);
return impl()->FailureExpression();
}
IdentifierT name = impl()->GetSymbol();
ExpressionT key = factory()->NewStringLiteral(name, position());
result = factory()->NewProperty(result, key, pos, is_optional);
break;
}

View File

@ -101,6 +101,7 @@ shouldThrowSyntaxError('function foo() { new?.target; }');
shouldThrowSyntaxError('function tag() {} tag?.``;');
shouldThrowSyntaxError('const o = { tag() {} }; o?.tag``;');
shouldThrowSyntaxError('class A { #foo = "hi"; constructor() { this?.#foo; } }')
const o2 = {
count: 0,