mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -05:00
Separate behavior for the compiler isolate (#1973)
This commit is contained in:
parent
6131152a57
commit
48bf419669
9 changed files with 451 additions and 294 deletions
57
cli/cli_behavior.rs
Normal file
57
cli/cli_behavior.rs
Normal file
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,22 +1,84 @@
|
||||||
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
||||||
use crate::isolate_state::IsolateState;
|
use crate::isolate_state::*;
|
||||||
use crate::msg;
|
use crate::msg;
|
||||||
use crate::permissions::{DenoPermissions, PermissionAccessor};
|
use crate::ops;
|
||||||
use crate::resources;
|
use crate::resources;
|
||||||
use crate::resources::Resource;
|
use crate::resources::Resource;
|
||||||
use crate::resources::ResourceId;
|
use crate::resources::ResourceId;
|
||||||
use crate::startup_data;
|
use crate::startup_data;
|
||||||
use crate::workers;
|
use crate::workers;
|
||||||
|
use crate::workers::WorkerBehavior;
|
||||||
|
use deno_core::deno_buf;
|
||||||
|
use deno_core::deno_mod;
|
||||||
|
use deno_core::Behavior;
|
||||||
use deno_core::Buf;
|
use deno_core::Buf;
|
||||||
|
use deno_core::Op;
|
||||||
|
use deno_core::StartupData;
|
||||||
use futures::Future;
|
use futures::Future;
|
||||||
use serde_json;
|
use serde_json;
|
||||||
use std::str;
|
use std::str;
|
||||||
|
use std::sync::Arc;
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref C_RID: Mutex<Option<ResourceId>> = Mutex::new(None);
|
static ref C_RID: Mutex<Option<ResourceId>> = Mutex::new(None);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct CompilerBehavior {
|
||||||
|
pub state: Arc<IsolateState>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CompilerBehavior {
|
||||||
|
pub fn new(state: Arc<IsolateState>) -> Self {
|
||||||
|
Self { state }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl IsolateStateContainer for CompilerBehavior {
|
||||||
|
fn state(&self) -> Arc<IsolateState> {
|
||||||
|
self.state.clone()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl IsolateStateContainer for &CompilerBehavior {
|
||||||
|
fn state(&self) -> Arc<IsolateState> {
|
||||||
|
self.state.clone()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Behavior for CompilerBehavior {
|
||||||
|
fn startup_data(&mut self) -> Option<StartupData> {
|
||||||
|
Some(startup_data::compiler_isolate_init())
|
||||||
|
}
|
||||||
|
|
||||||
|
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_compiler,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl WorkerBehavior for CompilerBehavior {
|
||||||
|
fn set_internal_channels(&mut self, worker_channels: WorkerChannels) {
|
||||||
|
self.state = Arc::new(IsolateState::new(
|
||||||
|
self.state.flags.clone(),
|
||||||
|
self.state.argv.clone(),
|
||||||
|
Some(worker_channels),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// This corresponds to JS ModuleMetaData.
|
// This corresponds to JS ModuleMetaData.
|
||||||
// TODO Rename one or the other so they correspond.
|
// TODO Rename one or the other so they correspond.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -46,22 +108,16 @@ impl ModuleMetaData {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lazy_start(parent_state: &IsolateState) -> Resource {
|
fn lazy_start(parent_state: Arc<IsolateState>) -> Resource {
|
||||||
let mut cell = C_RID.lock().unwrap();
|
let mut cell = C_RID.lock().unwrap();
|
||||||
let startup_data = startup_data::compiler_isolate_init();
|
|
||||||
let permissions = DenoPermissions {
|
|
||||||
allow_read: PermissionAccessor::from(true),
|
|
||||||
allow_write: PermissionAccessor::from(true),
|
|
||||||
allow_net: PermissionAccessor::from(true),
|
|
||||||
..Default::default()
|
|
||||||
};
|
|
||||||
|
|
||||||
let rid = cell.get_or_insert_with(|| {
|
let rid = cell.get_or_insert_with(|| {
|
||||||
let resource = workers::spawn(
|
let resource = workers::spawn(
|
||||||
Some(startup_data),
|
CompilerBehavior::new(Arc::new(IsolateState::new(
|
||||||
parent_state,
|
parent_state.flags.clone(),
|
||||||
|
parent_state.argv.clone(),
|
||||||
|
None,
|
||||||
|
))),
|
||||||
"compilerMain()".to_string(),
|
"compilerMain()".to_string(),
|
||||||
permissions,
|
|
||||||
);
|
);
|
||||||
resource.rid
|
resource.rid
|
||||||
});
|
});
|
||||||
|
@ -78,7 +134,7 @@ fn req(specifier: &str, referrer: &str) -> Buf {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn compile_sync(
|
pub fn compile_sync(
|
||||||
parent_state: &IsolateState,
|
parent_state: Arc<IsolateState>,
|
||||||
specifier: &str,
|
specifier: &str,
|
||||||
referrer: &str,
|
referrer: &str,
|
||||||
module_meta_data: &ModuleMetaData,
|
module_meta_data: &ModuleMetaData,
|
||||||
|
@ -140,7 +196,12 @@ mod tests {
|
||||||
maybe_source_map: None,
|
maybe_source_map: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
out = compile_sync(&IsolateState::mock(), specifier, &referrer, &mut out);
|
out = compile_sync(
|
||||||
|
Arc::new(IsolateState::mock()),
|
||||||
|
specifier,
|
||||||
|
&referrer,
|
||||||
|
&mut out,
|
||||||
|
);
|
||||||
assert!(
|
assert!(
|
||||||
out
|
out
|
||||||
.maybe_output_code
|
.maybe_output_code
|
||||||
|
|
|
@ -179,6 +179,10 @@ pub fn permission_denied() -> DenoError {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn op_not_implemented() -> DenoError {
|
||||||
|
new(ErrorKind::BadResource, String::from("op not implemented"))
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum RustOrJsError {
|
pub enum RustOrJsError {
|
||||||
Rust(DenoError),
|
Rust(DenoError),
|
||||||
|
|
|
@ -1,33 +1,37 @@
|
||||||
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
||||||
use crate::cli::Cli;
|
|
||||||
use crate::compiler::compile_sync;
|
use crate::compiler::compile_sync;
|
||||||
use crate::compiler::ModuleMetaData;
|
use crate::compiler::ModuleMetaData;
|
||||||
use crate::errors::DenoError;
|
use crate::errors::DenoError;
|
||||||
use crate::errors::RustOrJsError;
|
use crate::errors::RustOrJsError;
|
||||||
use crate::isolate_state::IsolateState;
|
use crate::isolate_state::IsolateState;
|
||||||
|
use crate::isolate_state::IsolateStateContainer;
|
||||||
use crate::js_errors;
|
use crate::js_errors;
|
||||||
use crate::msg;
|
use crate::msg;
|
||||||
use deno_core;
|
use deno_core;
|
||||||
use deno_core::deno_mod;
|
use deno_core::deno_mod;
|
||||||
|
use deno_core::Behavior;
|
||||||
use deno_core::JSError;
|
use deno_core::JSError;
|
||||||
use futures::Async;
|
use futures::Async;
|
||||||
use futures::Future;
|
use futures::Future;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
type CoreIsolate = deno_core::Isolate<Cli>;
|
pub trait DenoBehavior: Behavior + IsolateStateContainer + Send {}
|
||||||
|
impl<T> DenoBehavior for T where T: Behavior + IsolateStateContainer + Send {}
|
||||||
|
|
||||||
|
type CoreIsolate<B> = deno_core::Isolate<B>;
|
||||||
|
|
||||||
/// Wraps deno_core::Isolate to provide source maps, ops for the CLI, and
|
/// Wraps deno_core::Isolate to provide source maps, ops for the CLI, and
|
||||||
/// high-level module loading
|
/// high-level module loading
|
||||||
pub struct Isolate {
|
pub struct Isolate<B: Behavior> {
|
||||||
inner: CoreIsolate,
|
inner: CoreIsolate<B>,
|
||||||
state: Arc<IsolateState>,
|
state: Arc<IsolateState>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Isolate {
|
impl<B: DenoBehavior> Isolate<B> {
|
||||||
pub fn new(cli: Cli) -> Isolate {
|
pub fn new(behavior: B) -> Isolate<B> {
|
||||||
let state = cli.state.clone();
|
let state = behavior.state().clone();
|
||||||
Self {
|
Self {
|
||||||
inner: CoreIsolate::new(cli),
|
inner: CoreIsolate::new(behavior),
|
||||||
state,
|
state,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -150,7 +154,7 @@ impl Isolate {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Future for Isolate {
|
impl<B: DenoBehavior> Future for Isolate<B> {
|
||||||
type Item = ();
|
type Item = ();
|
||||||
type Error = JSError;
|
type Error = JSError;
|
||||||
|
|
||||||
|
@ -170,7 +174,7 @@ fn fetch_module_meta_data_and_maybe_compile(
|
||||||
|| state.flags.recompile
|
|| state.flags.recompile
|
||||||
{
|
{
|
||||||
debug!(">>>>> compile_sync START");
|
debug!(">>>>> compile_sync START");
|
||||||
out = compile_sync(state, specifier, &referrer, &out);
|
out = compile_sync(state.clone(), specifier, &referrer, &out);
|
||||||
debug!(">>>>> compile_sync END");
|
debug!(">>>>> compile_sync END");
|
||||||
state.dir.code_cache(&out)?;
|
state.dir.code_cache(&out)?;
|
||||||
}
|
}
|
||||||
|
@ -180,8 +184,8 @@ fn fetch_module_meta_data_and_maybe_compile(
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use crate::cli_behavior::CliBehavior;
|
||||||
use crate::flags;
|
use crate::flags;
|
||||||
use crate::permissions::DenoPermissions;
|
|
||||||
use crate::tokio_util;
|
use crate::tokio_util;
|
||||||
use futures::future::lazy;
|
use futures::future::lazy;
|
||||||
use std::sync::atomic::Ordering;
|
use std::sync::atomic::Ordering;
|
||||||
|
@ -199,7 +203,7 @@ mod tests {
|
||||||
let state = Arc::new(IsolateState::new(flags, rest_argv, None));
|
let state = Arc::new(IsolateState::new(flags, rest_argv, None));
|
||||||
let state_ = state.clone();
|
let state_ = state.clone();
|
||||||
tokio_util::run(lazy(move || {
|
tokio_util::run(lazy(move || {
|
||||||
let cli = Cli::new(None, state.clone(), DenoPermissions::default());
|
let cli = CliBehavior::new(None, state.clone());
|
||||||
let mut isolate = Isolate::new(cli);
|
let mut isolate = Isolate::new(cli);
|
||||||
if let Err(err) = isolate.execute_mod(&filename, false) {
|
if let Err(err) = isolate.execute_mod(&filename, false) {
|
||||||
eprintln!("execute_mod err {:?}", err);
|
eprintln!("execute_mod err {:?}", err);
|
||||||
|
@ -222,7 +226,7 @@ mod tests {
|
||||||
let state = Arc::new(IsolateState::new(flags, rest_argv, None));
|
let state = Arc::new(IsolateState::new(flags, rest_argv, None));
|
||||||
let state_ = state.clone();
|
let state_ = state.clone();
|
||||||
tokio_util::run(lazy(move || {
|
tokio_util::run(lazy(move || {
|
||||||
let cli = Cli::new(None, state.clone(), DenoPermissions::default());
|
let cli = CliBehavior::new(None, state.clone());
|
||||||
let mut isolate = Isolate::new(cli);
|
let mut isolate = Isolate::new(cli);
|
||||||
if let Err(err) = isolate.execute_mod(&filename, false) {
|
if let Err(err) = isolate.execute_mod(&filename, false) {
|
||||||
eprintln!("execute_mod err {:?}", err);
|
eprintln!("execute_mod err {:?}", err);
|
||||||
|
|
|
@ -1,13 +1,17 @@
|
||||||
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
||||||
use crate::deno_dir;
|
use crate::deno_dir;
|
||||||
|
use crate::errors::DenoResult;
|
||||||
use crate::flags;
|
use crate::flags;
|
||||||
use crate::global_timer::GlobalTimer;
|
use crate::global_timer::GlobalTimer;
|
||||||
use crate::modules::Modules;
|
use crate::modules::Modules;
|
||||||
|
use crate::permissions::DenoPermissions;
|
||||||
|
use deno_core::deno_mod;
|
||||||
use deno_core::Buf;
|
use deno_core::Buf;
|
||||||
use futures::sync::mpsc as async_mpsc;
|
use futures::sync::mpsc as async_mpsc;
|
||||||
use std;
|
use std;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||||
|
use std::sync::Arc;
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
|
|
||||||
pub type WorkerSender = async_mpsc::Sender<Buf>;
|
pub type WorkerSender = async_mpsc::Sender<Buf>;
|
||||||
|
@ -33,6 +37,7 @@ pub struct Metrics {
|
||||||
pub struct IsolateState {
|
pub struct IsolateState {
|
||||||
pub dir: deno_dir::DenoDir,
|
pub dir: deno_dir::DenoDir,
|
||||||
pub argv: Vec<String>,
|
pub argv: Vec<String>,
|
||||||
|
pub permissions: DenoPermissions,
|
||||||
pub flags: flags::DenoFlags,
|
pub flags: flags::DenoFlags,
|
||||||
pub metrics: Metrics,
|
pub metrics: Metrics,
|
||||||
pub modules: Mutex<Modules>,
|
pub modules: Mutex<Modules>,
|
||||||
|
@ -52,6 +57,7 @@ impl IsolateState {
|
||||||
dir: deno_dir::DenoDir::new(flags.reload, flags.recompile, custom_root)
|
dir: deno_dir::DenoDir::new(flags.reload, flags.recompile, custom_root)
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
argv: argv_rest,
|
argv: argv_rest,
|
||||||
|
permissions: DenoPermissions::from_flags(&flags),
|
||||||
flags,
|
flags,
|
||||||
metrics: Metrics::default(),
|
metrics: Metrics::default(),
|
||||||
modules: Mutex::new(Modules::new()),
|
modules: Mutex::new(Modules::new()),
|
||||||
|
@ -76,6 +82,31 @@ impl IsolateState {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn check_read(&self, filename: &str) -> DenoResult<()> {
|
||||||
|
self.permissions.check_read(filename)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn check_write(&self, filename: &str) -> DenoResult<()> {
|
||||||
|
self.permissions.check_write(filename)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn check_env(&self) -> DenoResult<()> {
|
||||||
|
self.permissions.check_env()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn check_net(&self, filename: &str) -> DenoResult<()> {
|
||||||
|
self.permissions.check_net(filename)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn check_run(&self) -> DenoResult<()> {
|
||||||
|
self.permissions.check_run()
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub fn mock() -> IsolateState {
|
pub fn mock() -> IsolateState {
|
||||||
let argv = vec![String::from("./deno"), String::from("hello.js")];
|
let argv = vec![String::from("./deno"), String::from("hello.js")];
|
||||||
|
@ -108,3 +139,21 @@ impl IsolateState {
|
||||||
.fetch_add(bytes_received, Ordering::SeqCst);
|
.fetch_add(bytes_received, Ordering::SeqCst);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Provides state getter function
|
||||||
|
pub trait IsolateStateContainer {
|
||||||
|
fn state(&self) -> Arc<IsolateState>;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Provides state_resolve function for IsolateStateContainer implementors
|
||||||
|
pub trait IsolateStateModuleResolution: IsolateStateContainer {
|
||||||
|
fn state_resolve(&mut self, specifier: &str, referrer: deno_mod) -> deno_mod {
|
||||||
|
let state = self.state();
|
||||||
|
state.metrics.resolve_count.fetch_add(1, Ordering::Relaxed);
|
||||||
|
let mut modules = state.modules.lock().unwrap();
|
||||||
|
modules.resolve_cb(&state.dir, specifier, referrer)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Auto implementation for all IsolateStateContainer implementors
|
||||||
|
impl<T> IsolateStateModuleResolution for T where T: IsolateStateContainer {}
|
||||||
|
|
|
@ -9,7 +9,7 @@ extern crate futures;
|
||||||
extern crate serde_json;
|
extern crate serde_json;
|
||||||
|
|
||||||
mod ansi;
|
mod ansi;
|
||||||
pub mod cli;
|
pub mod cli_behavior;
|
||||||
pub mod compiler;
|
pub mod compiler;
|
||||||
pub mod deno_dir;
|
pub mod deno_dir;
|
||||||
pub mod errors;
|
pub mod errors;
|
||||||
|
@ -35,7 +35,7 @@ mod tokio_write;
|
||||||
pub mod version;
|
pub mod version;
|
||||||
pub mod workers;
|
pub mod workers;
|
||||||
|
|
||||||
use crate::cli::Cli;
|
use crate::cli_behavior::CliBehavior;
|
||||||
use crate::errors::RustOrJsError;
|
use crate::errors::RustOrJsError;
|
||||||
use crate::isolate::Isolate;
|
use crate::isolate::Isolate;
|
||||||
use crate::isolate_state::IsolateState;
|
use crate::isolate_state::IsolateState;
|
||||||
|
@ -111,8 +111,7 @@ fn main() {
|
||||||
let state = Arc::new(IsolateState::new(flags, rest_argv, None));
|
let state = Arc::new(IsolateState::new(flags, rest_argv, None));
|
||||||
let state_ = state.clone();
|
let state_ = state.clone();
|
||||||
let startup_data = startup_data::deno_isolate_init();
|
let startup_data = startup_data::deno_isolate_init();
|
||||||
let permissions = permissions::DenoPermissions::from_flags(&state.flags);
|
let cli = CliBehavior::new(Some(startup_data), state_);
|
||||||
let cli = Cli::new(Some(startup_data), state_, permissions);
|
|
||||||
let mut isolate = Isolate::new(cli);
|
let mut isolate = Isolate::new(cli);
|
||||||
|
|
||||||
let main_future = lazy(move || {
|
let main_future = lazy(move || {
|
||||||
|
|
382
cli/ops.rs
382
cli/ops.rs
|
@ -1,12 +1,11 @@
|
||||||
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
||||||
use atty;
|
use atty;
|
||||||
use crate::ansi;
|
use crate::ansi;
|
||||||
use crate::cli::Cli;
|
|
||||||
use crate::errors;
|
use crate::errors;
|
||||||
use crate::errors::{permission_denied, DenoError, DenoResult, ErrorKind};
|
use crate::errors::{op_not_implemented, DenoError, DenoResult, ErrorKind};
|
||||||
use crate::fs as deno_fs;
|
use crate::fs as deno_fs;
|
||||||
use crate::http_util;
|
use crate::http_util;
|
||||||
use crate::isolate_state::IsolateState;
|
use crate::isolate_state::{IsolateState, IsolateStateContainer};
|
||||||
use crate::js_errors::apply_source_map;
|
use crate::js_errors::apply_source_map;
|
||||||
use crate::js_errors::JSErrorColor;
|
use crate::js_errors::JSErrorColor;
|
||||||
use crate::msg;
|
use crate::msg;
|
||||||
|
@ -59,7 +58,10 @@ pub type OpWithError = dyn Future<Item = Buf, Error = DenoError> + Send;
|
||||||
// TODO Ideally we wouldn't have to box the OpWithError being returned.
|
// TODO Ideally we wouldn't have to box the OpWithError being returned.
|
||||||
// The box is just to make it easier to get a prototype refactor working.
|
// The box is just to make it easier to get a prototype refactor working.
|
||||||
type OpCreator =
|
type OpCreator =
|
||||||
fn(cli: &Cli, base: &msg::Base<'_>, data: deno_buf) -> Box<OpWithError>;
|
fn(sc: Box<&IsolateStateContainer>, base: &msg::Base<'_>, data: deno_buf)
|
||||||
|
-> Box<OpWithError>;
|
||||||
|
|
||||||
|
type OpSelector = fn(inner_type: msg::Any) -> DenoResult<Box<OpCreator>>;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn empty_buf() -> Buf {
|
fn empty_buf() -> Buf {
|
||||||
|
@ -70,10 +72,11 @@ fn empty_buf() -> Buf {
|
||||||
/// This functions invoked every time libdeno.send() is called.
|
/// This functions invoked every time libdeno.send() is called.
|
||||||
/// control corresponds to the first argument of libdeno.send().
|
/// control corresponds to the first argument of libdeno.send().
|
||||||
/// data corresponds to the second argument of libdeno.send().
|
/// data corresponds to the second argument of libdeno.send().
|
||||||
pub fn dispatch(
|
pub fn dispatch_all(
|
||||||
cli: &Cli,
|
sc: Box<&IsolateStateContainer>,
|
||||||
control: &[u8],
|
control: &[u8],
|
||||||
zero_copy: deno_buf,
|
zero_copy: deno_buf,
|
||||||
|
op_selector: OpSelector,
|
||||||
) -> (bool, Box<Op>) {
|
) -> (bool, Box<Op>) {
|
||||||
let bytes_sent_control = control.len();
|
let bytes_sent_control = control.len();
|
||||||
let bytes_sent_zero_copy = zero_copy.len();
|
let bytes_sent_zero_copy = zero_copy.len();
|
||||||
|
@ -82,66 +85,19 @@ pub fn dispatch(
|
||||||
let inner_type = base.inner_type();
|
let inner_type = base.inner_type();
|
||||||
let cmd_id = base.cmd_id();
|
let cmd_id = base.cmd_id();
|
||||||
|
|
||||||
let op: Box<OpWithError> = {
|
let op_func: Box<OpCreator> = match op_selector(inner_type) {
|
||||||
// Handle regular ops.
|
Ok(v) => v,
|
||||||
let op_creator: OpCreator = match inner_type {
|
Err(_) => panic!(format!(
|
||||||
msg::Any::Accept => op_accept,
|
"Unhandled message {}",
|
||||||
msg::Any::Chdir => op_chdir,
|
msg::enum_name_any(inner_type)
|
||||||
msg::Any::Chmod => op_chmod,
|
)),
|
||||||
msg::Any::Close => op_close,
|
|
||||||
msg::Any::CopyFile => op_copy_file,
|
|
||||||
msg::Any::Cwd => op_cwd,
|
|
||||||
msg::Any::Dial => op_dial,
|
|
||||||
msg::Any::Environ => op_env,
|
|
||||||
msg::Any::Exit => op_exit,
|
|
||||||
msg::Any::Fetch => op_fetch,
|
|
||||||
msg::Any::FetchModuleMetaData => op_fetch_module_meta_data,
|
|
||||||
msg::Any::FormatError => op_format_error,
|
|
||||||
msg::Any::GlobalTimer => op_global_timer,
|
|
||||||
msg::Any::GlobalTimerStop => op_global_timer_stop,
|
|
||||||
msg::Any::IsTTY => op_is_tty,
|
|
||||||
msg::Any::Listen => op_listen,
|
|
||||||
msg::Any::MakeTempDir => op_make_temp_dir,
|
|
||||||
msg::Any::Metrics => op_metrics,
|
|
||||||
msg::Any::Mkdir => op_mkdir,
|
|
||||||
msg::Any::Now => op_now,
|
|
||||||
msg::Any::Open => op_open,
|
|
||||||
msg::Any::PermissionRevoke => op_revoke_permission,
|
|
||||||
msg::Any::Permissions => op_permissions,
|
|
||||||
msg::Any::Read => op_read,
|
|
||||||
msg::Any::ReadDir => op_read_dir,
|
|
||||||
msg::Any::ReadFile => op_read_file,
|
|
||||||
msg::Any::Readlink => op_read_link,
|
|
||||||
msg::Any::Remove => op_remove,
|
|
||||||
msg::Any::Rename => op_rename,
|
|
||||||
msg::Any::ReplReadline => op_repl_readline,
|
|
||||||
msg::Any::ReplStart => op_repl_start,
|
|
||||||
msg::Any::Resources => op_resources,
|
|
||||||
msg::Any::Run => op_run,
|
|
||||||
msg::Any::RunStatus => op_run_status,
|
|
||||||
msg::Any::Seek => op_seek,
|
|
||||||
msg::Any::SetEnv => op_set_env,
|
|
||||||
msg::Any::Shutdown => op_shutdown,
|
|
||||||
msg::Any::Start => op_start,
|
|
||||||
msg::Any::Stat => op_stat,
|
|
||||||
msg::Any::Symlink => op_symlink,
|
|
||||||
msg::Any::Truncate => op_truncate,
|
|
||||||
msg::Any::WorkerGetMessage => op_worker_get_message,
|
|
||||||
msg::Any::WorkerPostMessage => op_worker_post_message,
|
|
||||||
msg::Any::Write => op_write,
|
|
||||||
msg::Any::WriteFile => op_write_file,
|
|
||||||
_ => panic!(format!(
|
|
||||||
"Unhandled message {}",
|
|
||||||
msg::enum_name_any(inner_type)
|
|
||||||
)),
|
|
||||||
};
|
|
||||||
op_creator(&cli, &base, zero_copy)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
cli
|
let state = sc.state().clone();
|
||||||
.state
|
|
||||||
.metrics_op_dispatched(bytes_sent_control, bytes_sent_zero_copy);
|
let op: Box<OpWithError> = op_func(sc, &base, zero_copy);
|
||||||
let state = cli.state.clone();
|
|
||||||
|
state.metrics_op_dispatched(bytes_sent_control, bytes_sent_zero_copy);
|
||||||
|
|
||||||
let boxed_op = Box::new(
|
let boxed_op = Box::new(
|
||||||
op.or_else(move |err: DenoError| -> Result<Buf, ()> {
|
op.or_else(move |err: DenoError| -> Result<Buf, ()> {
|
||||||
|
@ -188,8 +144,72 @@ pub fn dispatch(
|
||||||
(base.sync(), boxed_op)
|
(base.sync(), boxed_op)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn op_selector_compiler(
|
||||||
|
inner_type: msg::Any,
|
||||||
|
) -> DenoResult<Box<OpCreator>> {
|
||||||
|
let op_creator: Box<OpCreator> = match inner_type {
|
||||||
|
msg::Any::FetchModuleMetaData => Box::new(op_fetch_module_meta_data),
|
||||||
|
_ => match op_selector_std(inner_type) {
|
||||||
|
Ok(v) => v,
|
||||||
|
Err(e) => return Err(e),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
Ok(op_creator)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn op_selector_std(inner_type: msg::Any) -> DenoResult<Box<OpCreator>> {
|
||||||
|
let op_creator: OpCreator = match inner_type {
|
||||||
|
msg::Any::Accept => op_accept,
|
||||||
|
msg::Any::Chdir => op_chdir,
|
||||||
|
msg::Any::Chmod => op_chmod,
|
||||||
|
msg::Any::Close => op_close,
|
||||||
|
msg::Any::CopyFile => op_copy_file,
|
||||||
|
msg::Any::Cwd => op_cwd,
|
||||||
|
msg::Any::Dial => op_dial,
|
||||||
|
msg::Any::Environ => op_env,
|
||||||
|
msg::Any::Exit => op_exit,
|
||||||
|
msg::Any::Fetch => op_fetch,
|
||||||
|
msg::Any::FormatError => op_format_error,
|
||||||
|
msg::Any::GlobalTimer => op_global_timer,
|
||||||
|
msg::Any::GlobalTimerStop => op_global_timer_stop,
|
||||||
|
msg::Any::IsTTY => op_is_tty,
|
||||||
|
msg::Any::Listen => op_listen,
|
||||||
|
msg::Any::MakeTempDir => op_make_temp_dir,
|
||||||
|
msg::Any::Metrics => op_metrics,
|
||||||
|
msg::Any::Mkdir => op_mkdir,
|
||||||
|
msg::Any::Now => op_now,
|
||||||
|
msg::Any::Open => op_open,
|
||||||
|
msg::Any::PermissionRevoke => op_revoke_permission,
|
||||||
|
msg::Any::Permissions => op_permissions,
|
||||||
|
msg::Any::Read => op_read,
|
||||||
|
msg::Any::ReadDir => op_read_dir,
|
||||||
|
msg::Any::ReadFile => op_read_file,
|
||||||
|
msg::Any::Readlink => op_read_link,
|
||||||
|
msg::Any::Remove => op_remove,
|
||||||
|
msg::Any::Rename => op_rename,
|
||||||
|
msg::Any::ReplReadline => op_repl_readline,
|
||||||
|
msg::Any::ReplStart => op_repl_start,
|
||||||
|
msg::Any::Resources => op_resources,
|
||||||
|
msg::Any::Run => op_run,
|
||||||
|
msg::Any::RunStatus => op_run_status,
|
||||||
|
msg::Any::Seek => op_seek,
|
||||||
|
msg::Any::SetEnv => op_set_env,
|
||||||
|
msg::Any::Shutdown => op_shutdown,
|
||||||
|
msg::Any::Start => op_start,
|
||||||
|
msg::Any::Stat => op_stat,
|
||||||
|
msg::Any::Symlink => op_symlink,
|
||||||
|
msg::Any::Truncate => op_truncate,
|
||||||
|
msg::Any::WorkerGetMessage => op_worker_get_message,
|
||||||
|
msg::Any::WorkerPostMessage => op_worker_post_message,
|
||||||
|
msg::Any::Write => op_write,
|
||||||
|
msg::Any::WriteFile => op_write_file,
|
||||||
|
_ => return Err(op_not_implemented()),
|
||||||
|
};
|
||||||
|
Ok(Box::new(op_creator))
|
||||||
|
}
|
||||||
|
|
||||||
fn op_now(
|
fn op_now(
|
||||||
_cli: &Cli,
|
_sc: Box<&IsolateStateContainer>,
|
||||||
base: &msg::Base<'_>,
|
base: &msg::Base<'_>,
|
||||||
data: deno_buf,
|
data: deno_buf,
|
||||||
) -> Box<OpWithError> {
|
) -> Box<OpWithError> {
|
||||||
|
@ -213,7 +233,7 @@ fn op_now(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn op_is_tty(
|
fn op_is_tty(
|
||||||
_cli: &Cli,
|
_sc: Box<&IsolateStateContainer>,
|
||||||
base: &msg::Base<'_>,
|
base: &msg::Base<'_>,
|
||||||
_data: deno_buf,
|
_data: deno_buf,
|
||||||
) -> Box<OpWithError> {
|
) -> Box<OpWithError> {
|
||||||
|
@ -238,7 +258,7 @@ fn op_is_tty(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn op_exit(
|
fn op_exit(
|
||||||
_cli: &Cli,
|
_sc: Box<&IsolateStateContainer>,
|
||||||
base: &msg::Base<'_>,
|
base: &msg::Base<'_>,
|
||||||
_data: deno_buf,
|
_data: deno_buf,
|
||||||
) -> Box<OpWithError> {
|
) -> Box<OpWithError> {
|
||||||
|
@ -247,19 +267,15 @@ fn op_exit(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn op_start(
|
fn op_start(
|
||||||
cli: &Cli,
|
sc: Box<&IsolateStateContainer>,
|
||||||
base: &msg::Base<'_>,
|
base: &msg::Base<'_>,
|
||||||
data: deno_buf,
|
data: deno_buf,
|
||||||
) -> Box<OpWithError> {
|
) -> Box<OpWithError> {
|
||||||
assert_eq!(data.len(), 0);
|
assert_eq!(data.len(), 0);
|
||||||
let mut builder = FlatBufferBuilder::new();
|
let mut builder = FlatBufferBuilder::new();
|
||||||
|
|
||||||
let argv = cli
|
let state = sc.state();
|
||||||
.state
|
let argv = state.argv.iter().map(|s| s.as_str()).collect::<Vec<_>>();
|
||||||
.argv
|
|
||||||
.iter()
|
|
||||||
.map(|s| s.as_str())
|
|
||||||
.collect::<Vec<_>>();
|
|
||||||
let argv_off = builder.create_vector_of_strings(argv.as_slice());
|
let argv_off = builder.create_vector_of_strings(argv.as_slice());
|
||||||
|
|
||||||
let cwd_path = std::env::current_dir().unwrap();
|
let cwd_path = std::env::current_dir().unwrap();
|
||||||
|
@ -275,7 +291,7 @@ fn op_start(
|
||||||
let deno_version = version::DENO;
|
let deno_version = version::DENO;
|
||||||
let deno_version_off = builder.create_string(deno_version);
|
let deno_version_off = builder.create_string(deno_version);
|
||||||
|
|
||||||
let main_module = cli.state.main_module().map(|m| builder.create_string(&m));
|
let main_module = sc.state().main_module().map(|m| builder.create_string(&m));
|
||||||
|
|
||||||
let inner = msg::StartRes::create(
|
let inner = msg::StartRes::create(
|
||||||
&mut builder,
|
&mut builder,
|
||||||
|
@ -284,9 +300,9 @@ fn op_start(
|
||||||
pid: std::process::id(),
|
pid: std::process::id(),
|
||||||
argv: Some(argv_off),
|
argv: Some(argv_off),
|
||||||
main_module,
|
main_module,
|
||||||
debug_flag: cli.state.flags.log_debug,
|
debug_flag: sc.state().flags.log_debug,
|
||||||
types_flag: cli.state.flags.types,
|
types_flag: sc.state().flags.types,
|
||||||
version_flag: cli.state.flags.version,
|
version_flag: sc.state().flags.version,
|
||||||
v8_version: Some(v8_version_off),
|
v8_version: Some(v8_version_off),
|
||||||
deno_version: Some(deno_version_off),
|
deno_version: Some(deno_version_off),
|
||||||
no_color: !ansi::use_color(),
|
no_color: !ansi::use_color(),
|
||||||
|
@ -307,7 +323,7 @@ fn op_start(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn op_format_error(
|
fn op_format_error(
|
||||||
cli: &Cli,
|
sc: Box<&IsolateStateContainer>,
|
||||||
base: &msg::Base<'_>,
|
base: &msg::Base<'_>,
|
||||||
data: deno_buf,
|
data: deno_buf,
|
||||||
) -> Box<OpWithError> {
|
) -> Box<OpWithError> {
|
||||||
|
@ -316,7 +332,7 @@ fn op_format_error(
|
||||||
let orig_error = String::from(inner.error().unwrap());
|
let orig_error = String::from(inner.error().unwrap());
|
||||||
|
|
||||||
let js_error = JSError::from_v8_exception(&orig_error).unwrap();
|
let js_error = JSError::from_v8_exception(&orig_error).unwrap();
|
||||||
let js_error_mapped = apply_source_map(&js_error, &cli.state.dir);
|
let js_error_mapped = apply_source_map(&js_error, &sc.state().dir);
|
||||||
let js_error_string = JSErrorColor(&js_error_mapped).to_string();
|
let js_error_string = JSErrorColor(&js_error_mapped).to_string();
|
||||||
|
|
||||||
let mut builder = FlatBufferBuilder::new();
|
let mut builder = FlatBufferBuilder::new();
|
||||||
|
@ -367,7 +383,7 @@ pub fn odd_future(err: DenoError) -> Box<OpWithError> {
|
||||||
|
|
||||||
// https://github.com/denoland/deno/blob/golang/os.go#L100-L154
|
// https://github.com/denoland/deno/blob/golang/os.go#L100-L154
|
||||||
fn op_fetch_module_meta_data(
|
fn op_fetch_module_meta_data(
|
||||||
cli: &Cli,
|
sc: Box<&IsolateStateContainer>,
|
||||||
base: &msg::Base<'_>,
|
base: &msg::Base<'_>,
|
||||||
data: deno_buf,
|
data: deno_buf,
|
||||||
) -> Box<OpWithError> {
|
) -> Box<OpWithError> {
|
||||||
|
@ -377,33 +393,15 @@ fn op_fetch_module_meta_data(
|
||||||
let specifier = inner.specifier().unwrap();
|
let specifier = inner.specifier().unwrap();
|
||||||
let referrer = inner.referrer().unwrap();
|
let referrer = inner.referrer().unwrap();
|
||||||
|
|
||||||
// Check for allow read since this operation could be used to read from the file system.
|
|
||||||
if !cli.permissions.allows_read() {
|
|
||||||
debug!("No read permission for fetch_module_meta_data");
|
|
||||||
return odd_future(permission_denied());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for allow write since this operation could be used to write to the file system.
|
|
||||||
if !cli.permissions.allows_write() {
|
|
||||||
debug!("No network permission for fetch_module_meta_data");
|
|
||||||
return odd_future(permission_denied());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for allow net since this operation could be used to make https/http requests.
|
|
||||||
if !cli.permissions.allows_net() {
|
|
||||||
debug!("No network permission for fetch_module_meta_data");
|
|
||||||
return odd_future(permission_denied());
|
|
||||||
}
|
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
cli.state.dir.root.join("gen"),
|
sc.state().dir.root.join("gen"),
|
||||||
cli.state.dir.gen,
|
sc.state().dir.gen,
|
||||||
"Sanity check"
|
"Sanity check"
|
||||||
);
|
);
|
||||||
|
|
||||||
Box::new(futures::future::result(|| -> OpResult {
|
Box::new(futures::future::result(|| -> OpResult {
|
||||||
let builder = &mut FlatBufferBuilder::new();
|
let builder = &mut FlatBufferBuilder::new();
|
||||||
let out = cli.state.dir.fetch_module_meta_data(specifier, referrer)?;
|
let out = sc.state().dir.fetch_module_meta_data(specifier, referrer)?;
|
||||||
let data_off = builder.create_vector(out.source_code.as_slice());
|
let data_off = builder.create_vector(out.source_code.as_slice());
|
||||||
let msg_args = msg::FetchModuleMetaDataResArgs {
|
let msg_args = msg::FetchModuleMetaDataResArgs {
|
||||||
module_name: Some(builder.create_string(&out.module_name)),
|
module_name: Some(builder.create_string(&out.module_name)),
|
||||||
|
@ -425,7 +423,7 @@ fn op_fetch_module_meta_data(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn op_chdir(
|
fn op_chdir(
|
||||||
_cli: &Cli,
|
_sc: Box<&IsolateStateContainer>,
|
||||||
base: &msg::Base<'_>,
|
base: &msg::Base<'_>,
|
||||||
data: deno_buf,
|
data: deno_buf,
|
||||||
) -> Box<OpWithError> {
|
) -> Box<OpWithError> {
|
||||||
|
@ -439,19 +437,20 @@ fn op_chdir(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn op_global_timer_stop(
|
fn op_global_timer_stop(
|
||||||
cli: &Cli,
|
sc: Box<&IsolateStateContainer>,
|
||||||
base: &msg::Base<'_>,
|
base: &msg::Base<'_>,
|
||||||
data: deno_buf,
|
data: deno_buf,
|
||||||
) -> Box<OpWithError> {
|
) -> Box<OpWithError> {
|
||||||
assert!(base.sync());
|
assert!(base.sync());
|
||||||
assert_eq!(data.len(), 0);
|
assert_eq!(data.len(), 0);
|
||||||
let mut t = cli.state.global_timer.lock().unwrap();
|
let state = sc.state();
|
||||||
|
let mut t = state.global_timer.lock().unwrap();
|
||||||
t.cancel();
|
t.cancel();
|
||||||
ok_future(empty_buf())
|
ok_future(empty_buf())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn op_global_timer(
|
fn op_global_timer(
|
||||||
cli: &Cli,
|
sc: Box<&IsolateStateContainer>,
|
||||||
base: &msg::Base<'_>,
|
base: &msg::Base<'_>,
|
||||||
data: deno_buf,
|
data: deno_buf,
|
||||||
) -> Box<OpWithError> {
|
) -> Box<OpWithError> {
|
||||||
|
@ -462,7 +461,8 @@ fn op_global_timer(
|
||||||
let val = inner.timeout();
|
let val = inner.timeout();
|
||||||
assert!(val >= 0);
|
assert!(val >= 0);
|
||||||
|
|
||||||
let mut t = cli.state.global_timer.lock().unwrap();
|
let state = sc.state();
|
||||||
|
let mut t = state.global_timer.lock().unwrap();
|
||||||
let deadline = Instant::now() + Duration::from_millis(val as u64);
|
let deadline = Instant::now() + Duration::from_millis(val as u64);
|
||||||
let f = t.new_timeout(deadline);
|
let f = t.new_timeout(deadline);
|
||||||
|
|
||||||
|
@ -483,7 +483,7 @@ fn op_global_timer(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn op_set_env(
|
fn op_set_env(
|
||||||
cli: &Cli,
|
sc: Box<&IsolateStateContainer>,
|
||||||
base: &msg::Base<'_>,
|
base: &msg::Base<'_>,
|
||||||
data: deno_buf,
|
data: deno_buf,
|
||||||
) -> Box<OpWithError> {
|
) -> Box<OpWithError> {
|
||||||
|
@ -491,18 +491,22 @@ fn op_set_env(
|
||||||
let inner = base.inner_as_set_env().unwrap();
|
let inner = base.inner_as_set_env().unwrap();
|
||||||
let key = inner.key().unwrap();
|
let key = inner.key().unwrap();
|
||||||
let value = inner.value().unwrap();
|
let value = inner.value().unwrap();
|
||||||
if let Err(e) = cli.check_env() {
|
if let Err(e) = sc.state().check_env() {
|
||||||
return odd_future(e);
|
return odd_future(e);
|
||||||
}
|
}
|
||||||
std::env::set_var(key, value);
|
std::env::set_var(key, value);
|
||||||
ok_future(empty_buf())
|
ok_future(empty_buf())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn op_env(cli: &Cli, base: &msg::Base<'_>, data: deno_buf) -> Box<OpWithError> {
|
fn op_env(
|
||||||
|
sc: Box<&IsolateStateContainer>,
|
||||||
|
base: &msg::Base<'_>,
|
||||||
|
data: deno_buf,
|
||||||
|
) -> Box<OpWithError> {
|
||||||
assert_eq!(data.len(), 0);
|
assert_eq!(data.len(), 0);
|
||||||
let cmd_id = base.cmd_id();
|
let cmd_id = base.cmd_id();
|
||||||
|
|
||||||
if let Err(e) = cli.check_env() {
|
if let Err(e) = sc.state().check_env() {
|
||||||
return odd_future(e);
|
return odd_future(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -527,7 +531,7 @@ fn op_env(cli: &Cli, base: &msg::Base<'_>, data: deno_buf) -> Box<OpWithError> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn op_permissions(
|
fn op_permissions(
|
||||||
cli: &Cli,
|
sc: Box<&IsolateStateContainer>,
|
||||||
base: &msg::Base<'_>,
|
base: &msg::Base<'_>,
|
||||||
data: deno_buf,
|
data: deno_buf,
|
||||||
) -> Box<OpWithError> {
|
) -> Box<OpWithError> {
|
||||||
|
@ -537,11 +541,11 @@ fn op_permissions(
|
||||||
let inner = msg::PermissionsRes::create(
|
let inner = msg::PermissionsRes::create(
|
||||||
builder,
|
builder,
|
||||||
&msg::PermissionsResArgs {
|
&msg::PermissionsResArgs {
|
||||||
run: cli.permissions.allows_run(),
|
run: sc.state().permissions.allows_run(),
|
||||||
read: cli.permissions.allows_read(),
|
read: sc.state().permissions.allows_read(),
|
||||||
write: cli.permissions.allows_write(),
|
write: sc.state().permissions.allows_write(),
|
||||||
net: cli.permissions.allows_net(),
|
net: sc.state().permissions.allows_net(),
|
||||||
env: cli.permissions.allows_env(),
|
env: sc.state().permissions.allows_env(),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
ok_future(serialize_response(
|
ok_future(serialize_response(
|
||||||
|
@ -556,7 +560,7 @@ fn op_permissions(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn op_revoke_permission(
|
fn op_revoke_permission(
|
||||||
cli: &Cli,
|
sc: Box<&IsolateStateContainer>,
|
||||||
base: &msg::Base<'_>,
|
base: &msg::Base<'_>,
|
||||||
data: deno_buf,
|
data: deno_buf,
|
||||||
) -> Box<OpWithError> {
|
) -> Box<OpWithError> {
|
||||||
|
@ -564,11 +568,11 @@ fn op_revoke_permission(
|
||||||
let inner = base.inner_as_permission_revoke().unwrap();
|
let inner = base.inner_as_permission_revoke().unwrap();
|
||||||
let permission = inner.permission().unwrap();
|
let permission = inner.permission().unwrap();
|
||||||
let result = match permission {
|
let result = match permission {
|
||||||
"run" => cli.permissions.revoke_run(),
|
"run" => sc.state().permissions.revoke_run(),
|
||||||
"read" => cli.permissions.revoke_read(),
|
"read" => sc.state().permissions.revoke_read(),
|
||||||
"write" => cli.permissions.revoke_write(),
|
"write" => sc.state().permissions.revoke_write(),
|
||||||
"net" => cli.permissions.revoke_net(),
|
"net" => sc.state().permissions.revoke_net(),
|
||||||
"env" => cli.permissions.revoke_env(),
|
"env" => sc.state().permissions.revoke_env(),
|
||||||
_ => Ok(()),
|
_ => Ok(()),
|
||||||
};
|
};
|
||||||
if let Err(e) = result {
|
if let Err(e) = result {
|
||||||
|
@ -578,7 +582,7 @@ fn op_revoke_permission(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn op_fetch(
|
fn op_fetch(
|
||||||
cli: &Cli,
|
sc: Box<&IsolateStateContainer>,
|
||||||
base: &msg::Base<'_>,
|
base: &msg::Base<'_>,
|
||||||
data: deno_buf,
|
data: deno_buf,
|
||||||
) -> Box<OpWithError> {
|
) -> Box<OpWithError> {
|
||||||
|
@ -601,7 +605,7 @@ fn op_fetch(
|
||||||
}
|
}
|
||||||
let req = maybe_req.unwrap();
|
let req = maybe_req.unwrap();
|
||||||
|
|
||||||
if let Err(e) = cli.check_net(url) {
|
if let Err(e) = sc.state().check_net(url) {
|
||||||
return odd_future(e);
|
return odd_future(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -665,7 +669,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
fn op_make_temp_dir(
|
fn op_make_temp_dir(
|
||||||
cli: &Cli,
|
sc: Box<&IsolateStateContainer>,
|
||||||
base: &msg::Base<'_>,
|
base: &msg::Base<'_>,
|
||||||
data: deno_buf,
|
data: deno_buf,
|
||||||
) -> Box<OpWithError> {
|
) -> Box<OpWithError> {
|
||||||
|
@ -675,7 +679,7 @@ fn op_make_temp_dir(
|
||||||
let cmd_id = base.cmd_id();
|
let cmd_id = base.cmd_id();
|
||||||
|
|
||||||
// FIXME
|
// FIXME
|
||||||
if let Err(e) = cli.check_write("make_temp") {
|
if let Err(e) = sc.state().check_write("make_temp") {
|
||||||
return odd_future(e);
|
return odd_future(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -714,7 +718,7 @@ fn op_make_temp_dir(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn op_mkdir(
|
fn op_mkdir(
|
||||||
cli: &Cli,
|
sc: Box<&IsolateStateContainer>,
|
||||||
base: &msg::Base<'_>,
|
base: &msg::Base<'_>,
|
||||||
data: deno_buf,
|
data: deno_buf,
|
||||||
) -> Box<OpWithError> {
|
) -> Box<OpWithError> {
|
||||||
|
@ -724,7 +728,7 @@ fn op_mkdir(
|
||||||
let recursive = inner.recursive();
|
let recursive = inner.recursive();
|
||||||
let mode = inner.mode();
|
let mode = inner.mode();
|
||||||
|
|
||||||
if let Err(e) = cli.check_write(&path) {
|
if let Err(e) = sc.state().check_write(&path) {
|
||||||
return odd_future(e);
|
return odd_future(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -736,7 +740,7 @@ fn op_mkdir(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn op_chmod(
|
fn op_chmod(
|
||||||
cli: &Cli,
|
sc: Box<&IsolateStateContainer>,
|
||||||
base: &msg::Base<'_>,
|
base: &msg::Base<'_>,
|
||||||
data: deno_buf,
|
data: deno_buf,
|
||||||
) -> Box<OpWithError> {
|
) -> Box<OpWithError> {
|
||||||
|
@ -745,7 +749,7 @@ fn op_chmod(
|
||||||
let _mode = inner.mode();
|
let _mode = inner.mode();
|
||||||
let path = String::from(inner.path().unwrap());
|
let path = String::from(inner.path().unwrap());
|
||||||
|
|
||||||
if let Err(e) = cli.check_write(&path) {
|
if let Err(e) = sc.state().check_write(&path) {
|
||||||
return odd_future(e);
|
return odd_future(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -775,7 +779,7 @@ fn op_chmod(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn op_open(
|
fn op_open(
|
||||||
cli: &Cli,
|
sc: Box<&IsolateStateContainer>,
|
||||||
base: &msg::Base<'_>,
|
base: &msg::Base<'_>,
|
||||||
data: deno_buf,
|
data: deno_buf,
|
||||||
) -> Box<OpWithError> {
|
) -> Box<OpWithError> {
|
||||||
|
@ -824,20 +828,20 @@ fn op_open(
|
||||||
|
|
||||||
match mode {
|
match mode {
|
||||||
"r" => {
|
"r" => {
|
||||||
if let Err(e) = cli.check_read(&filename_str) {
|
if let Err(e) = sc.state().check_read(&filename_str) {
|
||||||
return odd_future(e);
|
return odd_future(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"w" | "a" | "x" => {
|
"w" | "a" | "x" => {
|
||||||
if let Err(e) = cli.check_write(&filename_str) {
|
if let Err(e) = sc.state().check_write(&filename_str) {
|
||||||
return odd_future(e);
|
return odd_future(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
&_ => {
|
&_ => {
|
||||||
if let Err(e) = cli.check_read(&filename_str) {
|
if let Err(e) = sc.state().check_read(&filename_str) {
|
||||||
return odd_future(e);
|
return odd_future(e);
|
||||||
}
|
}
|
||||||
if let Err(e) = cli.check_write(&filename_str) {
|
if let Err(e) = sc.state().check_write(&filename_str) {
|
||||||
return odd_future(e);
|
return odd_future(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -865,7 +869,7 @@ fn op_open(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn op_close(
|
fn op_close(
|
||||||
_cli: &Cli,
|
_sc: Box<&IsolateStateContainer>,
|
||||||
base: &msg::Base<'_>,
|
base: &msg::Base<'_>,
|
||||||
data: deno_buf,
|
data: deno_buf,
|
||||||
) -> Box<OpWithError> {
|
) -> Box<OpWithError> {
|
||||||
|
@ -882,7 +886,7 @@ fn op_close(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn op_shutdown(
|
fn op_shutdown(
|
||||||
_cli: &Cli,
|
_sc: Box<&IsolateStateContainer>,
|
||||||
base: &msg::Base<'_>,
|
base: &msg::Base<'_>,
|
||||||
data: deno_buf,
|
data: deno_buf,
|
||||||
) -> Box<OpWithError> {
|
) -> Box<OpWithError> {
|
||||||
|
@ -908,7 +912,7 @@ fn op_shutdown(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn op_read(
|
fn op_read(
|
||||||
_cli: &Cli,
|
_sc: Box<&IsolateStateContainer>,
|
||||||
base: &msg::Base<'_>,
|
base: &msg::Base<'_>,
|
||||||
data: deno_buf,
|
data: deno_buf,
|
||||||
) -> Box<OpWithError> {
|
) -> Box<OpWithError> {
|
||||||
|
@ -946,7 +950,7 @@ fn op_read(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn op_write(
|
fn op_write(
|
||||||
_cli: &Cli,
|
_sc: Box<&IsolateStateContainer>,
|
||||||
base: &msg::Base<'_>,
|
base: &msg::Base<'_>,
|
||||||
data: deno_buf,
|
data: deno_buf,
|
||||||
) -> Box<OpWithError> {
|
) -> Box<OpWithError> {
|
||||||
|
@ -983,7 +987,7 @@ fn op_write(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn op_seek(
|
fn op_seek(
|
||||||
_cli: &Cli,
|
_sc: Box<&IsolateStateContainer>,
|
||||||
base: &msg::Base<'_>,
|
base: &msg::Base<'_>,
|
||||||
data: deno_buf,
|
data: deno_buf,
|
||||||
) -> Box<OpWithError> {
|
) -> Box<OpWithError> {
|
||||||
|
@ -1005,7 +1009,7 @@ fn op_seek(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn op_remove(
|
fn op_remove(
|
||||||
cli: &Cli,
|
sc: Box<&IsolateStateContainer>,
|
||||||
base: &msg::Base<'_>,
|
base: &msg::Base<'_>,
|
||||||
data: deno_buf,
|
data: deno_buf,
|
||||||
) -> Box<OpWithError> {
|
) -> Box<OpWithError> {
|
||||||
|
@ -1015,7 +1019,7 @@ fn op_remove(
|
||||||
let path = PathBuf::from(path_);
|
let path = PathBuf::from(path_);
|
||||||
let recursive = inner.recursive();
|
let recursive = inner.recursive();
|
||||||
|
|
||||||
if let Err(e) = cli.check_write(path.to_str().unwrap()) {
|
if let Err(e) = sc.state().check_write(path.to_str().unwrap()) {
|
||||||
return odd_future(e);
|
return odd_future(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1035,7 +1039,7 @@ fn op_remove(
|
||||||
|
|
||||||
// Prototype https://github.com/denoland/deno/blob/golang/os.go#L171-L184
|
// Prototype https://github.com/denoland/deno/blob/golang/os.go#L171-L184
|
||||||
fn op_read_file(
|
fn op_read_file(
|
||||||
cli: &Cli,
|
sc: Box<&IsolateStateContainer>,
|
||||||
base: &msg::Base<'_>,
|
base: &msg::Base<'_>,
|
||||||
data: deno_buf,
|
data: deno_buf,
|
||||||
) -> Box<OpWithError> {
|
) -> Box<OpWithError> {
|
||||||
|
@ -1045,7 +1049,7 @@ fn op_read_file(
|
||||||
let filename_ = inner.filename().unwrap();
|
let filename_ = inner.filename().unwrap();
|
||||||
let filename = PathBuf::from(filename_);
|
let filename = PathBuf::from(filename_);
|
||||||
debug!("op_read_file {}", filename.display());
|
debug!("op_read_file {}", filename.display());
|
||||||
if let Err(e) = cli.check_read(&filename_) {
|
if let Err(e) = sc.state().check_read(&filename_) {
|
||||||
return odd_future(e);
|
return odd_future(e);
|
||||||
}
|
}
|
||||||
blocking(base.sync(), move || {
|
blocking(base.sync(), move || {
|
||||||
|
@ -1073,7 +1077,7 @@ fn op_read_file(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn op_copy_file(
|
fn op_copy_file(
|
||||||
cli: &Cli,
|
sc: Box<&IsolateStateContainer>,
|
||||||
base: &msg::Base<'_>,
|
base: &msg::Base<'_>,
|
||||||
data: deno_buf,
|
data: deno_buf,
|
||||||
) -> Box<OpWithError> {
|
) -> Box<OpWithError> {
|
||||||
|
@ -1084,10 +1088,10 @@ fn op_copy_file(
|
||||||
let to_ = inner.to().unwrap();
|
let to_ = inner.to().unwrap();
|
||||||
let to = PathBuf::from(to_);
|
let to = PathBuf::from(to_);
|
||||||
|
|
||||||
if let Err(e) = cli.check_read(&from_) {
|
if let Err(e) = sc.state().check_read(&from_) {
|
||||||
return odd_future(e);
|
return odd_future(e);
|
||||||
}
|
}
|
||||||
if let Err(e) = cli.check_write(&to_) {
|
if let Err(e) = sc.state().check_write(&to_) {
|
||||||
return odd_future(e);
|
return odd_future(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1129,7 +1133,7 @@ fn get_mode(_perm: &fs::Permissions) -> u32 {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn op_cwd(
|
fn op_cwd(
|
||||||
_cli: &Cli,
|
_sc: Box<&IsolateStateContainer>,
|
||||||
base: &msg::Base<'_>,
|
base: &msg::Base<'_>,
|
||||||
data: deno_buf,
|
data: deno_buf,
|
||||||
) -> Box<OpWithError> {
|
) -> Box<OpWithError> {
|
||||||
|
@ -1155,7 +1159,7 @@ fn op_cwd(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn op_stat(
|
fn op_stat(
|
||||||
cli: &Cli,
|
sc: Box<&IsolateStateContainer>,
|
||||||
base: &msg::Base<'_>,
|
base: &msg::Base<'_>,
|
||||||
data: deno_buf,
|
data: deno_buf,
|
||||||
) -> Box<OpWithError> {
|
) -> Box<OpWithError> {
|
||||||
|
@ -1166,7 +1170,7 @@ fn op_stat(
|
||||||
let filename = PathBuf::from(filename_);
|
let filename = PathBuf::from(filename_);
|
||||||
let lstat = inner.lstat();
|
let lstat = inner.lstat();
|
||||||
|
|
||||||
if let Err(e) = cli.check_read(&filename_) {
|
if let Err(e) = sc.state().check_read(&filename_) {
|
||||||
return odd_future(e);
|
return odd_future(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1207,7 +1211,7 @@ fn op_stat(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn op_read_dir(
|
fn op_read_dir(
|
||||||
cli: &Cli,
|
sc: Box<&IsolateStateContainer>,
|
||||||
base: &msg::Base<'_>,
|
base: &msg::Base<'_>,
|
||||||
data: deno_buf,
|
data: deno_buf,
|
||||||
) -> Box<OpWithError> {
|
) -> Box<OpWithError> {
|
||||||
|
@ -1216,7 +1220,7 @@ fn op_read_dir(
|
||||||
let cmd_id = base.cmd_id();
|
let cmd_id = base.cmd_id();
|
||||||
let path = String::from(inner.path().unwrap());
|
let path = String::from(inner.path().unwrap());
|
||||||
|
|
||||||
if let Err(e) = cli.check_read(&path) {
|
if let Err(e) = sc.state().check_read(&path) {
|
||||||
return odd_future(e);
|
return odd_future(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1268,7 +1272,7 @@ fn op_read_dir(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn op_write_file(
|
fn op_write_file(
|
||||||
cli: &Cli,
|
sc: Box<&IsolateStateContainer>,
|
||||||
base: &msg::Base<'_>,
|
base: &msg::Base<'_>,
|
||||||
data: deno_buf,
|
data: deno_buf,
|
||||||
) -> Box<OpWithError> {
|
) -> Box<OpWithError> {
|
||||||
|
@ -1279,7 +1283,7 @@ fn op_write_file(
|
||||||
let is_create = inner.is_create();
|
let is_create = inner.is_create();
|
||||||
let is_append = inner.is_append();
|
let is_append = inner.is_append();
|
||||||
|
|
||||||
if let Err(e) = cli.check_write(&filename) {
|
if let Err(e) = sc.state().check_write(&filename) {
|
||||||
return odd_future(e);
|
return odd_future(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1298,7 +1302,7 @@ fn op_write_file(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn op_rename(
|
fn op_rename(
|
||||||
cli: &Cli,
|
sc: Box<&IsolateStateContainer>,
|
||||||
base: &msg::Base<'_>,
|
base: &msg::Base<'_>,
|
||||||
data: deno_buf,
|
data: deno_buf,
|
||||||
) -> Box<OpWithError> {
|
) -> Box<OpWithError> {
|
||||||
|
@ -1307,7 +1311,7 @@ fn op_rename(
|
||||||
let oldpath = PathBuf::from(inner.oldpath().unwrap());
|
let oldpath = PathBuf::from(inner.oldpath().unwrap());
|
||||||
let newpath_ = inner.newpath().unwrap();
|
let newpath_ = inner.newpath().unwrap();
|
||||||
let newpath = PathBuf::from(newpath_);
|
let newpath = PathBuf::from(newpath_);
|
||||||
if let Err(e) = cli.check_write(&newpath_) {
|
if let Err(e) = sc.state().check_write(&newpath_) {
|
||||||
return odd_future(e);
|
return odd_future(e);
|
||||||
}
|
}
|
||||||
blocking(base.sync(), move || -> OpResult {
|
blocking(base.sync(), move || -> OpResult {
|
||||||
|
@ -1318,7 +1322,7 @@ fn op_rename(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn op_symlink(
|
fn op_symlink(
|
||||||
cli: &Cli,
|
sc: Box<&IsolateStateContainer>,
|
||||||
base: &msg::Base<'_>,
|
base: &msg::Base<'_>,
|
||||||
data: deno_buf,
|
data: deno_buf,
|
||||||
) -> Box<OpWithError> {
|
) -> Box<OpWithError> {
|
||||||
|
@ -1328,7 +1332,7 @@ fn op_symlink(
|
||||||
let newname_ = inner.newname().unwrap();
|
let newname_ = inner.newname().unwrap();
|
||||||
let newname = PathBuf::from(newname_);
|
let newname = PathBuf::from(newname_);
|
||||||
|
|
||||||
if let Err(e) = cli.check_write(&newname_) {
|
if let Err(e) = sc.state().check_write(&newname_) {
|
||||||
return odd_future(e);
|
return odd_future(e);
|
||||||
}
|
}
|
||||||
// TODO Use type for Windows.
|
// TODO Use type for Windows.
|
||||||
|
@ -1347,7 +1351,7 @@ fn op_symlink(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn op_read_link(
|
fn op_read_link(
|
||||||
cli: &Cli,
|
sc: Box<&IsolateStateContainer>,
|
||||||
base: &msg::Base<'_>,
|
base: &msg::Base<'_>,
|
||||||
data: deno_buf,
|
data: deno_buf,
|
||||||
) -> Box<OpWithError> {
|
) -> Box<OpWithError> {
|
||||||
|
@ -1357,7 +1361,7 @@ fn op_read_link(
|
||||||
let name_ = inner.name().unwrap();
|
let name_ = inner.name().unwrap();
|
||||||
let name = PathBuf::from(name_);
|
let name = PathBuf::from(name_);
|
||||||
|
|
||||||
if let Err(e) = cli.check_read(&name_) {
|
if let Err(e) = sc.state().check_read(&name_) {
|
||||||
return odd_future(e);
|
return odd_future(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1385,7 +1389,7 @@ fn op_read_link(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn op_repl_start(
|
fn op_repl_start(
|
||||||
cli: &Cli,
|
sc: Box<&IsolateStateContainer>,
|
||||||
base: &msg::Base<'_>,
|
base: &msg::Base<'_>,
|
||||||
data: deno_buf,
|
data: deno_buf,
|
||||||
) -> Box<OpWithError> {
|
) -> Box<OpWithError> {
|
||||||
|
@ -1395,7 +1399,7 @@ fn op_repl_start(
|
||||||
let history_file = String::from(inner.history_file().unwrap());
|
let history_file = String::from(inner.history_file().unwrap());
|
||||||
|
|
||||||
debug!("op_repl_start {}", history_file);
|
debug!("op_repl_start {}", history_file);
|
||||||
let history_path = repl::history_path(&cli.state.dir, &history_file);
|
let history_path = repl::history_path(&sc.state().dir, &history_file);
|
||||||
let repl = repl::Repl::new(history_path);
|
let repl = repl::Repl::new(history_path);
|
||||||
let resource = resources::add_repl(repl);
|
let resource = resources::add_repl(repl);
|
||||||
|
|
||||||
|
@ -1416,7 +1420,7 @@ fn op_repl_start(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn op_repl_readline(
|
fn op_repl_readline(
|
||||||
_cli: &Cli,
|
_sc: Box<&IsolateStateContainer>,
|
||||||
base: &msg::Base<'_>,
|
base: &msg::Base<'_>,
|
||||||
data: deno_buf,
|
data: deno_buf,
|
||||||
) -> Box<OpWithError> {
|
) -> Box<OpWithError> {
|
||||||
|
@ -1452,7 +1456,7 @@ fn op_repl_readline(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn op_truncate(
|
fn op_truncate(
|
||||||
cli: &Cli,
|
sc: Box<&IsolateStateContainer>,
|
||||||
base: &msg::Base<'_>,
|
base: &msg::Base<'_>,
|
||||||
data: deno_buf,
|
data: deno_buf,
|
||||||
) -> Box<OpWithError> {
|
) -> Box<OpWithError> {
|
||||||
|
@ -1462,7 +1466,7 @@ fn op_truncate(
|
||||||
let filename = String::from(inner.name().unwrap());
|
let filename = String::from(inner.name().unwrap());
|
||||||
let len = inner.len();
|
let len = inner.len();
|
||||||
|
|
||||||
if let Err(e) = cli.check_write(&filename) {
|
if let Err(e) = sc.state().check_write(&filename) {
|
||||||
return odd_future(e);
|
return odd_future(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1475,12 +1479,12 @@ fn op_truncate(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn op_listen(
|
fn op_listen(
|
||||||
cli: &Cli,
|
sc: Box<&IsolateStateContainer>,
|
||||||
base: &msg::Base<'_>,
|
base: &msg::Base<'_>,
|
||||||
data: deno_buf,
|
data: deno_buf,
|
||||||
) -> Box<OpWithError> {
|
) -> Box<OpWithError> {
|
||||||
assert_eq!(data.len(), 0);
|
assert_eq!(data.len(), 0);
|
||||||
if let Err(e) = cli.check_net("listen") {
|
if let Err(e) = sc.state().check_net("listen") {
|
||||||
return odd_future(e);
|
return odd_future(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1537,12 +1541,12 @@ fn new_conn(cmd_id: u32, tcp_stream: TcpStream) -> OpResult {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn op_accept(
|
fn op_accept(
|
||||||
cli: &Cli,
|
sc: Box<&IsolateStateContainer>,
|
||||||
base: &msg::Base<'_>,
|
base: &msg::Base<'_>,
|
||||||
data: deno_buf,
|
data: deno_buf,
|
||||||
) -> Box<OpWithError> {
|
) -> Box<OpWithError> {
|
||||||
assert_eq!(data.len(), 0);
|
assert_eq!(data.len(), 0);
|
||||||
if let Err(e) = cli.check_net("accept") {
|
if let Err(e) = sc.state().check_net("accept") {
|
||||||
return odd_future(e);
|
return odd_future(e);
|
||||||
}
|
}
|
||||||
let cmd_id = base.cmd_id();
|
let cmd_id = base.cmd_id();
|
||||||
|
@ -1563,12 +1567,12 @@ fn op_accept(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn op_dial(
|
fn op_dial(
|
||||||
cli: &Cli,
|
sc: Box<&IsolateStateContainer>,
|
||||||
base: &msg::Base<'_>,
|
base: &msg::Base<'_>,
|
||||||
data: deno_buf,
|
data: deno_buf,
|
||||||
) -> Box<OpWithError> {
|
) -> Box<OpWithError> {
|
||||||
assert_eq!(data.len(), 0);
|
assert_eq!(data.len(), 0);
|
||||||
if let Err(e) = cli.check_net("dial") {
|
if let Err(e) = sc.state().check_net("dial") {
|
||||||
return odd_future(e);
|
return odd_future(e);
|
||||||
}
|
}
|
||||||
let cmd_id = base.cmd_id();
|
let cmd_id = base.cmd_id();
|
||||||
|
@ -1589,7 +1593,7 @@ fn op_dial(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn op_metrics(
|
fn op_metrics(
|
||||||
cli: &Cli,
|
sc: Box<&IsolateStateContainer>,
|
||||||
base: &msg::Base<'_>,
|
base: &msg::Base<'_>,
|
||||||
data: deno_buf,
|
data: deno_buf,
|
||||||
) -> Box<OpWithError> {
|
) -> Box<OpWithError> {
|
||||||
|
@ -1599,7 +1603,7 @@ fn op_metrics(
|
||||||
let builder = &mut FlatBufferBuilder::new();
|
let builder = &mut FlatBufferBuilder::new();
|
||||||
let inner = msg::MetricsRes::create(
|
let inner = msg::MetricsRes::create(
|
||||||
builder,
|
builder,
|
||||||
&msg::MetricsResArgs::from(&cli.state.metrics),
|
&msg::MetricsResArgs::from(&sc.state().metrics),
|
||||||
);
|
);
|
||||||
ok_future(serialize_response(
|
ok_future(serialize_response(
|
||||||
cmd_id,
|
cmd_id,
|
||||||
|
@ -1613,7 +1617,7 @@ fn op_metrics(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn op_resources(
|
fn op_resources(
|
||||||
_cli: &Cli,
|
_sc: Box<&IsolateStateContainer>,
|
||||||
base: &msg::Base<'_>,
|
base: &msg::Base<'_>,
|
||||||
data: deno_buf,
|
data: deno_buf,
|
||||||
) -> Box<OpWithError> {
|
) -> Box<OpWithError> {
|
||||||
|
@ -1664,11 +1668,15 @@ fn subprocess_stdio_map(v: msg::ProcessStdio) -> std::process::Stdio {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn op_run(cli: &Cli, base: &msg::Base<'_>, data: deno_buf) -> Box<OpWithError> {
|
fn op_run(
|
||||||
|
sc: Box<&IsolateStateContainer>,
|
||||||
|
base: &msg::Base<'_>,
|
||||||
|
data: deno_buf,
|
||||||
|
) -> Box<OpWithError> {
|
||||||
assert!(base.sync());
|
assert!(base.sync());
|
||||||
let cmd_id = base.cmd_id();
|
let cmd_id = base.cmd_id();
|
||||||
|
|
||||||
if let Err(e) = cli.check_run() {
|
if let Err(e) = sc.state().check_run() {
|
||||||
return odd_future(e);
|
return odd_future(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1734,7 +1742,7 @@ fn op_run(cli: &Cli, base: &msg::Base<'_>, data: deno_buf) -> Box<OpWithError> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn op_run_status(
|
fn op_run_status(
|
||||||
cli: &Cli,
|
sc: Box<&IsolateStateContainer>,
|
||||||
base: &msg::Base<'_>,
|
base: &msg::Base<'_>,
|
||||||
data: deno_buf,
|
data: deno_buf,
|
||||||
) -> Box<OpWithError> {
|
) -> Box<OpWithError> {
|
||||||
|
@ -1743,7 +1751,7 @@ fn op_run_status(
|
||||||
let inner = base.inner_as_run_status().unwrap();
|
let inner = base.inner_as_run_status().unwrap();
|
||||||
let rid = inner.rid();
|
let rid = inner.rid();
|
||||||
|
|
||||||
if let Err(e) = cli.check_run() {
|
if let Err(e) = sc.state().check_run() {
|
||||||
return odd_future(e);
|
return odd_future(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1810,7 +1818,7 @@ impl Future for GetMessageFuture {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn op_worker_get_message(
|
fn op_worker_get_message(
|
||||||
cli: &Cli,
|
sc: Box<&IsolateStateContainer>,
|
||||||
base: &msg::Base<'_>,
|
base: &msg::Base<'_>,
|
||||||
data: deno_buf,
|
data: deno_buf,
|
||||||
) -> Box<OpWithError> {
|
) -> Box<OpWithError> {
|
||||||
|
@ -1818,7 +1826,7 @@ fn op_worker_get_message(
|
||||||
let cmd_id = base.cmd_id();
|
let cmd_id = base.cmd_id();
|
||||||
|
|
||||||
let op = GetMessageFuture {
|
let op = GetMessageFuture {
|
||||||
state: cli.state.clone(),
|
state: sc.state().clone(),
|
||||||
};
|
};
|
||||||
let op = op.map_err(move |_| -> DenoError { unimplemented!() });
|
let op = op.map_err(move |_| -> DenoError { unimplemented!() });
|
||||||
let op = op.and_then(move |maybe_buf| -> DenoResult<Buf> {
|
let op = op.and_then(move |maybe_buf| -> DenoResult<Buf> {
|
||||||
|
@ -1844,7 +1852,7 @@ fn op_worker_get_message(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn op_worker_post_message(
|
fn op_worker_post_message(
|
||||||
cli: &Cli,
|
sc: Box<&IsolateStateContainer>,
|
||||||
base: &msg::Base<'_>,
|
base: &msg::Base<'_>,
|
||||||
data: deno_buf,
|
data: deno_buf,
|
||||||
) -> Box<OpWithError> {
|
) -> Box<OpWithError> {
|
||||||
|
@ -1852,8 +1860,8 @@ fn op_worker_post_message(
|
||||||
|
|
||||||
let d = Vec::from(data.as_ref()).into_boxed_slice();
|
let d = Vec::from(data.as_ref()).into_boxed_slice();
|
||||||
|
|
||||||
assert!(cli.state.worker_channels.is_some());
|
assert!(sc.state().worker_channels.is_some());
|
||||||
let tx = match cli.state.worker_channels {
|
let tx = match sc.state().worker_channels {
|
||||||
None => panic!("expected worker_channels"),
|
None => panic!("expected worker_channels"),
|
||||||
Some(ref wc) => {
|
Some(ref wc) => {
|
||||||
let wc = wc.lock().unwrap();
|
let wc = wc.lock().unwrap();
|
||||||
|
@ -1876,6 +1884,7 @@ fn op_worker_post_message(
|
||||||
Box::new(op)
|
Box::new(op)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@ -1893,7 +1902,7 @@ mod tests {
|
||||||
allow_run: PermissionAccessor::from(true),
|
allow_run: PermissionAccessor::from(true),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
let cli = Cli::new(None, state, permissions);
|
let cli = Cli::new(None, state);
|
||||||
let builder = &mut FlatBufferBuilder::new();
|
let builder = &mut FlatBufferBuilder::new();
|
||||||
let fetch_msg_args = msg::FetchModuleMetaDataArgs {
|
let fetch_msg_args = msg::FetchModuleMetaDataArgs {
|
||||||
specifier: Some(builder.create_string("./somefile")),
|
specifier: Some(builder.create_string("./somefile")),
|
||||||
|
@ -1910,7 +1919,7 @@ mod tests {
|
||||||
let data = builder.finished_data();
|
let data = builder.finished_data();
|
||||||
let final_msg = msg::get_root_as_base(&data);
|
let final_msg = msg::get_root_as_base(&data);
|
||||||
let fetch_result =
|
let fetch_result =
|
||||||
op_fetch_module_meta_data(&cli, &final_msg, deno_buf::empty()).wait();
|
op_fetch_module_meta_data(Box::new(&cli), &final_msg, deno_buf::empty()).wait();
|
||||||
match fetch_result {
|
match fetch_result {
|
||||||
Ok(_) => assert!(true),
|
Ok(_) => assert!(true),
|
||||||
Err(e) => assert_eq!(e.to_string(), permission_denied().to_string()),
|
Err(e) => assert_eq!(e.to_string(), permission_denied().to_string()),
|
||||||
|
@ -2018,3 +2027,4 @@ mod tests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
|
@ -1,47 +1,42 @@
|
||||||
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
||||||
use crate::cli::Cli;
|
use crate::isolate::{DenoBehavior, Isolate};
|
||||||
use crate::flags::DenoFlags;
|
|
||||||
use crate::isolate::Isolate;
|
|
||||||
use crate::isolate_state::IsolateState;
|
|
||||||
use crate::isolate_state::WorkerChannels;
|
use crate::isolate_state::WorkerChannels;
|
||||||
use crate::js_errors::JSErrorColor;
|
use crate::js_errors::JSErrorColor;
|
||||||
use crate::permissions::DenoPermissions;
|
|
||||||
use crate::resources;
|
use crate::resources;
|
||||||
use crate::tokio_util;
|
use crate::tokio_util;
|
||||||
use deno_core::Buf;
|
use deno_core::Buf;
|
||||||
use deno_core::JSError;
|
use deno_core::JSError;
|
||||||
use deno_core::StartupData;
|
|
||||||
use futures::future::lazy;
|
use futures::future::lazy;
|
||||||
use futures::sync::mpsc;
|
use futures::sync::mpsc;
|
||||||
use futures::sync::oneshot;
|
use futures::sync::oneshot;
|
||||||
use futures::Future;
|
use futures::Future;
|
||||||
use futures::Poll;
|
use futures::Poll;
|
||||||
use std::sync::Arc;
|
|
||||||
use std::thread;
|
use std::thread;
|
||||||
|
|
||||||
/// Rust interface for WebWorkers.
|
/// Behavior trait specific to workers
|
||||||
pub struct Worker {
|
pub trait WorkerBehavior: DenoBehavior {
|
||||||
isolate: Isolate,
|
/// Used to setup internal channels at worker creation.
|
||||||
|
/// This is intended to be temporary fix.
|
||||||
|
/// TODO(afinch7) come up with a better solution to set worker channels
|
||||||
|
fn set_internal_channels(&mut self, worker_channels: WorkerChannels);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Worker {
|
/// Rust interface for WebWorkers.
|
||||||
pub fn new(
|
pub struct Worker<B: WorkerBehavior> {
|
||||||
startup_data: Option<StartupData>,
|
isolate: Isolate<B>,
|
||||||
flags: DenoFlags,
|
}
|
||||||
argv: Vec<String>,
|
|
||||||
permissions: DenoPermissions,
|
impl<B: WorkerBehavior> Worker<B> {
|
||||||
) -> (Self, WorkerChannels) {
|
pub fn new(mut behavior: B) -> (Self, WorkerChannels) {
|
||||||
let (worker_in_tx, worker_in_rx) = mpsc::channel::<Buf>(1);
|
let (worker_in_tx, worker_in_rx) = mpsc::channel::<Buf>(1);
|
||||||
let (worker_out_tx, worker_out_rx) = mpsc::channel::<Buf>(1);
|
let (worker_out_tx, worker_out_rx) = mpsc::channel::<Buf>(1);
|
||||||
|
|
||||||
let internal_channels = (worker_out_tx, worker_in_rx);
|
let internal_channels = (worker_out_tx, worker_in_rx);
|
||||||
let external_channels = (worker_in_tx, worker_out_rx);
|
let external_channels = (worker_in_tx, worker_out_rx);
|
||||||
|
|
||||||
let state =
|
behavior.set_internal_channels(internal_channels);
|
||||||
Arc::new(IsolateState::new(flags, argv, Some(internal_channels)));
|
|
||||||
|
|
||||||
let cli = Cli::new(startup_data, state, permissions);
|
let isolate = Isolate::new(behavior);
|
||||||
let isolate = Isolate::new(cli);
|
|
||||||
|
|
||||||
let worker = Worker { isolate };
|
let worker = Worker { isolate };
|
||||||
(worker, external_channels)
|
(worker, external_channels)
|
||||||
|
@ -52,7 +47,7 @@ impl Worker {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Future for Worker {
|
impl<B: WorkerBehavior> Future for Worker<B> {
|
||||||
type Item = ();
|
type Item = ();
|
||||||
type Error = JSError;
|
type Error = JSError;
|
||||||
|
|
||||||
|
@ -61,11 +56,9 @@ impl Future for Worker {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn spawn(
|
pub fn spawn<B: WorkerBehavior + 'static>(
|
||||||
startup_data: Option<StartupData>,
|
behavior: B,
|
||||||
state: &IsolateState,
|
|
||||||
js_source: String,
|
js_source: String,
|
||||||
permissions: DenoPermissions,
|
|
||||||
) -> resources::Resource {
|
) -> resources::Resource {
|
||||||
// TODO This function should return a Future, so that the caller can retrieve
|
// TODO This function should return a Future, so that the caller can retrieve
|
||||||
// the JSError if one is thrown. Currently it just prints to stderr and calls
|
// the JSError if one is thrown. Currently it just prints to stderr and calls
|
||||||
|
@ -74,14 +67,10 @@ pub fn spawn(
|
||||||
let (p, c) = oneshot::channel::<resources::Resource>();
|
let (p, c) = oneshot::channel::<resources::Resource>();
|
||||||
let builder = thread::Builder::new().name("worker".to_string());
|
let builder = thread::Builder::new().name("worker".to_string());
|
||||||
|
|
||||||
let flags = state.flags.clone();
|
|
||||||
let argv = state.argv.clone();
|
|
||||||
|
|
||||||
let _tid = builder
|
let _tid = builder
|
||||||
.spawn(move || {
|
.spawn(move || {
|
||||||
tokio_util::run(lazy(move || {
|
tokio_util::run(lazy(move || {
|
||||||
let (mut worker, external_channels) =
|
let (mut worker, external_channels) = Worker::new(behavior);
|
||||||
Worker::new(startup_data, flags, argv, permissions);
|
|
||||||
let resource = resources::add_worker(external_channels);
|
let resource = resources::add_worker(external_channels);
|
||||||
p.send(resource.clone()).unwrap();
|
p.send(resource.clone()).unwrap();
|
||||||
|
|
||||||
|
@ -113,14 +102,14 @@ pub fn spawn(
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::startup_data;
|
use crate::compiler::CompilerBehavior;
|
||||||
|
use crate::isolate_state::IsolateState;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_spawn() {
|
fn test_spawn() {
|
||||||
let startup_data = startup_data::compiler_isolate_init();
|
|
||||||
let resource = spawn(
|
let resource = spawn(
|
||||||
Some(startup_data),
|
CompilerBehavior::new(Arc::new(IsolateState::mock())),
|
||||||
&IsolateState::mock(),
|
|
||||||
r#"
|
r#"
|
||||||
onmessage = function(e) {
|
onmessage = function(e) {
|
||||||
let s = new TextDecoder().decode(e.data);;
|
let s = new TextDecoder().decode(e.data);;
|
||||||
|
@ -134,8 +123,7 @@ mod tests {
|
||||||
postMessage(new Uint8Array([1, 2, 3]));
|
postMessage(new Uint8Array([1, 2, 3]));
|
||||||
console.log("after postMessage");
|
console.log("after postMessage");
|
||||||
}
|
}
|
||||||
"#.into(),
|
"#.into(),
|
||||||
DenoPermissions::default(),
|
|
||||||
);
|
);
|
||||||
let msg = String::from("hi").into_boxed_str().into_boxed_bytes();
|
let msg = String::from("hi").into_boxed_str().into_boxed_bytes();
|
||||||
|
|
||||||
|
@ -154,12 +142,9 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn removed_from_resource_table_on_close() {
|
fn removed_from_resource_table_on_close() {
|
||||||
let startup_data = startup_data::compiler_isolate_init();
|
|
||||||
let resource = spawn(
|
let resource = spawn(
|
||||||
Some(startup_data),
|
CompilerBehavior::new(Arc::new(IsolateState::mock())),
|
||||||
&IsolateState::mock(),
|
|
||||||
"onmessage = () => close();".into(),
|
"onmessage = () => close();".into(),
|
||||||
DenoPermissions::default(),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|
|
@ -2,10 +2,9 @@
|
||||||
#![allow(unused_variables)]
|
#![allow(unused_variables)]
|
||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
|
|
||||||
use crate::errors::DenoResult;
|
use crate::isolate_state::IsolateStateContainer;
|
||||||
use crate::isolate_state::IsolateState;
|
use crate::isolate_state::IsolateState;
|
||||||
use crate::ops;
|
use crate::ops;
|
||||||
use crate::permissions::DenoPermissions;
|
|
||||||
use deno_core::deno_buf;
|
use deno_core::deno_buf;
|
||||||
use deno_core::deno_mod;
|
use deno_core::deno_mod;
|
||||||
use deno_core::Behavior;
|
use deno_core::Behavior;
|
||||||
|
@ -14,53 +13,30 @@ use deno_core::StartupData;
|
||||||
use std::sync::atomic::Ordering;
|
use std::sync::atomic::Ordering;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
// Buf represents a byte array returned from a "Op". The message might be empty
|
||||||
|
// (which will be translated into a null object on the javascript side) or it is
|
||||||
|
// a heap allocated opaque sequence of bytes. Usually a flatbuffer message.
|
||||||
|
pub type Buf = Box<[u8]>;
|
||||||
|
|
||||||
/// Implements deno_core::Behavior for the main Deno command-line.
|
/// Implements deno_core::Behavior for the main Deno command-line.
|
||||||
pub struct Cli {
|
pub struct CliBehavior {
|
||||||
startup_data: Option<StartupData>,
|
startup_data: Option<StartupData>,
|
||||||
pub state: Arc<IsolateState>,
|
pub state: Arc<IsolateState>,
|
||||||
pub permissions: Arc<DenoPermissions>, // TODO(ry) move to IsolateState
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Cli {
|
impl CliBehavior {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
startup_data: Option<StartupData>,
|
startup_data: Option<StartupData>,
|
||||||
state: Arc<IsolateState>,
|
state: Arc<IsolateState>,
|
||||||
permissions: DenoPermissions,
|
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
startup_data,
|
startup_data,
|
||||||
state,
|
state,
|
||||||
permissions: Arc::new(permissions),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn check_read(&self, filename: &str) -> DenoResult<()> {
|
|
||||||
self.permissions.check_read(filename)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn check_write(&self, filename: &str) -> DenoResult<()> {
|
|
||||||
self.permissions.check_write(filename)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn check_env(&self) -> DenoResult<()> {
|
|
||||||
self.permissions.check_env()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn check_net(&self, filename: &str) -> DenoResult<()> {
|
|
||||||
self.permissions.check_net(filename)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn check_run(&self) -> DenoResult<()> {
|
|
||||||
self.permissions.check_run()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Behavior for Cli {
|
impl Behavior for CliBehavior {
|
||||||
fn startup_data(&mut self) -> Option<StartupData> {
|
fn startup_data(&mut self) -> Option<StartupData> {
|
||||||
self.startup_data.take()
|
self.startup_data.take()
|
||||||
}
|
}
|
||||||
|
@ -80,6 +56,18 @@ impl Behavior for Cli {
|
||||||
control: &[u8],
|
control: &[u8],
|
||||||
zero_copy: deno_buf,
|
zero_copy: deno_buf,
|
||||||
) -> (bool, Box<Op>) {
|
) -> (bool, Box<Op>) {
|
||||||
ops::dispatch(self, control, zero_copy)
|
ops::dispatch_cli(self, control, zero_copy)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl IsolateStateContainer for CliBehavior {
|
||||||
|
fn state(&self) -> Arc<IsolateState> {
|
||||||
|
self.state.clone()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl IsolateStateContainer for &CliBehavior {
|
||||||
|
fn state(&self) -> Arc<IsolateState> {
|
||||||
|
self.state.clone()
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue