From cc1720132a9c875d377c559d301bccdda2fb71c1 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Tue, 21 Apr 2020 09:48:44 -0400 Subject: Move resource_table from deno::State to deno_core::Isolate (#4834) --- cli/state.rs | 48 ++++++++++++++++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 12 deletions(-) (limited to 'cli/state.rs') diff --git a/cli/state.rs b/cli/state.rs index 856190134..c59eb8eeb 100644 --- a/cli/state.rs +++ b/cli/state.rs @@ -14,7 +14,6 @@ use deno_core::ErrBox; use deno_core::ModuleLoader; use deno_core::ModuleSpecifier; use deno_core::Op; -use deno_core::ResourceTable; use deno_core::ZeroCopyBuf; use futures::future::FutureExt; use rand::rngs::StdRng; @@ -64,7 +63,6 @@ pub struct StateInner { pub next_worker_id: u32, pub start_time: Instant, pub seeded_rng: Option, - pub resource_table: ResourceTable, pub target_lib: TargetLib, pub debug_type: DebugType, } @@ -81,7 +79,25 @@ impl State { self.core_op(json_op(self.stateful_op(dispatcher))) } + pub fn stateful_json_op2( + &self, + dispatcher: D, + ) -> impl Fn(&mut deno_core::Isolate, &[u8], Option) -> Op + where + D: Fn( + &mut deno_core::Isolate, + &State, + Value, + Option, + ) -> Result, + { + use crate::ops::json_op; + self.core_op(json_op(self.stateful_op2(dispatcher))) + } + /// Wrap core `OpDispatcher` to collect metrics. + // TODO(ry) this should be private. Is called by stateful_json_op or + // stateful_minimal_op pub fn core_op( &self, dispatcher: D, @@ -142,19 +158,29 @@ impl State { } } - /// This is a special function that provides `state` argument to dispatcher. - pub fn stateful_minimal_op( + pub fn stateful_minimal_op2( &self, dispatcher: D, - ) -> impl Fn(bool, i32, Option) -> MinimalOp + ) -> impl Fn(&mut deno_core::Isolate, &[u8], Option) -> Op where - D: Fn(&State, bool, i32, Option) -> MinimalOp, + D: Fn( + &mut deno_core::Isolate, + &State, + bool, + i32, + Option, + ) -> MinimalOp, { let state = self.clone(); - move |is_sync: bool, - rid: i32, - zero_copy: Option| - -> MinimalOp { dispatcher(&state, is_sync, rid, zero_copy) } + self.core_op(crate::ops::minimal_op( + move |isolate: &mut deno_core::Isolate, + is_sync: bool, + rid: i32, + zero_copy: Option| + -> MinimalOp { + dispatcher(isolate, &state, is_sync, rid, zero_copy) + }, + )) } /// This is a special function that provides `state` argument to dispatcher. @@ -300,7 +326,6 @@ impl State { next_worker_id: 0, start_time: Instant::now(), seeded_rng, - resource_table: ResourceTable::default(), target_lib: TargetLib::Main, debug_type, })); @@ -336,7 +361,6 @@ impl State { next_worker_id: 0, start_time: Instant::now(), seeded_rng, - resource_table: ResourceTable::default(), target_lib: TargetLib::Worker, debug_type: DebugType::Dependent, })); -- cgit v1.2.3