From d6f911368bb8d4cb95e216aaa597afd62845c1a7 Mon Sep 17 00:00:00 2001 From: Joshua Litt Date: Mon, 21 Oct 2019 06:53:18 -0700 Subject: [PATCH] [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 Reviewed-by: Leszek Swirski Cr-Commit-Position: refs/heads/master@{#64428} --- src/parsing/parser-base.h | 8 +++++++- test/mjsunit/harmony/optional-chaining.js | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/parsing/parser-base.h b/src/parsing/parser-base.h index 315cbf2684..7512b02d18 100644 --- a/src/parsing/parser-base.h +++ b/src/parsing/parser-base.h @@ -3277,7 +3277,13 @@ ParserBase::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; } diff --git a/test/mjsunit/harmony/optional-chaining.js b/test/mjsunit/harmony/optional-chaining.js index 72b0559e00..a6121f5fcb 100644 --- a/test/mjsunit/harmony/optional-chaining.js +++ b/test/mjsunit/harmony/optional-chaining.js @@ -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,