summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeo Kettmeir <crowlkats@toaxl.com>2022-12-19 03:55:50 +0100
committerGitHub <noreply@github.com>2022-12-19 03:55:50 +0100
commit1d18b65edcc4398c7badcf4ad0a367cb1e585a68 (patch)
treee53b02e7d5ef2fb15666897e90babaefab311511
parent97f280eb9b28f1b7743eb73cea817f3a5d122b83 (diff)
fix(runtime): expose `extensions_with_js` from WorkerOptions (#17109)
Co-authored-by: Bartek IwaƄczuk <biwanczuk@gmail.com>
-rw-r--r--cli/standalone.rs1
-rw-r--r--cli/worker.rs2
-rw-r--r--core/runtime.rs4
-rw-r--r--runtime/examples/hello_runtime.rs1
-rw-r--r--runtime/worker.rs44
5 files changed, 48 insertions, 4 deletions
diff --git a/cli/standalone.rs b/cli/standalone.rs
index d4bf8edb3..9e495a810 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 81dcf5ca2..0b991fdd6 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 a95ca0ca6..498441a6d 100644
--- a/core/runtime.rs
+++ b/core/runtime.rs
@@ -258,14 +258,10 @@ pub struct RuntimeOptions {
pub extensions_with_js: Vec<Extension>,
/// V8 snapshot that should be loaded on startup.
- ///
- /// Currently can't be used with `will_snapshot`.
pub startup_snapshot: Option<Snapshot>,
/// 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 371ecf63f..13dcf51f5 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 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()