summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authordavidot <davidot@serenityos.org>2021-11-26 23:41:59 +0100
committerLinus Groh <mail@linusgroh.de>2021-11-30 17:05:32 +0000
commit73eb29dabe855488e9c436323f6959ac423bebe6 (patch)
tree9c49de20e958c0462b470fd23127285f09b77345 /Userland/Libraries
parent4d7e79fb72c33bf341688428948c3c8e90898960 (diff)
downloadserenity-73eb29dabe855488e9c436323f6959ac423bebe6.zip
LibJS: Lookahead for a period when parsing new.target
This allows us to skip saving and loading the state whenever we parse 'new'.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibJS/Parser.cpp8
1 files changed, 5 insertions, 3 deletions
diff --git a/Userland/Libraries/LibJS/Parser.cpp b/Userland/Libraries/LibJS/Parser.cpp
index cb758c802c..0f1127d6c3 100644
--- a/Userland/Libraries/LibJS/Parser.cpp
+++ b/Userland/Libraries/LibJS/Parser.cpp
@@ -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.