From c7a99aafac7fb57879d9da6283b5e88d183cd6a6 Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Thu, 16 Sep 2021 22:09:28 +0430 Subject: [PATCH] LibJS: Use ScopePusher to correctly push the scope in for statements We were previously pushing a scope but forgetting to actually set it as the current scope. --- Userland/Libraries/LibJS/Parser.cpp | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/Userland/Libraries/LibJS/Parser.cpp b/Userland/Libraries/LibJS/Parser.cpp index 096ab55e02..ed8c6b0567 100644 --- a/Userland/Libraries/LibJS/Parser.cpp +++ b/Userland/Libraries/LibJS/Parser.cpp @@ -2687,19 +2687,13 @@ NonnullRefPtr Parser::parse_for_statement() consume(TokenType::ParenOpen); - bool in_scope = false; - ScopeGuard guard([&]() { - if (in_scope) - m_state.let_scopes.take_last(); - }); + Optional scope_pusher; RefPtr init; if (!match(TokenType::Semicolon)) { if (match_variable_declaration()) { - if (!match(TokenType::Var)) { - m_state.let_scopes.append(NonnullRefPtrVector()); - in_scope = true; - } + if (!match(TokenType::Var)) + scope_pusher.emplace(*this, ScopePusher::Let, Scope::Block); init = parse_variable_declaration(true); if (match_for_in_of()) return parse_for_in_of_statement(*init);