0
0
Fork 0
mirror of https://github.com/denoland/rusty_v8.git synced 2025-01-11 16:42:32 -05:00

new_backing_store_from_boxed_slice doesn't need to be unsafe (#247)

This commit is contained in:
Ryan Dahl 2020-01-23 10:17:23 -05:00 committed by GitHub
parent 7e27c88708
commit aca89c2055
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 9 deletions

View file

@ -267,16 +267,18 @@ impl ArrayBuffer {
/// ///
/// The result can be later passed to ArrayBuffer::New. The raw pointer /// The result can be later passed to ArrayBuffer::New. The raw pointer
/// to the buffer must not be passed again to any V8 API function. /// 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]>, data: Box<[u8]>,
) -> UniqueRef<BackingStore> { ) -> UniqueRef<BackingStore> {
let byte_length = data.len(); let byte_length = data.len();
let data_ptr = Box::into_raw(data) as *mut c_void; let data_ptr = Box::into_raw(data) as *mut c_void;
UniqueRef::from_raw(v8__ArrayBuffer__NewBackingStore__with_data( unsafe {
data_ptr, UniqueRef::from_raw(v8__ArrayBuffer__NewBackingStore__with_data(
byte_length, data_ptr,
backing_store_deleter_callback, byte_length,
null_mut(), backing_store_deleter_callback,
)) null_mut(),
))
}
} }
} }

View file

@ -274,8 +274,7 @@ fn array_buffer() {
assert_eq!(false, bs.is_shared()); assert_eq!(false, bs.is_shared());
let data: Box<[u8]> = vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9].into_boxed_slice(); let data: Box<[u8]> = vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9].into_boxed_slice();
let unique_bs = let unique_bs = v8::ArrayBuffer::new_backing_store_from_boxed_slice(data);
unsafe { v8::ArrayBuffer::new_backing_store_from_boxed_slice(data) };
assert_eq!(10, unique_bs.byte_length()); assert_eq!(10, unique_bs.byte_length());
assert_eq!(false, unique_bs.is_shared()); assert_eq!(false, unique_bs.is_shared());
assert_eq!(unique_bs[0], 0); assert_eq!(unique_bs[0], 0);