diff options
Diffstat (limited to 'cli/ops')
-rw-r--r-- | cli/ops/compiler.rs | 7 | ||||
-rw-r--r-- | cli/ops/dispatch_json.rs | 31 | ||||
-rw-r--r-- | cli/ops/dispatch_minimal.rs | 5 | ||||
-rw-r--r-- | cli/ops/mod.rs | 1 | ||||
-rw-r--r-- | cli/ops/plugin.rs | 9 | ||||
-rw-r--r-- | cli/ops/web_worker.rs | 13 |
6 files changed, 29 insertions, 37 deletions
diff --git a/cli/ops/compiler.rs b/cli/ops/compiler.rs index 5af2f5eb0..d41369855 100644 --- a/cli/ops/compiler.rs +++ b/cli/ops/compiler.rs @@ -2,7 +2,6 @@ use super::dispatch_json::{JsonOp, Value}; use crate::op_error::OpError; use crate::ops::json_op; -use crate::ops::JsonOpDispatcher; use crate::state::State; use deno_core::CoreIsolate; use deno_core::CoreIsolateState; @@ -32,7 +31,11 @@ pub fn init( pub fn compiler_op<D>( response: Arc<Mutex<Option<String>>>, dispatcher: D, -) -> impl JsonOpDispatcher +) -> impl Fn( + &mut deno_core::CoreIsolateState, + Value, + &mut [ZeroCopyBuf], +) -> Result<JsonOp, OpError> where D: Fn( Arc<Mutex<Option<String>>>, diff --git a/cli/ops/dispatch_json.rs b/cli/ops/dispatch_json.rs index ad6947dd1..2ec9d6c2f 100644 --- a/cli/ops/dispatch_json.rs +++ b/cli/ops/dispatch_json.rs @@ -3,7 +3,6 @@ use crate::op_error::OpError; use deno_core::Buf; use deno_core::CoreIsolateState; use deno_core::Op; -use deno_core::OpDispatcher; use deno_core::ZeroCopyBuf; use futures::future::FutureExt; pub use serde_derive::Deserialize; @@ -45,36 +44,16 @@ struct AsyncArgs { promise_id: Option<u64>, } -/// Like OpDispatcher but with additional json `Value` parameter -/// and return a result of `JsonOp` instead of `Op`. -pub trait JsonOpDispatcher { - fn dispatch( - &self, - isolate_state: &mut CoreIsolateState, - json: Value, - zero_copy: &mut [ZeroCopyBuf], - ) -> Result<JsonOp, OpError>; -} - -impl<F> JsonOpDispatcher for F +pub fn json_op<D>( + d: D, +) -> impl Fn(&mut CoreIsolateState, &mut [ZeroCopyBuf]) -> Op where - F: Fn( + D: Fn( &mut CoreIsolateState, Value, &mut [ZeroCopyBuf], ) -> Result<JsonOp, OpError>, { - fn dispatch( - &self, - isolate_state: &mut CoreIsolateState, - json: Value, - zero_copy: &mut [ZeroCopyBuf], - ) -> Result<JsonOp, OpError> { - self(isolate_state, json, zero_copy) - } -} - -pub fn json_op(d: impl JsonOpDispatcher) -> impl OpDispatcher { move |isolate_state: &mut CoreIsolateState, zero_copy: &mut [ZeroCopyBuf]| { assert!(!zero_copy.is_empty(), "Expected JSON string at position 0"); let async_args: AsyncArgs = match serde_json::from_slice(&zero_copy[0]) { @@ -89,7 +68,7 @@ pub fn json_op(d: impl JsonOpDispatcher) -> impl OpDispatcher { let result = serde_json::from_slice(&zero_copy[0]) .map_err(OpError::from) - .and_then(|args| d.dispatch(isolate_state, args, &mut zero_copy[1..])); + .and_then(|args| d(isolate_state, args, &mut zero_copy[1..])); // Convert to Op match result { diff --git a/cli/ops/dispatch_minimal.rs b/cli/ops/dispatch_minimal.rs index 9cb81d4bc..df7d48b4e 100644 --- a/cli/ops/dispatch_minimal.rs +++ b/cli/ops/dispatch_minimal.rs @@ -9,7 +9,6 @@ use byteorder::{LittleEndian, WriteBytesExt}; use deno_core::Buf; use deno_core::CoreIsolateState; use deno_core::Op; -use deno_core::OpDispatcher; use deno_core::ZeroCopyBuf; use futures::future::FutureExt; use std::future::Future; @@ -119,7 +118,9 @@ fn test_parse_min_record() { assert_eq!(parse_min_record(&buf), None); } -pub fn minimal_op<D>(d: D) -> impl OpDispatcher +pub fn minimal_op<D>( + d: D, +) -> impl Fn(&mut CoreIsolateState, &mut [ZeroCopyBuf]) -> Op where D: Fn(&mut CoreIsolateState, bool, i32, &mut [ZeroCopyBuf]) -> MinimalOp, { diff --git a/cli/ops/mod.rs b/cli/ops/mod.rs index 331ed4aa1..ef8c3bd0f 100644 --- a/cli/ops/mod.rs +++ b/cli/ops/mod.rs @@ -4,7 +4,6 @@ mod dispatch_minimal; pub use dispatch_json::json_op; pub use dispatch_json::JsonOp; -pub use dispatch_json::JsonOpDispatcher; pub use dispatch_json::JsonResult; pub use dispatch_minimal::minimal_op; pub use dispatch_minimal::MinimalOp; diff --git a/cli/ops/plugin.rs b/cli/ops/plugin.rs index 3edcaa962..16debac50 100644 --- a/cli/ops/plugin.rs +++ b/cli/ops/plugin.rs @@ -3,6 +3,7 @@ use crate::op_error::OpError; use crate::ops::dispatch_json::Deserialize; use crate::ops::dispatch_json::JsonOp; use crate::ops::dispatch_json::Value; +use crate::ops::json_op; use crate::state::State; use deno_core::plugin_api; use deno_core::CoreIsolate; @@ -20,7 +21,10 @@ use std::task::Context; use std::task::Poll; pub fn init(i: &mut CoreIsolate, s: &State) { - i.register_op("op_open_plugin", s.stateful_json_op2(op_open_plugin)); + i.register_op( + "op_open_plugin", + s.core_op(json_op(s.stateful_op2(op_open_plugin))), + ); } #[derive(Deserialize)] @@ -106,8 +110,7 @@ impl<'a> plugin_api::Interface for PluginInterface<'a> { let plugin_lib = self.plugin_lib.clone(); self.isolate_state.op_registry.register( name, - move |isolate_state: &mut CoreIsolateState, - zero_copy: &mut [ZeroCopyBuf]| { + move |isolate_state, zero_copy| { let mut interface = PluginInterface::new(isolate_state, &plugin_lib); let op = dispatch_op_fn(&mut interface, zero_copy); match op { diff --git a/cli/ops/web_worker.rs b/cli/ops/web_worker.rs index 4a661d2be..553278b07 100644 --- a/cli/ops/web_worker.rs +++ b/cli/ops/web_worker.rs @@ -2,7 +2,6 @@ use super::dispatch_json::{JsonOp, Value}; use crate::op_error::OpError; use crate::ops::json_op; -use crate::ops::JsonOpDispatcher; use crate::state::State; use crate::web_worker::WebWorkerHandle; use crate::worker::WorkerEvent; @@ -15,7 +14,11 @@ use std::convert::From; pub fn web_worker_op<D>( sender: mpsc::Sender<WorkerEvent>, dispatcher: D, -) -> impl JsonOpDispatcher +) -> impl Fn( + &mut CoreIsolateState, + Value, + &mut [ZeroCopyBuf], +) -> Result<JsonOp, OpError> where D: Fn( &mpsc::Sender<WorkerEvent>, @@ -33,7 +36,11 @@ pub fn web_worker_op2<D>( handle: WebWorkerHandle, sender: mpsc::Sender<WorkerEvent>, dispatcher: D, -) -> impl JsonOpDispatcher +) -> impl Fn( + &mut CoreIsolateState, + Value, + &mut [ZeroCopyBuf], +) -> Result<JsonOp, OpError> where D: Fn( WebWorkerHandle, |