Commit ea8aa6a7 authored by Toon Verwaest's avatar Toon Verwaest Committed by Commit Bot

[parser] Set all tokens to ILLEGAL on parser error

Otherwise already peeked tokens will possibly pass later checks causing us to
parse more than necessary. Initially we held off on doing this since subsequent
Consume calls would fail after previous checks succeeded; especially in the
case of stack overflow. However, we've previously relaxed that DCHECK to also
pass if the parser has an error.

Change-Id: I413dffd475982d07299a08270fa94fdc3858e883
Reviewed-on: https://chromium-review.googlesource.com/c/1304313Reviewed-by: 's avatarMarja Hölttä <marja@chromium.org>
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57054}
parent dc704497
......@@ -3364,7 +3364,8 @@ ParserBase<Impl>::ParseFunctionExpression() {
// We don't want dynamic functions to actually declare their name
// "anonymous". We just want that name in the toString().
Consume(Token::IDENTIFIER);
DCHECK(scanner()->CurrentMatchesContextual(Token::ANONYMOUS));
DCHECK_IMPLIES(!has_error(),
scanner()->CurrentMatchesContextual(Token::ANONYMOUS));
} else if (peek_any_identifier()) {
bool is_await = false;
name = ParseIdentifierOrStrictReservedWord(
......@@ -4419,9 +4420,9 @@ ParserBase<Impl>::ParseAsyncFunctionLiteral() {
// Consuming token we did not peek yet, which could lead to a ILLEGAL token
// in the case of a stackoverflow.
Expect(Token::IDENTIFIER);
RETURN_IF_PARSE_ERROR;
DCHECK(scanner()->CurrentMatchesContextual(Token::ANONYMOUS));
Consume(Token::IDENTIFIER);
DCHECK_IMPLIES(!has_error(),
scanner()->CurrentMatchesContextual(Token::ANONYMOUS));
} else if (peek_any_identifier()) {
type = FunctionLiteral::kNamedExpression;
bool is_await = false;
......
......@@ -238,7 +238,12 @@ class Scanner {
// Sets the Scanner into an error state to stop further scanning and terminate
// the parsing by only returning ILLEGAL tokens after that.
V8_INLINE void set_parser_error() { source_->set_parser_error(); }
V8_INLINE void set_parser_error() {
source_->set_parser_error();
current_->token = Token::ILLEGAL;
next_->token = Token::ILLEGAL;
next_next_->token = Token::ILLEGAL;
}
V8_INLINE void reset_parser_error_flag() {
source_->reset_parser_error_flag();
}
......
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