LibJS: Avoid emptying the return value register in try/finally

This works because at the end of the finally chunk, a
ContinuePendingUnwind is generated which copies the saved return value
register into the return value register. In cases where
ContinuePendingUnwind is not generated such as when there is a break
statement in the finally block, the fonction will return undefined which
is consistent with V8 and SpiderMonkey.
This commit is contained in:
Lucien Fiorini 2025-03-27 12:02:14 +01:00 committed by Jelle Raaijmakers
commit 6b6e13e28c
Notes: github-actions[bot] 2025-03-27 12:19:55 +00:00
3 changed files with 14 additions and 6 deletions

View file

@ -490,3 +490,17 @@ test("Break with nested mixed try-catch/finally", () => {
expect(executionOrder).toEqual([1, 2]);
});
test("Break in finally return in try", () => {
function foo() {
do {
try {
return "bar";
} finally {
break;
}
} while (expect.fail("Continued after do-while loop"));
}
expect(foo()).toEqual(undefined);
});