Address feedback in review:
Use `Local` instead of `napi_value`, for consistency
Comment that `target` is guaranteed to be initialized but may be NULL
@@ -30,14 +30,22 @@ pub unsafe extern "C" fn get_isolate(_info: FunctionCallbackInfo) -> Env { unimp
pub unsafe extern "C" fn current_isolate() -> Env { panic!("current_isolate won't be implemented in n-api") }
pub unsafe extern "C" fn is_construct(env: Env, info: FunctionCallbackInfo) -> bool {
- let mut target: MaybeUninit<napi::napi_value> = MaybeUninit::zeroed();
+ let mut target: MaybeUninit<Local> = MaybeUninit::zeroed();
+
let status = napi::napi_get_new_target(
env,
info,
target.as_mut_ptr()
);
+
assert_eq!(status, napi::napi_status::napi_ok);
- let target: napi::napi_value = target.assume_init();
+
+ // napi_get_new_target is guaranteed to assign to target, so it's initialized.
+ let target: Local = target.assume_init();
+
+ // By the napi_get_new_target contract, target will either be NULL if the current
+ // function was called without `new`, or a valid napi_value handle if the current
+ // function was called with `new`.
!target.is_null()
}
