From 71bbe0ef6fb2c58e4af728fb488fa4b57781e3bb Mon Sep 17 00:00:00 2001 From: LongYinan Date: Sun, 25 Feb 2024 00:52:30 +0800 Subject: [PATCH] fix(napi): remove useless create_reference in slice => TypedArray impl (#1975) --- .../src/bindgen_runtime/js_values/arraybuffer.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/crates/napi/src/bindgen_runtime/js_values/arraybuffer.rs b/crates/napi/src/bindgen_runtime/js_values/arraybuffer.rs index e2d73c8c..255897ee 100644 --- a/crates/napi/src/bindgen_runtime/js_values/arraybuffer.rs +++ b/crates/napi/src/bindgen_runtime/js_values/arraybuffer.rs @@ -466,10 +466,19 @@ macro_rules! impl_from_slice { let mut data = ptr::null_mut(); let mut array_buffer = ptr::null_mut(); let mut byte_offset = 0; - let mut ref_ = ptr::null_mut(); check_status!( - unsafe { sys::napi_create_reference(env, napi_val, 1, &mut ref_) }, - "Failed to create reference from Buffer" + unsafe { + sys::napi_get_typedarray_info( + env, + napi_val, + &mut typed_array_type, + &mut length, + &mut data, + &mut array_buffer, + &mut byte_offset, + ) + }, + "Get TypedArray info failed" )?; check_status!( unsafe {