diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2022-02-11 13:41:56 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-11 13:41:56 +0100 |
commit | 2fa0096821cd04334210fcae6f54f85d304dc17a (patch) | |
tree | f4c76302e48861e2d7cf802feab9f3d560fd1c9c /runtime/worker.rs | |
parent | 2f2c778a074d0eff991c6c22da54429de3de6704 (diff) |
compat: support --compat in web workers (#13629)
Adds another callback to WebWorkerOptions that allows to execute
some modules before actual worker code executes. This allows to set up Node
global using std/node.
Diffstat (limited to 'runtime/worker.rs')
-rw-r--r-- | runtime/worker.rs | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/runtime/worker.rs b/runtime/worker.rs index 7a3a6c1c3..1dc9504d6 100644 --- a/runtime/worker.rs +++ b/runtime/worker.rs @@ -51,8 +51,9 @@ pub struct WorkerOptions { pub user_agent: String, pub seed: Option<u64>, pub module_loader: Rc<dyn ModuleLoader>, - // Callback invoked when creating new instance of WebWorker + // Callbacks invoked when creating new instance of WebWorker pub create_web_worker_cb: Arc<ops::worker_host::CreateWebWorkerCb>, + pub web_worker_preload_module_cb: Arc<ops::worker_host::PreloadModuleCb>, pub js_error_create_fn: Option<Rc<JsErrorCreateFn>>, pub maybe_inspector_server: Option<Arc<InspectorServer>>, pub should_break_on_first_statement: bool, @@ -126,7 +127,10 @@ impl MainWorker { deno_ffi::init::<Permissions>(unstable), // Runtime ops ops::runtime::init(main_module.clone()), - ops::worker_host::init(options.create_web_worker_cb.clone()), + ops::worker_host::init( + options.create_web_worker_cb.clone(), + options.web_worker_preload_module_cb.clone(), + ), ops::fs_events::init(), ops::fs::init(), ops::io::init(), @@ -367,6 +371,7 @@ mod tests { root_cert_store: None, seed: None, js_error_create_fn: None, + web_worker_preload_module_cb: Arc::new(|_| unreachable!()), create_web_worker_cb: Arc::new(|_| unreachable!()), maybe_inspector_server: None, should_break_on_first_statement: false, |