Files
ladybird/Tests/LibJS/Bytecode/input/try-finally.js
Andreas Kling a439dc8490 LibJS: Use explicit completion records for try/finally dispatch
Each finally scope gets two registers (completion_type and
completion_value) that form an explicit completion record. Every path
into the finally body sets these before jumping, and a dispatch chain
after the finally body routes to the correct continuation.

This replaces the old implicit protocol that relied on the exception
register, a saved_return_value register, and a scheduled_jump field
on ExecutionContext, allowing us to remove:

- 5 opcodes (ContinuePendingUnwind, ScheduleJump, LeaveFinally,
  RestoreScheduledJump, PrepareYield)
- 1 reserved register (saved_return_value)
- 2 ExecutionContext fields (scheduled_jump, previously_scheduled_jumps)
2026-02-09 08:51:12 +01:00

35 lines
650 B
JavaScript

function basicTryFinally() {
try {
return 1;
} finally {
console.log("finally");
}
}
basicTryFinally();
function breakThroughFinally() {
for (let i = 0; i < 10; i++) {
try {
if (i === 5) break;
} finally {
console.log(i);
}
}
}
breakThroughFinally();
function nestedTryFinallyWithBreak() {
outer: for (let i = 0; ; i++) {
try {
try {
break outer;
} finally {
console.log("inner");
}
} finally {
console.log("outer");
}
}
}
nestedTryFinallyWithBreak();