1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-25 15:29:32 -05:00

s/PinnedBuf/ZeroCopyBuf (#3782)

This commit is contained in:
Ryan Dahl 2020-01-24 15:10:49 -05:00 committed by GitHub
parent 86726f88f1
commit 5e32c5ea44
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
32 changed files with 145 additions and 138 deletions

View file

@ -2,16 +2,16 @@
use deno_core::CoreOp; use deno_core::CoreOp;
use deno_core::Isolate; use deno_core::Isolate;
use deno_core::Op; use deno_core::Op;
use deno_core::PinnedBuf;
use deno_core::StartupData; use deno_core::StartupData;
use deno_core::ZeroCopyBuf;
use std::collections::HashMap; use std::collections::HashMap;
use std::env; use std::env;
use std::path::PathBuf; use std::path::PathBuf;
fn op_fetch_asset( fn op_fetch_asset(
custom_assets: HashMap<String, PathBuf>, custom_assets: HashMap<String, PathBuf>,
) -> impl Fn(&[u8], Option<PinnedBuf>) -> CoreOp { ) -> impl Fn(&[u8], Option<ZeroCopyBuf>) -> CoreOp {
move |control: &[u8], zero_copy_buf: Option<PinnedBuf>| -> CoreOp { move |control: &[u8], zero_copy_buf: Option<ZeroCopyBuf>| -> CoreOp {
assert!(zero_copy_buf.is_none()); // zero_copy_buf unused in this op. assert!(zero_copy_buf.is_none()); // zero_copy_buf unused in this op.
let custom_assets = custom_assets.clone(); let custom_assets = custom_assets.clone();
let name = std::str::from_utf8(control).unwrap(); let name = std::str::from_utf8(control).unwrap();

View file

@ -30,7 +30,7 @@ struct CacheArgs {
fn op_cache( fn op_cache(
state: &ThreadSafeState, state: &ThreadSafeState,
args: Value, args: Value,
_zero_copy: Option<PinnedBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
let args: CacheArgs = serde_json::from_value(args)?; let args: CacheArgs = serde_json::from_value(args)?;
@ -55,7 +55,7 @@ struct SpecifiersReferrerArgs {
fn op_resolve_modules( fn op_resolve_modules(
state: &ThreadSafeState, state: &ThreadSafeState,
args: Value, args: Value,
_data: Option<PinnedBuf>, _data: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
let args: SpecifiersReferrerArgs = serde_json::from_value(args)?; let args: SpecifiersReferrerArgs = serde_json::from_value(args)?;
@ -86,7 +86,7 @@ fn op_resolve_modules(
fn op_fetch_source_files( fn op_fetch_source_files(
state: &ThreadSafeState, state: &ThreadSafeState,
args: Value, args: Value,
_data: Option<PinnedBuf>, _data: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
let args: SpecifiersReferrerArgs = serde_json::from_value(args)?; let args: SpecifiersReferrerArgs = serde_json::from_value(args)?;

View file

@ -48,11 +48,11 @@ struct AsyncArgs {
promise_id: Option<u64>, promise_id: Option<u64>,
} }
pub fn json_op<D>(d: D) -> impl Fn(&[u8], Option<PinnedBuf>) -> CoreOp pub fn json_op<D>(d: D) -> impl Fn(&[u8], Option<ZeroCopyBuf>) -> CoreOp
where where
D: Fn(Value, Option<PinnedBuf>) -> Result<JsonOp, ErrBox>, D: Fn(Value, Option<ZeroCopyBuf>) -> Result<JsonOp, ErrBox>,
{ {
move |control: &[u8], zero_copy: Option<PinnedBuf>| { move |control: &[u8], zero_copy: Option<ZeroCopyBuf>| {
let async_args: AsyncArgs = match serde_json::from_slice(control) { let async_args: AsyncArgs = match serde_json::from_slice(control) {
Ok(args) => args, Ok(args) => args,
Err(e) => { Err(e) => {

View file

@ -11,7 +11,7 @@ use deno_core::Buf;
use deno_core::CoreOp; use deno_core::CoreOp;
use deno_core::ErrBox; use deno_core::ErrBox;
use deno_core::Op; use deno_core::Op;
use deno_core::PinnedBuf; use deno_core::ZeroCopyBuf;
use futures::future::FutureExt; use futures::future::FutureExt;
use std::future::Future; use std::future::Future;
use std::pin::Pin; use std::pin::Pin;
@ -113,11 +113,11 @@ fn test_parse_min_record() {
assert_eq!(parse_min_record(&buf), None); assert_eq!(parse_min_record(&buf), None);
} }
pub fn minimal_op<D>(d: D) -> impl Fn(&[u8], Option<PinnedBuf>) -> CoreOp pub fn minimal_op<D>(d: D) -> impl Fn(&[u8], Option<ZeroCopyBuf>) -> CoreOp
where where
D: Fn(i32, Option<PinnedBuf>) -> Pin<Box<MinimalOp>>, D: Fn(i32, Option<ZeroCopyBuf>) -> Pin<Box<MinimalOp>>,
{ {
move |control: &[u8], zero_copy: Option<PinnedBuf>| { move |control: &[u8], zero_copy: Option<ZeroCopyBuf>| {
let mut record = match parse_min_record(control) { let mut record = match parse_min_record(control) {
Some(r) => r, Some(r) => r,
None => { None => {

View file

@ -27,7 +27,7 @@ struct FormatErrorArgs {
fn op_format_error( fn op_format_error(
state: &ThreadSafeState, state: &ThreadSafeState,
args: Value, args: Value,
_zero_copy: Option<PinnedBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
let args: FormatErrorArgs = serde_json::from_value(args)?; let args: FormatErrorArgs = serde_json::from_value(args)?;
let error = JSError::from_json(&args.error, &state.global_state.ts_compiler); let error = JSError::from_json(&args.error, &state.global_state.ts_compiler);
@ -47,7 +47,7 @@ struct ApplySourceMap {
fn op_apply_source_map( fn op_apply_source_map(
state: &ThreadSafeState, state: &ThreadSafeState,
args: Value, args: Value,
_zero_copy: Option<PinnedBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
let args: ApplySourceMap = serde_json::from_value(args)?; let args: ApplySourceMap = serde_json::from_value(args)?;

View file

@ -26,7 +26,7 @@ struct FetchArgs {
pub fn op_fetch( pub fn op_fetch(
state: &ThreadSafeState, state: &ThreadSafeState,
args: Value, args: Value,
data: Option<PinnedBuf>, data: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
let args: FetchArgs = serde_json::from_value(args)?; let args: FetchArgs = serde_json::from_value(args)?;
let url = args.url; let url = args.url;

View file

@ -45,7 +45,7 @@ struct OpenOptions {
fn op_open( fn op_open(
state: &ThreadSafeState, state: &ThreadSafeState,
args: Value, args: Value,
_zero_copy: Option<PinnedBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
let args: OpenArgs = serde_json::from_value(args)?; let args: OpenArgs = serde_json::from_value(args)?;
let filename = deno_fs::resolve_from_cwd(Path::new(&args.filename))?; let filename = deno_fs::resolve_from_cwd(Path::new(&args.filename))?;
@ -151,7 +151,7 @@ struct CloseArgs {
fn op_close( fn op_close(
state: &ThreadSafeState, state: &ThreadSafeState,
args: Value, args: Value,
_zero_copy: Option<PinnedBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
let args: CloseArgs = serde_json::from_value(args)?; let args: CloseArgs = serde_json::from_value(args)?;
@ -172,7 +172,7 @@ struct SeekArgs {
fn op_seek( fn op_seek(
state: &ThreadSafeState, state: &ThreadSafeState,
args: Value, args: Value,
_zero_copy: Option<PinnedBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
let args: SeekArgs = serde_json::from_value(args)?; let args: SeekArgs = serde_json::from_value(args)?;
let rid = args.rid as u32; let rid = args.rid as u32;

View file

@ -49,7 +49,7 @@ struct ChdirArgs {
fn op_chdir( fn op_chdir(
_state: &ThreadSafeState, _state: &ThreadSafeState,
args: Value, args: Value,
_zero_copy: Option<PinnedBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
let args: ChdirArgs = serde_json::from_value(args)?; let args: ChdirArgs = serde_json::from_value(args)?;
std::env::set_current_dir(&args.directory)?; std::env::set_current_dir(&args.directory)?;
@ -68,7 +68,7 @@ struct MkdirArgs {
fn op_mkdir( fn op_mkdir(
state: &ThreadSafeState, state: &ThreadSafeState,
args: Value, args: Value,
_zero_copy: Option<PinnedBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
let args: MkdirArgs = serde_json::from_value(args)?; let args: MkdirArgs = serde_json::from_value(args)?;
let path = deno_fs::resolve_from_cwd(Path::new(&args.path))?; let path = deno_fs::resolve_from_cwd(Path::new(&args.path))?;
@ -95,7 +95,7 @@ struct ChmodArgs {
fn op_chmod( fn op_chmod(
state: &ThreadSafeState, state: &ThreadSafeState,
args: Value, args: Value,
_zero_copy: Option<PinnedBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
let args: ChmodArgs = serde_json::from_value(args)?; let args: ChmodArgs = serde_json::from_value(args)?;
let path = deno_fs::resolve_from_cwd(Path::new(&args.path))?; let path = deno_fs::resolve_from_cwd(Path::new(&args.path))?;
@ -129,7 +129,7 @@ struct ChownArgs {
fn op_chown( fn op_chown(
state: &ThreadSafeState, state: &ThreadSafeState,
args: Value, args: Value,
_zero_copy: Option<PinnedBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
let args: ChownArgs = serde_json::from_value(args)?; let args: ChownArgs = serde_json::from_value(args)?;
let path = deno_fs::resolve_from_cwd(Path::new(&args.path))?; let path = deno_fs::resolve_from_cwd(Path::new(&args.path))?;
@ -157,7 +157,7 @@ struct RemoveArgs {
fn op_remove( fn op_remove(
state: &ThreadSafeState, state: &ThreadSafeState,
args: Value, args: Value,
_zero_copy: Option<PinnedBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
let args: RemoveArgs = serde_json::from_value(args)?; let args: RemoveArgs = serde_json::from_value(args)?;
let path = deno_fs::resolve_from_cwd(Path::new(&args.path))?; let path = deno_fs::resolve_from_cwd(Path::new(&args.path))?;
@ -191,7 +191,7 @@ struct CopyFileArgs {
fn op_copy_file( fn op_copy_file(
state: &ThreadSafeState, state: &ThreadSafeState,
args: Value, args: Value,
_zero_copy: Option<PinnedBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
let args: CopyFileArgs = serde_json::from_value(args)?; let args: CopyFileArgs = serde_json::from_value(args)?;
let from = deno_fs::resolve_from_cwd(Path::new(&args.from))?; let from = deno_fs::resolve_from_cwd(Path::new(&args.from))?;
@ -290,7 +290,7 @@ struct StatArgs {
fn op_stat( fn op_stat(
state: &ThreadSafeState, state: &ThreadSafeState,
args: Value, args: Value,
_zero_copy: Option<PinnedBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
let args: StatArgs = serde_json::from_value(args)?; let args: StatArgs = serde_json::from_value(args)?;
let filename = deno_fs::resolve_from_cwd(Path::new(&args.filename))?; let filename = deno_fs::resolve_from_cwd(Path::new(&args.filename))?;
@ -320,7 +320,7 @@ struct RealpathArgs {
fn op_realpath( fn op_realpath(
state: &ThreadSafeState, state: &ThreadSafeState,
args: Value, args: Value,
_zero_copy: Option<PinnedBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
let args: RealpathArgs = serde_json::from_value(args)?; let args: RealpathArgs = serde_json::from_value(args)?;
let path = deno_fs::resolve_from_cwd(Path::new(&args.path))?; let path = deno_fs::resolve_from_cwd(Path::new(&args.path))?;
@ -352,7 +352,7 @@ struct ReadDirArgs {
fn op_read_dir( fn op_read_dir(
state: &ThreadSafeState, state: &ThreadSafeState,
args: Value, args: Value,
_zero_copy: Option<PinnedBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
let args: ReadDirArgs = serde_json::from_value(args)?; let args: ReadDirArgs = serde_json::from_value(args)?;
let path = deno_fs::resolve_from_cwd(Path::new(&args.path))?; let path = deno_fs::resolve_from_cwd(Path::new(&args.path))?;
@ -389,7 +389,7 @@ struct RenameArgs {
fn op_rename( fn op_rename(
state: &ThreadSafeState, state: &ThreadSafeState,
args: Value, args: Value,
_zero_copy: Option<PinnedBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
let args: RenameArgs = serde_json::from_value(args)?; let args: RenameArgs = serde_json::from_value(args)?;
let oldpath = deno_fs::resolve_from_cwd(Path::new(&args.oldpath))?; let oldpath = deno_fs::resolve_from_cwd(Path::new(&args.oldpath))?;
@ -418,7 +418,7 @@ struct LinkArgs {
fn op_link( fn op_link(
state: &ThreadSafeState, state: &ThreadSafeState,
args: Value, args: Value,
_zero_copy: Option<PinnedBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
let args: LinkArgs = serde_json::from_value(args)?; let args: LinkArgs = serde_json::from_value(args)?;
let oldname = deno_fs::resolve_from_cwd(Path::new(&args.oldname))?; let oldname = deno_fs::resolve_from_cwd(Path::new(&args.oldname))?;
@ -446,7 +446,7 @@ struct SymlinkArgs {
fn op_symlink( fn op_symlink(
state: &ThreadSafeState, state: &ThreadSafeState,
args: Value, args: Value,
_zero_copy: Option<PinnedBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
let args: SymlinkArgs = serde_json::from_value(args)?; let args: SymlinkArgs = serde_json::from_value(args)?;
let oldname = deno_fs::resolve_from_cwd(Path::new(&args.oldname))?; let oldname = deno_fs::resolve_from_cwd(Path::new(&args.oldname))?;
@ -478,7 +478,7 @@ struct ReadLinkArgs {
fn op_read_link( fn op_read_link(
state: &ThreadSafeState, state: &ThreadSafeState,
args: Value, args: Value,
_zero_copy: Option<PinnedBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
let args: ReadLinkArgs = serde_json::from_value(args)?; let args: ReadLinkArgs = serde_json::from_value(args)?;
let name = deno_fs::resolve_from_cwd(Path::new(&args.name))?; let name = deno_fs::resolve_from_cwd(Path::new(&args.name))?;
@ -506,7 +506,7 @@ struct TruncateArgs {
fn op_truncate( fn op_truncate(
state: &ThreadSafeState, state: &ThreadSafeState,
args: Value, args: Value,
_zero_copy: Option<PinnedBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
let args: TruncateArgs = serde_json::from_value(args)?; let args: TruncateArgs = serde_json::from_value(args)?;
let filename = deno_fs::resolve_from_cwd(Path::new(&args.name))?; let filename = deno_fs::resolve_from_cwd(Path::new(&args.name))?;
@ -535,7 +535,7 @@ struct MakeTempDirArgs {
fn op_make_temp_dir( fn op_make_temp_dir(
state: &ThreadSafeState, state: &ThreadSafeState,
args: Value, args: Value,
_zero_copy: Option<PinnedBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
let args: MakeTempDirArgs = serde_json::from_value(args)?; let args: MakeTempDirArgs = serde_json::from_value(args)?;
@ -575,7 +575,7 @@ struct Utime {
fn op_utime( fn op_utime(
state: &ThreadSafeState, state: &ThreadSafeState,
args: Value, args: Value,
_zero_copy: Option<PinnedBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
let args: Utime = serde_json::from_value(args)?; let args: Utime = serde_json::from_value(args)?;
state.check_write(Path::new(&args.filename))?; state.check_write(Path::new(&args.filename))?;
@ -590,7 +590,7 @@ fn op_utime(
fn op_cwd( fn op_cwd(
_state: &ThreadSafeState, _state: &ThreadSafeState,
_args: Value, _args: Value,
_zero_copy: Option<PinnedBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
let path = std::env::current_dir()?; let path = std::env::current_dir()?;
let path_str = path.into_os_string().into_string().unwrap(); let path_str = path.into_os_string().into_string().unwrap();

View file

@ -182,7 +182,7 @@ where
pub fn op_read( pub fn op_read(
state: &ThreadSafeState, state: &ThreadSafeState,
rid: i32, rid: i32,
zero_copy: Option<PinnedBuf>, zero_copy: Option<ZeroCopyBuf>,
) -> Pin<Box<MinimalOp>> { ) -> Pin<Box<MinimalOp>> {
debug!("read rid={}", rid); debug!("read rid={}", rid);
let zero_copy = match zero_copy { let zero_copy = match zero_copy {
@ -327,7 +327,7 @@ where
pub fn op_write( pub fn op_write(
state: &ThreadSafeState, state: &ThreadSafeState,
rid: i32, rid: i32,
zero_copy: Option<PinnedBuf>, zero_copy: Option<ZeroCopyBuf>,
) -> Pin<Box<MinimalOp>> { ) -> Pin<Box<MinimalOp>> {
debug!("write rid={}", rid); debug!("write rid={}", rid);
let zero_copy = match zero_copy { let zero_copy = match zero_copy {

View file

@ -98,7 +98,7 @@ struct AcceptArgs {
fn op_accept( fn op_accept(
state: &ThreadSafeState, state: &ThreadSafeState,
args: Value, args: Value,
_zero_copy: Option<PinnedBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
let args: AcceptArgs = serde_json::from_value(args)?; let args: AcceptArgs = serde_json::from_value(args)?;
let rid = args.rid as u32; let rid = args.rid as u32;
@ -143,7 +143,7 @@ struct ConnectArgs {
fn op_connect( fn op_connect(
state: &ThreadSafeState, state: &ThreadSafeState,
args: Value, args: Value,
_zero_copy: Option<PinnedBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
let args: ConnectArgs = serde_json::from_value(args)?; let args: ConnectArgs = serde_json::from_value(args)?;
assert_eq!(args.transport, "tcp"); // TODO Support others. assert_eq!(args.transport, "tcp"); // TODO Support others.
@ -185,7 +185,7 @@ struct ShutdownArgs {
fn op_shutdown( fn op_shutdown(
state: &ThreadSafeState, state: &ThreadSafeState,
args: Value, args: Value,
_zero_copy: Option<PinnedBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
let args: ShutdownArgs = serde_json::from_value(args)?; let args: ShutdownArgs = serde_json::from_value(args)?;
@ -277,7 +277,7 @@ impl TcpListenerResource {
fn op_listen( fn op_listen(
state: &ThreadSafeState, state: &ThreadSafeState,
args: Value, args: Value,
_zero_copy: Option<PinnedBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
let args: ListenArgs = serde_json::from_value(args)?; let args: ListenArgs = serde_json::from_value(args)?;
assert_eq!(args.transport, "tcp"); assert_eq!(args.transport, "tcp");

View file

@ -38,7 +38,7 @@ pub fn init(i: &mut Isolate, s: &ThreadSafeState) {
fn op_start( fn op_start(
state: &ThreadSafeState, state: &ThreadSafeState,
_args: Value, _args: Value,
_zero_copy: Option<PinnedBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
let gs = &state.global_state; let gs = &state.global_state;
let script_args = if gs.flags.argv.len() >= 2 { let script_args = if gs.flags.argv.len() >= 2 {
@ -70,7 +70,7 @@ struct GetDirArgs {
fn op_get_dir( fn op_get_dir(
state: &ThreadSafeState, state: &ThreadSafeState,
args: Value, args: Value,
_zero_copy: Option<PinnedBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
state.check_env()?; state.check_env()?;
let args: GetDirArgs = serde_json::from_value(args)?; let args: GetDirArgs = serde_json::from_value(args)?;
@ -116,7 +116,7 @@ fn op_get_dir(
fn op_exec_path( fn op_exec_path(
state: &ThreadSafeState, state: &ThreadSafeState,
_args: Value, _args: Value,
_zero_copy: Option<PinnedBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
state.check_env()?; state.check_env()?;
let current_exe = env::current_exe().unwrap(); let current_exe = env::current_exe().unwrap();
@ -136,7 +136,7 @@ struct SetEnv {
fn op_set_env( fn op_set_env(
state: &ThreadSafeState, state: &ThreadSafeState,
args: Value, args: Value,
_zero_copy: Option<PinnedBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
let args: SetEnv = serde_json::from_value(args)?; let args: SetEnv = serde_json::from_value(args)?;
state.check_env()?; state.check_env()?;
@ -147,7 +147,7 @@ fn op_set_env(
fn op_env( fn op_env(
state: &ThreadSafeState, state: &ThreadSafeState,
_args: Value, _args: Value,
_zero_copy: Option<PinnedBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
state.check_env()?; state.check_env()?;
let v = env::vars().collect::<HashMap<String, String>>(); let v = env::vars().collect::<HashMap<String, String>>();
@ -162,7 +162,7 @@ struct GetEnv {
fn op_get_env( fn op_get_env(
state: &ThreadSafeState, state: &ThreadSafeState,
args: Value, args: Value,
_zero_copy: Option<PinnedBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
let args: GetEnv = serde_json::from_value(args)?; let args: GetEnv = serde_json::from_value(args)?;
state.check_env()?; state.check_env()?;
@ -181,7 +181,7 @@ struct Exit {
fn op_exit( fn op_exit(
_s: &ThreadSafeState, _s: &ThreadSafeState,
args: Value, args: Value,
_zero_copy: Option<PinnedBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
let args: Exit = serde_json::from_value(args)?; let args: Exit = serde_json::from_value(args)?;
std::process::exit(args.code) std::process::exit(args.code)
@ -190,7 +190,7 @@ fn op_exit(
fn op_is_tty( fn op_is_tty(
_s: &ThreadSafeState, _s: &ThreadSafeState,
_args: Value, _args: Value,
_zero_copy: Option<PinnedBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
Ok(JsonOp::Sync(json!({ Ok(JsonOp::Sync(json!({
"stdin": atty::is(atty::Stream::Stdin), "stdin": atty::is(atty::Stream::Stdin),
@ -202,7 +202,7 @@ fn op_is_tty(
fn op_hostname( fn op_hostname(
state: &ThreadSafeState, state: &ThreadSafeState,
_args: Value, _args: Value,
_zero_copy: Option<PinnedBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
state.check_env()?; state.check_env()?;
let hostname = sys_info::hostname().unwrap_or_else(|_| "".to_owned()); let hostname = sys_info::hostname().unwrap_or_else(|_| "".to_owned());

View file

@ -40,7 +40,7 @@ fn resolve_path(path: &str) -> String {
pub fn op_query_permission( pub fn op_query_permission(
state: &ThreadSafeState, state: &ThreadSafeState,
args: Value, args: Value,
_zero_copy: Option<PinnedBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
let args: PermissionArgs = serde_json::from_value(args)?; let args: PermissionArgs = serde_json::from_value(args)?;
let permissions = state.permissions.lock().unwrap(); let permissions = state.permissions.lock().unwrap();
@ -56,7 +56,7 @@ pub fn op_query_permission(
pub fn op_revoke_permission( pub fn op_revoke_permission(
state: &ThreadSafeState, state: &ThreadSafeState,
args: Value, args: Value,
_zero_copy: Option<PinnedBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
let args: PermissionArgs = serde_json::from_value(args)?; let args: PermissionArgs = serde_json::from_value(args)?;
let mut permissions = state.permissions.lock().unwrap(); let mut permissions = state.permissions.lock().unwrap();
@ -82,7 +82,7 @@ pub fn op_revoke_permission(
pub fn op_request_permission( pub fn op_request_permission(
state: &ThreadSafeState, state: &ThreadSafeState,
args: Value, args: Value,
_zero_copy: Option<PinnedBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
let args: PermissionArgs = serde_json::from_value(args)?; let args: PermissionArgs = serde_json::from_value(args)?;
let mut permissions = state.permissions.lock().unwrap(); let mut permissions = state.permissions.lock().unwrap();

View file

@ -60,7 +60,7 @@ pub fn op_open_plugin(
registry: &Arc<deno_core::OpRegistry>, registry: &Arc<deno_core::OpRegistry>,
state: &ThreadSafeState, state: &ThreadSafeState,
args: Value, args: Value,
_zero_copy: Option<PinnedBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
let args: OpenPluginArgs = serde_json::from_value(args)?; let args: OpenPluginArgs = serde_json::from_value(args)?;
let filename = deno_fs::resolve_from_cwd(Path::new(&args.filename))?; let filename = deno_fs::resolve_from_cwd(Path::new(&args.filename))?;

View file

@ -80,7 +80,7 @@ impl Resource for ChildResource {}
fn op_run( fn op_run(
state: &ThreadSafeState, state: &ThreadSafeState,
args: Value, args: Value,
_zero_copy: Option<PinnedBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
let run_args: RunArgs = serde_json::from_value(args)?; let run_args: RunArgs = serde_json::from_value(args)?;
@ -208,7 +208,7 @@ struct RunStatusArgs {
fn op_run_status( fn op_run_status(
state: &ThreadSafeState, state: &ThreadSafeState,
args: Value, args: Value,
_zero_copy: Option<PinnedBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
let args: RunStatusArgs = serde_json::from_value(args)?; let args: RunStatusArgs = serde_json::from_value(args)?;
let rid = args.rid as u32; let rid = args.rid as u32;
@ -256,7 +256,7 @@ struct KillArgs {
fn op_kill( fn op_kill(
state: &ThreadSafeState, state: &ThreadSafeState,
args: Value, args: Value,
_zero_copy: Option<PinnedBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
state.check_run()?; state.check_run()?;

View file

@ -16,7 +16,7 @@ pub fn init(i: &mut Isolate, s: &ThreadSafeState) {
fn op_get_random_values( fn op_get_random_values(
state: &ThreadSafeState, state: &ThreadSafeState,
_args: Value, _args: Value,
zero_copy: Option<PinnedBuf>, zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
assert!(zero_copy.is_some()); assert!(zero_copy.is_some());

View file

@ -34,7 +34,7 @@ struct ReplStartArgs {
fn op_repl_start( fn op_repl_start(
state: &ThreadSafeState, state: &ThreadSafeState,
args: Value, args: Value,
_zero_copy: Option<PinnedBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
let args: ReplStartArgs = serde_json::from_value(args)?; let args: ReplStartArgs = serde_json::from_value(args)?;
@ -57,7 +57,7 @@ struct ReplReadlineArgs {
fn op_repl_readline( fn op_repl_readline(
state: &ThreadSafeState, state: &ThreadSafeState,
args: Value, args: Value,
_zero_copy: Option<PinnedBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
let args: ReplReadlineArgs = serde_json::from_value(args)?; let args: ReplReadlineArgs = serde_json::from_value(args)?;
let rid = args.rid as u32; let rid = args.rid as u32;

View file

@ -11,7 +11,7 @@ pub fn init(i: &mut Isolate, s: &ThreadSafeState) {
fn op_resources( fn op_resources(
state: &ThreadSafeState, state: &ThreadSafeState,
_args: Value, _args: Value,
_zero_copy: Option<PinnedBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
let resource_table = state.lock_resource_table(); let resource_table = state.lock_resource_table();
let serialized_resources = resource_table.entries(); let serialized_resources = resource_table.entries();

View file

@ -24,7 +24,7 @@ struct CompileArgs {
fn op_compile( fn op_compile(
state: &ThreadSafeState, state: &ThreadSafeState,
args: Value, args: Value,
_zero_copy: Option<PinnedBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
let args: CompileArgs = serde_json::from_value(args)?; let args: CompileArgs = serde_json::from_value(args)?;
Ok(JsonOp::Async(runtime_compile_async( Ok(JsonOp::Async(runtime_compile_async(
@ -45,7 +45,7 @@ struct TranspileArgs {
fn op_transpile( fn op_transpile(
state: &ThreadSafeState, state: &ThreadSafeState,
args: Value, args: Value,
_zero_copy: Option<PinnedBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
let args: TranspileArgs = serde_json::from_value(args)?; let args: TranspileArgs = serde_json::from_value(args)?;
Ok(JsonOp::Async(runtime_transpile_async( Ok(JsonOp::Async(runtime_transpile_async(

View file

@ -58,7 +58,7 @@ struct SignalArgs {
fn op_signal_bind( fn op_signal_bind(
state: &ThreadSafeState, state: &ThreadSafeState,
args: Value, args: Value,
_zero_copy: Option<PinnedBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
let args: BindSignalArgs = serde_json::from_value(args)?; let args: BindSignalArgs = serde_json::from_value(args)?;
let mut table = state.lock_resource_table(); let mut table = state.lock_resource_table();
@ -78,7 +78,7 @@ fn op_signal_bind(
fn op_signal_poll( fn op_signal_poll(
state: &ThreadSafeState, state: &ThreadSafeState,
args: Value, args: Value,
_zero_copy: Option<PinnedBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
let args: SignalArgs = serde_json::from_value(args)?; let args: SignalArgs = serde_json::from_value(args)?;
let rid = args.rid as u32; let rid = args.rid as u32;
@ -101,7 +101,7 @@ fn op_signal_poll(
pub fn op_signal_unbind( pub fn op_signal_unbind(
state: &ThreadSafeState, state: &ThreadSafeState,
args: Value, args: Value,
_zero_copy: Option<PinnedBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
let args: SignalArgs = serde_json::from_value(args)?; let args: SignalArgs = serde_json::from_value(args)?;
let rid = args.rid as u32; let rid = args.rid as u32;
@ -122,7 +122,7 @@ pub fn op_signal_unbind(
pub fn op_signal_bind( pub fn op_signal_bind(
_state: &ThreadSafeState, _state: &ThreadSafeState,
_args: Value, _args: Value,
_zero_copy: Option<PinnedBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
unimplemented!(); unimplemented!();
} }
@ -131,7 +131,7 @@ pub fn op_signal_bind(
fn op_signal_unbind( fn op_signal_unbind(
_state: &ThreadSafeState, _state: &ThreadSafeState,
_args: Value, _args: Value,
_zero_copy: Option<PinnedBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
unimplemented!(); unimplemented!();
} }
@ -140,7 +140,7 @@ fn op_signal_unbind(
fn op_signal_poll( fn op_signal_poll(
_state: &ThreadSafeState, _state: &ThreadSafeState,
_args: Value, _args: Value,
_zero_copy: Option<PinnedBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
unimplemented!(); unimplemented!();
} }

View file

@ -23,7 +23,7 @@ pub fn init(i: &mut Isolate, s: &ThreadSafeState) {
fn op_global_timer_stop( fn op_global_timer_stop(
state: &ThreadSafeState, state: &ThreadSafeState,
_args: Value, _args: Value,
_zero_copy: Option<PinnedBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
let state = state; let state = state;
let mut t = state.global_timer.lock().unwrap(); let mut t = state.global_timer.lock().unwrap();
@ -39,7 +39,7 @@ struct GlobalTimerArgs {
fn op_global_timer( fn op_global_timer(
state: &ThreadSafeState, state: &ThreadSafeState,
args: Value, args: Value,
_zero_copy: Option<PinnedBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
let args: GlobalTimerArgs = serde_json::from_value(args)?; let args: GlobalTimerArgs = serde_json::from_value(args)?;
let val = args.timeout; let val = args.timeout;
@ -61,7 +61,7 @@ fn op_global_timer(
fn op_now( fn op_now(
state: &ThreadSafeState, state: &ThreadSafeState,
_args: Value, _args: Value,
_zero_copy: Option<PinnedBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
let seconds = state.start_time.elapsed().as_secs(); let seconds = state.start_time.elapsed().as_secs();
let mut subsec_nanos = state.start_time.elapsed().subsec_nanos(); let mut subsec_nanos = state.start_time.elapsed().subsec_nanos();

View file

@ -63,7 +63,7 @@ struct ConnectTLSArgs {
pub fn op_connect_tls( pub fn op_connect_tls(
state: &ThreadSafeState, state: &ThreadSafeState,
args: Value, args: Value,
_zero_copy: Option<PinnedBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
let args: ConnectTLSArgs = serde_json::from_value(args)?; let args: ConnectTLSArgs = serde_json::from_value(args)?;
let cert_file = args.cert_file.clone(); let cert_file = args.cert_file.clone();
@ -246,7 +246,7 @@ struct ListenTlsArgs {
fn op_listen_tls( fn op_listen_tls(
state: &ThreadSafeState, state: &ThreadSafeState,
args: Value, args: Value,
_zero_copy: Option<PinnedBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
let args: ListenTlsArgs = serde_json::from_value(args)?; let args: ListenTlsArgs = serde_json::from_value(args)?;
assert_eq!(args.transport, "tcp"); assert_eq!(args.transport, "tcp");
@ -357,7 +357,7 @@ struct AcceptTlsArgs {
fn op_accept_tls( fn op_accept_tls(
state: &ThreadSafeState, state: &ThreadSafeState,
args: Value, args: Value,
_zero_copy: Option<PinnedBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
let args: AcceptTlsArgs = serde_json::from_value(args)?; let args: AcceptTlsArgs = serde_json::from_value(args)?;
let rid = args.rid as u32; let rid = args.rid as u32;

View file

@ -27,7 +27,7 @@ pub fn init(i: &mut Isolate, s: &ThreadSafeState) {
fn op_worker_get_message( fn op_worker_get_message(
state: &ThreadSafeState, state: &ThreadSafeState,
_args: Value, _args: Value,
_data: Option<PinnedBuf>, _data: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
let state_ = state.clone(); let state_ = state.clone();
let op = async move { let op = async move {
@ -44,7 +44,7 @@ fn op_worker_get_message(
fn op_worker_post_message( fn op_worker_post_message(
state: &ThreadSafeState, state: &ThreadSafeState,
_args: Value, _args: Value,
data: Option<PinnedBuf>, data: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
let d = Vec::from(data.unwrap().as_ref()).into_boxed_slice(); let d = Vec::from(data.unwrap().as_ref()).into_boxed_slice();
let mut sender = state.worker_channels.sender.clone(); let mut sender = state.worker_channels.sender.clone();

View file

@ -69,7 +69,7 @@ struct CreateWorkerArgs {
fn op_create_worker( fn op_create_worker(
state: &ThreadSafeState, state: &ThreadSafeState,
args: Value, args: Value,
_data: Option<PinnedBuf>, _data: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
let args: CreateWorkerArgs = serde_json::from_value(args)?; let args: CreateWorkerArgs = serde_json::from_value(args)?;
@ -180,7 +180,7 @@ struct WorkerArgs {
fn op_host_get_worker_loaded( fn op_host_get_worker_loaded(
state: &ThreadSafeState, state: &ThreadSafeState,
args: Value, args: Value,
_data: Option<PinnedBuf>, _data: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
let args: WorkerArgs = serde_json::from_value(args)?; let args: WorkerArgs = serde_json::from_value(args)?;
let id = args.id as u32; let id = args.id as u32;
@ -198,7 +198,7 @@ fn op_host_get_worker_loaded(
fn op_host_poll_worker( fn op_host_poll_worker(
state: &ThreadSafeState, state: &ThreadSafeState,
args: Value, args: Value,
_data: Option<PinnedBuf>, _data: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
let args: WorkerArgs = serde_json::from_value(args)?; let args: WorkerArgs = serde_json::from_value(args)?;
let id = args.id as u32; let id = args.id as u32;
@ -226,7 +226,7 @@ fn op_host_poll_worker(
fn op_host_close_worker( fn op_host_close_worker(
state: &ThreadSafeState, state: &ThreadSafeState,
args: Value, args: Value,
_data: Option<PinnedBuf>, _data: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
let args: WorkerArgs = serde_json::from_value(args)?; let args: WorkerArgs = serde_json::from_value(args)?;
let id = args.id as u32; let id = args.id as u32;
@ -249,7 +249,7 @@ fn op_host_close_worker(
fn op_host_resume_worker( fn op_host_resume_worker(
state: &ThreadSafeState, state: &ThreadSafeState,
args: Value, args: Value,
_data: Option<PinnedBuf>, _data: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
let args: WorkerArgs = serde_json::from_value(args)?; let args: WorkerArgs = serde_json::from_value(args)?;
let id = args.id as u32; let id = args.id as u32;
@ -270,7 +270,7 @@ struct HostGetMessageArgs {
fn op_host_get_message( fn op_host_get_message(
state: &ThreadSafeState, state: &ThreadSafeState,
args: Value, args: Value,
_data: Option<PinnedBuf>, _data: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
let args: HostGetMessageArgs = serde_json::from_value(args)?; let args: HostGetMessageArgs = serde_json::from_value(args)?;
let state_ = state.clone(); let state_ = state.clone();
@ -297,7 +297,7 @@ struct HostPostMessageArgs {
fn op_host_post_message( fn op_host_post_message(
state: &ThreadSafeState, state: &ThreadSafeState,
args: Value, args: Value,
data: Option<PinnedBuf>, data: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
let args: HostPostMessageArgs = serde_json::from_value(args)?; let args: HostPostMessageArgs = serde_json::from_value(args)?;
let id = args.id as u32; let id = args.id as u32;
@ -317,7 +317,7 @@ fn op_host_post_message(
fn op_metrics( fn op_metrics(
state: &ThreadSafeState, state: &ThreadSafeState,
_args: Value, _args: Value,
_zero_copy: Option<PinnedBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> { ) -> Result<JsonOp, ErrBox> {
let m = &state.metrics; let m = &state.metrics;

View file

@ -15,8 +15,8 @@ use deno_core::ErrBox;
use deno_core::Loader; use deno_core::Loader;
use deno_core::ModuleSpecifier; use deno_core::ModuleSpecifier;
use deno_core::Op; use deno_core::Op;
use deno_core::PinnedBuf;
use deno_core::ResourceTable; use deno_core::ResourceTable;
use deno_core::ZeroCopyBuf;
use futures::channel::mpsc; use futures::channel::mpsc;
use futures::future::FutureExt; use futures::future::FutureExt;
use futures::future::TryFutureExt; use futures::future::TryFutureExt;
@ -83,13 +83,13 @@ impl ThreadSafeState {
pub fn core_op<D>( pub fn core_op<D>(
&self, &self,
dispatcher: D, dispatcher: D,
) -> impl Fn(&[u8], Option<PinnedBuf>) -> CoreOp ) -> impl Fn(&[u8], Option<ZeroCopyBuf>) -> CoreOp
where where
D: Fn(&[u8], Option<PinnedBuf>) -> CoreOp, D: Fn(&[u8], Option<ZeroCopyBuf>) -> CoreOp,
{ {
let state = self.clone(); let state = self.clone();
move |control: &[u8], zero_copy: Option<PinnedBuf>| -> CoreOp { move |control: &[u8], zero_copy: Option<ZeroCopyBuf>| -> CoreOp {
let bytes_sent_control = control.len(); let bytes_sent_control = control.len();
let bytes_sent_zero_copy = let bytes_sent_zero_copy =
zero_copy.as_ref().map(|b| b.len()).unwrap_or(0); zero_copy.as_ref().map(|b| b.len()).unwrap_or(0);
@ -126,13 +126,13 @@ impl ThreadSafeState {
pub fn stateful_minimal_op<D>( pub fn stateful_minimal_op<D>(
&self, &self,
dispatcher: D, dispatcher: D,
) -> impl Fn(i32, Option<PinnedBuf>) -> Pin<Box<MinimalOp>> ) -> impl Fn(i32, Option<ZeroCopyBuf>) -> Pin<Box<MinimalOp>>
where where
D: Fn(&ThreadSafeState, i32, Option<PinnedBuf>) -> Pin<Box<MinimalOp>>, D: Fn(&ThreadSafeState, i32, Option<ZeroCopyBuf>) -> Pin<Box<MinimalOp>>,
{ {
let state = self.clone(); let state = self.clone();
move |rid: i32, zero_copy: Option<PinnedBuf>| -> Pin<Box<MinimalOp>> { move |rid: i32, zero_copy: Option<ZeroCopyBuf>| -> Pin<Box<MinimalOp>> {
dispatcher(&state, rid, zero_copy) dispatcher(&state, rid, zero_copy)
} }
} }
@ -145,15 +145,19 @@ impl ThreadSafeState {
pub fn stateful_op<D>( pub fn stateful_op<D>(
&self, &self,
dispatcher: D, dispatcher: D,
) -> impl Fn(Value, Option<PinnedBuf>) -> Result<JsonOp, ErrBox> ) -> impl Fn(Value, Option<ZeroCopyBuf>) -> Result<JsonOp, ErrBox>
where where
D: Fn(&ThreadSafeState, Value, Option<PinnedBuf>) -> Result<JsonOp, ErrBox>, D: Fn(
&ThreadSafeState,
Value,
Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox>,
{ {
let state = self.clone(); let state = self.clone();
move |args: Value, zero_copy: Option<PinnedBuf>| -> Result<JsonOp, ErrBox> { move |args: Value,
dispatcher(&state, args, zero_copy) zero_copy: Option<ZeroCopyBuf>|
} -> Result<JsonOp, ErrBox> { dispatcher(&state, args, zero_copy) }
} }
} }

View file

@ -2,7 +2,7 @@
use crate::es_isolate::EsIsolate; use crate::es_isolate::EsIsolate;
use crate::isolate::Isolate; use crate::isolate::Isolate;
use crate::isolate::PinnedBuf; use crate::isolate::ZeroCopyBuf;
use rusty_v8 as v8; use rusty_v8 as v8;
use v8::MapFnTo; use v8::MapFnTo;
@ -405,9 +405,9 @@ fn send(
Err(..) => &[], Err(..) => &[],
}; };
let zero_copy: Option<PinnedBuf> = let zero_copy: Option<ZeroCopyBuf> =
v8::Local::<v8::ArrayBufferView>::try_from(args.get(2)) v8::Local::<v8::ArrayBufferView>::try_from(args.get(2))
.map(PinnedBuf::new) .map(ZeroCopyBuf::new)
.ok(); .ok();
// If response is empty then it's either async op or exception was thrown // If response is empty then it's either async op or exception was thrown

View file

@ -597,7 +597,7 @@ pub mod tests {
use super::*; use super::*;
use crate::isolate::js_check; use crate::isolate::js_check;
use crate::isolate::tests::run_in_task; use crate::isolate::tests::run_in_task;
use crate::isolate::PinnedBuf; use crate::isolate::ZeroCopyBuf;
use crate::modules::SourceCodeInfoFuture; use crate::modules::SourceCodeInfoFuture;
use crate::ops::*; use crate::ops::*;
use std::io; use std::io;
@ -642,7 +642,7 @@ pub mod tests {
let mut isolate = EsIsolate::new(loader, StartupData::None, false); let mut isolate = EsIsolate::new(loader, StartupData::None, false);
let dispatcher = 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); dispatch_count_.fetch_add(1, Ordering::Relaxed);
assert_eq!(control.len(), 1); assert_eq!(control.len(), 1);
assert_eq!(control[0], 42); assert_eq!(control[0], 42);

View file

@ -108,12 +108,12 @@ fn test_record_from() {
pub type HttpOp = dyn Future<Output = Result<i32, std::io::Error>> + Send; pub type HttpOp = dyn Future<Output = Result<i32, std::io::Error>> + Send;
pub type HttpOpHandler = 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( fn http_op(
handler: HttpOpHandler, handler: HttpOpHandler,
) -> impl Fn(&[u8], Option<PinnedBuf>) -> CoreOp { ) -> impl Fn(&[u8], Option<ZeroCopyBuf>) -> CoreOp {
move |control: &[u8], zero_copy_buf: Option<PinnedBuf>| -> CoreOp { move |control: &[u8], zero_copy_buf: Option<ZeroCopyBuf>| -> CoreOp {
let record = Record::from(control); let record = Record::from(control);
let is_sync = record.promise_id == 0; let is_sync = record.promise_id == 0;
let op = handler(record.clone(), zero_copy_buf); let op = handler(record.clone(), zero_copy_buf);
@ -232,7 +232,7 @@ impl Future for Accept {
fn op_accept( fn op_accept(
record: Record, record: Record,
_zero_copy_buf: Option<PinnedBuf>, _zero_copy_buf: Option<ZeroCopyBuf>,
) -> Pin<Box<HttpOp>> { ) -> Pin<Box<HttpOp>> {
let rid = record.arg as u32; let rid = record.arg as u32;
debug!("accept {}", rid); debug!("accept {}", rid);
@ -250,7 +250,7 @@ fn op_accept(
fn op_listen( fn op_listen(
_record: Record, _record: Record,
_zero_copy_buf: Option<PinnedBuf>, _zero_copy_buf: Option<ZeroCopyBuf>,
) -> Pin<Box<HttpOp>> { ) -> Pin<Box<HttpOp>> {
debug!("listen"); debug!("listen");
let fut = async { let fut = async {
@ -266,7 +266,7 @@ fn op_listen(
fn op_close( fn op_close(
record: Record, record: Record,
_zero_copy_buf: Option<PinnedBuf>, _zero_copy_buf: Option<ZeroCopyBuf>,
) -> Pin<Box<HttpOp>> { ) -> Pin<Box<HttpOp>> {
debug!("close"); debug!("close");
let fut = async move { let fut = async move {
@ -282,7 +282,7 @@ fn op_close(
struct Read { struct Read {
rid: ResourceId, rid: ResourceId,
buf: PinnedBuf, buf: ZeroCopyBuf,
} }
impl Future for Read { impl Future for Read {
@ -304,7 +304,7 @@ impl Future for Read {
fn op_read( fn op_read(
record: Record, record: Record,
zero_copy_buf: Option<PinnedBuf>, zero_copy_buf: Option<ZeroCopyBuf>,
) -> Pin<Box<HttpOp>> { ) -> Pin<Box<HttpOp>> {
let rid = record.arg as u32; let rid = record.arg as u32;
debug!("read rid={}", rid); debug!("read rid={}", rid);
@ -325,7 +325,7 @@ fn op_read(
struct Write { struct Write {
rid: ResourceId, rid: ResourceId,
buf: PinnedBuf, buf: ZeroCopyBuf,
} }
impl Future for Write { impl Future for Write {
@ -347,7 +347,7 @@ impl Future for Write {
fn op_write( fn op_write(
record: Record, record: Record,
zero_copy_buf: Option<PinnedBuf>, zero_copy_buf: Option<ZeroCopyBuf>,
) -> Pin<Box<HttpOp>> { ) -> Pin<Box<HttpOp>> {
let rid = record.arg as u32; let rid = record.arg as u32;
debug!("write rid={}", rid); debug!("write rid={}", rid);

View file

@ -30,20 +30,21 @@ use std::pin::Pin;
use std::sync::{Arc, Mutex, Once}; use std::sync::{Arc, Mutex, Once};
use std::task::Context; use std::task::Context;
use std::task::Poll; 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, /// ArrayBuffer object. JavaScript objects can normally be garbage collected,
/// but the existence of a PinnedBuf inhibits this until it is dropped. It /// but the existence of a ZeroCopyBuf inhibits this until it is dropped. It
/// behaves much like an Arc<[u8]>, although a PinnedBuf currently can't be /// behaves much like an Arc<[u8]>, although a ZeroCopyBuf currently can't be
/// cloned. /// cloned.
pub struct PinnedBuf { pub struct ZeroCopyBuf {
backing_store: v8::SharedRef<v8::BackingStore>, backing_store: v8::SharedRef<v8::BackingStore>,
byte_offset: usize, byte_offset: usize,
byte_length: 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 { pub fn new(view: v8::Local<v8::ArrayBufferView>) -> Self {
let backing_store = view.buffer().unwrap().get_backing_store(); let backing_store = view.buffer().unwrap().get_backing_store();
let byte_offset = view.byte_offset(); let byte_offset = view.byte_offset();
@ -56,7 +57,7 @@ impl PinnedBuf {
} }
} }
impl Deref for PinnedBuf { impl Deref for ZeroCopyBuf {
type Target = [u8]; type Target = [u8];
fn deref(&self) -> &[u8] { fn deref(&self) -> &[u8] {
let buf = unsafe { &**self.backing_store.get() }; 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] { fn deref_mut(&mut self) -> &mut [u8] {
let buf = unsafe { &mut **self.backing_store.get() }; let buf = unsafe { &mut **self.backing_store.get() };
&mut buf[self.byte_offset..self.byte_offset + self.byte_length] &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] { fn as_ref(&self) -> &[u8] {
&*self &*self
} }
} }
impl AsMut<[u8]> for PinnedBuf { impl AsMut<[u8]> for ZeroCopyBuf {
fn as_mut(&mut self) -> &mut [u8] { fn as_mut(&mut self) -> &mut [u8] {
&mut *self &mut *self
} }
@ -436,7 +437,7 @@ impl Isolate {
/// Requires runtime to explicitly ask for op ids before using any of the ops. /// 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 pub fn register_op<F>(&self, name: &str, op: F) -> OpId
where 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) self.op_registry.register(name, op)
} }
@ -476,7 +477,7 @@ impl Isolate {
&mut self, &mut self,
op_id: OpId, op_id: OpId,
control_buf: &[u8], control_buf: &[u8],
zero_copy_buf: Option<PinnedBuf>, zero_copy_buf: Option<ZeroCopyBuf>,
) -> Option<(OpId, Box<[u8]>)> { ) -> Option<(OpId, Box<[u8]>)> {
let maybe_op = self.op_registry.call(op_id, control_buf, zero_copy_buf); 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 mut isolate = Isolate::new(StartupData::None, false);
let dispatcher = 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); dispatch_count_.fetch_add(1, Ordering::Relaxed);
match mode { match mode {
Mode::Async => { Mode::Async => {

View file

@ -1,5 +1,5 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
use crate::PinnedBuf; use crate::ZeroCopyBuf;
use futures::Future; use futures::Future;
use std::collections::HashMap; use std::collections::HashMap;
use std::pin::Pin; use std::pin::Pin;
@ -32,7 +32,7 @@ pub type CoreOp = Op<CoreError>;
/// Main type describing op /// Main type describing op
pub type OpDispatcher = pub type OpDispatcher =
dyn Fn(&[u8], Option<PinnedBuf>) -> CoreOp + Send + Sync + 'static; dyn Fn(&[u8], Option<ZeroCopyBuf>) -> CoreOp + Send + Sync + 'static;
#[derive(Default)] #[derive(Default)]
pub struct OpRegistry { pub struct OpRegistry {
@ -53,7 +53,7 @@ impl OpRegistry {
pub fn register<F>(&self, name: &str, op: F) -> OpId pub fn register<F>(&self, name: &str, op: F) -> OpId
where 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 mut lock = self.dispatchers.write().unwrap();
let op_id = lock.len() as u32; let op_id = lock.len() as u32;
@ -82,7 +82,7 @@ impl OpRegistry {
&self, &self,
op_id: OpId, op_id: OpId,
control: &[u8], control: &[u8],
zero_copy_buf: Option<PinnedBuf>, zero_copy_buf: Option<ZeroCopyBuf>,
) -> Option<CoreOp> { ) -> Option<CoreOp> {
// Op with id 0 has special meaning - it's a special op that is always // 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` // provided to retrieve op id map. The map consists of name to `OpId`

View file

@ -1,4 +1,4 @@
use crate::isolate::PinnedBuf; use crate::isolate::ZeroCopyBuf;
use crate::ops::CoreOp; use crate::ops::CoreOp;
pub type PluginInitFn = fn(context: &mut dyn PluginInitContext); pub type PluginInitFn = fn(context: &mut dyn PluginInitContext);
@ -7,7 +7,9 @@ pub trait PluginInitContext {
fn register_op( fn register_op(
&mut self, &mut self,
name: &str, name: &str,
op: Box<dyn Fn(&[u8], Option<PinnedBuf>) -> CoreOp + Send + Sync + 'static>, op: Box<
dyn Fn(&[u8], Option<ZeroCopyBuf>) -> CoreOp + Send + Sync + 'static,
>,
); );
} }

View file

@ -12,8 +12,8 @@ use deno_core::CoreOp;
use deno_core::ErrBox; use deno_core::ErrBox;
use deno_core::Isolate; use deno_core::Isolate;
use deno_core::ModuleSpecifier; use deno_core::ModuleSpecifier;
use deno_core::PinnedBuf;
use deno_core::StartupData; use deno_core::StartupData;
use deno_core::ZeroCopyBuf;
pub use ops::EmitResult; pub use ops::EmitResult;
use ops::WrittenFile; use ops::WrittenFile;
use std::fs; use std::fs;
@ -45,11 +45,11 @@ pub struct TSState {
fn compiler_op<D>( fn compiler_op<D>(
ts_state: Arc<Mutex<TSState>>, ts_state: Arc<Mutex<TSState>>,
dispatcher: D, dispatcher: D,
) -> impl Fn(&[u8], Option<PinnedBuf>) -> CoreOp ) -> impl Fn(&[u8], Option<ZeroCopyBuf>) -> CoreOp
where where
D: Fn(&mut TSState, &[u8]) -> CoreOp, D: Fn(&mut TSState, &[u8]) -> CoreOp,
{ {
move |control: &[u8], zero_copy_buf: Option<PinnedBuf>| -> CoreOp { move |control: &[u8], zero_copy_buf: Option<ZeroCopyBuf>| -> CoreOp {
assert!(zero_copy_buf.is_none()); // zero_copy_buf unused in compiler. assert!(zero_copy_buf.is_none()); // zero_copy_buf unused in compiler.
let mut s = ts_state.lock().unwrap(); let mut s = ts_state.lock().unwrap();
dispatcher(&mut s, control) dispatcher(&mut s, control)

View file

@ -5,7 +5,7 @@ extern crate futures;
use deno_core::CoreOp; use deno_core::CoreOp;
use deno_core::Op; use deno_core::Op;
use deno_core::PluginInitContext; use deno_core::PluginInitContext;
use deno_core::{Buf, PinnedBuf}; use deno_core::{Buf, ZeroCopyBuf};
use futures::future::FutureExt; use futures::future::FutureExt;
fn init(context: &mut dyn PluginInitContext) { fn init(context: &mut dyn PluginInitContext) {
@ -14,7 +14,7 @@ fn init(context: &mut dyn PluginInitContext) {
} }
init_fn!(init); init_fn!(init);
pub fn op_test_sync(data: &[u8], zero_copy: Option<PinnedBuf>) -> CoreOp { pub fn op_test_sync(data: &[u8], zero_copy: Option<ZeroCopyBuf>) -> CoreOp {
if let Some(buf) = zero_copy { if let Some(buf) = zero_copy {
let data_str = std::str::from_utf8(&data[..]).unwrap(); let data_str = std::str::from_utf8(&data[..]).unwrap();
let buf_str = std::str::from_utf8(&buf[..]).unwrap(); let buf_str = std::str::from_utf8(&buf[..]).unwrap();
@ -28,7 +28,7 @@ pub fn op_test_sync(data: &[u8], zero_copy: Option<PinnedBuf>) -> CoreOp {
Op::Sync(result_box) Op::Sync(result_box)
} }
pub fn op_test_async(data: &[u8], zero_copy: Option<PinnedBuf>) -> CoreOp { pub fn op_test_async(data: &[u8], zero_copy: Option<ZeroCopyBuf>) -> CoreOp {
let data_str = std::str::from_utf8(&data[..]).unwrap().to_string(); let data_str = std::str::from_utf8(&data[..]).unwrap().to_string();
let fut = async move { let fut = async move {
if let Some(buf) = zero_copy { if let Some(buf) = zero_copy {