From 813d671d7677a24cafaa60dfd2ab15a5c2c9bc08 Mon Sep 17 00:00:00 2001 From: LongYinan Date: Thu, 28 Oct 2021 18:11:06 +0800 Subject: [PATCH] fix(napi-derive-backend): always generate CallContext for constructor function --- crates/backend/src/codegen/fn.rs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/crates/backend/src/codegen/fn.rs b/crates/backend/src/codegen/fn.rs index 0a009516..8eb50426 100644 --- a/crates/backend/src/codegen/fn.rs +++ b/crates/backend/src/codegen/fn.rs @@ -39,16 +39,17 @@ impl TryToTokens for NapiFn { } }; - let function_call = if args_len == 0 && self.fn_self.is_none() { - quote! { #native_call } - } else { - quote! { - CallbackInfo::<#args_len>::new(env, cb, None).and_then(|mut cb| { - #(#arg_conversions)* - #native_call - }) - } - }; + let function_call = + if args_len == 0 && self.fn_self.is_none() && self.kind != FnKind::Constructor { + quote! { #native_call } + } else { + quote! { + CallbackInfo::<#args_len>::new(env, cb, None).and_then(|mut cb| { + #(#arg_conversions)* + #native_call + }) + } + }; (quote! { #(#attrs)*