1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:57:35 +00:00

LibJS: Lookahead for a period when parsing new.target

This allows us to skip saving and loading the state whenever we parse
'new'.
This commit is contained in:
davidot 2021-11-26 23:41:59 +01:00 committed by Linus Groh
parent 4d7e79fb72
commit 73eb29dabe

View file

@ -851,6 +851,10 @@ RefPtr<Statement> Parser::try_parse_labelled_statement(AllowLabelledFunction all
RefPtr<MetaProperty> Parser::try_parse_new_target_expression()
{
// Optimization which skips the save/load state.
if (next_token().type() != TokenType::Period)
return {};
save_state();
auto rule_start = push_start();
ArmedScopeGuard state_rollback_guard = [&] {
@ -858,9 +862,7 @@ RefPtr<MetaProperty> Parser::try_parse_new_target_expression()
};
consume(TokenType::New);
if (!match(TokenType::Period))
return {};
consume();
consume(TokenType::Period);
if (!match(TokenType::Identifier))
return {};
// The string 'target' cannot have escapes so we check original value.