Permalink
Browse files

[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/1461161
Reviewed-by: Georg Neis <neis@chromium.org>
Commit-Queue: Caitlin Potter <caitp@igalia.com>
Cr-Commit-Position: refs/heads/master@{#59515}
  • Loading branch information...
caitp authored and Commit Bot committed Feb 8, 2019
1 parent 855623a commit 14835613288992b96a2db987a8bf32ffe2ec3589
@@ -2274,6 +2274,11 @@ ParserBase<Impl>::ParseObjectPropertyDefinition(ParsePropertyInfo* prop_info,
Token::Value name_token = peek();
Scanner::Location next_loc = scanner()->peek_location();

if (name_token == Token::PRIVATE_NAME) {
ReportUnexpectedToken(Next());
return impl()->NullLiteralProperty();
}

ExpressionT name_expression = ParseProperty(prop_info);
IdentifierT name = prop_info->name;
ParseFunctionFlags function_flags = prop_info->function_flags;
@@ -5620,6 +5620,8 @@ TEST(PrivateMembersInNonClassNoErrors) {
{"function() {", "}"},
{"() => {", "}"},
{"class C { test() {", "} }"},
{"const {", "} = {}"},
{"({", "} = {})"},
{nullptr, nullptr}};
const char* class_body_data[] = {
"#a = 1",
@@ -0,0 +1,13 @@
// 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;
}
}
@@ -0,0 +1,4 @@
*%(basename)s:10: SyntaxError: Unexpected identifier
const { #x: x } = this;
^^
SyntaxError: Unexpected identifier
@@ -0,0 +1,15 @@
// 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);

0 comments on commit 1483561

Please sign in to comment.