From c44eb732ee25945df42e399f84f76429acea149a Mon Sep 17 00:00:00 2001 From: Ben Grant Date: Wed, 23 Oct 2024 11:24:52 -0700 Subject: [PATCH] Do not propagate nullptr out of NAPIFunction::call --- src/bun.js/bindings/napi.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/bun.js/bindings/napi.cpp b/src/bun.js/bindings/napi.cpp index caa4f1c8e5..28600a96b0 100644 --- a/src/bun.js/bindings/napi.cpp +++ b/src/bun.js/bindings/napi.cpp @@ -545,9 +545,10 @@ public: auto scope = DECLARE_THROW_SCOPE(vm); Bun::NapiHandleScope handleScope(jsCast(globalObject)); - auto result = callback(env, frame.toNapi()); + napi_value napi_result = callback(env, frame.toNapi()); + JSValue result = napi_result ? toJS(napi_result) : jsUndefined(); - RELEASE_AND_RETURN(scope, JSValue::encode(toJS(result))); + RELEASE_AND_RETURN(scope, JSValue::encode(result)); } NAPIFunction(JSC::VM& vm, JSC::NativeExecutable* exec, JSGlobalObject* globalObject, Structure* structure, Zig::CFFIFunction method, void* dataPtr)