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 12, 2021
1 parent a81526a commit 7f0556c
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 @@ -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())
})
};

Expand Down

0 comments on commit 7f0556c

Please sign in to comment.