perf(napi): ignore callback info while no arguments
This commit is contained in:
parent
3565808d9a
commit
e69a763284
1 changed files with 20 additions and 9 deletions
|
@ -19,7 +19,25 @@ impl TryToTokens for NapiFn {
|
||||||
let register = self.gen_fn_register();
|
let register = self.gen_fn_register();
|
||||||
|
|
||||||
let attrs = &self.attrs;
|
let attrs = &self.attrs;
|
||||||
|
let function_call_tokens = if args_len == 0 && self.fn_self.is_none() {
|
||||||
|
quote! {
|
||||||
|
{
|
||||||
|
let #receiver_ret_name = #receiver();
|
||||||
|
#ret
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
quote! {
|
||||||
|
CallbackInfo::<#args_len>::new(env, cb, None).and_then(|mut cb| {
|
||||||
|
#(#arg_conversions)*
|
||||||
|
let #receiver_ret_name = {
|
||||||
|
#receiver(#(#arg_names),*)
|
||||||
|
};
|
||||||
|
|
||||||
|
#ret
|
||||||
|
})
|
||||||
|
}
|
||||||
|
};
|
||||||
(quote! {
|
(quote! {
|
||||||
#(#attrs)*
|
#(#attrs)*
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
|
@ -30,14 +48,7 @@ impl TryToTokens for NapiFn {
|
||||||
cb: sys::napi_callback_info
|
cb: sys::napi_callback_info
|
||||||
) -> sys::napi_value {
|
) -> sys::napi_value {
|
||||||
unsafe {
|
unsafe {
|
||||||
CallbackInfo::<#args_len>::new(env, cb, None).and_then(|mut cb| {
|
#function_call_tokens.unwrap_or_else(|e| {
|
||||||
#(#arg_conversions)*
|
|
||||||
let #receiver_ret_name = {
|
|
||||||
#receiver(#(#arg_names),*)
|
|
||||||
};
|
|
||||||
|
|
||||||
#ret
|
|
||||||
}).unwrap_or_else(|e| {
|
|
||||||
JsError::from(e).throw_into(env);
|
JsError::from(e).throw_into(env);
|
||||||
std::ptr::null_mut::<sys::napi_value__>()
|
std::ptr::null_mut::<sys::napi_value__>()
|
||||||
})
|
})
|
||||||
|
@ -188,7 +199,7 @@ impl NapiFn {
|
||||||
|
|
||||||
match self.fn_self {
|
match self.fn_self {
|
||||||
Some(FnSelf::Value) => {
|
Some(FnSelf::Value) => {
|
||||||
// impossible, errord in parser
|
// impossible, panic! in parser
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
Some(FnSelf::Ref) | Some(FnSelf::MutRef) => quote! { this.#name },
|
Some(FnSelf::Ref) | Some(FnSelf::MutRef) => quote! { this.#name },
|
||||||
|
|
Loading…
Reference in a new issue