diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2020-02-25 09:14:27 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-25 09:14:27 -0500 |
commit | 91b606aaae23bcb790b55adc5fe70a182a37d564 (patch) | |
tree | 16b56a21ffcb3991569eda984fbd14073bdbd3ae /cli/ops | |
parent | 805992b14a65a6dbfb857dea6d9b657477de043d (diff) |
Clean up how we use opIds (#4118)
Diffstat (limited to 'cli/ops')
-rw-r--r-- | cli/ops/compiler.rs | 40 | ||||
-rw-r--r-- | cli/ops/errors.rs | 14 | ||||
-rw-r--r-- | cli/ops/fetch.rs | 3 | ||||
-rw-r--r-- | cli/ops/files.rs | 7 | ||||
-rw-r--r-- | cli/ops/fs.rs | 43 | ||||
-rw-r--r-- | cli/ops/fs_events.rs | 11 | ||||
-rw-r--r-- | cli/ops/io.rs | 77 | ||||
-rw-r--r-- | cli/ops/net.rs | 41 | ||||
-rw-r--r-- | cli/ops/os.rs | 24 | ||||
-rw-r--r-- | cli/ops/permissions.rs | 13 | ||||
-rw-r--r-- | cli/ops/plugins.rs | 2 | ||||
-rw-r--r-- | cli/ops/process.rs | 10 | ||||
-rw-r--r-- | cli/ops/random.rs | 5 | ||||
-rw-r--r-- | cli/ops/repl.rs | 11 | ||||
-rw-r--r-- | cli/ops/resources.rs | 3 | ||||
-rw-r--r-- | cli/ops/runtime.rs | 5 | ||||
-rw-r--r-- | cli/ops/runtime_compiler.rs | 5 | ||||
-rw-r--r-- | cli/ops/signal.rs | 16 | ||||
-rw-r--r-- | cli/ops/timers.rs | 12 | ||||
-rw-r--r-- | cli/ops/tls.rs | 32 | ||||
-rw-r--r-- | cli/ops/web_worker.rs | 4 | ||||
-rw-r--r-- | cli/ops/worker_host.rs | 18 |
22 files changed, 133 insertions, 263 deletions
diff --git a/cli/ops/compiler.rs b/cli/ops/compiler.rs index a559bb539..015c77c4e 100644 --- a/cli/ops/compiler.rs +++ b/cli/ops/compiler.rs @@ -5,25 +5,22 @@ use super::dispatch_json::Value; use crate::futures::future::try_join_all; use crate::msg; use crate::op_error::OpError; -use crate::ops::json_op; use crate::state::State; use deno_core::Loader; use deno_core::*; use futures::future::FutureExt; pub fn init(i: &mut Isolate, s: &State) { - i.register_op("cache", s.core_op(json_op(s.stateful_op(op_cache)))); + i.register_op("op_cache", s.stateful_json_op(op_cache)); + i.register_op("op_resolve_modules", s.stateful_json_op(op_resolve_modules)); i.register_op( - "resolve_modules", - s.core_op(json_op(s.stateful_op(op_resolve_modules))), + "op_fetch_source_files", + s.stateful_json_op(op_fetch_source_files), ); + let custom_assets = std::collections::HashMap::new(); // TODO(ry) use None. i.register_op( - "fetch_source_files", - s.core_op(json_op(s.stateful_op(op_fetch_source_files))), - ); - i.register_op( - "fetch_asset", - s.core_op(json_op(s.stateful_op(op_fetch_asset))), + "op_fetch_asset", + deno_typescript::op_fetch_asset(custom_assets), ); } @@ -169,26 +166,3 @@ fn op_fetch_source_files( Ok(JsonOp::Async(future)) } - -#[derive(Deserialize, Debug)] -struct FetchRemoteAssetArgs { - name: String, -} - -fn op_fetch_asset( - _state: &State, - args: Value, - _data: Option<ZeroCopyBuf>, -) -> Result<JsonOp, OpError> { - let args: FetchRemoteAssetArgs = serde_json::from_value(args)?; - debug!("args.name: {}", args.name); - - let source_code = - if let Some(source_code) = deno_typescript::get_asset(&args.name) { - source_code.to_string() - } else { - panic!("Asset not found: \"{}\"", args.name) - }; - - Ok(JsonOp::Sync(json!({ "sourceCode": source_code }))) -} diff --git a/cli/ops/errors.rs b/cli/ops/errors.rs index b5cc75f7a..c588759cf 100644 --- a/cli/ops/errors.rs +++ b/cli/ops/errors.rs @@ -3,7 +3,6 @@ use super::dispatch_json::{Deserialize, JsonOp, Value}; use crate::diagnostics::Diagnostic; use crate::fmt_errors::JSError; use crate::op_error::OpError; -use crate::ops::json_op; use crate::source_maps::get_orig_position; use crate::source_maps::CachedMaps; use crate::state::State; @@ -12,16 +11,13 @@ use std::collections::HashMap; pub fn init(i: &mut Isolate, s: &State) { i.register_op( - "apply_source_map", - s.core_op(json_op(s.stateful_op(op_apply_source_map))), + "op_apply_source_map", + s.stateful_json_op(op_apply_source_map), ); + i.register_op("op_format_error", s.stateful_json_op(op_format_error)); i.register_op( - "format_error", - s.core_op(json_op(s.stateful_op(op_format_error))), - ); - i.register_op( - "format_diagnostic", - s.core_op(json_op(s.stateful_op(op_format_diagnostic))), + "op_format_diagnostic", + s.stateful_json_op(op_format_diagnostic), ); } diff --git a/cli/ops/fetch.rs b/cli/ops/fetch.rs index efcadc6a0..9f36ad5fd 100644 --- a/cli/ops/fetch.rs +++ b/cli/ops/fetch.rs @@ -3,7 +3,6 @@ use super::dispatch_json::{Deserialize, JsonOp, Value}; use super::io::StreamResource; use crate::http_util::{create_http_client, HttpBody}; use crate::op_error::OpError; -use crate::ops::json_op; use crate::state::State; use deno_core::*; use futures::future::FutureExt; @@ -14,7 +13,7 @@ use std; use std::convert::From; pub fn init(i: &mut Isolate, s: &State) { - i.register_op("fetch", s.core_op(json_op(s.stateful_op(op_fetch)))); + i.register_op("op_fetch", s.stateful_json_op(op_fetch)); } #[derive(Deserialize)] diff --git a/cli/ops/files.rs b/cli/ops/files.rs index 2fc41bc34..4bf8b1688 100644 --- a/cli/ops/files.rs +++ b/cli/ops/files.rs @@ -3,7 +3,6 @@ use super::dispatch_json::{Deserialize, JsonOp, Value}; use super::io::StreamResource; use crate::fs as deno_fs; use crate::op_error::OpError; -use crate::ops::json_op; use crate::state::State; use deno_core::*; use futures::future::FutureExt; @@ -14,9 +13,9 @@ use std::path::Path; use tokio; pub fn init(i: &mut Isolate, s: &State) { - i.register_op("open", s.core_op(json_op(s.stateful_op(op_open)))); - i.register_op("close", s.core_op(json_op(s.stateful_op(op_close)))); - i.register_op("seek", s.core_op(json_op(s.stateful_op(op_seek)))); + i.register_op("op_open", s.stateful_json_op(op_open)); + i.register_op("op_close", s.stateful_json_op(op_close)); + i.register_op("op_seek", s.stateful_json_op(op_seek)); } #[derive(Deserialize)] diff --git a/cli/ops/fs.rs b/cli/ops/fs.rs index 014ba04a3..13c2418cb 100644 --- a/cli/ops/fs.rs +++ b/cli/ops/fs.rs @@ -4,7 +4,6 @@ use super::dispatch_json::{blocking_json, Deserialize, JsonOp, Value}; use crate::fs as deno_fs; use crate::op_error::OpError; use crate::ops::dispatch_json::JsonResult; -use crate::ops::json_op; use crate::state::State; use deno_core::*; use remove_dir_all::remove_dir_all; @@ -19,30 +18,24 @@ use std::os::unix::fs::MetadataExt; use std::os::unix::fs::PermissionsExt; pub fn init(i: &mut Isolate, s: &State) { - i.register_op("chdir", s.core_op(json_op(s.stateful_op(op_chdir)))); - i.register_op("mkdir", s.core_op(json_op(s.stateful_op(op_mkdir)))); - i.register_op("chmod", s.core_op(json_op(s.stateful_op(op_chmod)))); - i.register_op("chown", s.core_op(json_op(s.stateful_op(op_chown)))); - i.register_op("remove", s.core_op(json_op(s.stateful_op(op_remove)))); - i.register_op("copy_file", s.core_op(json_op(s.stateful_op(op_copy_file)))); - i.register_op("stat", s.core_op(json_op(s.stateful_op(op_stat)))); - i.register_op("realpath", s.core_op(json_op(s.stateful_op(op_realpath)))); - i.register_op("read_dir", s.core_op(json_op(s.stateful_op(op_read_dir)))); - i.register_op("rename", s.core_op(json_op(s.stateful_op(op_rename)))); - i.register_op("link", s.core_op(json_op(s.stateful_op(op_link)))); - i.register_op("symlink", s.core_op(json_op(s.stateful_op(op_symlink)))); - i.register_op("read_link", s.core_op(json_op(s.stateful_op(op_read_link)))); - i.register_op("truncate", s.core_op(json_op(s.stateful_op(op_truncate)))); - i.register_op( - "make_temp_dir", - s.core_op(json_op(s.stateful_op(op_make_temp_dir))), - ); - i.register_op( - "make_temp_file", - s.core_op(json_op(s.stateful_op(op_make_temp_file))), - ); - i.register_op("cwd", s.core_op(json_op(s.stateful_op(op_cwd)))); - i.register_op("utime", s.core_op(json_op(s.stateful_op(op_utime)))); + i.register_op("op_chdir", s.stateful_json_op(op_chdir)); + i.register_op("op_mkdir", s.stateful_json_op(op_mkdir)); + i.register_op("op_chmod", s.stateful_json_op(op_chmod)); + i.register_op("op_chown", s.stateful_json_op(op_chown)); + i.register_op("op_remove", s.stateful_json_op(op_remove)); + i.register_op("op_copy_file", s.stateful_json_op(op_copy_file)); + i.register_op("op_stat", s.stateful_json_op(op_stat)); + i.register_op("op_realpath", s.stateful_json_op(op_realpath)); + i.register_op("op_read_dir", s.stateful_json_op(op_read_dir)); + i.register_op("op_rename", s.stateful_json_op(op_rename)); + i.register_op("op_link", s.stateful_json_op(op_link)); + i.register_op("op_symlink", s.stateful_json_op(op_symlink)); + i.register_op("op_read_link", s.stateful_json_op(op_read_link)); + i.register_op("op_truncate", s.stateful_json_op(op_truncate)); + i.register_op("op_make_temp_dir", s.stateful_json_op(op_make_temp_dir)); + i.register_op("op_make_temp_file", s.stateful_json_op(op_make_temp_file)); + i.register_op("op_cwd", s.stateful_json_op(op_cwd)); + i.register_op("op_utime", s.stateful_json_op(op_utime)); } #[derive(Deserialize)] diff --git a/cli/ops/fs_events.rs b/cli/ops/fs_events.rs index 3b4c9b9e5..21e402344 100644 --- a/cli/ops/fs_events.rs +++ b/cli/ops/fs_events.rs @@ -1,7 +1,6 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. use super::dispatch_json::{Deserialize, JsonOp, Value}; use crate::op_error::OpError; -use crate::ops::json_op; use crate::state::State; use deno_core::*; use futures::future::poll_fn; @@ -18,14 +17,8 @@ use std::path::PathBuf; use tokio::sync::mpsc; pub fn init(i: &mut Isolate, s: &State) { - i.register_op( - "fs_events_open", - s.core_op(json_op(s.stateful_op(op_fs_events_open))), - ); - i.register_op( - "fs_events_poll", - s.core_op(json_op(s.stateful_op(op_fs_events_poll))), - ); + i.register_op("op_fs_events_open", s.stateful_json_op(op_fs_events_open)); + i.register_op("op_fs_events_poll", s.stateful_json_op(op_fs_events_poll)); } struct FsEventsResource { diff --git a/cli/ops/io.rs b/cli/ops/io.rs index b150fa978..8edb1f748 100644 --- a/cli/ops/io.rs +++ b/cli/ops/io.rs @@ -47,11 +47,11 @@ lazy_static! { pub fn init(i: &mut Isolate, s: &State) { i.register_op( - "read", + "op_read", s.core_op(minimal_op(s.stateful_minimal_op(op_read))), ); i.register_op( - "write", + "op_write", s.core_op(minimal_op(s.stateful_minimal_op(op_write))), ); } @@ -124,23 +124,6 @@ enum IoState { Done, } -/// Tries to read some bytes directly into the given `buf` in asynchronous -/// manner, returning a future type. -/// -/// The returned future will resolve to both the I/O stream and the buffer -/// as well as the number of bytes read once the read operation is completed. -pub fn read<T>(state: &State, rid: ResourceId, buf: T) -> Read<T> -where - T: AsMut<[u8]>, -{ - Read { - rid, - buf, - io_state: IoState::Pending, - state: state.clone(), - } -} - /// A future which can be used to easily read available number of bytes to fill /// a buffer. /// @@ -185,13 +168,17 @@ pub fn op_read( zero_copy: Option<ZeroCopyBuf>, ) -> Pin<Box<MinimalOp>> { debug!("read rid={}", rid); - let zero_copy = match zero_copy { - None => return futures::future::err(no_buffer_specified()).boxed_local(), - Some(buf) => buf, - }; - - let fut = read(state, rid as u32, zero_copy); - fut.boxed_local() + if zero_copy.is_none() { + return futures::future::err(no_buffer_specified()).boxed_local(); + } + // TODO(ry) Probably poll_fn can be used here and the Read struct eliminated. + Read { + rid: rid as u32, + buf: zero_copy.unwrap(), + io_state: IoState::Pending, + state: state.clone(), + } + .boxed_local() } /// `DenoAsyncWrite` is the same as the `tokio_io::AsyncWrite` trait @@ -261,24 +248,6 @@ pub struct Write<T> { nwritten: i32, } -/// Creates a future that will write some of the buffer `buf` to -/// the stream resource with `rid`. -/// -/// Any error which happens during writing will cause both the stream and the -/// buffer to get destroyed. -pub fn write<T>(state: &State, rid: ResourceId, buf: T) -> Write<T> -where - T: AsRef<[u8]>, -{ - Write { - rid, - buf, - io_state: IoState::Pending, - state: state.clone(), - nwritten: 0, - } -} - /// This is almost the same implementation as in tokio, difference is /// that error type is `OpError` instead of `std::io::Error`. impl<T> Future for Write<T> @@ -329,12 +298,16 @@ pub fn op_write( zero_copy: Option<ZeroCopyBuf>, ) -> Pin<Box<MinimalOp>> { debug!("write rid={}", rid); - let zero_copy = match zero_copy { - None => return futures::future::err(no_buffer_specified()).boxed_local(), - Some(buf) => buf, - }; - - let fut = write(state, rid as u32, zero_copy); - - fut.boxed_local() + if zero_copy.is_none() { + return futures::future::err(no_buffer_specified()).boxed_local(); + } + // TODO(ry) Probably poll_fn can be used here and the Write struct eliminated. + Write { + rid: rid as u32, + buf: zero_copy.unwrap(), + io_state: IoState::Pending, + state: state.clone(), + nwritten: 0, + } + .boxed_local() } diff --git a/cli/ops/net.rs b/cli/ops/net.rs index cdc5d9f1f..2b3638fdb 100644 --- a/cli/ops/net.rs +++ b/cli/ops/net.rs @@ -2,7 +2,6 @@ use super::dispatch_json::{Deserialize, JsonOp, Value}; use super::io::StreamResource; use crate::op_error::OpError; -use crate::ops::json_op; use crate::resolve_addr::resolve_addr; use crate::state::State; use deno_core::*; @@ -21,12 +20,12 @@ use tokio::net::TcpStream; use tokio::net::UdpSocket; pub fn init(i: &mut Isolate, s: &State) { - i.register_op("accept", s.core_op(json_op(s.stateful_op(op_accept)))); - i.register_op("connect", s.core_op(json_op(s.stateful_op(op_connect)))); - i.register_op("shutdown", s.core_op(json_op(s.stateful_op(op_shutdown)))); - i.register_op("listen", s.core_op(json_op(s.stateful_op(op_listen)))); - i.register_op("receive", s.core_op(json_op(s.stateful_op(op_receive)))); - i.register_op("send", s.core_op(json_op(s.stateful_op(op_send)))); + i.register_op("op_accept", s.stateful_json_op(op_accept)); + i.register_op("op_connect", s.stateful_json_op(op_connect)); + i.register_op("op_shutdown", s.stateful_json_op(op_shutdown)); + i.register_op("op_listen", s.stateful_json_op(op_listen)); + i.register_op("op_receive", s.stateful_json_op(op_receive)); + i.register_op("op_send", s.stateful_json_op(op_send)); } #[derive(Debug, PartialEq)] @@ -35,15 +34,6 @@ enum AcceptState { Done, } -/// Simply accepts a connection. -pub fn accept(state: &State, rid: ResourceId) -> Accept { - Accept { - accept_state: AcceptState::Pending, - rid, - state, - } -} - /// A future representing state of accepting a TCP connection. pub struct Accept<'a> { accept_state: AcceptState, @@ -109,7 +99,12 @@ fn op_accept( } let op = async move { - let (tcp_stream, _socket_addr) = accept(&state_, rid).await?; + let accept_fut = Accept { + accept_state: AcceptState::Pending, + rid, + state: &state_, + }; + let (tcp_stream, _socket_addr) = accept_fut.await?; let local_addr = tcp_stream.local_addr()?; let remote_addr = tcp_stream.peer_addr()?; let mut state = state_.borrow_mut(); @@ -164,10 +159,6 @@ struct ReceiveArgs { rid: i32, } -fn receive(state: &State, rid: ResourceId, buf: ZeroCopyBuf) -> Receive { - Receive { state, rid, buf } -} - fn op_receive( state: &State, args: Value, @@ -182,8 +173,12 @@ fn op_receive( let state_ = state.clone(); let op = async move { - let (size, remote_addr) = receive(&state_, rid, buf).await?; - + let receive_fut = Receive { + state: &state_, + rid, + buf, + }; + let (size, remote_addr) = receive_fut.await?; Ok(json!({ "size": size, "remoteAddr": { diff --git a/cli/ops/os.rs b/cli/ops/os.rs index 8e4f1e95d..c0479c656 100644 --- a/cli/ops/os.rs +++ b/cli/ops/os.rs @@ -1,7 +1,6 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. use super::dispatch_json::{Deserialize, JsonOp, Value}; use crate::op_error::OpError; -use crate::ops::json_op; use crate::state::State; use atty; use deno_core::*; @@ -12,19 +11,16 @@ use sys_info; use url::Url; pub fn init(i: &mut Isolate, s: &State) { - i.register_op("exit", s.core_op(json_op(s.stateful_op(op_exit)))); - i.register_op("is_tty", s.core_op(json_op(s.stateful_op(op_is_tty)))); - i.register_op("env", s.core_op(json_op(s.stateful_op(op_env)))); - i.register_op("exec_path", s.core_op(json_op(s.stateful_op(op_exec_path)))); - i.register_op("set_env", s.core_op(json_op(s.stateful_op(op_set_env)))); - i.register_op("get_env", s.core_op(json_op(s.stateful_op(op_get_env)))); - i.register_op("get_dir", s.core_op(json_op(s.stateful_op(op_get_dir)))); - i.register_op("hostname", s.core_op(json_op(s.stateful_op(op_hostname)))); - i.register_op("loadavg", s.core_op(json_op(s.stateful_op(op_loadavg)))); - i.register_op( - "os_release", - s.core_op(json_op(s.stateful_op(op_os_release))), - ); + i.register_op("op_exit", s.stateful_json_op(op_exit)); + i.register_op("op_is_tty", s.stateful_json_op(op_is_tty)); + i.register_op("op_env", s.stateful_json_op(op_env)); + i.register_op("op_exec_path", s.stateful_json_op(op_exec_path)); + i.register_op("op_set_env", s.stateful_json_op(op_set_env)); + i.register_op("op_get_env", s.stateful_json_op(op_get_env)); + i.register_op("op_get_dir", s.stateful_json_op(op_get_dir)); + i.register_op("op_hostname", s.stateful_json_op(op_hostname)); + i.register_op("op_loadavg", s.stateful_json_op(op_loadavg)); + i.register_op("op_os_release", s.stateful_json_op(op_os_release)); } #[derive(Deserialize)] diff --git a/cli/ops/permissions.rs b/cli/ops/permissions.rs index 7737174a2..6d109e0a8 100644 --- a/cli/ops/permissions.rs +++ b/cli/ops/permissions.rs @@ -2,23 +2,22 @@ use super::dispatch_json::{Deserialize, JsonOp, Value}; use crate::fs as deno_fs; use crate::op_error::OpError; -use crate::ops::json_op; use crate::state::State; use deno_core::*; use std::path::Path; pub fn init(i: &mut Isolate, s: &State) { i.register_op( - "query_permission", - s.core_op(json_op(s.stateful_op(op_query_permission))), + "op_query_permission", + s.stateful_json_op(op_query_permission), ); i.register_op( - "revoke_permission", - s.core_op(json_op(s.stateful_op(op_revoke_permission))), + "op_revoke_permission", + s.stateful_json_op(op_revoke_permission), ); i.register_op( - "request_permission", - s.core_op(json_op(s.stateful_op(op_request_permission))), + "op_request_permission", + s.stateful_json_op(op_request_permission), ); } diff --git a/cli/ops/plugins.rs b/cli/ops/plugins.rs index 67ad5a13a..816c7ebb4 100644 --- a/cli/ops/plugins.rs +++ b/cli/ops/plugins.rs @@ -13,7 +13,7 @@ use std::rc::Rc; pub fn init(i: &mut Isolate, s: &State, r: Rc<deno_core::OpRegistry>) { let r_ = r; i.register_op( - "open_plugin", + "op_open_plugin", s.core_op(json_op(s.stateful_op(move |state, args, zero_copy| { op_open_plugin(&r_, state, args, zero_copy) }))), diff --git a/cli/ops/process.rs b/cli/ops/process.rs index fe461bd28..9da87bd39 100644 --- a/cli/ops/process.rs +++ b/cli/ops/process.rs @@ -2,7 +2,6 @@ use super::dispatch_json::{Deserialize, JsonOp, Value}; use super::io::StreamResource; use crate::op_error::OpError; -use crate::ops::json_op; use crate::signal::kill; use crate::state::State; use deno_core::*; @@ -22,12 +21,9 @@ use tokio::process::Command; use std::os::unix::process::ExitStatusExt; pub fn init(i: &mut Isolate, s: &State) { - i.register_op("run", s.core_op(json_op(s.stateful_op(op_run)))); - i.register_op( - "run_status", - s.core_op(json_op(s.stateful_op(op_run_status))), - ); - i.register_op("kill", s.core_op(json_op(s.stateful_op(op_kill)))); + i.register_op("op_run", s.stateful_json_op(op_run)); + i.register_op("op_run_status", s.stateful_json_op(op_run_status)); + i.register_op("op_kill", s.stateful_json_op(op_kill)); } fn clone_file(rid: u32, state: &State) -> Result<std::fs::File, OpError> { diff --git a/cli/ops/random.rs b/cli/ops/random.rs index 436b4d4fa..4430aa9c5 100644 --- a/cli/ops/random.rs +++ b/cli/ops/random.rs @@ -1,7 +1,6 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. use super::dispatch_json::{JsonOp, Value}; use crate::op_error::OpError; -use crate::ops::json_op; use crate::state::State; use deno_core::*; use rand::thread_rng; @@ -9,8 +8,8 @@ use rand::Rng; pub fn init(i: &mut Isolate, s: &State) { i.register_op( - "get_random_values", - s.core_op(json_op(s.stateful_op(op_get_random_values))), + "op_get_random_values", + s.stateful_json_op(op_get_random_values), ); } diff --git a/cli/ops/repl.rs b/cli/ops/repl.rs index abd88b973..3645cb902 100644 --- a/cli/ops/repl.rs +++ b/cli/ops/repl.rs @@ -1,7 +1,6 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. use super::dispatch_json::{blocking_json, Deserialize, JsonOp, Value}; use crate::op_error::OpError; -use crate::ops::json_op; use crate::repl; use crate::repl::Repl; use crate::state::State; @@ -10,14 +9,8 @@ use std::sync::Arc; use std::sync::Mutex; pub fn init(i: &mut Isolate, s: &State) { - i.register_op( - "repl_start", - s.core_op(json_op(s.stateful_op(op_repl_start))), - ); - i.register_op( - "repl_readline", - s.core_op(json_op(s.stateful_op(op_repl_readline))), - ); + i.register_op("op_repl_start", s.stateful_json_op(op_repl_start)); + i.register_op("op_repl_readline", s.stateful_json_op(op_repl_readline)); } struct ReplResource(Arc<Mutex<Repl>>); diff --git a/cli/ops/resources.rs b/cli/ops/resources.rs index 787894c2c..3031725e2 100644 --- a/cli/ops/resources.rs +++ b/cli/ops/resources.rs @@ -1,12 +1,11 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. use super::dispatch_json::{JsonOp, Value}; use crate::op_error::OpError; -use crate::ops::json_op; use crate::state::State; use deno_core::*; pub fn init(i: &mut Isolate, s: &State) { - i.register_op("resources", s.core_op(json_op(s.stateful_op(op_resources)))); + i.register_op("op_resources", s.stateful_json_op(op_resources)); } fn op_resources( diff --git a/cli/ops/runtime.rs b/cli/ops/runtime.rs index fda05f434..a888ce9a8 100644 --- a/cli/ops/runtime.rs +++ b/cli/ops/runtime.rs @@ -3,7 +3,6 @@ use super::dispatch_json::{JsonOp, Value}; use crate::colors; use crate::fs as deno_fs; use crate::op_error::OpError; -use crate::ops::json_op; use crate::state::State; use crate::version; use crate::DenoSubcommand; @@ -21,8 +20,8 @@ static BUILD_OS: &str = "win"; static BUILD_ARCH: &str = "x64"; pub fn init(i: &mut Isolate, s: &State) { - i.register_op("start", s.core_op(json_op(s.stateful_op(op_start)))); - i.register_op("metrics", s.core_op(json_op(s.stateful_op(op_metrics)))); + i.register_op("op_start", s.stateful_json_op(op_start)); + i.register_op("op_metrics", s.stateful_json_op(op_metrics)); } fn op_start( diff --git a/cli/ops/runtime_compiler.rs b/cli/ops/runtime_compiler.rs index a9b907e28..056056746 100644 --- a/cli/ops/runtime_compiler.rs +++ b/cli/ops/runtime_compiler.rs @@ -3,14 +3,13 @@ use super::dispatch_json::{Deserialize, JsonOp, Value}; use crate::compilers::runtime_compile_async; use crate::compilers::runtime_transpile_async; use crate::op_error::OpError; -use crate::ops::json_op; use crate::state::State; use deno_core::*; use std::collections::HashMap; pub fn init(i: &mut Isolate, s: &State) { - i.register_op("compile", s.core_op(json_op(s.stateful_op(op_compile)))); - i.register_op("transpile", s.core_op(json_op(s.stateful_op(op_transpile)))); + i.register_op("op_compile", s.stateful_json_op(op_compile)); + i.register_op("op_transpile", s.stateful_json_op(op_transpile)); } #[derive(Deserialize, Debug)] diff --git a/cli/ops/signal.rs b/cli/ops/signal.rs index 07a9cd527..035c5ff45 100644 --- a/cli/ops/signal.rs +++ b/cli/ops/signal.rs @@ -1,7 +1,6 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. use super::dispatch_json::{JsonOp, Value}; use crate::op_error::OpError; -use crate::ops::json_op; use crate::state::State; use deno_core::*; @@ -17,18 +16,9 @@ use std::task::Waker; use tokio::signal::unix::{signal, Signal, SignalKind}; pub fn init(i: &mut Isolate, s: &State) { - i.register_op( - "signal_bind", - s.core_op(json_op(s.stateful_op(op_signal_bind))), - ); - i.register_op( - "signal_unbind", - s.core_op(json_op(s.stateful_op(op_signal_unbind))), - ); - i.register_op( - "signal_poll", - s.core_op(json_op(s.stateful_op(op_signal_poll))), - ); + i.register_op("op_signal_bind", s.stateful_json_op(op_signal_bind)); + i.register_op("op_signal_unbind", s.stateful_json_op(op_signal_unbind)); + i.register_op("op_signal_poll", s.stateful_json_op(op_signal_poll)); } #[cfg(unix)] diff --git a/cli/ops/timers.rs b/cli/ops/timers.rs index b9a7dbdf7..33aa7f828 100644 --- a/cli/ops/timers.rs +++ b/cli/ops/timers.rs @@ -1,7 +1,6 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. use super::dispatch_json::{Deserialize, JsonOp, Value}; use crate::op_error::OpError; -use crate::ops::json_op; use crate::state::State; use deno_core::*; use futures::future::FutureExt; @@ -11,14 +10,11 @@ use std::time::Instant; pub fn init(i: &mut Isolate, s: &State) { i.register_op( - "global_timer_stop", - s.core_op(json_op(s.stateful_op(op_global_timer_stop))), + "op_global_timer_stop", + s.stateful_json_op(op_global_timer_stop), ); - i.register_op( - "global_timer", - s.core_op(json_op(s.stateful_op(op_global_timer))), - ); - i.register_op("now", s.core_op(json_op(s.stateful_op(op_now)))); + i.register_op("op_global_timer", s.stateful_json_op(op_global_timer)); + i.register_op("op_now", s.stateful_json_op(op_now)); } fn op_global_timer_stop( diff --git a/cli/ops/tls.rs b/cli/ops/tls.rs index 8c648faaf..af507ce6a 100644 --- a/cli/ops/tls.rs +++ b/cli/ops/tls.rs @@ -2,7 +2,6 @@ use super::dispatch_json::{Deserialize, JsonOp, Value}; use super::io::StreamResource; use crate::op_error::OpError; -use crate::ops::json_op; use crate::resolve_addr::resolve_addr; use crate::state::State; use deno_core::*; @@ -34,18 +33,9 @@ use webpki::DNSNameRef; use webpki_roots; pub fn init(i: &mut Isolate, s: &State) { - i.register_op( - "connect_tls", - s.core_op(json_op(s.stateful_op(op_connect_tls))), - ); - i.register_op( - "listen_tls", - s.core_op(json_op(s.stateful_op(op_listen_tls))), - ); - i.register_op( - "accept_tls", - s.core_op(json_op(s.stateful_op(op_accept_tls))), - ); + i.register_op("op_connect_tls", s.stateful_json_op(op_connect_tls)); + i.register_op("op_listen_tls", s.stateful_json_op(op_listen_tls)); + i.register_op("op_accept_tls", s.stateful_json_op(op_accept_tls)); } #[derive(Deserialize)] @@ -281,15 +271,6 @@ enum AcceptTlsState { Done, } -/// Simply accepts a TLS connection. -pub fn accept_tls(state: &State, rid: ResourceId) -> AcceptTls { - AcceptTls { - accept_state: AcceptTlsState::Pending, - rid, - state: state.clone(), - } -} - /// A future representing state of accepting a TLS connection. pub struct AcceptTls { accept_state: AcceptTlsState, @@ -347,7 +328,12 @@ fn op_accept_tls( let rid = args.rid as u32; let state = state.clone(); let op = async move { - let (tcp_stream, _socket_addr) = accept_tls(&state.clone(), rid).await?; + let accept_fut = AcceptTls { + accept_state: AcceptTlsState::Pending, + rid, + state: state.clone(), + }; + let (tcp_stream, _socket_addr) = accept_fut.await?; let local_addr = tcp_stream.local_addr()?; let remote_addr = tcp_stream.peer_addr()?; let tls_acceptor = { diff --git a/cli/ops/web_worker.rs b/cli/ops/web_worker.rs index db3ecd6ce..f293fcf7e 100644 --- a/cli/ops/web_worker.rs +++ b/cli/ops/web_worker.rs @@ -29,14 +29,14 @@ where pub fn init(i: &mut Isolate, s: &State, sender: &mpsc::Sender<WorkerEvent>) { i.register_op( - "worker_post_message", + "op_worker_post_message", s.core_op(json_op(web_worker_op( sender.clone(), op_worker_post_message, ))), ); i.register_op( - "worker_close", + "op_worker_close", s.core_op(json_op(web_worker_op(sender.clone(), op_worker_close))), ); } diff --git a/cli/ops/worker_host.rs b/cli/ops/worker_host.rs index 910f44459..55afd6bf9 100644 --- a/cli/ops/worker_host.rs +++ b/cli/ops/worker_host.rs @@ -4,7 +4,6 @@ use crate::fmt_errors::JSError; use crate::futures::SinkExt; use crate::global_state::GlobalState; use crate::op_error::OpError; -use crate::ops::json_op; use crate::permissions::DenoPermissions; use crate::startup_data; use crate::state::State; @@ -21,21 +20,18 @@ use std::convert::From; use std::thread::JoinHandle; pub fn init(i: &mut Isolate, s: &State) { + i.register_op("op_create_worker", s.stateful_json_op(op_create_worker)); i.register_op( - "create_worker", - s.core_op(json_op(s.stateful_op(op_create_worker))), + "op_host_terminate_worker", + s.stateful_json_op(op_host_terminate_worker), ); i.register_op( - "host_terminate_worker", - s.core_op(json_op(s.stateful_op(op_host_terminate_worker))), + "op_host_post_message", + s.stateful_json_op(op_host_post_message), ); i.register_op( - "host_post_message", - s.core_op(json_op(s.stateful_op(op_host_post_message))), - ); - i.register_op( - "host_get_message", - s.core_op(json_op(s.stateful_op(op_host_get_message))), + "op_host_get_message", + s.stateful_json_op(op_host_get_message), ); } |