LibJS: Fix Parser.parse_template_literal looping forever

parse_template_literal now breaks out of the loop if it sees something
it doesn't expect. Additionally, it now checks for EOFs.
This commit is contained in:
Matthew Olsson 2020-06-03 15:36:25 -07:00 committed by Andreas Kling
parent a586a84450
commit 5046f15824
Notes: sideshowbarker 2024-07-19 05:51:24 +09:00

View file

@ -719,7 +719,7 @@ NonnullRefPtr<TemplateLiteral> Parser::parse_template_literal(bool is_tagged)
if (!match(TokenType::TemplateLiteralString))
append_empty_string();
while (!match(TokenType::TemplateLiteralEnd) && !match(TokenType::UnterminatedTemplateLiteral)) {
while (!done() && !match(TokenType::TemplateLiteralEnd) && !match(TokenType::UnterminatedTemplateLiteral)) {
if (match(TokenType::TemplateLiteralString)) {
auto token = consume();
expressions.append(parse_string_literal(token));
@ -741,6 +741,9 @@ NonnullRefPtr<TemplateLiteral> Parser::parse_template_literal(bool is_tagged)
if (!match(TokenType::TemplateLiteralString))
append_empty_string();
} else {
expected("Template literal string or expression");
break;
}
}