From 0df21d7f3025484bbf47c5b0cf4bcff06fe7676a Mon Sep 17 00:00:00 2001 From: Zack Radisic <56137411+zackradisic@users.noreply.github.com> Date: Wed, 10 Sep 2025 16:51:06 -0700 Subject: [PATCH] handle scope exceptions --- src/bun.js/api/server.zig | 2 +- src/bun.js/bindings/JSBunRequest.cpp | 4 +++- src/bun.js/webcore/Request.zig | 9 +++++++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/bun.js/api/server.zig b/src/bun.js/api/server.zig index b5274008d1..4e5db13be9 100644 --- a/src/bun.js/api/server.zig +++ b/src/bun.js/api/server.zig @@ -2266,7 +2266,7 @@ pub fn NewServer(protocol_enum: enum { http, https }, development_kind: enum { d return .{ .js_request = switch (create_js_request) { .yes => request_object.toJS(this.globalThis), - .bake => request_object.toJSForBake(this.globalThis, req), + .bake => request_object.toJSForBake(this.globalThis, req) catch |err| this.globalThis.takeException(err), .no => .zero, }, .request_object = request_object, diff --git a/src/bun.js/bindings/JSBunRequest.cpp b/src/bun.js/bindings/JSBunRequest.cpp index e11e603403..9b4a0f3685 100644 --- a/src/bun.js/bindings/JSBunRequest.cpp +++ b/src/bun.js/bindings/JSBunRequest.cpp @@ -22,14 +22,16 @@ extern "C" JSC::EncodedJSValue Bun__JSRequest__createFromUwsReqForBake(Zig::Glob auto& vm = globalObject->vm(); auto scope = DECLARE_THROW_SCOPE(vm); auto* structure = globalObject->m_JSBunRequestStructure.get(globalObject); + RETURN_IF_EXCEPTION(scope, {}); // the params are passed into the page component as a prop so we'll make // this empty for now auto* emptyParams = JSC::constructEmptyObject(globalObject); + RETURN_IF_EXCEPTION(scope, {}); JSBunRequest* request = JSBunRequest::create(vm, structure, requestPtr, emptyParams); - scope.assertNoException(); + RETURN_IF_EXCEPTION(scope, {}); return JSValue::encode(request); } diff --git a/src/bun.js/webcore/Request.zig b/src/bun.js/webcore/Request.zig index 6b23a9f0a2..f5f7810779 100644 --- a/src/bun.js/webcore/Request.zig +++ b/src/bun.js/webcore/Request.zig @@ -179,8 +179,13 @@ pub fn toJS(this: *Request, globalObject: *JSGlobalObject) JSValue { } extern "C" fn Bun__JSRequest__createFromUwsReqForBake(globalObject: *jsc.JSGlobalObject, requestPtr: *Request, req: *uws.Request) jsc.JSValue; -pub fn toJSForBake(this: *Request, globalObject: *JSGlobalObject, req: *uws.Request) JSValue { - return Bun__JSRequest__createFromUwsReqForBake(globalObject, this, req); +pub fn toJSForBake(this: *Request, globalObject: *JSGlobalObject, req: *uws.Request) bun.JSError!JSValue { + return bun.jsc.fromJSHostCall( + globalObject, + @src(), + Bun__JSRequest__createFromUwsReqForBake, + .{ globalObject, this, req }, + ); } extern "JS" fn Bun__getParamsIfBunRequest(this_value: JSValue) JSValue;