LibJS/Bytecode: Fix multiple wrong jumps in ForStatement codegen

This commit is contained in:
Andreas Kling 2023-06-15 19:13:00 +02:00
parent 0772a23c65
commit 6f39882f11
Notes: sideshowbarker 2024-07-17 03:10:07 +09:00

View file

@ -831,8 +831,16 @@ Bytecode::CodeGenerationErrorOr<void> ForStatement::generate_labelled_evaluation
Bytecode::Label { end_block });
}
if (m_update) {
generator.switch_to_basic_block(*update_block_ptr);
TRY(m_update->generate_bytecode(generator));
generator.emit<Bytecode::Op::Jump>().set_targets(
Bytecode::Label { *test_block_ptr },
{});
}
generator.switch_to_basic_block(*body_block_ptr);
generator.begin_continuable_scope(Bytecode::Label { *update_block_ptr }, label_set);
generator.begin_continuable_scope(Bytecode::Label { m_update ? *update_block_ptr : *test_block_ptr }, label_set);
generator.begin_breakable_scope(Bytecode::Label { end_block }, label_set);
TRY(m_body->generate_bytecode(generator));
generator.end_breakable_scope();
@ -843,14 +851,11 @@ Bytecode::CodeGenerationErrorOr<void> ForStatement::generate_labelled_evaluation
generator.emit<Bytecode::Op::Jump>().set_targets(
Bytecode::Label { *update_block_ptr },
{});
generator.switch_to_basic_block(*update_block_ptr);
TRY(m_update->generate_bytecode(generator));
} else {
generator.emit<Bytecode::Op::Jump>().set_targets(
Bytecode::Label { *test_block_ptr },
{});
}
generator.emit<Bytecode::Op::Jump>().set_targets(
Bytecode::Label { *test_block_ptr },
{});
}
generator.switch_to_basic_block(end_block);