summaryrefslogtreecommitdiff
path: root/cli/standalone.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2020-12-11 18:49:26 +0100
committerGitHub <noreply@github.com>2020-12-11 18:49:26 +0100
commit65e72b68acf57da8462b8e7b057e7adb9393b698 (patch)
tree00e955e1186b9512b009acbb6ee80feb8a3f1733 /cli/standalone.rs
parent9414dee9e56a9f42c07ada4f8e1be864a1a1b936 (diff)
refactor(cli): decouple ops from ProgramState and Flags (#8659)
This commit does major refactor of "Worker" and "WebWorker", in order to decouple them from "ProgramState" and "Flags". The main points of interest are "create_main_worker()" and "create_web_worker_callback()" functions which are responsible for creating "Worker" and "WebWorker" in CLI context. As a result it is now possible to factor out common "runtime" functionality into a separate crate.
Diffstat (limited to 'cli/standalone.rs')
-rw-r--r--cli/standalone.rs30
1 files changed, 22 insertions, 8 deletions
diff --git a/cli/standalone.rs b/cli/standalone.rs
index df7106c97..d7ffd0fd2 100644
--- a/cli/standalone.rs
+++ b/cli/standalone.rs
@@ -1,9 +1,9 @@
use crate::colors;
use crate::flags::Flags;
use crate::permissions::Permissions;
-use crate::program_state::ProgramState;
use crate::tokio_util;
use crate::worker::MainWorker;
+use crate::worker::WorkerOptions;
use deno_core::error::type_error;
use deno_core::error::AnyError;
use deno_core::futures::FutureExt;
@@ -21,6 +21,7 @@ use std::io::Write;
use std::path::PathBuf;
use std::pin::Pin;
use std::rc::Rc;
+use std::sync::Arc;
const MAGIC_TRAILER: &[u8; 8] = b"d3n0l4nd";
@@ -109,16 +110,29 @@ async fn run(source_code: String, args: Vec<String>) -> Result<(), AnyError> {
// TODO(lucacasonato): remove once you can specify this correctly through embedded metadata
flags.unstable = true;
let main_module = ModuleSpecifier::resolve_url(SPECIFIER)?;
- let program_state = ProgramState::new(flags.clone())?;
let permissions = Permissions::allow_all();
let module_loader = Rc::new(EmbeddedModuleLoader(source_code));
- let mut worker = MainWorker::from_options(
- &program_state,
- main_module.clone(),
- permissions,
+ let create_web_worker_cb = Arc::new(|_| {
+ todo!("Worker are currently not supported in standalone binaries");
+ });
+
+ let options = WorkerOptions {
+ apply_source_maps: false,
+ args: flags.argv.clone(),
+ debug_flag: false,
+ unstable: true,
+ ca_filepath: None,
+ seed: None,
+ js_error_create_fn: None,
+ create_web_worker_cb,
+ attach_inspector: false,
+ maybe_inspector_server: None,
+ should_break_on_first_statement: false,
module_loader,
- None,
- );
+ };
+ let mut worker =
+ MainWorker::from_options(main_module.clone(), permissions, &options);
+ worker.bootstrap(&options);
worker.execute_module(&main_module).await?;
worker.execute("window.dispatchEvent(new Event('load'))")?;
worker.run_event_loop().await?;