Skip to content

Commit

Permalink
Add comment to ptr::null_mut() call back
Browse files Browse the repository at this point in the history
  • Loading branch information
kjvalencik committed Nov 17, 2021
1 parent a6dbc73 commit 5e16313
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
})
};

Expand Down

0 comments on commit 5e16313

Please sign in to comment.