Commit e3d761d9 authored by vabr's avatar vabr Committed by Commit bot

ParserBase should accept ESCAPED_STRICT_RESERVED_WORD as an identifier

ParserBase::is_any_identifier currently does not recognise
Token::ESCAPED_STRICT_RESERVED_WORD as an identifier. This seems different
from what ParserBase::ParseIdentifierName does, and also prevents
"l\u0065t", unlike "let", from becoming a label.

This CL extends is_any_identifier to also accept ESCAPED_STRICT_RESERVED_WORD.

BUG=v8:5692

Review-Url: https://codereview.chromium.org/2695973003
Cr-Commit-Position: refs/heads/master@{#43204}
parent 8a54a471
......@@ -811,6 +811,7 @@ class ParserBase {
bool is_any_identifier(Token::Value token) {
return token == Token::IDENTIFIER || token == Token::ENUM ||
token == Token::AWAIT || token == Token::ASYNC ||
token == Token::ESCAPED_STRICT_RESERVED_WORD ||
token == Token::FUTURE_STRICT_RESERVED_WORD || token == Token::LET ||
token == Token::STATIC || token == Token::YIELD;
}
......@@ -1673,7 +1674,8 @@ ParserBase<Impl>::ParseIdentifierOrStrictReservedWord(
!IsAsyncFunction(function_kind)) ||
next == Token::ASYNC) {
*is_strict_reserved = false;
} else if (next == Token::FUTURE_STRICT_RESERVED_WORD || next == Token::LET ||
} else if (next == Token::ESCAPED_STRICT_RESERVED_WORD ||
next == Token::FUTURE_STRICT_RESERVED_WORD || next == Token::LET ||
next == Token::STATIC ||
(next == Token::YIELD && !IsGeneratorFunction(function_kind))) {
*is_strict_reserved = true;
......
......@@ -9449,3 +9449,20 @@ TEST(NoPessimisticContextAllocation) {
}
}
}
TEST(EscapedStrictReservedWord) {
// Test that identifiers which are both escaped and only reserved in the
// strict mode are accepted in non-strict mode.
const char* context_data[][2] = {{"", ""}, {NULL, NULL}};
const char* statement_data[] = {"if (true) l\u0065t: ;",
"function l\u0065t() { }",
"(function l\u0065t() { })",
"async function l\u0065t() { }",
"(async function l\u0065t() { })",
"l\u0065t => 42",
"async l\u0065t => 42",
NULL};
RunParserSyncTest(context_data, statement_data, kSuccess);
}
// Copyright 2017 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.
// "let" in non-strict mode can be a label, even if composed of unicode escape
// sequences.
var wasTouched = false;
l\u0065t:
do {
break l\u0065t;
wasTouched = true;
} while (false);
// Verify that in addition to no exception thrown, breaking to the label also
// works.
assertFalse(wasTouched);
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