diff options
Diffstat (limited to 'runtime/ops')
-rw-r--r-- | runtime/ops/fs.rs | 2 | ||||
-rw-r--r-- | runtime/ops/io.rs | 35 | ||||
-rw-r--r-- | runtime/ops/os.rs | 40 | ||||
-rw-r--r-- | runtime/ops/runtime.rs | 2 | ||||
-rw-r--r-- | runtime/ops/signal.rs | 6 |
5 files changed, 32 insertions, 53 deletions
diff --git a/runtime/ops/fs.rs b/runtime/ops/fs.rs index 819f3f3ac..3ae3bf0f0 100644 --- a/runtime/ops/fs.rs +++ b/runtime/ops/fs.rs @@ -1769,7 +1769,7 @@ async fn op_utime_async( .unwrap() } -fn op_cwd(state: &mut OpState, _args: (), _: ()) -> Result<String, AnyError> { +fn op_cwd(state: &mut OpState, _: (), _: ()) -> Result<String, AnyError> { let path = current_dir()?; state .borrow_mut::<Permissions>() diff --git a/runtime/ops/io.rs b/runtime/ops/io.rs index 82fe3605c..0687fc397 100644 --- a/runtime/ops/io.rs +++ b/runtime/ops/io.rs @@ -1,7 +1,6 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. use deno_core::error::not_supported; -use deno_core::error::null_opbuf; use deno_core::error::resource_unavailable; use deno_core::error::AnyError; use deno_core::op_async; @@ -387,9 +386,8 @@ impl Resource for StdFileResource { fn op_read_sync( state: &mut OpState, rid: ResourceId, - buf: Option<ZeroCopyBuf>, + mut buf: 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 buf) @@ -402,22 +400,21 @@ fn op_read_sync( async fn op_read_async( state: Rc<RefCell<OpState>>, rid: ResourceId, - buf: Option<ZeroCopyBuf>, + mut buf: ZeroCopyBuf, ) -> Result<u32, AnyError> { - let buf = &mut buf.ok_or_else(null_opbuf)?; let resource = state.borrow().resource_table.get_any(rid)?; let nread = if let Some(s) = resource.downcast_rc::<ChildStdoutResource>() { - s.read(buf).await? + s.read(&mut buf).await? } else if let Some(s) = resource.downcast_rc::<ChildStderrResource>() { - s.read(buf).await? + s.read(&mut buf).await? } else if let Some(s) = resource.downcast_rc::<TcpStreamResource>() { - s.read(buf).await? + s.read(&mut buf).await? } else if let Some(s) = resource.downcast_rc::<TlsStreamResource>() { - s.read(buf).await? + s.read(&mut buf).await? } else if let Some(s) = resource.downcast_rc::<UnixStreamResource>() { - s.read(buf).await? + s.read(&mut buf).await? } else if let Some(s) = resource.downcast_rc::<StdFileResource>() { - s.read(buf).await? + s.read(&mut buf).await? } else { return Err(not_supported()); }; @@ -427,9 +424,8 @@ async fn op_read_async( fn op_write_sync( state: &mut OpState, rid: ResourceId, - buf: Option<ZeroCopyBuf>, + buf: 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(&buf) @@ -442,20 +438,19 @@ fn op_write_sync( async fn op_write_async( state: Rc<RefCell<OpState>>, rid: ResourceId, - buf: Option<ZeroCopyBuf>, + buf: ZeroCopyBuf, ) -> Result<u32, AnyError> { - let buf = &buf.ok_or_else(null_opbuf)?; let resource = state.borrow().resource_table.get_any(rid)?; let nwritten = if let Some(s) = resource.downcast_rc::<ChildStdinResource>() { - s.write(buf).await? + s.write(&buf).await? } else if let Some(s) = resource.downcast_rc::<TcpStreamResource>() { - s.write(buf).await? + s.write(&buf).await? } else if let Some(s) = resource.downcast_rc::<TlsStreamResource>() { - s.write(buf).await? + s.write(&buf).await? } else if let Some(s) = resource.downcast_rc::<UnixStreamResource>() { - s.write(buf).await? + s.write(&buf).await? } else if let Some(s) = resource.downcast_rc::<StdFileResource>() { - s.write(buf).await? + s.write(&buf).await? } else { return Err(not_supported()); }; diff --git a/runtime/ops/os.rs b/runtime/ops/os.rs index c9567a7d7..0a6269ac5 100644 --- a/runtime/ops/os.rs +++ b/runtime/ops/os.rs @@ -7,7 +7,6 @@ use deno_core::op_sync; use deno_core::url::Url; use deno_core::Extension; use deno_core::OpState; -use serde::Deserialize; use serde::Serialize; use std::collections::HashMap; use std::env; @@ -29,11 +28,7 @@ pub fn init() -> Extension { .build() } -fn op_exec_path( - state: &mut OpState, - _args: (), - _: (), -) -> Result<String, AnyError> { +fn op_exec_path(state: &mut OpState, _: (), _: ()) -> Result<String, AnyError> { let current_exe = env::current_exe().unwrap(); state .borrow_mut::<Permissions>() @@ -47,31 +42,24 @@ fn op_exec_path( into_string(path.into_os_string()) } -#[derive(Deserialize)] -pub struct SetEnv { - key: String, - value: String, -} - fn op_set_env( state: &mut OpState, - args: SetEnv, - _: (), + key: String, + value: String, ) -> Result<(), AnyError> { - state.borrow_mut::<Permissions>().env.check(&args.key)?; - let invalid_key = - args.key.is_empty() || args.key.contains(&['=', '\0'] as &[char]); - let invalid_value = args.value.contains('\0'); + state.borrow_mut::<Permissions>().env.check(&key)?; + let invalid_key = key.is_empty() || key.contains(&['=', '\0'] as &[char]); + let invalid_value = value.contains('\0'); if invalid_key || invalid_value { return Err(type_error("Key or value contains invalid characters.")); } - env::set_var(args.key, args.value); + env::set_var(key, value); Ok(()) } fn op_env( state: &mut OpState, - _args: (), + _: (), _: (), ) -> Result<HashMap<String, String>, AnyError> { state.borrow_mut::<Permissions>().env.check_all()?; @@ -113,7 +101,7 @@ fn op_exit(_state: &mut OpState, code: i32, _: ()) -> Result<(), AnyError> { fn op_loadavg( state: &mut OpState, - _args: (), + _: (), _: (), ) -> Result<(f64, f64, f64), AnyError> { super::check_unstable(state, "Deno.loadavg"); @@ -124,11 +112,7 @@ fn op_loadavg( } } -fn op_hostname( - state: &mut OpState, - _args: (), - _: (), -) -> Result<String, AnyError> { +fn op_hostname(state: &mut OpState, _: (), _: ()) -> Result<String, AnyError> { super::check_unstable(state, "Deno.hostname"); state.borrow_mut::<Permissions>().env.check_all()?; let hostname = sys_info::hostname().unwrap_or_else(|_| "".to_string()); @@ -137,7 +121,7 @@ fn op_hostname( fn op_os_release( state: &mut OpState, - _args: (), + _: (), _: (), ) -> Result<String, AnyError> { super::check_unstable(state, "Deno.osRelease"); @@ -161,7 +145,7 @@ struct MemInfo { fn op_system_memory_info( state: &mut OpState, - _args: (), + _: (), _: (), ) -> Result<Option<MemInfo>, AnyError> { super::check_unstable(state, "Deno.systemMemoryInfo"); diff --git a/runtime/ops/runtime.rs b/runtime/ops/runtime.rs index 981ec7b91..66dd0de4b 100644 --- a/runtime/ops/runtime.rs +++ b/runtime/ops/runtime.rs @@ -20,7 +20,7 @@ pub fn init(main_module: ModuleSpecifier) -> Extension { fn op_main_module( state: &mut OpState, - _args: (), + _: (), _: (), ) -> Result<String, AnyError> { let main = state.borrow::<ModuleSpecifier>().to_string(); diff --git a/runtime/ops/signal.rs b/runtime/ops/signal.rs index eef72f511..aa419c6c8 100644 --- a/runtime/ops/signal.rs +++ b/runtime/ops/signal.rs @@ -224,7 +224,7 @@ pub fn op_signal_unbind( #[cfg(not(unix))] pub fn op_signal_bind( _state: &mut OpState, - _args: (), + _: (), _: (), ) -> Result<(), AnyError> { Err(generic_error("not implemented")) @@ -233,7 +233,7 @@ pub fn op_signal_bind( #[cfg(not(unix))] fn op_signal_unbind( _state: &mut OpState, - _args: (), + _: (), _: (), ) -> Result<(), AnyError> { Err(generic_error("not implemented")) @@ -242,7 +242,7 @@ fn op_signal_unbind( #[cfg(not(unix))] async fn op_signal_poll( _state: Rc<RefCell<OpState>>, - _args: (), + _: (), _: (), ) -> Result<(), AnyError> { Err(generic_error("not implemented")) |