diff options
author | Leo Kettmeir <crowlkats@toaxl.com> | 2022-12-19 03:55:50 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-19 03:55:50 +0100 |
commit | 1d18b65edcc4398c7badcf4ad0a367cb1e585a68 (patch) | |
tree | e53b02e7d5ef2fb15666897e90babaefab311511 /runtime/worker.rs | |
parent | 97f280eb9b28f1b7743eb73cea817f3a5d122b83 (diff) |
fix(runtime): expose `extensions_with_js` from WorkerOptions (#17109)
Co-authored-by: Bartek IwaĆczuk <biwanczuk@gmail.com>
Diffstat (limited to 'runtime/worker.rs')
-rw-r--r-- | runtime/worker.rs | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/runtime/worker.rs b/runtime/worker.rs index 41da8588b..b6bb51bc6 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<Extension>, + + /// 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<Extension>, + + /// V8 snapshot that should be loaded on startup. pub startup_snapshot: Option<Snapshot>, pub unsafely_ignore_certificate_errors: Option<Vec<String>>, pub root_cert_store: Option<RootCertStore>, pub seed: Option<u64>, + + /// 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<dyn ModuleLoader>, pub npm_resolver: Option<Rc<dyn RequireNpmResolver>>, // Callbacks invoked when creating new instance of WebWorker @@ -81,6 +105,8 @@ pub struct WorkerOptions { pub web_worker_preload_module_cb: Arc<ops::worker_host::WorkerEventCb>, pub web_worker_pre_execute_module_cb: Arc<ops::worker_host::WorkerEventCb>, pub format_js_error_fn: Option<Arc<FormatJsErrorFn>>, + + /// Source map reference for errors. pub source_map_getter: Option<Box<dyn SourceMapGetter>>, pub maybe_inspector_server: Option<Arc<InspectorServer>>, // 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<GetErrorClassFn>, pub cache_storage_dir: Option<std::path::PathBuf>, pub origin_storage_dir: Option<std::path::PathBuf>, 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<SharedArrayBufferStore>, + + /// 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<CompiledWasmModuleStore>, 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() |