From e86e3add2b208d23edd27e266c62f2acd2118b46 Mon Sep 17 00:00:00 2001 From: Ranger <32590310+southorange0929@users.noreply.github.com> Date: Wed, 10 Apr 2024 14:57:04 +0800 Subject: [PATCH] fix(napi): napi_adjust_external_memory should be hidden with wasm target (#2031) --- .../src/bindgen_runtime/js_values/external.rs | 33 ++++++++++--------- crates/napi/src/env.rs | 1 + 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/crates/napi/src/bindgen_runtime/js_values/external.rs b/crates/napi/src/bindgen_runtime/js_values/external.rs index 13f31824..42ac99da 100644 --- a/crates/napi/src/bindgen_runtime/js_values/external.rs +++ b/crates/napi/src/bindgen_runtime/js_values/external.rs @@ -141,23 +141,26 @@ impl ToNapiValue for External { "Create external value failed" )?; - let mut adjusted_external_memory_size = std::mem::MaybeUninit::new(0); + #[cfg(not(target_family = "wasm"))] + { + let mut adjusted_external_memory_size = std::mem::MaybeUninit::new(0); - if size_hint != 0 { - check_status!( - unsafe { - sys::napi_adjust_external_memory( - env, - size_hint, - adjusted_external_memory_size.as_mut_ptr(), - ) - }, - "Adjust external memory failed" - )?; - }; + if size_hint != 0 { + check_status!( + unsafe { + sys::napi_adjust_external_memory( + env, + size_hint, + adjusted_external_memory_size.as_mut_ptr(), + ) + }, + "Adjust external memory failed" + )?; + }; - (Box::leak(unsafe { Box::from_raw(obj_ptr) })).adjusted_size = - unsafe { adjusted_external_memory_size.assume_init() }; + (Box::leak(unsafe { Box::from_raw(obj_ptr) })).adjusted_size = + unsafe { adjusted_external_memory_size.assume_init() }; + } Ok(napi_value) } diff --git a/crates/napi/src/env.rs b/crates/napi/src/env.rs index b27e30c4..58657355 100644 --- a/crates/napi/src/env.rs +++ b/crates/napi/src/env.rs @@ -1407,6 +1407,7 @@ pub(crate) unsafe extern "C" fn raw_finalize( ) { let tagged_object = finalize_data as *mut T; drop(unsafe { Box::from_raw(tagged_object) }); + #[cfg(not(target_family = "wasm"))] if !finalize_hint.is_null() { let size_hint = unsafe { *Box::from_raw(finalize_hint as *mut i64) }; if size_hint != 0 {