diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/bindings.rs | 6 | ||||
-rw-r--r-- | core/es_isolate.rs | 4 | ||||
-rw-r--r-- | core/examples/http_bench.rs | 20 | ||||
-rw-r--r-- | core/isolate.rs | 27 | ||||
-rw-r--r-- | core/ops.rs | 8 | ||||
-rw-r--r-- | core/plugins.rs | 6 |
6 files changed, 37 insertions, 34 deletions
diff --git a/core/bindings.rs b/core/bindings.rs index 1c146934b..81858f5bd 100644 --- a/core/bindings.rs +++ b/core/bindings.rs @@ -2,7 +2,7 @@ use crate::es_isolate::EsIsolate; use crate::isolate::Isolate; -use crate::isolate::PinnedBuf; +use crate::isolate::ZeroCopyBuf; use rusty_v8 as v8; use v8::MapFnTo; @@ -405,9 +405,9 @@ fn send( Err(..) => &[], }; - let zero_copy: Option<PinnedBuf> = + let zero_copy: Option<ZeroCopyBuf> = v8::Local::<v8::ArrayBufferView>::try_from(args.get(2)) - .map(PinnedBuf::new) + .map(ZeroCopyBuf::new) .ok(); // If response is empty then it's either async op or exception was thrown diff --git a/core/es_isolate.rs b/core/es_isolate.rs index aa20b383b..52875b931 100644 --- a/core/es_isolate.rs +++ b/core/es_isolate.rs @@ -597,7 +597,7 @@ pub mod tests { use super::*; use crate::isolate::js_check; use crate::isolate::tests::run_in_task; - use crate::isolate::PinnedBuf; + use crate::isolate::ZeroCopyBuf; use crate::modules::SourceCodeInfoFuture; use crate::ops::*; use std::io; @@ -642,7 +642,7 @@ pub mod tests { let mut isolate = EsIsolate::new(loader, StartupData::None, false); let dispatcher = - move |control: &[u8], _zero_copy: Option<PinnedBuf>| -> CoreOp { + move |control: &[u8], _zero_copy: Option<ZeroCopyBuf>| -> CoreOp { dispatch_count_.fetch_add(1, Ordering::Relaxed); assert_eq!(control.len(), 1); assert_eq!(control[0], 42); diff --git a/core/examples/http_bench.rs b/core/examples/http_bench.rs index 5a5b43c51..8151c4575 100644 --- a/core/examples/http_bench.rs +++ b/core/examples/http_bench.rs @@ -108,12 +108,12 @@ fn test_record_from() { pub type HttpOp = dyn Future<Output = Result<i32, std::io::Error>> + Send; pub type HttpOpHandler = - fn(record: Record, zero_copy_buf: Option<PinnedBuf>) -> Pin<Box<HttpOp>>; + fn(record: Record, zero_copy_buf: Option<ZeroCopyBuf>) -> Pin<Box<HttpOp>>; fn http_op( handler: HttpOpHandler, -) -> impl Fn(&[u8], Option<PinnedBuf>) -> CoreOp { - move |control: &[u8], zero_copy_buf: Option<PinnedBuf>| -> CoreOp { +) -> impl Fn(&[u8], Option<ZeroCopyBuf>) -> CoreOp { + move |control: &[u8], zero_copy_buf: Option<ZeroCopyBuf>| -> CoreOp { let record = Record::from(control); let is_sync = record.promise_id == 0; let op = handler(record.clone(), zero_copy_buf); @@ -232,7 +232,7 @@ impl Future for Accept { fn op_accept( record: Record, - _zero_copy_buf: Option<PinnedBuf>, + _zero_copy_buf: Option<ZeroCopyBuf>, ) -> Pin<Box<HttpOp>> { let rid = record.arg as u32; debug!("accept {}", rid); @@ -250,7 +250,7 @@ fn op_accept( fn op_listen( _record: Record, - _zero_copy_buf: Option<PinnedBuf>, + _zero_copy_buf: Option<ZeroCopyBuf>, ) -> Pin<Box<HttpOp>> { debug!("listen"); let fut = async { @@ -266,7 +266,7 @@ fn op_listen( fn op_close( record: Record, - _zero_copy_buf: Option<PinnedBuf>, + _zero_copy_buf: Option<ZeroCopyBuf>, ) -> Pin<Box<HttpOp>> { debug!("close"); let fut = async move { @@ -282,7 +282,7 @@ fn op_close( struct Read { rid: ResourceId, - buf: PinnedBuf, + buf: ZeroCopyBuf, } impl Future for Read { @@ -304,7 +304,7 @@ impl Future for Read { fn op_read( record: Record, - zero_copy_buf: Option<PinnedBuf>, + zero_copy_buf: Option<ZeroCopyBuf>, ) -> Pin<Box<HttpOp>> { let rid = record.arg as u32; debug!("read rid={}", rid); @@ -325,7 +325,7 @@ fn op_read( struct Write { rid: ResourceId, - buf: PinnedBuf, + buf: ZeroCopyBuf, } impl Future for Write { @@ -347,7 +347,7 @@ impl Future for Write { fn op_write( record: Record, - zero_copy_buf: Option<PinnedBuf>, + zero_copy_buf: Option<ZeroCopyBuf>, ) -> Pin<Box<HttpOp>> { let rid = record.arg as u32; debug!("write rid={}", rid); diff --git a/core/isolate.rs b/core/isolate.rs index e76aaf5cb..a72090d1a 100644 --- a/core/isolate.rs +++ b/core/isolate.rs @@ -30,20 +30,21 @@ use std::pin::Pin; use std::sync::{Arc, Mutex, Once}; use std::task::Context; use std::task::Poll; -/// A PinnedBuf encapsulates a slice that's been borrowed from a JavaScript + +/// A ZeroCopyBuf encapsulates a slice that's been borrowed from a JavaScript /// ArrayBuffer object. JavaScript objects can normally be garbage collected, -/// but the existence of a PinnedBuf inhibits this until it is dropped. It -/// behaves much like an Arc<[u8]>, although a PinnedBuf currently can't be +/// but the existence of a ZeroCopyBuf inhibits this until it is dropped. It +/// behaves much like an Arc<[u8]>, although a ZeroCopyBuf currently can't be /// cloned. -pub struct PinnedBuf { +pub struct ZeroCopyBuf { backing_store: v8::SharedRef<v8::BackingStore>, byte_offset: usize, byte_length: usize, } -unsafe impl Send for PinnedBuf {} +unsafe impl Send for ZeroCopyBuf {} -impl PinnedBuf { +impl ZeroCopyBuf { pub fn new(view: v8::Local<v8::ArrayBufferView>) -> Self { let backing_store = view.buffer().unwrap().get_backing_store(); let byte_offset = view.byte_offset(); @@ -56,7 +57,7 @@ impl PinnedBuf { } } -impl Deref for PinnedBuf { +impl Deref for ZeroCopyBuf { type Target = [u8]; fn deref(&self) -> &[u8] { let buf = unsafe { &**self.backing_store.get() }; @@ -64,20 +65,20 @@ impl Deref for PinnedBuf { } } -impl DerefMut for PinnedBuf { +impl DerefMut for ZeroCopyBuf { fn deref_mut(&mut self) -> &mut [u8] { let buf = unsafe { &mut **self.backing_store.get() }; &mut buf[self.byte_offset..self.byte_offset + self.byte_length] } } -impl AsRef<[u8]> for PinnedBuf { +impl AsRef<[u8]> for ZeroCopyBuf { fn as_ref(&self) -> &[u8] { &*self } } -impl AsMut<[u8]> for PinnedBuf { +impl AsMut<[u8]> for ZeroCopyBuf { fn as_mut(&mut self) -> &mut [u8] { &mut *self } @@ -436,7 +437,7 @@ impl Isolate { /// Requires runtime to explicitly ask for op ids before using any of the ops. pub fn register_op<F>(&self, name: &str, op: F) -> OpId where - F: Fn(&[u8], Option<PinnedBuf>) -> CoreOp + Send + Sync + 'static, + F: Fn(&[u8], Option<ZeroCopyBuf>) -> CoreOp + Send + Sync + 'static, { self.op_registry.register(name, op) } @@ -476,7 +477,7 @@ impl Isolate { &mut self, op_id: OpId, control_buf: &[u8], - zero_copy_buf: Option<PinnedBuf>, + zero_copy_buf: Option<ZeroCopyBuf>, ) -> Option<(OpId, Box<[u8]>)> { let maybe_op = self.op_registry.call(op_id, control_buf, zero_copy_buf); @@ -817,7 +818,7 @@ pub mod tests { let mut isolate = Isolate::new(StartupData::None, false); let dispatcher = - move |control: &[u8], _zero_copy: Option<PinnedBuf>| -> CoreOp { + move |control: &[u8], _zero_copy: Option<ZeroCopyBuf>| -> CoreOp { dispatch_count_.fetch_add(1, Ordering::Relaxed); match mode { Mode::Async => { diff --git a/core/ops.rs b/core/ops.rs index e0bdb0184..f1798a398 100644 --- a/core/ops.rs +++ b/core/ops.rs @@ -1,5 +1,5 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -use crate::PinnedBuf; +use crate::ZeroCopyBuf; use futures::Future; use std::collections::HashMap; use std::pin::Pin; @@ -32,7 +32,7 @@ pub type CoreOp = Op<CoreError>; /// Main type describing op pub type OpDispatcher = - dyn Fn(&[u8], Option<PinnedBuf>) -> CoreOp + Send + Sync + 'static; + dyn Fn(&[u8], Option<ZeroCopyBuf>) -> CoreOp + Send + Sync + 'static; #[derive(Default)] pub struct OpRegistry { @@ -53,7 +53,7 @@ impl OpRegistry { pub fn register<F>(&self, name: &str, op: F) -> OpId where - F: Fn(&[u8], Option<PinnedBuf>) -> CoreOp + Send + Sync + 'static, + F: Fn(&[u8], Option<ZeroCopyBuf>) -> CoreOp + Send + Sync + 'static, { let mut lock = self.dispatchers.write().unwrap(); let op_id = lock.len() as u32; @@ -82,7 +82,7 @@ impl OpRegistry { &self, op_id: OpId, control: &[u8], - zero_copy_buf: Option<PinnedBuf>, + zero_copy_buf: Option<ZeroCopyBuf>, ) -> Option<CoreOp> { // Op with id 0 has special meaning - it's a special op that is always // provided to retrieve op id map. The map consists of name to `OpId` diff --git a/core/plugins.rs b/core/plugins.rs index 53a2e706f..14cfce307 100644 --- a/core/plugins.rs +++ b/core/plugins.rs @@ -1,4 +1,4 @@ -use crate::isolate::PinnedBuf; +use crate::isolate::ZeroCopyBuf; use crate::ops::CoreOp; pub type PluginInitFn = fn(context: &mut dyn PluginInitContext); @@ -7,7 +7,9 @@ pub trait PluginInitContext { fn register_op( &mut self, name: &str, - op: Box<dyn Fn(&[u8], Option<PinnedBuf>) -> CoreOp + Send + Sync + 'static>, + op: Box< + dyn Fn(&[u8], Option<ZeroCopyBuf>) -> CoreOp + Send + Sync + 'static, + >, ); } |