Merge pull request #1228 from Hywan/fix-option-t-null

fix(napi) `undefined` is recognized as a valid `None` for `Option<T>`
This commit is contained in:
LongYinan 2022-07-07 22:30:07 +08:00 committed by GitHub
commit d0a9cbfa86
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -169,7 +169,7 @@ impl<T: ValidateNapiValue> ValidateNapiValue for Option<T> {
)?; )?;
let received_type = ValueType::from(result); let received_type = ValueType::from(result);
if received_type == ValueType::Null { if received_type == ValueType::Null || received_type == ValueType::Undefined {
Ok(ptr::null_mut()) Ok(ptr::null_mut())
} else if let Ok(validate_ret) = unsafe { T::validate(env, napi_val) } { } else if let Ok(validate_ret) = unsafe { T::validate(env, napi_val) } {
Ok(validate_ret) Ok(validate_ret)