fix: wrong name len used for function creating

This commit is contained in:
forehalo 2021-09-29 20:18:29 +08:00 committed by LongYinan
parent 5b39035541
commit aa77c8ff97

View file

@ -243,8 +243,8 @@ impl NapiFn {
quote! {} quote! {}
} else { } else {
let name_str = self.name.to_string(); let name_str = self.name.to_string();
let name_len = name_str.len();
let js_name = &self.js_name; let js_name = &self.js_name;
let name_len = js_name.len();
let module_register_name = get_register_ident(&name_str); let module_register_name = get_register_ident(&name_str);
let intermediate_ident = get_intermediate_ident(&name_str); let intermediate_ident = get_intermediate_ident(&name_str);
@ -255,12 +255,11 @@ impl NapiFn {
fn #module_register_name() { fn #module_register_name() {
unsafe fn cb(env: sys::napi_env) -> Result<sys::napi_value> { unsafe fn cb(env: sys::napi_env) -> Result<sys::napi_value> {
let mut fn_ptr = std::ptr::null_mut(); let mut fn_ptr = std::ptr::null_mut();
let js_name = std::ffi::CString::new(#js_name).unwrap();
check_status!( check_status!(
sys::napi_create_function( sys::napi_create_function(
env, env,
js_name.as_ptr(), #js_name.as_ptr() as *const _,
#name_len, #name_len,
Some(#intermediate_ident), Some(#intermediate_ident),
std::ptr::null_mut(), std::ptr::null_mut(),