From 093e09217c7dbe2db18c0aa83dc64341d405b457 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Thu, 23 Jan 2020 12:16:56 -0500 Subject: [PATCH] SharedArrayBuffer::new_backing_store_from_boxed_slice doesn't need to be unsafe --- src/shared_array_buffer.rs | 16 +++++++++------- tests/test_api.rs | 4 +--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/shared_array_buffer.rs b/src/shared_array_buffer.rs index 859f3b56..d12afd66 100644 --- a/src/shared_array_buffer.rs +++ b/src/shared_array_buffer.rs @@ -113,16 +113,18 @@ impl SharedArrayBuffer { /// /// The result can be later passed to SharedArrayBuffer::New. The raw pointer /// to the buffer must not be passed again to any V8 API function. - pub unsafe fn new_backing_store_from_boxed_slice( + pub fn new_backing_store_from_boxed_slice( data: Box<[u8]>, ) -> UniqueRef { let byte_length = data.len(); let data_ptr = Box::into_raw(data) as *mut c_void; - UniqueRef::from_raw(v8__SharedArrayBuffer__NewBackingStore__with_data( - data_ptr, - byte_length, - backing_store_deleter_callback, - null_mut(), - )) + unsafe { + UniqueRef::from_raw(v8__SharedArrayBuffer__NewBackingStore__with_data( + data_ptr, + byte_length, + backing_store_deleter_callback, + null_mut(), + )) + } } } diff --git a/tests/test_api.rs b/tests/test_api.rs index 38f54ae6..7b4a383e 100644 --- a/tests/test_api.rs +++ b/tests/test_api.rs @@ -1913,9 +1913,7 @@ fn shared_array_buffer() { } let data: Box<[u8]> = vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9].into_boxed_slice(); - let bs = unsafe { - v8::SharedArrayBuffer::new_backing_store_from_boxed_slice(data) - }; + let bs = v8::SharedArrayBuffer::new_backing_store_from_boxed_slice(data); assert_eq!(bs.byte_length(), 10); assert_eq!(bs.is_shared(), true);