1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 07:14:47 -05:00

fix(runtime): expose extensions_with_js from WorkerOptions (#17109)

Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
This commit is contained in:
Leo Kettmeir 2022-12-19 03:55:50 +01:00 committed by GitHub
parent 97f280eb9b
commit 1d18b65edc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 48 additions and 4 deletions

View file

@ -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,

View file

@ -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,

View file

@ -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.

View file

@ -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,

View file

@ -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()