diff options
author | andy finch <andyfinch7@gmail.com> | 2019-03-19 20:55:59 -0400 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2019-03-19 20:55:59 -0400 |
commit | 48bf419669694802f82b418b901cb282957fb64f (patch) | |
tree | 2304fb01719d3c18ca25aeb5456e9dea910db870 /cli/cli_behavior.rs | |
parent | 6131152a575f86c7510702091ba18f061628674f (diff) |
Separate behavior for the compiler isolate (#1973)
Diffstat (limited to 'cli/cli_behavior.rs')
-rw-r--r-- | cli/cli_behavior.rs | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/cli/cli_behavior.rs b/cli/cli_behavior.rs new file mode 100644 index 000000000..f1bd5a555 --- /dev/null +++ b/cli/cli_behavior.rs @@ -0,0 +1,57 @@ +// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. +use crate::isolate_state::*; +use crate::ops; +use deno_core::deno_buf; +use deno_core::deno_mod; +use deno_core::Behavior; +use deno_core::Op; +use deno_core::StartupData; +use std::sync::Arc; + +/// Implements deno_core::Behavior for the main Deno command-line. +pub struct CliBehavior { + startup_data: Option<StartupData>, + pub state: Arc<IsolateState>, +} + +impl CliBehavior { + pub fn new( + startup_data: Option<StartupData>, + state: Arc<IsolateState>, + ) -> Self { + Self { + startup_data, + state, + } + } +} + +impl IsolateStateContainer for &CliBehavior { + fn state(&self) -> Arc<IsolateState> { + self.state.clone() + } +} + +impl IsolateStateContainer for CliBehavior { + fn state(&self) -> Arc<IsolateState> { + self.state.clone() + } +} + +impl Behavior for CliBehavior { + fn startup_data(&mut self) -> Option<StartupData> { + self.startup_data.take() + } + + fn resolve(&mut self, specifier: &str, referrer: deno_mod) -> deno_mod { + self.state_resolve(specifier, referrer) + } + + fn dispatch( + &mut self, + control: &[u8], + zero_copy: deno_buf, + ) -> (bool, Box<Op>) { + ops::dispatch_all(Box::new(self), control, zero_copy, ops::op_selector_std) + } +} |