// 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, pub state: Arc, } impl CliBehavior { pub fn new( startup_data: Option, state: Arc, ) -> Self { Self { startup_data, state, } } } impl IsolateStateContainer for &CliBehavior { fn state(&self) -> Arc { self.state.clone() } } impl IsolateStateContainer for CliBehavior { fn state(&self) -> Arc { self.state.clone() } } impl Behavior for CliBehavior { fn startup_data(&mut self) -> Option { 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) { ops::dispatch_all(self, control, zero_copy, ops::op_selector_std) } }