From 1d18b65edcc4398c7badcf4ad0a367cb1e585a68 Mon Sep 17 00:00:00 2001 From: Leo Kettmeir Date: Mon, 19 Dec 2022 03:55:50 +0100 Subject: [PATCH] fix(runtime): expose `extensions_with_js` from WorkerOptions (#17109) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bartek IwaƄczuk --- cli/standalone.rs | 1 + cli/worker.rs | 2 ++ core/runtime.rs | 4 --- runtime/examples/hello_runtime.rs | 1 + runtime/worker.rs | 44 +++++++++++++++++++++++++++++++ 5 files changed, 48 insertions(+), 4 deletions(-) diff --git a/cli/standalone.rs b/cli/standalone.rs index d4bf8edb3f..9e495a810b 100644 --- a/cli/standalone.rs +++ b/cli/standalone.rs @@ -287,6 +287,7 @@ pub async fn run( inspect: ps.options.is_inspecting(), }, extensions: ops::cli_exts(ps.clone()), + extensions_with_js: vec![], startup_snapshot: Some(crate::js::deno_isolate_init()), unsafely_ignore_certificate_errors: metadata .unsafely_ignore_certificate_errors, diff --git a/cli/worker.rs b/cli/worker.rs index 81dcf5ca25..0b991fdd68 100644 --- a/cli/worker.rs +++ b/cli/worker.rs @@ -523,6 +523,7 @@ async fn create_main_worker_internal( inspect: ps.options.is_inspecting(), }, extensions, + extensions_with_js: vec![], startup_snapshot: Some(crate::js::deno_isolate_init()), unsafely_ignore_certificate_errors: ps .options @@ -752,6 +753,7 @@ mod tests { inspect: false, }, extensions: vec![], + extensions_with_js: vec![], startup_snapshot: Some(crate::js::deno_isolate_init()), unsafely_ignore_certificate_errors: None, root_cert_store: None, diff --git a/core/runtime.rs b/core/runtime.rs index a95ca0ca64..498441a6d4 100644 --- a/core/runtime.rs +++ b/core/runtime.rs @@ -258,14 +258,10 @@ pub struct RuntimeOptions { pub extensions_with_js: Vec, /// V8 snapshot that should be loaded on startup. - /// - /// Currently can't be used with `will_snapshot`. pub startup_snapshot: Option, /// Prepare runtime to take snapshot of loaded code. /// The snapshot is determinstic and uses predictable random numbers. - /// - /// Currently can't be used with `startup_snapshot`. pub will_snapshot: bool, /// Isolate creation parameters. diff --git a/runtime/examples/hello_runtime.rs b/runtime/examples/hello_runtime.rs index 371ecf63fa..13dcf51f55 100644 --- a/runtime/examples/hello_runtime.rs +++ b/runtime/examples/hello_runtime.rs @@ -43,6 +43,7 @@ async fn main() -> Result<(), AnyError> { inspect: false, }, extensions: vec![], + extensions_with_js: vec![], startup_snapshot: None, unsafely_ignore_certificate_errors: None, root_cert_store: None, diff --git a/runtime/worker.rs b/runtime/worker.rs index 41da8588b2..b6bb51bc66 100644 --- a/runtime/worker.rs +++ b/runtime/worker.rs @@ -69,11 +69,35 @@ pub struct MainWorker { pub struct WorkerOptions { pub bootstrap: BootstrapOptions, + + /// JsRuntime extensions, not to be confused with ES modules. + /// Only ops registered by extensions will be initialized. If you need + /// to execute JS code from extensions, use `extensions_with_js` options + /// instead. pub extensions: Vec, + + /// JsRuntime extensions, not to be confused with ES modules. + /// Ops registered by extensions will be initialized and JS code will be + /// executed. If you don't need to execute JS code from extensions, use + /// `extensions` option instead. + /// + /// This is useful when creating snapshots, in such case you would pass + /// extensions using `extensions_with_js`, later when creating a runtime + /// from the snapshot, you would pass these extensions using `extensions` + /// option. + pub extensions_with_js: Vec, + + /// V8 snapshot that should be loaded on startup. pub startup_snapshot: Option, pub unsafely_ignore_certificate_errors: Option>, pub root_cert_store: Option, pub seed: Option, + + /// Implementation of `ModuleLoader` which will be + /// called when V8 requests to load ES modules. + /// + /// If not provided runtime will error if code being + /// executed tries to load modules. pub module_loader: Rc, pub npm_resolver: Option>, // Callbacks invoked when creating new instance of WebWorker @@ -81,6 +105,8 @@ pub struct WorkerOptions { pub web_worker_preload_module_cb: Arc, pub web_worker_pre_execute_module_cb: Arc, pub format_js_error_fn: Option>, + + /// Source map reference for errors. pub source_map_getter: Option>, pub maybe_inspector_server: Option>, // If true, the worker will wait for inspector session and break on first @@ -90,12 +116,28 @@ pub struct WorkerOptions { // If true, the worker will wait for inspector session before executing // user code. pub should_wait_for_inspector_session: bool, + + /// Allows to map error type to a string "class" used to represent + /// error in JavaScript. pub get_error_class_fn: Option, pub cache_storage_dir: Option, pub origin_storage_dir: Option, pub blob_store: BlobStore, pub broadcast_channel: InMemoryBroadcastChannel, + + /// The store to use for transferring SharedArrayBuffers between isolates. + /// If multiple isolates should have the possibility of sharing + /// SharedArrayBuffers, they should use the same [SharedArrayBufferStore]. If + /// no [SharedArrayBufferStore] is specified, SharedArrayBuffer can not be + /// serialized. pub shared_array_buffer_store: Option, + + /// The store to use for transferring `WebAssembly.Module` objects between + /// isolates. + /// If multiple isolates should have the possibility of sharing + /// `WebAssembly.Module` objects, they should use the same + /// [CompiledWasmModuleStore]. If no [CompiledWasmModuleStore] is specified, + /// `WebAssembly.Module` objects cannot be serialized. pub compiled_wasm_module_store: Option, pub stdio: Stdio, } @@ -130,6 +172,7 @@ impl Default for WorkerOptions { npm_resolver: Default::default(), blob_store: Default::default(), extensions: Default::default(), + extensions_with_js: Default::default(), startup_snapshot: Default::default(), bootstrap: Default::default(), stdio: Default::default(), @@ -248,6 +291,7 @@ impl MainWorker { shared_array_buffer_store: options.shared_array_buffer_store.clone(), compiled_wasm_module_store: options.compiled_wasm_module_store.clone(), extensions, + extensions_with_js: options.extensions_with_js, inspector: options.maybe_inspector_server.is_some(), is_main: true, ..Default::default()