From aa77c8ff97ed9fab4792a02d15b91cdedbc806f9 Mon Sep 17 00:00:00 2001 From: forehalo Date: Wed, 29 Sep 2021 20:18:29 +0800 Subject: [PATCH] fix: wrong name len used for function creating --- crates/backend/src/codegen/fn.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/backend/src/codegen/fn.rs b/crates/backend/src/codegen/fn.rs index 5f2d1ab2..e44666a0 100644 --- a/crates/backend/src/codegen/fn.rs +++ b/crates/backend/src/codegen/fn.rs @@ -243,8 +243,8 @@ impl NapiFn { quote! {} } else { let name_str = self.name.to_string(); - let name_len = name_str.len(); let js_name = &self.js_name; + let name_len = js_name.len(); let module_register_name = get_register_ident(&name_str); let intermediate_ident = get_intermediate_ident(&name_str); @@ -255,12 +255,11 @@ impl NapiFn { fn #module_register_name() { unsafe fn cb(env: sys::napi_env) -> Result { let mut fn_ptr = std::ptr::null_mut(); - let js_name = std::ffi::CString::new(#js_name).unwrap(); check_status!( sys::napi_create_function( env, - js_name.as_ptr(), + #js_name.as_ptr() as *const _, #name_len, Some(#intermediate_ident), std::ptr::null_mut(),