From c153d1779eee424fcb47645ea16e93d4eaad8d83 Mon Sep 17 00:00:00 2001 From: Luke Wilde Date: Thu, 30 Jun 2022 15:55:57 +0100 Subject: [PATCH] LibJS/Bytecode: End the for variable scope at the start of its end block If the for loop's body is not block terminated, we will generate a Jump to the end block which will block terminate the body. Then, we ended the lexical variable scope if needed. However, since the body is now block terminated, the "LeaveLexicalEnvironment" instruction that is generated by end_variable_scope is now dropped on the floor. This fixes this by moving it to the beginning of the end 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 cf243901f7..98c9872450 100644 --- a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp +++ b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp @@ -897,13 +897,13 @@ Bytecode::CodeGenerationErrorOr ForStatement::generate_labelled_evaluation {}); } + generator.switch_to_basic_block(end_block); + generator.emit(result_reg); + if (has_lexical_environment) generator.end_variable_scope(); generator.end_breakable_scope(); - - generator.switch_to_basic_block(end_block); - generator.emit(result_reg); return {}; }