diff --git a/napi/src/env.rs b/napi/src/env.rs index 9438f35a..5a982b21 100644 --- a/napi/src/env.rs +++ b/napi/src/env.rs @@ -344,13 +344,15 @@ impl Env { pub fn create_function(&self, name: &str, callback: Callback) -> Result { let mut raw_result = ptr::null_mut(); + let name = CString::new(name.to_owned())?; + let len = name.as_bytes().len(); check_status(unsafe { sys::napi_create_function( self.0, - name.as_ptr() as *const c_char, - name.len() as _, + name.into_raw(), + len, Some(callback), - callback as *mut c_void, + ptr::null_mut(), &mut raw_result, ) })?; diff --git a/napi/src/js_values/mod.rs b/napi/src/js_values/mod.rs index 227fc9e1..65387f5f 100644 --- a/napi/src/js_values/mod.rs +++ b/napi/src/js_values/mod.rs @@ -257,7 +257,7 @@ macro_rules! impl_object_methods { where T: NapiValue, { - let key = CString::new(name)?; + let key = CString::new(name.to_owned())?; check_status(unsafe { sys::napi_set_named_property(self.0.env, self.0.value, key.as_ptr(), value.raw()) })