Compare commits

...

1 Commits

Author SHA1 Message Date
Claude Bot
bc729511eb fix(bindings): handle pending exceptions in ReadableStream__empty and ReadableStream__used
When accessing Response.json().body after catching a stack overflow exception,
the pending exception state was not being properly handled in the C++ bindings.
This caused a debug assertion failure: "Unexpected exception observed".

The fix adds proper exception handling using DECLARE_THROW_SCOPE and
RETURN_IF_EXCEPTION to both ReadableStream__empty and ReadableStream__used
functions.

Fixes: ENG-23921

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-29 05:22:11 +00:00
2 changed files with 33 additions and 2 deletions

View File

@@ -2919,17 +2919,23 @@ JSC::EncodedJSValue JSC__JSModuleLoader__evaluate(JSC::JSGlobalObject* globalObj
JSC::EncodedJSValue ReadableStream__empty(Zig::GlobalObject* globalObject)
{
auto& vm = JSC::getVM(globalObject);
auto scope = DECLARE_THROW_SCOPE(vm);
auto clientData = WebCore::clientData(vm);
auto* function = globalObject->getDirect(vm, clientData->builtinNames().createEmptyReadableStreamPrivateName()).getObject();
return JSValue::encode(JSC::call(globalObject, function, JSC::ArgList(), "ReadableStream.create"_s));
auto result = JSC::call(globalObject, function, JSC::ArgList(), "ReadableStream.create"_s);
RETURN_IF_EXCEPTION(scope, {});
return JSValue::encode(result);
}
JSC::EncodedJSValue ReadableStream__used(Zig::GlobalObject* globalObject)
{
auto& vm = JSC::getVM(globalObject);
auto scope = DECLARE_THROW_SCOPE(vm);
auto clientData = WebCore::clientData(vm);
auto* function = globalObject->getDirect(vm, clientData->builtinNames().createUsedReadableStreamPrivateName()).getObject();
return JSValue::encode(JSC::call(globalObject, function, JSC::ArgList(), "ReadableStream.create"_s));
auto result = JSC::call(globalObject, function, JSC::ArgList(), "ReadableStream.create"_s);
RETURN_IF_EXCEPTION(scope, {});
return JSValue::encode(result);
}
JSC::EncodedJSValue JSC__JSValue__createRangeError(const ZigString* message, const ZigString* arg1,

View File

@@ -0,0 +1,25 @@
import { test } from "bun:test";
// Fixes: ENG-23921
// Accessing Response.json().body after catching a stack overflow exception
// should not crash the runtime.
test(
"Response.json().body should not crash after catching stack overflow",
() => {
function F0() {
if (!new.target) {
throw "must be called with new";
}
const v3 = this.constructor;
try {
new v3();
} catch (e) {}
// This should not crash - it used to trigger an assertion failure
// due to a pending exception not being properly handled
Response.json().body;
}
// This should not crash
new F0();
},
{ timeout: 60000 },
);