mirror of
https://github.com/oven-sh/bun
synced 2026-02-12 03:48:56 +00:00
Fix unhandled exception in JSC__JSPromise__wrap when resolving promise (#23961)
### What does this PR do? Previously, `JSC__JSPromise__wrap` would call `JSC::JSPromise::resolvedPromise(globalObject, result)` without checking if an exception was thrown during promise resolution. This could happen in certain edge cases, such as when the result value is a thenable that triggers stack overflow, or when the promise resolution mechanism itself encounters an error. When such exceptions occurred, they would escape back to the Zig code, causing the CatchScope assertion to fail with "ASSERTION FAILED: Unexpected exception observed on thread" instead of being properly handled. This PR adds an exception check immediately after calling `JSC::JSPromise::resolvedPromise()` and before the `RELEASE_AND_RETURN` macro. If an exception is detected, the function now clears it and returns a rejected promise with the exception value, ensuring consistent error handling behavior. This matches the pattern already used earlier in the function for the initial function call exception handling. ### How did you verify your code works? new and existing tests --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
@@ -49,7 +49,7 @@ describe("2-arg form", () => {
|
||||
test("print size", () => {
|
||||
expect(normalizeBunSnapshot(Bun.inspect(new Response(Bun.file(import.meta.filename)))), import.meta.dir)
|
||||
.toMatchInlineSnapshot(`
|
||||
"Response (3.82 KB) {
|
||||
"Response (4.15 KB) {
|
||||
ok: true,
|
||||
url: "",
|
||||
status: 200,
|
||||
@@ -109,3 +109,17 @@ test("new Response(123, { method: 456 }) does not throw", () => {
|
||||
// @ts-expect-error
|
||||
expect(() => new Response("123", { method: 456 })).not.toThrow();
|
||||
});
|
||||
|
||||
test("handle stack overflow", () => {
|
||||
function f0(a1, a2) {
|
||||
const v4 = new Response();
|
||||
// @ts-ignore
|
||||
const v5 = v4.text(a2, a2, v4, f0, f0);
|
||||
a1(a1); // Recursive call causes stack overflow
|
||||
return v5;
|
||||
}
|
||||
expect(() => {
|
||||
// @ts-ignore
|
||||
f0(f0);
|
||||
}).toThrow("Maximum call stack size exceeded.");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user