handle scope exceptions

This commit is contained in:
Zack Radisic
2025-09-10 16:51:06 -07:00
parent 0919e45c23
commit 0df21d7f30
3 changed files with 11 additions and 4 deletions

View File

@@ -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,

View File

@@ -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);
}

View File

@@ -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;