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:
parent
e46fa3ac8b
commit
f1fde01025
2 changed files with 40 additions and 6 deletions
34
Userland/Libraries/LibJS/Tests/try-catch-finally-return.js
Normal file
34
Userland/Libraries/LibJS/Tests/try-catch-finally-return.js
Normal 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");
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue