diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2020-06-01 22:44:17 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-01 22:44:17 -0400 |
commit | 8b1b4766a1e747437a2b88fcadc26162a1bec640 (patch) | |
tree | 98dd0d14ca28c62519269f0ad0703db7686f92e5 /cli/worker.rs | |
parent | 40419c664d402d4c3c5783d0ae337d23c106f619 (diff) |
Move create_main_worker to MainWorker::create (#6034)
Diffstat (limited to 'cli/worker.rs')
-rw-r--r-- | cli/worker.rs | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/cli/worker.rs b/cli/worker.rs index 524091422..70cadcc23 100644 --- a/cli/worker.rs +++ b/cli/worker.rs @@ -1,7 +1,10 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. use crate::fmt_errors::JSError; +use crate::global_state::GlobalState; use crate::inspector::DenoInspector; use crate::ops; +use crate::ops::io::get_stdio; +use crate::startup_data; use crate::state::State; use deno_core::Buf; use deno_core::CoreIsolate; @@ -246,7 +249,8 @@ impl DerefMut for Worker { pub struct MainWorker(Worker); impl MainWorker { - pub fn new(name: String, startup_data: StartupData, state: State) -> Self { + // TODO(ry) combine MainWorker::new and MainWorker::create. + fn new(name: String, startup_data: StartupData, state: State) -> Self { let state_ = state.clone(); let mut worker = Worker::new(name, startup_data, state_); { @@ -274,6 +278,35 @@ impl MainWorker { } Self(worker) } + + pub fn create( + global_state: GlobalState, + main_module: ModuleSpecifier, + ) -> Result<MainWorker, ErrBox> { + let state = State::new( + global_state.clone(), + None, + main_module, + global_state.maybe_import_map.clone(), + false, + )?; + let mut worker = MainWorker::new( + "main".to_string(), + startup_data::deno_isolate_init(), + state, + ); + { + let (stdin, stdout, stderr) = get_stdio(); + let state_rc = CoreIsolate::state(&worker.isolate); + let state = state_rc.borrow(); + let mut t = state.resource_table.borrow_mut(); + t.add("stdin", Box::new(stdin)); + t.add("stdout", Box::new(stdout)); + t.add("stderr", Box::new(stderr)); + } + worker.execute("bootstrap.mainRuntime()")?; + Ok(worker) + } } impl Deref for MainWorker { |