diff --git a/src/types/mod.rs b/src/types/mod.rs index 33fba63a3..8789e1aaf 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -773,7 +773,12 @@ impl JsFunction { FunctionContext::with(env, &info, |cx| { convert_panics(env, AssertUnwindSafe(|| f(cx))) .map(|v| v.to_raw()) - .unwrap_or_else(|_| ptr::null_mut()) + // We do not have a Js Value to return, most likely due to an exception. + // If we are in a throwing state, constructing a Js Value would be invalid. + // While not explicitly written, the Node-API documentation includes many examples + // of returning `NULL` when a native function does not return a value. + // https://nodejs.org/api/n-api.html#n_api_napi_create_function + .unwrap_or_else(|_: Throw| ptr::null_mut()) }) };