diff options
author | Aaron O'Mullan <aaron.omullan@gmail.com> | 2021-04-18 14:39:26 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-18 14:39:26 +0200 |
commit | 8fb1af14129850ce5a124572b6b8131056727594 (patch) | |
tree | d5e008582f255b0f4190e4384a29a21d1104dfc9 /core/bindings.rs | |
parent | 043021cbd3b9c26807978d956babcf9f607cfbc2 (diff) |
refactor(core): remove ZeroCopyBuf's dep on the bindings mod (#10232)
Also cleanup `bindings::deserialize()/decode()` so they
use the `ZeroCopyBuf` abstraction rather than reimplementing it.
This cleanup will facilitate moving `ZeroCopyBuf` to `serde_v8`
since it's now self contained and there are no other
`get_backing_store_slice()` callers.
Diffstat (limited to 'core/bindings.rs')
-rw-r--r-- | core/bindings.rs | 44 |
1 files changed, 4 insertions, 40 deletions
diff --git a/core/bindings.rs b/core/bindings.rs index 0a67be102..48450a619 100644 --- a/core/bindings.rs +++ b/core/bindings.rs @@ -12,7 +12,6 @@ use crate::ZeroCopyBuf; use rusty_v8 as v8; use serde::Serialize; use serde_v8::to_v8; -use std::cell::Cell; use std::convert::TryFrom; use std::convert::TryInto; use std::io::{stdout, Write}; @@ -287,29 +286,6 @@ pub extern "C" fn promise_reject_callback(message: v8::PromiseRejectMessage) { }; } -pub(crate) unsafe fn get_backing_store_slice( - backing_store: &v8::SharedRef<v8::BackingStore>, - byte_offset: usize, - byte_length: usize, -) -> &[u8] { - let cells: *const [Cell<u8>] = - &backing_store[byte_offset..byte_offset + byte_length]; - let bytes = cells as *const [u8]; - &*bytes -} - -#[allow(clippy::mut_from_ref)] -pub(crate) unsafe fn get_backing_store_slice_mut( - backing_store: &v8::SharedRef<v8::BackingStore>, - byte_offset: usize, - byte_length: usize, -) -> &mut [u8] { - let cells: *const [Cell<u8>] = - &backing_store[byte_offset..byte_offset + byte_length]; - let bytes = cells as *const _ as *mut [u8]; - &mut *bytes -} - fn print( scope: &mut v8::HandleScope, args: v8::FunctionCallbackArguments, @@ -599,14 +575,8 @@ fn decode( } }; - let backing_store = view.buffer(scope).unwrap().get_backing_store(); - let buf = unsafe { - get_backing_store_slice( - &backing_store, - view.byte_offset(), - view.byte_length(), - ) - }; + let zero_copy = ZeroCopyBuf::new(scope, view); + let buf = &zero_copy; // Strip BOM let buf = @@ -694,14 +664,8 @@ fn deserialize( } }; - let backing_store = view.buffer(scope).unwrap().get_backing_store(); - let buf = unsafe { - get_backing_store_slice( - &backing_store, - view.byte_offset(), - view.byte_length(), - ) - }; + let zero_copy = ZeroCopyBuf::new(scope, view); + let buf = &zero_copy; let serialize_deserialize = Box::new(SerializeDeserialize {}); let mut value_deserializer = |