diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2020-04-21 09:48:44 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-21 09:48:44 -0400 |
commit | cc1720132a9c875d377c559d301bccdda2fb71c1 (patch) | |
tree | bba93c08ab0eaea148e754381b5a668f1a88ca28 /cli/state.rs | |
parent | ef6ee25e09c902e1f9d89a40cf05660432e7143c (diff) |
Move resource_table from deno::State to deno_core::Isolate (#4834)
Diffstat (limited to 'cli/state.rs')
-rw-r--r-- | cli/state.rs | 48 |
1 files changed, 36 insertions, 12 deletions
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<StdRng>, - 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<D>( + &self, + dispatcher: D, + ) -> impl Fn(&mut deno_core::Isolate, &[u8], Option<ZeroCopyBuf>) -> Op + where + D: Fn( + &mut deno_core::Isolate, + &State, + Value, + Option<ZeroCopyBuf>, + ) -> Result<JsonOp, OpError>, + { + 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<D>( &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<D>( + pub fn stateful_minimal_op2<D>( &self, dispatcher: D, - ) -> impl Fn(bool, i32, Option<ZeroCopyBuf>) -> MinimalOp + ) -> impl Fn(&mut deno_core::Isolate, &[u8], Option<ZeroCopyBuf>) -> Op where - D: Fn(&State, bool, i32, Option<ZeroCopyBuf>) -> MinimalOp, + D: Fn( + &mut deno_core::Isolate, + &State, + bool, + i32, + Option<ZeroCopyBuf>, + ) -> MinimalOp, { let state = self.clone(); - move |is_sync: bool, - rid: i32, - zero_copy: Option<ZeroCopyBuf>| - -> 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<ZeroCopyBuf>| + -> 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, })); |