diff --git a/runtime/worker.rs b/runtime/worker.rs index 9b27559391..36833da329 100644 --- a/runtime/worker.rs +++ b/runtime/worker.rs @@ -18,6 +18,7 @@ use deno_core::serde_v8; use deno_core::v8; use deno_core::CompiledWasmModuleStore; use deno_core::Extension; +use deno_core::FsModuleLoader; use deno_core::GetErrorClassFn; use deno_core::JsRuntime; use deno_core::LocalInspectorSession; @@ -105,6 +106,41 @@ fn grab_cb( v8::Global::new(scope, cb) } +impl Default for WorkerOptions { + fn default() -> Self { + Self { + web_worker_preload_module_cb: Arc::new(|_| { + unimplemented!("web workers are not supported") + }), + web_worker_pre_execute_module_cb: Arc::new(|_| { + unimplemented!("web workers are not supported") + }), + create_web_worker_cb: Arc::new(|_| { + unimplemented!("web workers are not supported") + }), + module_loader: Rc::new(FsModuleLoader), + seed: None, + unsafely_ignore_certificate_errors: Default::default(), + should_break_on_first_statement: Default::default(), + compiled_wasm_module_store: Default::default(), + shared_array_buffer_store: Default::default(), + maybe_inspector_server: Default::default(), + format_js_error_fn: Default::default(), + get_error_class_fn: Default::default(), + origin_storage_dir: Default::default(), + cache_storage_dir: Default::default(), + broadcast_channel: Default::default(), + source_map_getter: Default::default(), + root_cert_store: Default::default(), + npm_resolver: Default::default(), + blob_store: Default::default(), + extensions: Default::default(), + bootstrap: Default::default(), + stdio: Default::default(), + } + } +} + impl MainWorker { pub fn bootstrap_from_options( main_module: ModuleSpecifier, @@ -533,7 +569,7 @@ mod tests { create_web_worker_cb: Arc::new(|_| unreachable!()), maybe_inspector_server: None, should_break_on_first_statement: false, - module_loader: Rc::new(deno_core::FsModuleLoader), + module_loader: Rc::new(FsModuleLoader), npm_resolver: None, get_error_class_fn: None, cache_storage_dir: None, diff --git a/runtime/worker_bootstrap.rs b/runtime/worker_bootstrap.rs index 31e7c43825..8af78c21a5 100644 --- a/runtime/worker_bootstrap.rs +++ b/runtime/worker_bootstrap.rs @@ -1,7 +1,12 @@ -use crate::ops::runtime::ppid; +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. + use deno_core::serde_json; use deno_core::serde_json::json; use deno_core::ModuleSpecifier; +use std::thread; + +use crate::colors; +use crate::ops::runtime::ppid; /// Common bootstrap options for MainWorker & WebWorker #[derive(Clone)] @@ -24,6 +29,32 @@ pub struct BootstrapOptions { pub inspect: bool, } +impl Default for BootstrapOptions { + fn default() -> Self { + let cpu_count = thread::available_parallelism() + .map(|p| p.get()) + .unwrap_or(1); + + let runtime_version = env!("CARGO_PKG_VERSION").into(); + let user_agent = format!("Deno/{}", runtime_version); + + Self { + runtime_version, + user_agent, + cpu_count, + no_color: !colors::use_color(), + is_tty: colors::is_tty(), + enable_testing_features: Default::default(), + debug_flag: Default::default(), + ts_version: Default::default(), + location: Default::default(), + unstable: Default::default(), + inspect: Default::default(), + args: Default::default(), + } + } +} + impl BootstrapOptions { pub fn as_json(&self) -> String { let payload = json!({