[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/1304313
Reviewed-by: Marja Hölttä <marja@chromium.org>
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57054}
This commit is contained in:
Toon Verwaest 2018-10-29 09:08:28 +01:00 committed by Commit Bot
parent dc704497ee
commit ea8aa6a7c7
2 changed files with 11 additions and 5 deletions

View File

@ -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;

View File

@ -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();
}