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}
This commit is contained in:
parent
8a54a47175
commit
e3d761d94b
@ -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);
|
||||
}
|
||||
|
16
test/mjsunit/regress/regress-5692.js
Normal file
16
test/mjsunit/regress/regress-5692.js
Normal file
@ -0,0 +1,16 @@
|
||||
// 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);
|
Loading…
Reference in New Issue
Block a user