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

Reland "[parser] Set all tokens to ILLEGAL on parser error"

Fix: Skip sanity check of illegal tokens
Additional fix: set c0_ to kEndOfInput

Bug: v8:8363, v8:7926
Change-Id: I4f1222945914462e495d9ed6b86d38e478adbe39
Reviewed-on: https://chromium-review.googlesource.com/c/1304298
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: 's avatarMarja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57085}
parent 9195ca99
......@@ -3365,7 +3365,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(
......@@ -4420,9 +4421,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;
......
......@@ -408,6 +408,7 @@ void Scanner::SanityCheckTokenDesc(const TokenDesc& token) const {
switch (token.token) {
case Token::UNINITIALIZED:
case Token::ILLEGAL:
// token.literal_chars & other members might be garbage. That's ok.
break;
case Token::TEMPLATE_SPAN:
......
......@@ -238,7 +238,16 @@ 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() {
if (!source_->has_parser_error()) {
c0_ = kEndOfInput;
source_->set_parser_error();
for (TokenDesc& desc : token_storage_) {
desc.token = Token::ILLEGAL;
desc.contextual_token = Token::UNINITIALIZED;
}
}
}
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