diff --git a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp index b26e55cc58..cce2818b6b 100644 --- a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp +++ b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp @@ -642,12 +642,13 @@ Bytecode::CodeGenerationErrorOr WhileStatement::generate_bytecode(Bytecode generator.begin_continuable_scope(Bytecode::Label { test_block }); generator.begin_breakable_scope(Bytecode::Label { end_block }); TRY(m_body->generate_bytecode(generator)); + generator.end_breakable_scope(); + generator.end_continuable_scope(); + if (!generator.is_current_block_terminated()) { generator.emit().set_targets( Bytecode::Label { test_block }, {}); - generator.end_continuable_scope(); - generator.end_breakable_scope(); generator.switch_to_basic_block(end_block); generator.emit(result_reg); } @@ -687,12 +688,13 @@ Bytecode::CodeGenerationErrorOr DoWhileStatement::generate_bytecode(Byteco generator.begin_continuable_scope(Bytecode::Label { test_block }); generator.begin_breakable_scope(Bytecode::Label { end_block }); TRY(m_body->generate_bytecode(generator)); + generator.end_breakable_scope(); + generator.end_continuable_scope(); + if (!generator.is_current_block_terminated()) { generator.emit().set_targets( Bytecode::Label { test_block }, {}); - generator.end_continuable_scope(); - generator.end_breakable_scope(); generator.switch_to_basic_block(end_block); generator.emit(result_reg); } @@ -756,6 +758,7 @@ Bytecode::CodeGenerationErrorOr ForStatement::generate_bytecode(Bytecode:: generator.begin_continuable_scope(Bytecode::Label { *update_block_ptr }); generator.begin_breakable_scope(Bytecode::Label { end_block }); TRY(m_body->generate_bytecode(generator)); + generator.end_breakable_scope(); generator.end_continuable_scope(); if (!generator.is_current_block_terminated()) { @@ -772,7 +775,6 @@ Bytecode::CodeGenerationErrorOr ForStatement::generate_bytecode(Bytecode:: Bytecode::Label { *test_block_ptr }, {}); - generator.end_breakable_scope(); generator.switch_to_basic_block(end_block); generator.emit(result_reg); }