1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

fix(ext/napi): pass user context to napi_threadsafe_fn finalizers (#26229)

Fixes https://github.com/denoland/deno/issues/26228
This commit is contained in:
Divy Srivastava 2024-10-14 12:41:34 +05:30 committed by GitHub
parent 7c3da2ec1c
commit d22195e741
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 5 additions and 3 deletions

View file

@ -692,7 +692,7 @@ impl Drop for TsFn {
if let Some(finalizer) = self.thread_finalize_cb {
unsafe {
(finalizer)(self.env as _, self.thread_finalize_data, ptr::null_mut());
(finalizer)(self.env as _, self.thread_finalize_data, self.context);
}
}
}

View file

@ -46,6 +46,7 @@ fn create_custom_gc(env: sys::napi_env) {
"Create async resource string in napi_register_module_v1 napi_register_module_v1"
);
let mut custom_gc_tsfn = ptr::null_mut();
let context = Box::into_raw(Box::new(0)) as *mut c_void;
check_status_or_panic!(
unsafe {
sys::napi_create_threadsafe_function(
@ -57,7 +58,7 @@ fn create_custom_gc(env: sys::napi_env) {
1,
ptr::null_mut(),
Some(custom_gc_finalize),
ptr::null_mut(),
context,
Some(custom_gc),
&mut custom_gc_tsfn,
)
@ -80,8 +81,9 @@ unsafe extern "C" fn empty(
unsafe extern "C" fn custom_gc_finalize(
_env: sys::napi_env,
_finalize_data: *mut c_void,
_finalize_hint: *mut c_void,
finalize_hint: *mut c_void,
) {
let _ = Box::from_raw(finalize_hint as *mut i32);
}
extern "C" fn custom_gc(