diff --git a/src/parsing/parser-base.h b/src/parsing/parser-base.h index b8039d0ec9..acc96b665d 100644 --- a/src/parsing/parser-base.h +++ b/src/parsing/parser-base.h @@ -947,9 +947,6 @@ class ParserBase { } V8_NOINLINE void ReportUnexpectedToken(Token::Value token); - V8_NOINLINE void ReportUnexpectedTokenAt( - Scanner::Location location, Token::Value token, - MessageTemplate message = MessageTemplate::kUnexpectedToken); void ValidateFormalParameters(LanguageMode language_mode, const FormalParametersT& parameters, @@ -1457,20 +1454,7 @@ ParserBase::FunctionState::~FunctionState() { template void ParserBase::ReportUnexpectedToken(Token::Value token) { - return ReportUnexpectedTokenAt(scanner_->location(), token); -} - -template -void ParserBase::ReportUnexpectedTokenAt( - Scanner::Location source_location, Token::Value token, - MessageTemplate message) { - const char* arg = nullptr; - impl()->GetUnexpectedTokenMessage(token, &message, &source_location, &arg); - if (Impl::IsPreParser()) { - impl()->ReportUnidentifiableError(); - } else { - impl()->ReportMessageAt(source_location, message, arg); - } + return impl()->ReportUnexpectedTokenAt(scanner_->location(), token); } template @@ -1858,7 +1842,7 @@ ParserBase::ParseArrowParametersWithRest( // as the formal parameters of'(x, y, ...z) => foo', and is not itself a // valid expression. if (peek() != Token::RPAREN || PeekAhead() != Token::ARROW) { - ReportUnexpectedTokenAt(ellipsis, Token::ELLIPSIS); + impl()->ReportUnexpectedTokenAt(ellipsis, Token::ELLIPSIS); return impl()->FailureExpression(); } @@ -2225,7 +2209,7 @@ ParserBase::ParseClassPropertyDefinition(ClassInfo* class_info, case ParsePropertyKind::kValue: case ParsePropertyKind::kShorthand: case ParsePropertyKind::kSpread: - ReportUnexpectedTokenAt( + impl()->ReportUnexpectedTokenAt( Scanner::Location(name_token_position, name_expression->position()), name_token); return impl()->NullLiteralProperty(); @@ -3928,7 +3912,7 @@ ParserBase::ParseArrowFunctionLiteral( // ASI inserts `;` after arrow parameters if a line terminator is found. // `=> ...` is never a valid expression, so report as syntax error. // If next token is not `=>`, it's a syntax error anyways. - ReportUnexpectedTokenAt(scanner_->peek_location(), Token::ARROW); + impl()->ReportUnexpectedTokenAt(scanner_->peek_location(), Token::ARROW); return impl()->FailureExpression(); } diff --git a/src/parsing/parser.cc b/src/parsing/parser.cc index ba244ad298..0b9f211ef9 100644 --- a/src/parsing/parser.cc +++ b/src/parsing/parser.cc @@ -81,63 +81,64 @@ FunctionLiteral* Parser::DefaultConstructor(const AstRawString* name, return function_literal; } -void Parser::GetUnexpectedTokenMessage(Token::Value token, - MessageTemplate* message, - Scanner::Location* location, - const char** arg) { +void Parser::ReportUnexpectedTokenAt(Scanner::Location location, + Token::Value token, + MessageTemplate message) { + const char* arg = nullptr; switch (token) { case Token::EOS: - *message = MessageTemplate::kUnexpectedEOS; + message = MessageTemplate::kUnexpectedEOS; break; case Token::SMI: case Token::NUMBER: case Token::BIGINT: - *message = MessageTemplate::kUnexpectedTokenNumber; + message = MessageTemplate::kUnexpectedTokenNumber; break; case Token::STRING: - *message = MessageTemplate::kUnexpectedTokenString; + message = MessageTemplate::kUnexpectedTokenString; break; case Token::PRIVATE_NAME: case Token::IDENTIFIER: - *message = MessageTemplate::kUnexpectedTokenIdentifier; + message = MessageTemplate::kUnexpectedTokenIdentifier; break; case Token::AWAIT: case Token::ENUM: - *message = MessageTemplate::kUnexpectedReserved; + message = MessageTemplate::kUnexpectedReserved; break; case Token::LET: case Token::STATIC: case Token::YIELD: case Token::FUTURE_STRICT_RESERVED_WORD: - *message = is_strict(language_mode()) - ? MessageTemplate::kUnexpectedStrictReserved - : MessageTemplate::kUnexpectedTokenIdentifier; + message = is_strict(language_mode()) + ? MessageTemplate::kUnexpectedStrictReserved + : MessageTemplate::kUnexpectedTokenIdentifier; break; case Token::TEMPLATE_SPAN: case Token::TEMPLATE_TAIL: - *message = MessageTemplate::kUnexpectedTemplateString; + message = MessageTemplate::kUnexpectedTemplateString; break; case Token::ESCAPED_STRICT_RESERVED_WORD: case Token::ESCAPED_KEYWORD: - *message = MessageTemplate::kInvalidEscapedReservedWord; + message = MessageTemplate::kInvalidEscapedReservedWord; break; case Token::ILLEGAL: if (scanner()->has_error()) { - *message = scanner()->error(); - *location = scanner()->error_location(); + message = scanner()->error(); + location = scanner()->error_location(); } else { - *message = MessageTemplate::kInvalidOrUnexpectedToken; + message = MessageTemplate::kInvalidOrUnexpectedToken; } break; case Token::REGEXP_LITERAL: - *message = MessageTemplate::kUnexpectedTokenRegExp; + message = MessageTemplate::kUnexpectedTokenRegExp; break; default: const char* name = Token::String(token); DCHECK_NOT_NULL(name); - *arg = name; + arg = name; break; } + ReportMessageAt(location, message, arg); } // ---------------------------------------------------------------------------- diff --git a/src/parsing/parser.h b/src/parsing/parser.h index 878707ba5d..cc0ceb2607 100644 --- a/src/parsing/parser.h +++ b/src/parsing/parser.h @@ -331,8 +331,6 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase) { Block* finally_block, const SourceRange& finally_range, const CatchInfo& catch_info, int pos); - void GetUnexpectedTokenMessage(Token::Value token, MessageTemplate* message, - Scanner::Location* location, const char** arg); void ParseAndRewriteGeneratorFunctionBody(int pos, FunctionKind kind, ScopedPtrList* body); void ParseAndRewriteAsyncGeneratorFunctionBody( @@ -755,6 +753,10 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase) { scanner_.set_parser_error(); } + void ReportUnexpectedTokenAt( + Scanner::Location location, Token::Value token, + MessageTemplate message = MessageTemplate::kUnexpectedToken); + // "null" return type creators. V8_INLINE static std::nullptr_t NullIdentifier() { return nullptr; } V8_INLINE static std::nullptr_t NullExpression() { return nullptr; } diff --git a/src/parsing/preparser.h b/src/parsing/preparser.h index aa218c7ee3..d403854743 100644 --- a/src/parsing/preparser.h +++ b/src/parsing/preparser.h @@ -1112,10 +1112,11 @@ class PreParser : public ParserBase { return PreParserStatement::Default(); } - V8_INLINE void GetUnexpectedTokenMessage(Token::Value token, - MessageTemplate* message, - Scanner::Location* location, - const char** arg) {} + V8_INLINE void ReportUnexpectedTokenAt( + Scanner::Location location, Token::Value token, + MessageTemplate message = MessageTemplate::kUnexpectedToken) { + ReportUnidentifiableError(); + } V8_INLINE void ParseAndRewriteGeneratorFunctionBody( int pos, FunctionKind kind, PreParserScopedStatementList* body) { ParseStatementList(body, Token::RBRACE);