From 515f3e0b8596fda1fe7d39cccded71cbfbaa1c4b Mon Sep 17 00:00:00 2001 From: Luke Wilde Date: Tue, 15 Mar 2022 01:44:32 +0000 Subject: [PATCH] LibJS/Bytecode: End for's variable scope after update block generation The update block can generate bytecode that refers to the lexical environment, so we have to end the scope after it has been generated. Previously the Jump to the update block would terminate the block, causing us to leave the lexical environment just before jumping to the update block. --- Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp index cd2ac0f7a4d..03c4fc09000 100644 --- a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp +++ b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp @@ -782,9 +782,6 @@ Bytecode::CodeGenerationErrorOr ForStatement::generate_bytecode(Bytecode:: generator.end_breakable_scope(); generator.end_continuable_scope(); - if (has_lexical_environment) - generator.end_variable_scope(); - if (!generator.is_current_block_terminated()) { if (m_update) { generator.emit().set_targets( @@ -803,6 +800,9 @@ Bytecode::CodeGenerationErrorOr ForStatement::generate_bytecode(Bytecode:: generator.emit(result_reg); } + if (has_lexical_environment) + generator.end_variable_scope(); + return {}; }