Commit 14835613 authored by Caitlin Potter's avatar Caitlin Potter Committed by Commit Bot

[parser] don't accept PRIVATE_NAME for object literal property names

Currently, PRIVATE_NAME / PrivateIdentifier is not valid in
ObjectLiterals or other places expecting the PropertyName production.
A SyntaxError here prevents an access violation later on when attempting
to dereference a null property key

BUG=v8:8808
R=gsathya@chromium.org, littledan@chromium.org

Change-Id: Idde9c669cb48c1595b83115351a8fe0caed40eef
Reviewed-on: https://chromium-review.googlesource.com/c/1461161Reviewed-by: 's avatarGeorg Neis <neis@chromium.org>
Commit-Queue: Caitlin Potter <caitp@igalia.com>
Cr-Commit-Position: refs/heads/master@{#59515}
parent 855623a4
...@@ -2274,6 +2274,11 @@ ParserBase<Impl>::ParseObjectPropertyDefinition(ParsePropertyInfo* prop_info, ...@@ -2274,6 +2274,11 @@ ParserBase<Impl>::ParseObjectPropertyDefinition(ParsePropertyInfo* prop_info,
Token::Value name_token = peek(); Token::Value name_token = peek();
Scanner::Location next_loc = scanner()->peek_location(); Scanner::Location next_loc = scanner()->peek_location();
if (name_token == Token::PRIVATE_NAME) {
ReportUnexpectedToken(Next());
return impl()->NullLiteralProperty();
}
ExpressionT name_expression = ParseProperty(prop_info); ExpressionT name_expression = ParseProperty(prop_info);
IdentifierT name = prop_info->name; IdentifierT name = prop_info->name;
ParseFunctionFlags function_flags = prop_info->function_flags; ParseFunctionFlags function_flags = prop_info->function_flags;
......
...@@ -5620,6 +5620,8 @@ TEST(PrivateMembersInNonClassNoErrors) { ...@@ -5620,6 +5620,8 @@ TEST(PrivateMembersInNonClassNoErrors) {
{"function() {", "}"}, {"function() {", "}"},
{"() => {", "}"}, {"() => {", "}"},
{"class C { test() {", "} }"}, {"class C { test() {", "} }"},
{"const {", "} = {}"},
{"({", "} = {})"},
{nullptr, nullptr}}; {nullptr, nullptr}};
const char* class_body_data[] = { const char* class_body_data[] = {
"#a = 1", "#a = 1",
......
// Copyright 2019 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.
// Flags: --harmony-class-fields
class Foo {
#x = 1;
destructureX() {
const { #x: x } = this;
return x;
}
}
*%(basename)s:10: SyntaxError: Unexpected identifier
const { #x: x } = this;
^^
SyntaxError: Unexpected identifier
// Copyright 2019 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.
// Flags: --harmony-class-fields
assertThrows(() => eval(`
class Foo {
#x = 1;
destructureX() {
const { #x: x } = this;
return x;
}
}
`), SyntaxError);
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