From c1ec042a0011eeba2480b892a335ca7804c59180 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Sun, 19 Apr 2020 23:54:46 -0400 Subject: Modify op dispatcher to include &mut Isolate argument (#4821) - Removes unnecessary RwLock and Rc around the op registry table - Preparation to move resource_table to deno_core::Isolate. - Towards #3453, #4222 --- cli/ops/dispatch_json.rs | 16 ++++++++++++---- cli/ops/dispatch_minimal.rs | 8 ++++++-- cli/ops/plugins.rs | 21 +++++++++++---------- cli/ops/web_worker.rs | 18 ++++++++++++++---- 4 files changed, 43 insertions(+), 20 deletions(-) (limited to 'cli/ops') diff --git a/cli/ops/dispatch_json.rs b/cli/ops/dispatch_json.rs index b1a7bc723..bfffd6d09 100644 --- a/cli/ops/dispatch_json.rs +++ b/cli/ops/dispatch_json.rs @@ -41,11 +41,19 @@ struct AsyncArgs { promise_id: Option, } -pub fn json_op(d: D) -> impl Fn(&[u8], Option) -> Op +pub fn json_op( + d: D, +) -> impl Fn(&mut deno_core::Isolate, &[u8], Option) -> Op where - D: Fn(Value, Option) -> Result, + D: Fn( + &mut deno_core::Isolate, + Value, + Option, + ) -> Result, { - move |control: &[u8], zero_copy: Option| { + move |isolate: &mut deno_core::Isolate, + control: &[u8], + zero_copy: Option| { let async_args: AsyncArgs = match serde_json::from_slice(control) { Ok(args) => args, Err(e) => { @@ -58,7 +66,7 @@ where let result = serde_json::from_slice(control) .map_err(OpError::from) - .and_then(|args| d(args, zero_copy)); + .and_then(|args| d(isolate, args, zero_copy)); // Convert to Op match result { diff --git a/cli/ops/dispatch_minimal.rs b/cli/ops/dispatch_minimal.rs index 7fdd12401..37907d60c 100644 --- a/cli/ops/dispatch_minimal.rs +++ b/cli/ops/dispatch_minimal.rs @@ -113,11 +113,15 @@ fn test_parse_min_record() { assert_eq!(parse_min_record(&buf), None); } -pub fn minimal_op(d: D) -> impl Fn(&[u8], Option) -> Op +pub fn minimal_op( + d: D, +) -> impl Fn(&mut deno_core::Isolate, &[u8], Option) -> Op where D: Fn(bool, i32, Option) -> MinimalOp, { - move |control: &[u8], zero_copy: Option| { + move |_isolate: &mut deno_core::Isolate, + control: &[u8], + zero_copy: Option| { let mut record = match parse_min_record(control) { Some(r) => r, None => { diff --git a/cli/ops/plugins.rs b/cli/ops/plugins.rs index 816c7ebb4..c0dffc90f 100644 --- a/cli/ops/plugins.rs +++ b/cli/ops/plugins.rs @@ -3,20 +3,21 @@ use crate::fs as deno_fs; use crate::op_error::OpError; use crate::ops::json_op; use crate::state::State; -use deno_core::*; +use deno_core::Isolate; +use deno_core::OpDispatcher; +use deno_core::OpId; +use deno_core::PluginInitContext; +use deno_core::PluginInitFn; +use deno_core::ZeroCopyBuf; use dlopen::symbor::Library; use std::collections::HashMap; use std::ffi::OsStr; use std::path::Path; -use std::rc::Rc; -pub fn init(i: &mut Isolate, s: &State, r: Rc) { - let r_ = r; +pub fn init(i: &mut Isolate, s: &State) { i.register_op( "op_open_plugin", - s.core_op(json_op(s.stateful_op(move |state, args, zero_copy| { - op_open_plugin(&r_, state, args, zero_copy) - }))), + s.core_op(json_op(s.stateful_op2(op_open_plugin))), ); } @@ -52,7 +53,7 @@ struct OpenPluginArgs { } pub fn op_open_plugin( - registry: &Rc, + isolate: &mut deno_core::Isolate, state: &State, args: Value, _zero_copy: Option, @@ -91,8 +92,8 @@ pub fn op_open_plugin( // The inclusion of prefix and rid is designed to avoid any // op name collision beyond the bound of a single loaded // plugin instance. - let op_id = registry - .register(&format!("plugin_{}_{}", rid, op.0), state.core_op(op.1)); + let op_id = isolate + .register_op(&format!("plugin_{}_{}", rid, op.0), state.core_op(op.1)); plugin_resource.ops.insert(op.0, op_id); } diff --git a/cli/ops/web_worker.rs b/cli/ops/web_worker.rs index 8cade7d40..ee376719f 100644 --- a/cli/ops/web_worker.rs +++ b/cli/ops/web_worker.rs @@ -12,7 +12,11 @@ use std::convert::From; pub fn web_worker_op( sender: mpsc::Sender, dispatcher: D, -) -> impl Fn(Value, Option) -> Result +) -> impl Fn( + &mut deno_core::Isolate, + Value, + Option, +) -> Result where D: Fn( &mpsc::Sender, @@ -20,7 +24,8 @@ where Option, ) -> Result, { - move |args: Value, + move |_isolate: &mut deno_core::Isolate, + args: Value, zero_copy: Option| -> Result { dispatcher(&sender, args, zero_copy) } } @@ -29,7 +34,11 @@ pub fn web_worker_op2( handle: WebWorkerHandle, sender: mpsc::Sender, dispatcher: D, -) -> impl Fn(Value, Option) -> Result +) -> impl Fn( + &mut deno_core::Isolate, + Value, + Option, +) -> Result where D: Fn( WebWorkerHandle, @@ -38,7 +47,8 @@ where Option, ) -> Result, { - move |args: Value, + move |_isolate: &mut deno_core::Isolate, + args: Value, zero_copy: Option| -> Result { dispatcher(handle.clone(), &sender, args, zero_copy) -- cgit v1.2.3