Commit 3c8eaa19 authored by Toon Verwaest's avatar Toon Verwaest Committed by Commit Bot

[parser] Restructure checks in ParseAndClassifyIdentifier

Change-Id: I7662e9d500070a2bbe49562a9efbb459247819d5
Reviewed-on: https://chromium-review.googlesource.com/c/1264655Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56410}
parent fe757702
...@@ -1683,16 +1683,10 @@ template <typename Impl> ...@@ -1683,16 +1683,10 @@ template <typename Impl>
typename ParserBase<Impl>::IdentifierT typename ParserBase<Impl>::IdentifierT
ParserBase<Impl>::ParseAndClassifyIdentifier(bool* ok) { ParserBase<Impl>::ParseAndClassifyIdentifier(bool* ok) {
Token::Value next = Next(); Token::Value next = Next();
if (next == Token::IDENTIFIER || next == Token::ASYNC || STATIC_ASSERT(Token::IDENTIFIER + 1 == Token::ASYNC);
(next == Token::AWAIT && !parsing_module_ && !is_async_function())) { if (IsInRange(next, Token::IDENTIFIER, Token::ASYNC)) {
IdentifierT name = impl()->GetSymbol(); IdentifierT name = impl()->GetSymbol();
if (impl()->IsArguments(name) && scope()->ShouldBanArguments()) {
ReportMessage(MessageTemplate::kArgumentsDisallowedInInitializer);
*ok = false;
return impl()->NullIdentifier();
}
// When this function is used to read a formal parameter, we don't always // When this function is used to read a formal parameter, we don't always
// know whether the function is going to be strict or sloppy. Indeed for // know whether the function is going to be strict or sloppy. Indeed for
// arrow functions we don't always know that the identifier we are reading // arrow functions we don't always know that the identifier we are reading
...@@ -1700,15 +1694,18 @@ ParserBase<Impl>::ParseAndClassifyIdentifier(bool* ok) { ...@@ -1700,15 +1694,18 @@ ParserBase<Impl>::ParseAndClassifyIdentifier(bool* ok) {
// must detect because we know we're in strict mode, we also record any // must detect because we know we're in strict mode, we also record any
// error that we might make in the future once we know the language mode. // error that we might make in the future once we know the language mode.
if (impl()->IsEvalOrArguments(name)) { if (impl()->IsEvalOrArguments(name)) {
if (impl()->IsArguments(name) && scope()->ShouldBanArguments()) {
ReportMessage(MessageTemplate::kArgumentsDisallowedInInitializer);
*ok = false;
return impl()->NullIdentifier();
}
classifier()->RecordStrictModeFormalParameterError( classifier()->RecordStrictModeFormalParameterError(
scanner()->location(), MessageTemplate::kStrictEvalArguments); scanner()->location(), MessageTemplate::kStrictEvalArguments);
if (is_strict(language_mode())) { if (is_strict(language_mode())) {
classifier()->RecordBindingPatternError( classifier()->RecordBindingPatternError(
scanner()->location(), MessageTemplate::kStrictEvalArguments); scanner()->location(), MessageTemplate::kStrictEvalArguments);
} }
} else if (next == Token::AWAIT) {
classifier()->RecordAsyncArrowFormalParametersError(
scanner()->location(), MessageTemplate::kAwaitBindingIdentifier);
} }
if (classifier()->duplicate_finder() != nullptr && if (classifier()->duplicate_finder() != nullptr &&
...@@ -1716,7 +1713,12 @@ ParserBase<Impl>::ParseAndClassifyIdentifier(bool* ok) { ...@@ -1716,7 +1713,12 @@ ParserBase<Impl>::ParseAndClassifyIdentifier(bool* ok) {
ast_value_factory())) { ast_value_factory())) {
classifier()->RecordDuplicateFormalParameterError(scanner()->location()); classifier()->RecordDuplicateFormalParameterError(scanner()->location());
} }
return name; return name;
} else if (next == Token::AWAIT && !parsing_module_ && !is_async_function()) {
classifier()->RecordAsyncArrowFormalParametersError(
scanner()->location(), MessageTemplate::kAwaitBindingIdentifier);
return impl()->GetSymbol();
} else if (is_sloppy(language_mode()) && } else if (is_sloppy(language_mode()) &&
(Token::IsStrictReservedWord(next) || (Token::IsStrictReservedWord(next) ||
(next == Token::YIELD && !is_generator()))) { (next == Token::YIELD && !is_generator()))) {
......
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