Commit fd2edb0e authored by caitpotter88's avatar caitpotter88 Committed by Commit bot

[parser] unify metaproperty parsing and require unescaped property name

BUG=v8:4756
LOG=N
R=adamk@chromium.org, littledan@chromium.org, wingo@igalia.com

Review URL: https://codereview.chromium.org/1700123003

Cr-Commit-Position: refs/heads/master@{#34050}
parent 163ef099
......@@ -397,6 +397,7 @@ class CallSite {
"Illegal '%' directive in function with non-simple parameter list") \
T(IllegalReturn, "Illegal return statement") \
T(InvalidEscapedReservedWord, "Keyword must not contain escaped characters") \
T(InvalidEscapedMetaProperty, "'%' must not contain escaped characters") \
T(InvalidLhsInAssignment, "Invalid left-hand side in assignment") \
T(InvalidCoverInitializedName, "Invalid shorthand property initializer") \
T(InvalidDestructuringTarget, "Invalid destructuring assignment target") \
......
......@@ -454,6 +454,9 @@ class ParserBase : public Traits {
scanner()->is_next_contextual_keyword(keyword);
}
void ExpectMetaProperty(Vector<const char> property_name,
const char* full_name, int pos, bool* ok);
void ExpectContextualKeyword(Vector<const char> keyword, bool* ok) {
Expect(Token::IDENTIFIER, ok);
if (!*ok) return;
......@@ -2540,11 +2543,10 @@ ParserBase<Traits>::ParseMemberExpression(ExpressionClassifier* classifier,
Consume(Token::FUNCTION);
int function_token_position = position();
if (FLAG_harmony_function_sent && Check(Token::PERIOD)) {
if (FLAG_harmony_function_sent && peek() == Token::PERIOD) {
// function.sent
int pos = position();
ExpectContextualKeyword(CStrVector("sent"), CHECK_OK);
ExpectMetaProperty(CStrVector("sent"), "function.sent", pos, CHECK_OK);
if (!is_generator()) {
// TODO(neis): allow escaping into closures?
......@@ -2769,13 +2771,26 @@ ParserBase<Traits>::ParseSuperExpression(bool is_new,
return this->EmptyExpression();
}
template <class Traits>
void ParserBase<Traits>::ExpectMetaProperty(Vector<const char> property_name,
const char* full_name, int pos,
bool* ok) {
Consume(Token::PERIOD);
ExpectContextualKeyword(property_name, ok);
if (!*ok) return;
if (scanner()->literal_contains_escapes()) {
Traits::ReportMessageAt(
Scanner::Location(pos, scanner()->location().end_pos),
MessageTemplate::kInvalidEscapedMetaProperty, full_name);
*ok = false;
}
}
template <class Traits>
typename ParserBase<Traits>::ExpressionT
ParserBase<Traits>::ParseNewTargetExpression(bool* ok) {
int pos = position();
Consume(Token::PERIOD);
ExpectContextualKeyword(CStrVector("target"), CHECK_OK);
ExpectMetaProperty(CStrVector("target"), "new.target", pos, CHECK_OK);
if (!scope_->ReceiverScope()->is_function_scope()) {
ReportMessageAt(scanner()->location(),
......
......@@ -8007,3 +8007,39 @@ TEST(MiscSyntaxErrors) {
RunParserSyncTest(context_data, error_data, kError, NULL, 0, NULL, 0);
}
TEST(FunctionSentErrors) {
// clang-format off
const char* context_data[][2] = {
{ "'use strict'", "" },
{ "", "" },
{ NULL, NULL }
};
const char* error_data[] = {
"var x = function.sent",
"function* g() { yield function.s\\u0065nt; }",
NULL
};
// clang-format on
bool old_flag = i::FLAG_harmony_function_sent;
i::FLAG_harmony_function_sent = true;
RunParserSyncTest(context_data, error_data, kError);
i::FLAG_harmony_function_sent = old_flag;
}
TEST(NewTargetErrors) {
// clang-format off
const char* context_data[][2] = {
{ "'use strict'", "" },
{ "", "" },
{ NULL, NULL }
};
const char* error_data[] = {
"var x = new.target",
"function f() { return new.t\\u0061rget; }",
NULL
};
// clang-format on
RunParserSyncTest(context_data, error_data, kError);
}
// Copyright 2016 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-function-sent
function* f() {
return function.s\u0065nt;
}
for (var i of f()) print(i);
*%(basename)s:8: SyntaxError: 'function.sent' must not contain escaped characters
return function.s\u0065nt;
^^^^^^^^^^^^^^^^^^
SyntaxError: 'function.sent' must not contain escaped characters
// Copyright 2016 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.
//
//
function f() {
return new.t\u0061rget;
}
var o = new f();
*%(basename)s:8: SyntaxError: 'new.target' must not contain escaped characters
return new.t\u0061rget;
^^^^^^^^^^^^^^^
SyntaxError: 'new.target' must not contain escaped characters
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