diff options
| author | Aaron O'Mullan <aaron.omullan@gmail.com> | 2021-04-02 15:47:57 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-04-02 09:47:57 -0400 |
| commit | 058579da562989ed15c86598053644bbc86c6747 (patch) | |
| tree | 7f0f2bf30684dcbb350b93d987771f17a4abd250 /runtime | |
| parent | adf57610904cb4f4ef25fb077f6e39c9017a4ea9 (diff) | |
refactor(ops): remove variadic buffers (#9944)
Diffstat (limited to 'runtime')
| -rw-r--r-- | runtime/ops/fs.rs | 99 | ||||
| -rw-r--r-- | runtime/ops/fs_events.rs | 5 | ||||
| -rw-r--r-- | runtime/ops/io.rs | 22 | ||||
| -rw-r--r-- | runtime/ops/mod.rs | 10 | ||||
| -rw-r--r-- | runtime/ops/net.rs | 32 | ||||
| -rw-r--r-- | runtime/ops/net_unix.rs | 10 | ||||
| -rw-r--r-- | runtime/ops/os.rs | 22 | ||||
| -rw-r--r-- | runtime/ops/permissions.rs | 6 | ||||
| -rw-r--r-- | runtime/ops/plugin.rs | 12 | ||||
| -rw-r--r-- | runtime/ops/process.rs | 7 | ||||
| -rw-r--r-- | runtime/ops/runtime.rs | 4 | ||||
| -rw-r--r-- | runtime/ops/signal.rs | 13 | ||||
| -rw-r--r-- | runtime/ops/timers.rs | 21 | ||||
| -rw-r--r-- | runtime/ops/tls.rs | 9 | ||||
| -rw-r--r-- | runtime/ops/tty.rs | 6 | ||||
| -rw-r--r-- | runtime/ops/web_worker.rs | 7 | ||||
| -rw-r--r-- | runtime/ops/worker_host.rs | 14 |
17 files changed, 141 insertions, 158 deletions
diff --git a/runtime/ops/fs.rs b/runtime/ops/fs.rs index cb20cf471..bc166b4ad 100644 --- a/runtime/ops/fs.rs +++ b/runtime/ops/fs.rs @@ -10,7 +10,6 @@ use deno_core::error::AnyError; use deno_core::serde_json; use deno_core::serde_json::json; use deno_core::serde_json::Value; -use deno_core::BufVec; use deno_core::OpState; use deno_core::RcRef; use deno_core::ResourceId; @@ -183,7 +182,7 @@ fn open_helper( fn op_open_sync( state: &mut OpState, args: OpenArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let (path, open_options) = open_helper(state, args)?; let std_file = open_options.open(path)?; @@ -196,7 +195,7 @@ fn op_open_sync( async fn op_open_async( state: Rc<RefCell<OpState>>, args: OpenArgs, - _zero_copy: BufVec, + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let (path, open_options) = open_helper(&mut state.borrow_mut(), args)?; let tokio_file = tokio::fs::OpenOptions::from(open_options) @@ -235,7 +234,7 @@ fn seek_helper(args: SeekArgs) -> Result<(u32, SeekFrom), AnyError> { fn op_seek_sync( state: &mut OpState, args: SeekArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let (rid, seek_from) = seek_helper(args)?; let pos = StdFileResource::with(state, rid, |r| match r { @@ -250,7 +249,7 @@ fn op_seek_sync( async fn op_seek_async( state: Rc<RefCell<OpState>>, args: SeekArgs, - _zero_copy: BufVec, + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let (rid, seek_from) = seek_helper(args)?; @@ -281,7 +280,7 @@ pub struct FdatasyncArgs { fn op_fdatasync_sync( state: &mut OpState, args: FdatasyncArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let rid = args.rid; StdFileResource::with(state, rid, |r| match r { @@ -294,7 +293,7 @@ fn op_fdatasync_sync( async fn op_fdatasync_async( state: Rc<RefCell<OpState>>, args: FdatasyncArgs, - _zero_copy: BufVec, + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let rid = args.rid; @@ -325,7 +324,7 @@ pub struct FsyncArgs { fn op_fsync_sync( state: &mut OpState, args: FsyncArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let rid = args.rid; StdFileResource::with(state, rid, |r| match r { @@ -338,7 +337,7 @@ fn op_fsync_sync( async fn op_fsync_async( state: Rc<RefCell<OpState>>, args: FsyncArgs, - _zero_copy: BufVec, + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let rid = args.rid; @@ -369,7 +368,7 @@ pub struct FstatArgs { fn op_fstat_sync( state: &mut OpState, args: FstatArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { super::check_unstable(state, "Deno.fstat"); let metadata = StdFileResource::with(state, args.rid, |r| match r { @@ -382,7 +381,7 @@ fn op_fstat_sync( async fn op_fstat_async( state: Rc<RefCell<OpState>>, args: FstatArgs, - _zero_copy: BufVec, + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { super::check_unstable2(&state, "Deno.fstat"); @@ -415,7 +414,7 @@ pub struct UmaskArgs { fn op_umask( state: &mut OpState, args: UmaskArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { super::check_unstable(state, "Deno.umask"); // TODO implement umask for Windows @@ -452,7 +451,7 @@ pub struct ChdirArgs { fn op_chdir( state: &mut OpState, args: ChdirArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let d = PathBuf::from(&args.directory); state.borrow::<Permissions>().read.check(&d)?; @@ -471,7 +470,7 @@ pub struct MkdirArgs { fn op_mkdir_sync( state: &mut OpState, args: MkdirArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let path = Path::new(&args.path).to_path_buf(); let mode = args.mode.unwrap_or(0o777) & 0o777; @@ -491,7 +490,7 @@ fn op_mkdir_sync( async fn op_mkdir_async( state: Rc<RefCell<OpState>>, args: MkdirArgs, - _zero_copy: BufVec, + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let path = Path::new(&args.path).to_path_buf(); let mode = args.mode.unwrap_or(0o777) & 0o777; @@ -527,7 +526,7 @@ pub struct ChmodArgs { fn op_chmod_sync( state: &mut OpState, args: ChmodArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let path = Path::new(&args.path).to_path_buf(); let mode = args.mode & 0o777; @@ -553,7 +552,7 @@ fn op_chmod_sync( async fn op_chmod_async( state: Rc<RefCell<OpState>>, args: ChmodArgs, - _zero_copy: BufVec, + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let path = Path::new(&args.path).to_path_buf(); let mode = args.mode & 0o777; @@ -595,7 +594,7 @@ pub struct ChownArgs { fn op_chown_sync( state: &mut OpState, args: ChownArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let path = Path::new(&args.path).to_path_buf(); state.borrow::<Permissions>().write.check(&path)?; @@ -623,7 +622,7 @@ fn op_chown_sync( async fn op_chown_async( state: Rc<RefCell<OpState>>, args: ChownArgs, - _zero_copy: BufVec, + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let path = Path::new(&args.path).to_path_buf(); @@ -665,7 +664,7 @@ pub struct RemoveArgs { fn op_remove_sync( state: &mut OpState, args: RemoveArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let path = PathBuf::from(&args.path); let recursive = args.recursive; @@ -707,7 +706,7 @@ fn op_remove_sync( async fn op_remove_async( state: Rc<RefCell<OpState>>, args: RemoveArgs, - _zero_copy: BufVec, + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let path = PathBuf::from(&args.path); let recursive = args.recursive; @@ -763,7 +762,7 @@ pub struct CopyFileArgs { fn op_copy_file_sync( state: &mut OpState, args: CopyFileArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let from = PathBuf::from(&args.from); let to = PathBuf::from(&args.to); @@ -788,7 +787,7 @@ fn op_copy_file_sync( async fn op_copy_file_async( state: Rc<RefCell<OpState>>, args: CopyFileArgs, - _zero_copy: BufVec, + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let from = PathBuf::from(&args.from); let to = PathBuf::from(&args.to); @@ -885,7 +884,7 @@ pub struct StatArgs { fn op_stat_sync( state: &mut OpState, args: StatArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let path = PathBuf::from(&args.path); let lstat = args.lstat; @@ -902,7 +901,7 @@ fn op_stat_sync( async fn op_stat_async( state: Rc<RefCell<OpState>>, args: StatArgs, - _zero_copy: BufVec, + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let path = PathBuf::from(&args.path); let lstat = args.lstat; @@ -934,7 +933,7 @@ pub struct RealpathArgs { fn op_realpath_sync( state: &mut OpState, args: RealpathArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let path = PathBuf::from(&args.path); @@ -955,7 +954,7 @@ fn op_realpath_sync( async fn op_realpath_async( state: Rc<RefCell<OpState>>, args: RealpathArgs, - _zero_copy: BufVec, + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let path = PathBuf::from(&args.path); @@ -989,7 +988,7 @@ pub struct ReadDirArgs { fn op_read_dir_sync( state: &mut OpState, args: ReadDirArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let path = PathBuf::from(&args.path); @@ -1019,7 +1018,7 @@ fn op_read_dir_sync( async fn op_read_dir_async( state: Rc<RefCell<OpState>>, args: ReadDirArgs, - _zero_copy: BufVec, + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let path = PathBuf::from(&args.path); { @@ -1061,7 +1060,7 @@ pub struct RenameArgs { fn op_rename_sync( state: &mut OpState, args: RenameArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let oldpath = PathBuf::from(&args.oldpath); let newpath = PathBuf::from(&args.newpath); @@ -1078,7 +1077,7 @@ fn op_rename_sync( async fn op_rename_async( state: Rc<RefCell<OpState>>, args: RenameArgs, - _zero_copy: BufVec, + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let oldpath = PathBuf::from(&args.oldpath); let newpath = PathBuf::from(&args.newpath); @@ -1112,7 +1111,7 @@ pub struct LinkArgs { fn op_link_sync( state: &mut OpState, args: LinkArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let oldpath = PathBuf::from(&args.oldpath); let newpath = PathBuf::from(&args.newpath); @@ -1131,7 +1130,7 @@ fn op_link_sync( async fn op_link_async( state: Rc<RefCell<OpState>>, args: LinkArgs, - _zero_copy: BufVec, + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let oldpath = PathBuf::from(&args.oldpath); let newpath = PathBuf::from(&args.newpath); @@ -1173,7 +1172,7 @@ pub struct SymlinkOptions { fn op_symlink_sync( state: &mut OpState, args: SymlinkArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let oldpath = PathBuf::from(&args.oldpath); let newpath = PathBuf::from(&args.newpath); @@ -1222,7 +1221,7 @@ fn op_symlink_sync( async fn op_symlink_async( state: Rc<RefCell<OpState>>, args: SymlinkArgs, - _zero_copy: BufVec, + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let oldpath = PathBuf::from(&args.oldpath); let newpath = PathBuf::from(&args.newpath); @@ -1280,7 +1279,7 @@ pub struct ReadLinkArgs { fn op_read_link_sync( state: &mut OpState, args: ReadLinkArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let path = PathBuf::from(&args.path); @@ -1295,7 +1294,7 @@ fn op_read_link_sync( async fn op_read_link_async( state: Rc<RefCell<OpState>>, args: ReadLinkArgs, - _zero_copy: BufVec, + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let path = PathBuf::from(&args.path); { @@ -1322,7 +1321,7 @@ pub struct FtruncateArgs { fn op_ftruncate_sync( state: &mut OpState, args: FtruncateArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { super::check_unstable(state, "Deno.ftruncate"); let rid = args.rid; @@ -1337,7 +1336,7 @@ fn op_ftruncate_sync( async fn op_ftruncate_async( state: Rc<RefCell<OpState>>, args: FtruncateArgs, - _zero_copy: BufVec, + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { super::check_unstable2(&state, "Deno.ftruncate"); let rid = args.rid; @@ -1371,7 +1370,7 @@ pub struct TruncateArgs { fn op_truncate_sync( state: &mut OpState, args: TruncateArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let path = PathBuf::from(&args.path); let len = args.len; @@ -1387,7 +1386,7 @@ fn op_truncate_sync( async fn op_truncate_async( state: Rc<RefCell<OpState>>, args: TruncateArgs, - _zero_copy: BufVec, + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let path = PathBuf::from(&args.path); let len = args.len; @@ -1461,7 +1460,7 @@ pub struct MakeTempArgs { fn op_make_temp_dir_sync( state: &mut OpState, args: MakeTempArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let dir = args.dir.map(|s| PathBuf::from(&s)); let prefix = args.prefix.map(String::from); @@ -1490,7 +1489,7 @@ fn op_make_temp_dir_sync( async fn op_make_temp_dir_async( state: Rc<RefCell<OpState>>, args: MakeTempArgs, - _zero_copy: BufVec, + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let dir = args.dir.map(|s| PathBuf::from(&s)); let prefix = args.prefix.map(String::from); @@ -1524,7 +1523,7 @@ async fn op_make_temp_dir_async( fn op_make_temp_file_sync( state: &mut OpState, args: MakeTempArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let dir = args.dir.map(|s| PathBuf::from(&s)); let prefix = args.prefix.map(String::from); @@ -1553,7 +1552,7 @@ fn op_make_temp_file_sync( async fn op_make_temp_file_async( state: Rc<RefCell<OpState>>, args: MakeTempArgs, - _zero_copy: BufVec, + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let dir = args.dir.map(|s| PathBuf::from(&s)); let prefix = args.prefix.map(String::from); @@ -1595,7 +1594,7 @@ pub struct FutimeArgs { fn op_futime_sync( state: &mut OpState, args: FutimeArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { super::check_unstable(state, "Deno.futimeSync"); let rid = args.rid; @@ -1618,7 +1617,7 @@ fn op_futime_sync( async fn op_futime_async( state: Rc<RefCell<OpState>>, args: FutimeArgs, - _zero_copy: BufVec, + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { super::check_unstable2(&state, "Deno.futime"); let rid = args.rid; @@ -1667,7 +1666,7 @@ pub struct UtimeArgs { fn op_utime_sync( state: &mut OpState, args: UtimeArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { super::check_unstable(state, "Deno.utime"); @@ -1683,7 +1682,7 @@ fn op_utime_sync( async fn op_utime_async( state: Rc<RefCell<OpState>>, args: UtimeArgs, - _zero_copy: BufVec, + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { super::check_unstable(&state.borrow(), "Deno.utime"); @@ -1704,7 +1703,7 @@ async fn op_utime_async( fn op_cwd( state: &mut OpState, _args: Value, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let path = current_dir()?; state diff --git a/runtime/ops/fs_events.rs b/runtime/ops/fs_events.rs index 9bfaf6d47..fed28a3d2 100644 --- a/runtime/ops/fs_events.rs +++ b/runtime/ops/fs_events.rs @@ -6,7 +6,6 @@ use deno_core::error::AnyError; use deno_core::serde_json::json; use deno_core::serde_json::Value; use deno_core::AsyncRefCell; -use deno_core::BufVec; use deno_core::CancelFuture; use deno_core::CancelHandle; use deno_core::OpState; @@ -93,7 +92,7 @@ pub struct OpenArgs { fn op_fs_events_open( state: &mut OpState, args: OpenArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let (sender, receiver) = mpsc::channel::<Result<FsEvent, AnyError>>(16); let sender = std::sync::Mutex::new(sender); @@ -134,7 +133,7 @@ pub struct PollArgs { async fn op_fs_events_poll( state: Rc<RefCell<OpState>>, args: PollArgs, - _zero_copy: BufVec, + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let resource = state .borrow() diff --git a/runtime/ops/io.rs b/runtime/ops/io.rs index d87cfcf94..e5a571f81 100644 --- a/runtime/ops/io.rs +++ b/runtime/ops/io.rs @@ -1,5 +1,6 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +use deno_core::error::null_opbuf; use deno_core::error::resource_unavailable; use deno_core::error::AnyError; use deno_core::error::{bad_resource_id, not_supported}; @@ -7,7 +8,6 @@ use deno_core::serde_json::json; use deno_core::serde_json::Value; use deno_core::AsyncMutFuture; use deno_core::AsyncRefCell; -use deno_core::BufVec; use deno_core::CancelHandle; use deno_core::CancelTryFuture; use deno_core::JsRuntime; @@ -523,11 +523,12 @@ impl Resource for StdFileResource { fn op_read_sync( state: &mut OpState, rid: ResourceId, - bufs: &mut [ZeroCopyBuf], + buf: Option<ZeroCopyBuf>, ) -> Result<u32, AnyError> { + let mut buf = buf.ok_or_else(null_opbuf)?; StdFileResource::with(state, rid, move |r| match r { Ok(std_file) => std_file - .read(&mut bufs[0]) + .read(&mut buf) .map(|n: usize| n as u32) .map_err(AnyError::from), Err(_) => Err(not_supported()), @@ -537,9 +538,9 @@ fn op_read_sync( async fn op_read_async( state: Rc<RefCell<OpState>>, rid: ResourceId, - mut bufs: BufVec, + buf: Option<ZeroCopyBuf>, ) -> Result<u32, AnyError> { - let buf = &mut bufs[0]; + let buf = &mut buf.ok_or_else(null_opbuf)?; let resource = state .borrow() .resource_table @@ -568,11 +569,12 @@ async fn op_read_async( fn op_write_sync( state: &mut OpState, rid: ResourceId, - bufs: &mut [ZeroCopyBuf], + buf: Option<ZeroCopyBuf>, ) -> Result<u32, AnyError> { + let buf = buf.ok_or_else(null_opbuf)?; StdFileResource::with(state, rid, move |r| match r { Ok(std_file) => std_file - .write(&bufs[0]) + .write(&buf) .map(|nwritten: usize| nwritten as u32) .map_err(AnyError::from), Err(_) => Err(not_supported()), @@ -582,9 +584,9 @@ fn op_write_sync( async fn op_write_async( state: Rc<RefCell<OpState>>, rid: ResourceId, - bufs: BufVec, + buf: Option<ZeroCopyBuf>, ) -> Result<u32, AnyError> { - let buf = &bufs[0]; + let buf = &buf.ok_or_else(null_opbuf)?; let resource = state .borrow() .resource_table @@ -616,7 +618,7 @@ struct ShutdownArgs { async fn op_shutdown( state: Rc<RefCell<OpState>>, args: ShutdownArgs, - _zero_copy: BufVec, + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let resource = state .borrow() diff --git a/runtime/ops/mod.rs b/runtime/ops/mod.rs index 073b17c86..b497f6a42 100644 --- a/runtime/ops/mod.rs +++ b/runtime/ops/mod.rs @@ -31,7 +31,6 @@ use deno_core::json_op_async; use deno_core::json_op_sync; use deno_core::serde::de::DeserializeOwned; use deno_core::serde::Serialize; -use deno_core::BufVec; use deno_core::JsRuntime; use deno_core::OpState; use deno_core::ValueOrVector; @@ -45,7 +44,7 @@ pub fn reg_json_async<F, V, R, RV>( name: &'static str, op_fn: F, ) where - F: Fn(Rc<RefCell<OpState>>, V, BufVec) -> R + 'static, + F: Fn(Rc<RefCell<OpState>>, V, Option<ZeroCopyBuf>) -> R + 'static, V: DeserializeOwned, R: Future<Output = Result<RV, AnyError>> + 'static, RV: Serialize + 'static, @@ -55,7 +54,7 @@ pub fn reg_json_async<F, V, R, RV>( pub fn reg_json_sync<F, V, R>(rt: &mut JsRuntime, name: &'static str, op_fn: F) where - F: Fn(&mut OpState, V, &mut [ZeroCopyBuf]) -> Result<R, AnyError> + 'static, + F: Fn(&mut OpState, V, Option<ZeroCopyBuf>) -> Result<R, AnyError> + 'static, V: DeserializeOwned, R: Serialize + 'static, { @@ -64,7 +63,7 @@ where pub fn reg_bin_async<F, R, RV>(rt: &mut JsRuntime, name: &'static str, op_fn: F) where - F: Fn(Rc<RefCell<OpState>>, u32, BufVec) -> R + 'static, + F: Fn(Rc<RefCell<OpState>>, u32, Option<ZeroCopyBuf>) -> R + 'static, R: Future<Output = Result<RV, AnyError>> + 'static, RV: ValueOrVector, { @@ -73,7 +72,8 @@ where pub fn reg_bin_sync<F, R>(rt: &mut JsRuntime, name: &'static str, op_fn: F) where - F: Fn(&mut OpState, u32, &mut [ZeroCopyBuf]) -> Result<R, AnyError> + 'static, + F: + Fn(&mut OpState, u32, Option<ZeroCopyBuf>) -> Result<R, AnyError> + 'static, R: ValueOrVector, { rt.register_op(name, metrics_op(name, bin_op_sync(op_fn))); diff --git a/runtime/ops/net.rs b/runtime/ops/net.rs index 6ec393bac..7d81fcee0 100644 --- a/runtime/ops/net.rs +++ b/runtime/ops/net.rs @@ -6,13 +6,13 @@ use crate::resolve_addr::resolve_addr_sync; use deno_core::error::bad_resource; use deno_core::error::custom_error; use deno_core::error::generic_error; +use deno_core::error::null_opbuf; use deno_core::error::type_error; use deno_core::error::AnyError; use deno_core::serde_json; use deno_core::serde_json::json; use deno_core::serde_json::Value; use deno_core::AsyncRefCell; -use deno_core::BufVec; use deno_core::CancelHandle; use deno_core::CancelTryFuture; use deno_core::OpState; @@ -63,7 +63,7 @@ pub(crate) struct AcceptArgs { async fn accept_tcp( state: Rc<RefCell<OpState>>, args: AcceptArgs, - _zero_copy: BufVec, + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let rid = args.rid; @@ -110,13 +110,13 @@ async fn accept_tcp( async fn op_accept( state: Rc<RefCell<OpState>>, args: Value, - bufs: BufVec, + _buf: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let args: AcceptArgs = serde_json::from_value(args)?; match args.transport.as_str() { - "tcp" => accept_tcp(state, args, bufs).await, + "tcp" => accept_tcp(state, args, _buf).await, #[cfg(unix)] - "unix" => net_unix::accept_unix(state, args, bufs).await, + "unix" => net_unix::accept_unix(state, args, _buf).await, _ => Err(generic_error(format!( "Unsupported transport protocol {}", args.transport @@ -133,10 +133,10 @@ pub(crate) struct ReceiveArgs { async fn receive_udp( state: Rc<RefCell<OpState>>, args: ReceiveArgs, - zero_copy: BufVec, + zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { - assert_eq!(zero_copy.len(), 1, "Invalid number of arguments"); - let mut zero_copy = zero_copy[0].clone(); + let zero_copy = zero_copy.ok_or_else(null_opbuf)?; + let mut zero_copy = zero_copy.clone(); let rid = args.rid; @@ -164,10 +164,8 @@ async fn receive_udp( async fn op_datagram_receive( state: Rc<RefCell<OpState>>, args: Value, - zero_copy: BufVec, + zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { - assert_eq!(zero_copy.len(), 1, "Invalid number of arguments"); - let args: ReceiveArgs = serde_json::from_value(args)?; match args.transport.as_str() { "udp" => receive_udp(state, args, zero_copy).await, @@ -191,10 +189,10 @@ struct SendArgs { async fn op_datagram_send( state: Rc<RefCell<OpState>>, args: Value, - zero_copy: BufVec, + zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { - assert_eq!(zero_copy.len(), 1, "Invalid number of arguments"); - let zero_copy = zero_copy[0].clone(); + let zero_copy = zero_copy.ok_or_else(null_opbuf)?; + let zero_copy = zero_copy.clone(); match serde_json::from_value(args)? { SendArgs { @@ -260,7 +258,7 @@ struct ConnectArgs { async fn op_connect( state: Rc<RefCell<OpState>>, args: Value, - _zero_copy: BufVec, + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { match serde_json::from_value(args)? { ConnectArgs { @@ -424,7 +422,7 @@ fn listen_udp( fn op_listen( state: &mut OpState, args: Value, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let permissions = state.borrow::<Permissions>(); match serde_json::from_value(args)? { @@ -550,7 +548,7 @@ pub struct NameServer { async fn op_dns_resolve( state: Rc<RefCell<OpState>>, args: ResolveAddrArgs, - _zero_copy: BufVec, + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let ResolveAddrArgs { query, diff --git a/runtime/ops/net_unix.rs b/runtime/ops/net_unix.rs index 6d9afb70f..0cc001ab4 100644 --- a/runtime/ops/net_unix.rs +++ b/runtime/ops/net_unix.rs @@ -5,16 +5,17 @@ use crate::ops::net::AcceptArgs; use crate::ops::net::ReceiveArgs; use deno_core::error::bad_resource; use deno_core::error::custom_error; +use deno_core::error::null_opbuf; use deno_core::error::AnyError; use deno_core::serde_json::json; use deno_core::serde_json::Value; use deno_core::AsyncRefCell; -use deno_core::BufVec; use deno_core::CancelHandle; use deno_core::CancelTryFuture; use deno_core::OpState; use deno_core::RcRef; use deno_core::Resource; +use deno_core::ZeroCopyBuf; use serde::Deserialize; use std::borrow::Cow; use std::cell::RefCell; @@ -63,7 +64,7 @@ pub struct UnixListenArgs { pub(crate) async fn accept_unix( state: Rc<RefCell<OpState>>, args: AcceptArgs, - _bufs: BufVec, + _bufs: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let rid = args.rid; @@ -100,12 +101,11 @@ pub(crate) async fn accept_unix( pub(crate) async fn receive_unix_packet( state: Rc<RefCell<OpState>>, args: ReceiveArgs, - bufs: BufVec, + buf: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { - assert_eq!(bufs.len(), 1, "Invalid number of arguments"); + let mut buf = buf.ok_or_else(null_opbuf)?; let rid = args.rid; - let mut buf = bufs.into_iter().next().unwrap(); let resource = state .borrow() diff --git a/runtime/ops/os.rs b/runtime/ops/os.rs index dec7f9bd6..500c023aa 100644 --- a/runtime/ops/os.rs +++ b/runtime/ops/os.rs @@ -28,7 +28,7 @@ pub fn init(rt: &mut deno_core::JsRuntime) { fn op_exec_path( state: &mut OpState, _args: Value, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let current_exe = env::current_exe().unwrap(); state @@ -51,7 +51,7 @@ pub struct SetEnv { fn op_set_env( state: &mut OpState, args: SetEnv, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { state.borrow::<Permissions>().env.check()?; let invalid_key = @@ -67,7 +67,7 @@ fn op_set_env( fn op_env( state: &mut OpState, _args: Value, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { state.borrow::<Permissions>().env.check()?; let v = env::vars().collect::<HashMap<String, String>>(); @@ -82,7 +82,7 @@ pub struct GetEnv { fn op_get_env( state: &mut OpState, args: GetEnv, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { state.borrow::<Permissions>().env.check()?; if args.key.is_empty() || args.key.contains(&['=', '\0'] as &[char]) { @@ -103,7 +103,7 @@ pub struct DeleteEnv { fn op_delete_env( state: &mut OpState, args: DeleteEnv, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { state.borrow::<Permissions>().env.check()?; if args.key.is_empty() || args.key.contains(&['=', '\0'] as &[char]) { @@ -121,7 +121,7 @@ pub struct Exit { fn op_exit( _state: &mut OpState, args: Exit, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { std::process::exit(args.code) } @@ -129,7 +129,7 @@ fn op_exit( fn op_loadavg( state: &mut OpState, _args: Value, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { super::check_unstable(state, "Deno.loadavg"); state.borrow::<Permissions>().env.check()?; @@ -142,7 +142,7 @@ fn op_loadavg( fn op_hostname( state: &mut OpState, _args: Value, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { super::check_unstable(state, "Deno.hostname"); state.borrow::<Permissions>().env.check()?; @@ -153,7 +153,7 @@ fn op_hostname( fn op_os_release( state: &mut OpState, _args: Value, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { super::check_unstable(state, "Deno.osRelease"); state.borrow::<Permissions>().env.check()?; @@ -164,7 +164,7 @@ fn op_os_release( fn op_system_memory_info( state: &mut OpState, _args: Value, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { super::check_unstable(state, "Deno.systemMemoryInfo"); state.borrow::<Permissions>().env.check()?; @@ -185,7 +185,7 @@ fn op_system_memory_info( fn op_system_cpu_info( state: &mut OpState, _args: Value, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { super::check_unstable(state, "Deno.systemCpuInfo"); state.borrow::<Permissions>().env.check()?; diff --git a/runtime/ops/permissions.rs b/runtime/ops/permissions.rs index 264df5051..61eed6bf4 100644 --- a/runtime/ops/permissions.rs +++ b/runtime/ops/permissions.rs @@ -28,7 +28,7 @@ pub struct PermissionArgs { pub fn op_query_permission( state: &mut OpState, args: PermissionArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let permissions = state.borrow::<Permissions>(); let path = args.path.as_deref(); @@ -59,7 +59,7 @@ pub fn op_query_permission( pub fn op_revoke_permission( state: &mut OpState, args: PermissionArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let permissions = state.borrow_mut::<Permissions>(); let path = args.path.as_deref(); @@ -90,7 +90,7 @@ pub fn op_revoke_permission( pub fn op_request_permission( state: &mut OpState, args: PermissionArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let permissions = state.borrow_mut::<Permissions>(); let path = args.path.as_deref(); diff --git a/runtime/ops/plugin.rs b/runtime/ops/plugin.rs index 7fc59d082..709c5730d 100644 --- a/runtime/ops/plugin.rs +++ b/runtime/ops/plugin.rs @@ -6,7 +6,6 @@ use deno_core::futures::prelude::*; use deno_core::plugin_api; use deno_core::serde_json::json; use deno_core::serde_json::Value; -use deno_core::BufVec; use deno_core::JsRuntime; use deno_core::Op; use deno_core::OpAsyncFuture; @@ -38,7 +37,7 @@ pub struct OpenPluginArgs { pub fn op_open_plugin( state: &mut OpState, args: OpenPluginArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let filename = PathBuf::from(&args.filename); @@ -111,16 +110,9 @@ impl<'a> plugin_api::Interface for PluginInterface<'a> { ) -> OpId { let plugin_lib = self.plugin_lib.clone(); let plugin_op_fn: Box<OpFn> = Box::new(move |state_rc, _payload, buf| { - // For sig compat map Option<ZeroCopyBuf> to BufVec - let mut bufs: BufVec = match buf { - Some(b) => vec![b], - None => vec![], - } - .into(); - let mut state = state_rc.borrow_mut(); let mut interface = PluginInterface::new(&mut state, &plugin_lib); - let op = dispatch_op_fn(&mut interface, &mut bufs); + let op = dispatch_op_fn(&mut interface, buf); match op { sync_op @ Op::Sync(..) => sync_op, Op::Async(fut) => Op::Async(PluginOpAsyncFuture::new(&plugin_lib, fut)), diff --git a/runtime/ops/process.rs b/runtime/ops/process.rs index 437cfac76..d6b4dcc1f 100644 --- a/runtime/ops/process.rs +++ b/runtime/ops/process.rs @@ -12,7 +12,6 @@ use deno_core::serde_json::json; use deno_core::serde_json::Value; use deno_core::AsyncMutFuture; use deno_core::AsyncRefCell; -use deno_core::BufVec; use deno_core::OpState; use deno_core::RcRef; use deno_core::Resource; @@ -85,7 +84,7 @@ impl ChildResource { fn op_run( state: &mut OpState, run_args: RunArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { state.borrow::<Permissions>().run.check()?; @@ -185,7 +184,7 @@ pub struct RunStatusArgs { async fn op_run_status( state: Rc<RefCell<OpState>>, args: RunStatusArgs, - _zero_copy: BufVec, + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let rid = args.rid; @@ -280,7 +279,7 @@ struct KillArgs { fn op_kill( state: &mut OpState, args: KillArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { super::check_unstable(state, "Deno.kill"); state.borrow::<Permissions>().run.check()?; diff --git a/runtime/ops/runtime.rs b/runtime/ops/runtime.rs index 420931b0c..9d29671c9 100644 --- a/runtime/ops/runtime.rs +++ b/runtime/ops/runtime.rs @@ -24,7 +24,7 @@ pub fn init(rt: &mut deno_core::JsRuntime, main_module: ModuleSpecifier) { fn op_main_module( state: &mut OpState, _args: Value, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let main = state.borrow::<ModuleSpecifier>().to_string(); let main_url = deno_core::resolve_url_or_path(&main)?; @@ -42,7 +42,7 @@ fn op_main_module( fn op_metrics( state: &mut OpState, _args: Value, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let m = state.borrow::<RuntimeMetrics>(); let combined = m.combined_metrics(); diff --git a/runtime/ops/signal.rs b/runtime/ops/signal.rs index 0113a6189..ef29ddec7 100644 --- a/runtime/ops/signal.rs +++ b/runtime/ops/signal.rs @@ -1,7 +1,6 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. use deno_core::error::AnyError; use deno_core::serde_json::Value; -use deno_core::BufVec; use deno_core::OpState; use deno_core::ZeroCopyBuf; use std::cell::RefCell; @@ -70,7 +69,7 @@ pub struct SignalArgs { fn op_signal_bind( state: &mut OpState, args: BindSignalArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { super::check_unstable(state, "Deno.signal"); let resource = SignalStreamResource { @@ -89,7 +88,7 @@ fn op_signal_bind( async fn op_signal_poll( state: Rc<RefCell<OpState>>, args: SignalArgs, - _zero_copy: BufVec, + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { super::check_unstable2(&state, "Deno.signal"); let rid = args.rid; @@ -112,7 +111,7 @@ async fn op_signal_poll( pub fn op_signal_unbind( state: &mut OpState, args: SignalArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { super::check_unstable(state, "Deno.signal"); let rid = args.rid; @@ -127,7 +126,7 @@ pub fn op_signal_unbind( pub fn op_signal_bind( _state: &mut OpState, _args: Value, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { unimplemented!(); } @@ -136,7 +135,7 @@ pub fn op_signal_bind( fn op_signal_unbind( _state: &mut OpState, _args: Value, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { unimplemented!(); } @@ -145,7 +144,7 @@ fn op_signal_unbind( async fn op_signal_poll( _state: Rc<RefCell<OpState>>, _args: Value, - _zero_copy: BufVec, + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { unimplemented!(); } diff --git a/runtime/ops/timers.rs b/runtime/ops/timers.rs index 4395b4885..b283125de 100644 --- a/runtime/ops/timers.rs +++ b/runtime/ops/timers.rs @@ -9,7 +9,7 @@ //! calls it) for an entire Isolate. This is what is implemented here. use crate::permissions::Permissions; -use deno_core::error::type_error; +use deno_core::error::null_opbuf; use deno_core::error::AnyError; use deno_core::futures; use deno_core::futures::channel::oneshot; @@ -17,7 +17,6 @@ use deno_core::futures::FutureExt; use deno_core::futures::TryFutureExt; use deno_core::serde_json::json; use deno_core::serde_json::Value; -use deno_core::BufVec; use deno_core::OpState; use deno_core::ZeroCopyBuf; use serde::Deserialize; @@ -85,7 +84,7 @@ pub fn init(rt: &mut deno_core::JsRuntime) { fn op_global_timer_stop( state: &mut OpState, _args: Value, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let global_timer = state.borrow_mut::<GlobalTimer>(); global_timer.cancel(); @@ -108,7 +107,7 @@ pub struct GlobalTimerArgs { fn op_global_timer_start( state: &mut OpState, args: GlobalTimerArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let val = args.timeout; @@ -121,7 +120,7 @@ fn op_global_timer_start( async fn op_global_timer( state: Rc<RefCell<OpState>>, _args: Value, - _zero_copy: BufVec, + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let maybe_timer_fut = { let mut s = state.borrow_mut(); @@ -141,13 +140,9 @@ async fn op_global_timer( fn op_now( op_state: &mut OpState, _argument: u32, - zero_copy: &mut [ZeroCopyBuf], + zero_copy: Option<ZeroCopyBuf>, ) -> Result<u32, AnyError> { - match zero_copy.len() { - 0 => return Err(type_error("no buffer specified")), - 1 => {} - _ => return Err(type_error("Invalid number of arguments")), - } + let mut zero_copy = zero_copy.ok_or_else(null_opbuf)?; let start_time = op_state.borrow::<StartTime>(); let seconds = start_time.elapsed().as_secs(); @@ -163,7 +158,7 @@ fn op_now( let result = (seconds * 1_000) as f64 + (subsec_nanos / 1_000_000.0); - (&mut zero_copy[0]).copy_from_slice(&result.to_be_bytes()); + (&mut zero_copy).copy_from_slice(&result.to_be_bytes()); Ok(0) } @@ -177,7 +172,7 @@ pub struct SleepArgs { fn op_sleep_sync( state: &mut OpState, args: SleepArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { super::check_unstable(state, "Deno.sleepSync"); sleep(Duration::from_millis(args.millis)); diff --git a/runtime/ops/tls.rs b/runtime/ops/tls.rs index 52c9d322a..00f000a97 100644 --- a/runtime/ops/tls.rs +++ b/runtime/ops/tls.rs @@ -14,7 +14,6 @@ use deno_core::error::AnyError; use deno_core::serde_json::json; use deno_core::serde_json::Value; use deno_core::AsyncRefCell; -use deno_core::BufVec; use deno_core::CancelHandle; use deno_core::CancelTryFuture; use deno_core::OpState; @@ -97,7 +96,7 @@ struct StartTlsArgs { async fn op_start_tls( state: Rc<RefCell<OpState>>, args: StartTlsArgs, - _zero_copy: BufVec, + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let rid = args.rid; @@ -167,7 +166,7 @@ async fn op_start_tls( async fn op_connect_tls( state: Rc<RefCell<OpState>>, args: ConnectTlsArgs, - _zero_copy: BufVec, + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { { let s = state.borrow(); @@ -307,7 +306,7 @@ pub struct ListenTlsArgs { fn op_listen_tls( state: &mut OpState, args: ListenTlsArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { assert_eq!(args.transport, "tcp"); @@ -357,7 +356,7 @@ pub struct AcceptTlsArgs { async fn op_accept_tls( state: Rc<RefCell<OpState>>, args: AcceptTlsArgs, - _zero_copy: BufVec, + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let rid = args.rid; diff --git a/runtime/ops/tty.rs b/runtime/ops/tty.rs index 33d04620f..6253cc837 100644 --- a/runtime/ops/tty.rs +++ b/runtime/ops/tty.rs @@ -67,7 +67,7 @@ pub struct SetRawArgs { fn op_set_raw( state: &mut OpState, args: SetRawArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { super::check_unstable(state, "Deno.setRaw"); @@ -222,7 +222,7 @@ pub struct IsattyArgs { fn op_isatty( state: &mut OpState, args: IsattyArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let rid = args.rid; @@ -263,7 +263,7 @@ struct ConsoleSize { fn op_console_size( state: &mut OpState, args: ConsoleSizeArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<ConsoleSize, AnyError> { super::check_unstable(state, "Deno.consoleSize"); diff --git a/runtime/ops/web_worker.rs b/runtime/ops/web_worker.rs index 17561882e..7918b97ea 100644 --- a/runtime/ops/web_worker.rs +++ b/runtime/ops/web_worker.rs @@ -2,6 +2,7 @@ use crate::web_worker::WebWorkerHandle; use crate::web_worker::WorkerEvent; +use deno_core::error::null_opbuf; use deno_core::futures::channel::mpsc; use deno_core::serde_json::{json, Value}; @@ -15,9 +16,9 @@ pub fn init( super::reg_json_sync( rt, "op_worker_post_message", - move |_state, _args: Value, bufs| { - assert_eq!(bufs.len(), 1, "Invalid number of arguments"); - let msg_buf: Box<[u8]> = (*bufs[0]).into(); + move |_state, _args: Value, buf| { + let buf = buf.ok_or_else(null_opbuf)?; + let msg_buf: Box<[u8]> = (*buf).into(); sender_ .clone() .try_send(WorkerEvent::Message(msg_buf)) diff --git a/runtime/ops/worker_host.rs b/runtime/ops/worker_host.rs index 424e7a70c..6891241dd 100644 --- a/runtime/ops/worker_host.rs +++ b/runtime/ops/worker_host.rs @@ -14,6 +14,7 @@ use crate::web_worker::WebWorkerHandle; use crate::web_worker::WorkerEvent; use deno_core::error::custom_error; use deno_core::error::generic_error; +use deno_core::error::null_opbuf; use deno_core::error::AnyError; use deno_core::error::JsError; use deno_core::futures::channel::mpsc; @@ -23,7 +24,6 @@ use deno_core::serde::Deserialize; use deno_core::serde::Deserializer; use deno_core::serde_json::json; use deno_core::serde_json::Value; -use deno_core::BufVec; use deno_core::ModuleSpecifier; use deno_core::OpState; use deno_core::ZeroCopyBuf; @@ -369,7 +369,7 @@ pub struct CreateWorkerArgs { fn op_create_worker( state: &mut OpState, args: CreateWorkerArgs, - _data: &mut [ZeroCopyBuf], + _data: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let specifier = args.specifier.clone(); let maybe_source_code = if args.has_source_code { @@ -457,7 +457,7 @@ pub struct WorkerArgs { fn op_host_terminate_worker( state: &mut OpState, args: WorkerArgs, - _data: &mut [ZeroCopyBuf], + _data: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let id = args.id as u32; let worker_thread = state @@ -533,7 +533,7 @@ fn try_remove_and_close(state: Rc<RefCell<OpState>>, id: u32) { async fn op_host_get_message( state: Rc<RefCell<OpState>>, args: WorkerArgs, - _zero_copy: BufVec, + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let id = args.id as u32; @@ -567,11 +567,11 @@ async fn op_host_get_message( fn op_host_post_message( state: &mut OpState, args: WorkerArgs, - data: &mut [ZeroCopyBuf], + data: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { - assert_eq!(data.len(), 1, "Invalid number of arguments"); + let data = data.ok_or_else(null_opbuf)?; let id = args.id as u32; - let msg = Vec::from(&*data[0]).into_boxed_slice(); + let msg = Vec::from(&*data).into_boxed_slice(); debug!("post message to worker {}", id); let worker_thread = state |
