1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-29 03:42:07 +00:00

LibJS: Generate unwind chains for break in Bytecode

This uses a newly added instruction `ScheduleJump`
This instruction tells the finally proceeding it, that instead of
jumping to it's next block it should jump to the designated block.
This commit is contained in:
Hendiadyoin1 2022-11-25 16:15:34 +01:00 committed by Linus Groh
parent 495ba53e46
commit f5376cb282
9 changed files with 123 additions and 19 deletions

View file

@ -2168,17 +2168,11 @@ Bytecode::CodeGenerationErrorOr<void> BreakStatement::generate_bytecode(Bytecode
// We need to execute the finally block, but tell it to resume
// execution at the designated block
if (m_target_label.is_null()) {
generator.perform_needed_unwinds<Bytecode::Op::Jump>(true);
generator.emit<Bytecode::Op::Jump>().set_targets(
generator.nearest_breakable_scope(),
{});
generator.generate_break();
return {};
}
auto target_to_jump_to = generator.perform_needed_unwinds_for_labelled_break_and_return_target_block(m_target_label);
generator.emit<Bytecode::Op::Jump>().set_targets(
target_to_jump_to,
{});
generator.generate_break(m_target_label);
return {};
}
@ -2192,6 +2186,7 @@ Bytecode::CodeGenerationErrorOr<void> TryStatement::generate_bytecode(Bytecode::
Bytecode::BasicBlock* next_block { nullptr };
if (m_finalizer) {
// FIXME: See notes in Op.h->ScheduleJump
auto& finalizer_block = generator.make_block();
generator.switch_to_basic_block(finalizer_block);
generator.emit<Bytecode::Op::LeaveUnwindContext>();