Skip to content

Commit

Permalink
chore(napi): remove Read from Uint8Array (#2346)
Browse files Browse the repository at this point in the history
  • Loading branch information
Brooooooklyn authored Nov 7, 2024
1 parent f2377e2 commit ae8eab3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
18 changes: 2 additions & 16 deletions crates/napi/src/bindgen_runtime/js_values/arraybuffer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::ffi::c_void;
use std::io::{self, Read};
use std::mem;
use std::ops::{Deref, DerefMut};
use std::ptr;
Expand Down Expand Up @@ -33,8 +32,6 @@ trait Finalizer {

fn data_managed_type(&self) -> &DataManagedType;

fn len(&self) -> &usize;

fn ref_count(&self) -> usize;
}

Expand Down Expand Up @@ -68,10 +65,6 @@ macro_rules! impl_typed_array {
&self.data_managed_type
}

fn len(&self) -> &usize {
&self.length
}

fn ref_count(&self) -> usize {
Arc::strong_count(&self.drop_in_vm)
}
Expand Down Expand Up @@ -604,14 +597,14 @@ macro_rules! impl_from_slice {
};
}

unsafe extern "C" fn finalizer<Data, T: Finalizer<RustType = Data>>(
unsafe extern "C" fn finalizer<Data, T: Finalizer<RustType = Data> + AsRef<[Data]>>(
_env: sys::napi_env,
finalize_data: *mut c_void,
finalize_hint: *mut c_void,
) {
let data = unsafe { *Box::from_raw(finalize_hint as *mut T) };
let data_managed_type = *data.data_managed_type();
let length = *data.len();
let length = data.as_ref().len();
match data_managed_type {
DataManagedType::Vm => {
// do nothing
Expand Down Expand Up @@ -686,13 +679,6 @@ impl Uint8Array {
}
}

impl Read for Uint8Array {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
let mut inner: &[u8] = &*self;
Read::read(&mut inner, buf)
}
}

/// Zero copy Uint8ClampedArray slice shared between Rust and Node.js.
/// It can only be used in non-async context and the lifetime is bound to the fn closure.
/// If you want to use Node.js `Uint8ClampedArray` in async context or want to extend the lifetime, use `Uint8ClampedArray` instead.
Expand Down
10 changes: 8 additions & 2 deletions crates/napi/src/js_values/value_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,15 @@ impl<T: NapiRaw> Ref<T> {
}

pub fn unref(&mut self, env: &Env) -> Result<()> {
check_status!(unsafe { sys::napi_reference_unref(env.0, self.raw_ref, &mut 0) })?;
check_status!(
unsafe { sys::napi_reference_unref(env.0, self.raw_ref, &mut 0) },
"unref Ref failed"
)?;

check_status!(unsafe { sys::napi_delete_reference(env.0, self.raw_ref) })?;
check_status!(
unsafe { sys::napi_delete_reference(env.0, self.raw_ref) },
"delete Ref failed"
)?;
self.taken = true;
Ok(())
}
Expand Down

0 comments on commit ae8eab3

Please sign in to comment.