diff options
Diffstat (limited to 'cli/ops.rs')
-rw-r--r-- | cli/ops.rs | 113 |
1 files changed, 55 insertions, 58 deletions
diff --git a/cli/ops.rs b/cli/ops.rs index 3d43b2401..baa159a68 100644 --- a/cli/ops.rs +++ b/cli/ops.rs @@ -1,12 +1,10 @@ // Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. use atty; use crate::ansi; -use crate::cli_behavior::CliBehavior; use crate::errors; use crate::errors::{DenoError, DenoResult, ErrorKind}; use crate::fs as deno_fs; use crate::http_util; -use crate::isolate_state::IsolateState; use crate::js_errors::apply_source_map; use crate::js_errors::JSErrorColor; use crate::msg; @@ -17,6 +15,7 @@ use crate::resources; use crate::resources::table_entries; use crate::resources::Resource; use crate::startup_data; +use crate::state::ThreadSafeState; use crate::tokio_util; use crate::tokio_write; use crate::version; @@ -42,7 +41,6 @@ use std::net::Shutdown; use std::path::Path; use std::path::PathBuf; use std::process::Command; -use std::sync::Arc; use std::time::{Duration, Instant, UNIX_EPOCH}; use tokio; use tokio::net::TcpListener; @@ -62,7 +60,7 @@ pub type OpWithError = dyn Future<Item = Buf, Error = DenoError> + Send; // 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. type OpCreator = - fn(state: &Arc<IsolateState>, base: &msg::Base<'_>, data: deno_buf) + fn(state: &ThreadSafeState, base: &msg::Base<'_>, data: deno_buf) -> Box<OpWithError>; type OpSelector = fn(inner_type: msg::Any) -> Option<OpCreator>; @@ -77,7 +75,7 @@ fn empty_buf() -> Buf { /// control corresponds to the first argument of Deno.core.dispatch(). /// data corresponds to the second argument of Deno.core.dispatch(). pub fn dispatch_all( - state: &Arc<IsolateState>, + state: &ThreadSafeState, control: &[u8], zero_copy: deno_buf, op_selector: OpSelector, @@ -209,7 +207,7 @@ pub fn op_selector_std(inner_type: msg::Any) -> Option<OpCreator> { // If the High precision flag is not set, the // nanoseconds are rounded on 2ms. fn op_now( - state: &Arc<IsolateState>, + state: &ThreadSafeState, base: &msg::Base<'_>, data: deno_buf, ) -> Box<OpWithError> { @@ -245,7 +243,7 @@ fn op_now( } fn op_is_tty( - _state: &Arc<IsolateState>, + _state: &ThreadSafeState, base: &msg::Base<'_>, _data: deno_buf, ) -> Box<OpWithError> { @@ -270,7 +268,7 @@ fn op_is_tty( } fn op_exit( - _state: &Arc<IsolateState>, + _state: &ThreadSafeState, base: &msg::Base<'_>, _data: deno_buf, ) -> Box<OpWithError> { @@ -279,7 +277,7 @@ fn op_exit( } fn op_start( - state: &Arc<IsolateState>, + state: &ThreadSafeState, base: &msg::Base<'_>, data: deno_buf, ) -> Box<OpWithError> { @@ -335,7 +333,7 @@ fn op_start( } fn op_format_error( - state: &Arc<IsolateState>, + state: &ThreadSafeState, base: &msg::Base<'_>, data: deno_buf, ) -> Box<OpWithError> { @@ -394,7 +392,7 @@ pub fn odd_future(err: DenoError) -> Box<OpWithError> { // https://github.com/denoland/deno/blob/golang/os.go#L100-L154 fn op_fetch_module_meta_data( - state: &Arc<IsolateState>, + state: &ThreadSafeState, base: &msg::Base<'_>, data: deno_buf, ) -> Box<OpWithError> { @@ -435,7 +433,7 @@ fn op_fetch_module_meta_data( } fn op_chdir( - _state: &Arc<IsolateState>, + _state: &ThreadSafeState, base: &msg::Base<'_>, data: deno_buf, ) -> Box<OpWithError> { @@ -449,7 +447,7 @@ fn op_chdir( } fn op_global_timer_stop( - state: &Arc<IsolateState>, + state: &ThreadSafeState, base: &msg::Base<'_>, data: deno_buf, ) -> Box<OpWithError> { @@ -462,7 +460,7 @@ fn op_global_timer_stop( } fn op_global_timer( - state: &Arc<IsolateState>, + state: &ThreadSafeState, base: &msg::Base<'_>, data: deno_buf, ) -> Box<OpWithError> { @@ -495,7 +493,7 @@ fn op_global_timer( } fn op_set_env( - state: &Arc<IsolateState>, + state: &ThreadSafeState, base: &msg::Base<'_>, data: deno_buf, ) -> Box<OpWithError> { @@ -511,7 +509,7 @@ fn op_set_env( } fn op_env( - state: &Arc<IsolateState>, + state: &ThreadSafeState, base: &msg::Base<'_>, data: deno_buf, ) -> Box<OpWithError> { @@ -543,7 +541,7 @@ fn op_env( } fn op_permissions( - state: &Arc<IsolateState>, + state: &ThreadSafeState, base: &msg::Base<'_>, data: deno_buf, ) -> Box<OpWithError> { @@ -573,7 +571,7 @@ fn op_permissions( } fn op_revoke_permission( - state: &Arc<IsolateState>, + state: &ThreadSafeState, base: &msg::Base<'_>, data: deno_buf, ) -> Box<OpWithError> { @@ -596,7 +594,7 @@ fn op_revoke_permission( } fn op_fetch( - state: &Arc<IsolateState>, + state: &ThreadSafeState, base: &msg::Base<'_>, data: deno_buf, ) -> Box<OpWithError> { @@ -683,7 +681,7 @@ where } fn op_make_temp_dir( - state: &Arc<IsolateState>, + state: &ThreadSafeState, base: &msg::Base<'_>, data: deno_buf, ) -> Box<OpWithError> { @@ -732,7 +730,7 @@ fn op_make_temp_dir( } fn op_mkdir( - state: &Arc<IsolateState>, + state: &ThreadSafeState, base: &msg::Base<'_>, data: deno_buf, ) -> Box<OpWithError> { @@ -754,7 +752,7 @@ fn op_mkdir( } fn op_chmod( - state: &Arc<IsolateState>, + state: &ThreadSafeState, base: &msg::Base<'_>, data: deno_buf, ) -> Box<OpWithError> { @@ -793,7 +791,7 @@ fn op_chmod( } fn op_open( - state: &Arc<IsolateState>, + state: &ThreadSafeState, base: &msg::Base<'_>, data: deno_buf, ) -> Box<OpWithError> { @@ -883,7 +881,7 @@ fn op_open( } fn op_close( - _state: &Arc<IsolateState>, + _state: &ThreadSafeState, base: &msg::Base<'_>, data: deno_buf, ) -> Box<OpWithError> { @@ -900,7 +898,7 @@ fn op_close( } fn op_shutdown( - _state: &Arc<IsolateState>, + _state: &ThreadSafeState, base: &msg::Base<'_>, data: deno_buf, ) -> Box<OpWithError> { @@ -926,7 +924,7 @@ fn op_shutdown( } fn op_read( - _state: &Arc<IsolateState>, + _state: &ThreadSafeState, base: &msg::Base<'_>, data: deno_buf, ) -> Box<OpWithError> { @@ -964,7 +962,7 @@ fn op_read( } fn op_write( - _state: &Arc<IsolateState>, + _state: &ThreadSafeState, base: &msg::Base<'_>, data: deno_buf, ) -> Box<OpWithError> { @@ -1001,7 +999,7 @@ fn op_write( } fn op_seek( - _state: &Arc<IsolateState>, + _state: &ThreadSafeState, base: &msg::Base<'_>, data: deno_buf, ) -> Box<OpWithError> { @@ -1023,7 +1021,7 @@ fn op_seek( } fn op_remove( - state: &Arc<IsolateState>, + state: &ThreadSafeState, base: &msg::Base<'_>, data: deno_buf, ) -> Box<OpWithError> { @@ -1052,7 +1050,7 @@ fn op_remove( } fn op_copy_file( - state: &Arc<IsolateState>, + state: &ThreadSafeState, base: &msg::Base<'_>, data: deno_buf, ) -> Box<OpWithError> { @@ -1108,7 +1106,7 @@ fn get_mode(_perm: &fs::Permissions) -> u32 { } fn op_cwd( - _state: &Arc<IsolateState>, + _state: &ThreadSafeState, base: &msg::Base<'_>, data: deno_buf, ) -> Box<OpWithError> { @@ -1134,7 +1132,7 @@ fn op_cwd( } fn op_stat( - state: &Arc<IsolateState>, + state: &ThreadSafeState, base: &msg::Base<'_>, data: deno_buf, ) -> Box<OpWithError> { @@ -1186,7 +1184,7 @@ fn op_stat( } fn op_read_dir( - state: &Arc<IsolateState>, + state: &ThreadSafeState, base: &msg::Base<'_>, data: deno_buf, ) -> Box<OpWithError> { @@ -1247,7 +1245,7 @@ fn op_read_dir( } fn op_rename( - state: &Arc<IsolateState>, + state: &ThreadSafeState, base: &msg::Base<'_>, data: deno_buf, ) -> Box<OpWithError> { @@ -1267,7 +1265,7 @@ fn op_rename( } fn op_link( - state: &Arc<IsolateState>, + state: &ThreadSafeState, base: &msg::Base<'_>, data: deno_buf, ) -> Box<OpWithError> { @@ -1289,7 +1287,7 @@ fn op_link( } fn op_symlink( - state: &Arc<IsolateState>, + state: &ThreadSafeState, base: &msg::Base<'_>, data: deno_buf, ) -> Box<OpWithError> { @@ -1318,7 +1316,7 @@ fn op_symlink( } fn op_read_link( - state: &Arc<IsolateState>, + state: &ThreadSafeState, base: &msg::Base<'_>, data: deno_buf, ) -> Box<OpWithError> { @@ -1356,7 +1354,7 @@ fn op_read_link( } fn op_repl_start( - state: &Arc<IsolateState>, + state: &ThreadSafeState, base: &msg::Base<'_>, data: deno_buf, ) -> Box<OpWithError> { @@ -1387,7 +1385,7 @@ fn op_repl_start( } fn op_repl_readline( - _state: &Arc<IsolateState>, + _state: &ThreadSafeState, base: &msg::Base<'_>, data: deno_buf, ) -> Box<OpWithError> { @@ -1423,7 +1421,7 @@ fn op_repl_readline( } fn op_truncate( - state: &Arc<IsolateState>, + state: &ThreadSafeState, base: &msg::Base<'_>, data: deno_buf, ) -> Box<OpWithError> { @@ -1446,7 +1444,7 @@ fn op_truncate( } fn op_listen( - state: &Arc<IsolateState>, + state: &ThreadSafeState, base: &msg::Base<'_>, data: deno_buf, ) -> Box<OpWithError> { @@ -1508,7 +1506,7 @@ fn new_conn(cmd_id: u32, tcp_stream: TcpStream) -> OpResult { } fn op_accept( - state: &Arc<IsolateState>, + state: &ThreadSafeState, base: &msg::Base<'_>, data: deno_buf, ) -> Box<OpWithError> { @@ -1534,7 +1532,7 @@ fn op_accept( } fn op_dial( - state: &Arc<IsolateState>, + state: &ThreadSafeState, base: &msg::Base<'_>, data: deno_buf, ) -> Box<OpWithError> { @@ -1560,7 +1558,7 @@ fn op_dial( } fn op_metrics( - state: &Arc<IsolateState>, + state: &ThreadSafeState, base: &msg::Base<'_>, data: deno_buf, ) -> Box<OpWithError> { @@ -1584,7 +1582,7 @@ fn op_metrics( } fn op_resources( - _state: &Arc<IsolateState>, + _state: &ThreadSafeState, base: &msg::Base<'_>, data: deno_buf, ) -> Box<OpWithError> { @@ -1636,7 +1634,7 @@ fn subprocess_stdio_map(v: msg::ProcessStdio) -> std::process::Stdio { } fn op_run( - state: &Arc<IsolateState>, + state: &ThreadSafeState, base: &msg::Base<'_>, data: deno_buf, ) -> Box<OpWithError> { @@ -1709,7 +1707,7 @@ fn op_run( } fn op_run_status( - state: &Arc<IsolateState>, + state: &ThreadSafeState, base: &msg::Base<'_>, data: deno_buf, ) -> Box<OpWithError> { @@ -1765,7 +1763,7 @@ fn op_run_status( } struct GetMessageFuture { - pub state: Arc<IsolateState>, + pub state: ThreadSafeState, } impl Future for GetMessageFuture { @@ -1782,7 +1780,7 @@ impl Future for GetMessageFuture { /// Get message from host as guest worker fn op_worker_get_message( - state: &Arc<IsolateState>, + state: &ThreadSafeState, base: &msg::Base<'_>, data: deno_buf, ) -> Box<OpWithError> { @@ -1817,7 +1815,7 @@ fn op_worker_get_message( /// Post message to host as guest worker fn op_worker_post_message( - state: &Arc<IsolateState>, + state: &ThreadSafeState, base: &msg::Base<'_>, data: deno_buf, ) -> Box<OpWithError> { @@ -1847,7 +1845,7 @@ fn op_worker_post_message( /// Create worker as the host fn op_create_worker( - state: &Arc<IsolateState>, + state: &ThreadSafeState, base: &msg::Base<'_>, data: deno_buf, ) -> Box<OpWithError> { @@ -1859,16 +1857,15 @@ fn op_create_worker( Box::new(futures::future::result(move || -> OpResult { let parent_state = state.clone(); - let child_state = Arc::new(IsolateState::new( + let child_state = ThreadSafeState::new( parent_state.flags.clone(), parent_state.argv.clone(), - )); + ); let rid = child_state.resource.rid; - let behavior = CliBehavior::new(child_state); let name = format!("USER-WORKER-{}", specifier); let mut worker = - Worker::new(name, startup_data::deno_isolate_init(), behavior); + Worker::new(name, startup_data::deno_isolate_init(), child_state); js_check(worker.execute("denoMain()")); js_check(worker.execute("workerMain()")); let result = worker.execute_mod(specifier, false); @@ -1899,7 +1896,7 @@ fn op_create_worker( /// Return when the worker closes fn op_host_get_worker_closed( - state: &Arc<IsolateState>, + state: &ThreadSafeState, base: &msg::Base<'_>, data: deno_buf, ) -> Box<OpWithError> { @@ -1930,7 +1927,7 @@ fn op_host_get_worker_closed( /// Get message from guest worker as host fn op_host_get_message( - _state: &Arc<IsolateState>, + _state: &ThreadSafeState, base: &msg::Base<'_>, data: deno_buf, ) -> Box<OpWithError> { @@ -1964,7 +1961,7 @@ fn op_host_get_message( /// Post message to guest worker as host fn op_host_post_message( - _state: &Arc<IsolateState>, + _state: &ThreadSafeState, base: &msg::Base<'_>, data: deno_buf, ) -> Box<OpWithError> { |