From 7f0556cc42f757f7a12821f9e66c52e0dcf5cf7a Mon Sep 17 00:00:00 2001 From: "K.J. Valencik" Date: Fri, 12 Nov 2021 12:53:43 -0500 Subject: [PATCH] Add comment to `ptr::null_mut()` call back --- src/types/mod.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/types/mod.rs b/src/types/mod.rs index 111f109c7..8aec03e63 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -774,7 +774,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()) }) };