fix(napi): remove previous reference if value_ref existed
Usually happens while using ZST
This commit is contained in:
parent
767c040d94
commit
525d881590
3 changed files with 8 additions and 3 deletions
|
@ -375,7 +375,7 @@ impl NapiStruct {
|
||||||
"Failed to wrap native object of class `{}`",
|
"Failed to wrap native object of class `{}`",
|
||||||
#js_name_raw
|
#js_name_raw
|
||||||
)?;
|
)?;
|
||||||
napi::bindgen_prelude::Reference::<#name>::add_ref(wrapped_value, (wrapped_value, object_ref, finalize_callbacks_ptr));
|
napi::bindgen_prelude::Reference::<#name>::add_ref(env, wrapped_value, (wrapped_value, object_ref, finalize_callbacks_ptr));
|
||||||
Ok(result)
|
Ok(result)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,6 +94,7 @@ impl<const N: usize> CallbackInfo<N> {
|
||||||
};
|
};
|
||||||
|
|
||||||
Reference::<T>::add_ref(
|
Reference::<T>::add_ref(
|
||||||
|
self.env,
|
||||||
value_ref as *mut c_void,
|
value_ref as *mut c_void,
|
||||||
(value_ref as *mut c_void, object_ref, finalize_callbacks_ptr),
|
(value_ref as *mut c_void, object_ref, finalize_callbacks_ptr),
|
||||||
);
|
);
|
||||||
|
@ -176,6 +177,7 @@ impl<const N: usize> CallbackInfo<N> {
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Reference::<T>::add_ref(
|
Reference::<T>::add_ref(
|
||||||
|
self.env,
|
||||||
value_ref as *mut c_void,
|
value_ref as *mut c_void,
|
||||||
(value_ref as *mut c_void, object_ref, finalize_callbacks_ptr),
|
(value_ref as *mut c_void, object_ref, finalize_callbacks_ptr),
|
||||||
);
|
);
|
||||||
|
|
|
@ -59,9 +59,12 @@ impl<T> Drop for Reference<T> {
|
||||||
|
|
||||||
impl<T: 'static> Reference<T> {
|
impl<T: 'static> Reference<T> {
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub fn add_ref(t: *mut c_void, value: RefInformation) {
|
pub fn add_ref(env: crate::sys::napi_env, t: *mut c_void, value: RefInformation) {
|
||||||
REFERENCE_MAP.borrow_mut(|map| {
|
REFERENCE_MAP.borrow_mut(|map| {
|
||||||
map.insert(t, value);
|
if let Some((_, previous_ref, previous_rc)) = map.insert(t, value) {
|
||||||
|
unsafe { Rc::from_raw(previous_rc) };
|
||||||
|
unsafe { crate::sys::napi_delete_reference(env, previous_ref) };
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue