feat(napi-derive) Support #[napi(strict)]
on &T
and &mut T
. (#1238)
This commit is contained in:
parent
0f14799776
commit
6a9fdba8b6
1 changed files with 30 additions and 23 deletions
|
@ -188,22 +188,7 @@ impl NapiFn {
|
||||||
path: &syn::PatType,
|
path: &syn::PatType,
|
||||||
) -> TokenStream {
|
) -> TokenStream {
|
||||||
let ty = &*path.ty;
|
let ty = &*path.ty;
|
||||||
match ty {
|
|
||||||
syn::Type::Reference(syn::TypeReference {
|
|
||||||
mutability: Some(_),
|
|
||||||
elem,
|
|
||||||
..
|
|
||||||
}) => {
|
|
||||||
quote! {
|
|
||||||
let #arg_name = <#elem as napi::bindgen_prelude::FromNapiMutRef>::from_napi_mut_ref(env, cb.get_arg(#index))?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
syn::Type::Reference(syn::TypeReference { elem, .. }) => {
|
|
||||||
quote! {
|
|
||||||
let #arg_name = <#elem as napi::bindgen_prelude::FromNapiRef>::from_napi_ref(env, cb.get_arg(#index))?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
let type_check = if self.return_if_invalid {
|
let type_check = if self.return_if_invalid {
|
||||||
quote! {
|
quote! {
|
||||||
if let Ok(maybe_promise) = <#ty as napi::bindgen_prelude::ValidateNapiValue>::validate(env, cb.get_arg(#index)) {
|
if let Ok(maybe_promise) = <#ty as napi::bindgen_prelude::ValidateNapiValue>::validate(env, cb.get_arg(#index)) {
|
||||||
|
@ -225,6 +210,28 @@ impl NapiFn {
|
||||||
quote! {}
|
quote! {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
match ty {
|
||||||
|
syn::Type::Reference(syn::TypeReference {
|
||||||
|
mutability: Some(_),
|
||||||
|
elem,
|
||||||
|
..
|
||||||
|
}) => {
|
||||||
|
quote! {
|
||||||
|
let #arg_name = {
|
||||||
|
#type_check
|
||||||
|
<#elem as napi::bindgen_prelude::FromNapiMutRef>::from_napi_mut_ref(env, cb.get_arg(#index))?
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
syn::Type::Reference(syn::TypeReference { elem, .. }) => {
|
||||||
|
quote! {
|
||||||
|
let #arg_name = {
|
||||||
|
#type_check
|
||||||
|
<#elem as napi::bindgen_prelude::FromNapiRef>::from_napi_ref(env, cb.get_arg(#index))?
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
quote! {
|
quote! {
|
||||||
let #arg_name = {
|
let #arg_name = {
|
||||||
#type_check
|
#type_check
|
||||||
|
|
Loading…
Reference in a new issue