1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 10:57:35 +00:00

LibJS: Fix returning from try statement

Not sure if this regressed at some point or just never worked, it
definitely wasn't tested at all. We would always return undefined when
returning from a try statement block, handler, or finalizer.
This commit is contained in:
Linus Groh 2021-04-03 14:56:54 +02:00 committed by Andreas Kling
parent e46fa3ac8b
commit f1fde01025
2 changed files with 40 additions and 6 deletions

View file

@ -0,0 +1,34 @@
test("return from try block", () => {
function foo() {
try {
return "foo";
} catch {
return "bar";
}
}
expect(foo()).toBe("foo");
});
test("return from catch block", () => {
function foo() {
try {
throw "foo";
} catch {
return "bar";
}
}
expect(foo()).toBe("bar");
});
test("return from finally block", () => {
function foo() {
try {
return "foo";
} catch {
return "bar";
} finally {
return "baz";
}
}
expect(foo()).toBe("baz");
});