0
0
Fork 0
mirror of https://github.com/denoland/rusty_v8.git synced 2024-12-24 08:09:16 -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,11 +267,12 @@ impl ArrayBuffer {
///
/// 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.
pub unsafe fn new_backing_store_from_boxed_slice(
pub fn new_backing_store_from_boxed_slice(
data: Box<[u8]>,
) -> UniqueRef<BackingStore> {
let byte_length = data.len();
let data_ptr = Box::into_raw(data) as *mut c_void;
unsafe {
UniqueRef::from_raw(v8__ArrayBuffer__NewBackingStore__with_data(
data_ptr,
byte_length,
@ -280,3 +281,4 @@ impl ArrayBuffer {
))
}
}
}

View file

@ -274,8 +274,7 @@ fn array_buffer() {
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 unique_bs =
unsafe { v8::ArrayBuffer::new_backing_store_from_boxed_slice(data) };
let unique_bs = v8::ArrayBuffer::new_backing_store_from_boxed_slice(data);
assert_eq!(10, unique_bs.byte_length());
assert_eq!(false, unique_bs.is_shared());
assert_eq!(unique_bs[0], 0);