diff options
author | Aaron O'Mullan <aaron.omullan@gmail.com> | 2021-10-08 17:03:49 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-08 17:03:49 +0200 |
commit | 6b43e862fd44044d94d5df077b30d0cb112fc4d2 (patch) | |
tree | aa031a71c9252a87e56ff27526a2454385d4d9d7 /runtime | |
parent | 5f405bf1143e5e32ba69f12d6ad10374631ba64b (diff) |
feat(runtime): allow passing extensions via Worker options (#12362)
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/examples/hello_runtime.rs | 1 | ||||
-rw-r--r-- | runtime/web_worker.rs | 4 | ||||
-rw-r--r-- | runtime/worker.rs | 7 |
3 files changed, 9 insertions, 3 deletions
diff --git a/runtime/examples/hello_runtime.rs b/runtime/examples/hello_runtime.rs index eb4557c04..5ff482c56 100644 --- a/runtime/examples/hello_runtime.rs +++ b/runtime/examples/hello_runtime.rs @@ -36,6 +36,7 @@ async fn main() -> Result<(), AnyError> { ts_version: "x".to_string(), unstable: false, }, + extensions: vec![], unsafely_ignore_certificate_errors: None, root_cert_store: None, user_agent: "hello_runtime".to_string(), diff --git a/runtime/web_worker.rs b/runtime/web_worker.rs index 3db74dc57..e269110de 100644 --- a/runtime/web_worker.rs +++ b/runtime/web_worker.rs @@ -260,6 +260,7 @@ pub struct WebWorker { pub struct WebWorkerOptions { pub bootstrap: BootstrapOptions, + pub extensions: Vec<Extension>, pub unsafely_ignore_certificate_errors: Option<Vec<String>>, pub root_cert_store: Option<RootCertStore>, pub user_agent: String, @@ -297,7 +298,7 @@ impl WebWorker { permissions: Permissions, main_module: ModuleSpecifier, worker_id: WorkerId, - options: WebWorkerOptions, + mut options: WebWorkerOptions, ) -> (Self, SendableWebWorkerHandle) { // Permissions: many ops depend on this let unstable = options.bootstrap.unstable; @@ -377,6 +378,7 @@ impl WebWorker { // Append exts extensions.extend(runtime_exts); extensions.extend(deno_ns_exts); // May be empty + extensions.extend(std::mem::take(&mut options.extensions)); let mut js_runtime = JsRuntime::new(RuntimeOptions { module_loader: Some(options.module_loader.clone()), diff --git a/runtime/worker.rs b/runtime/worker.rs index 8327c0dd9..e1b9599a3 100644 --- a/runtime/worker.rs +++ b/runtime/worker.rs @@ -44,6 +44,7 @@ pub struct MainWorker { pub struct WorkerOptions { pub bootstrap: BootstrapOptions, + pub extensions: Vec<Extension>, pub unsafely_ignore_certificate_errors: Option<Vec<String>>, pub root_cert_store: Option<RootCertStore>, pub user_agent: String, @@ -77,7 +78,7 @@ impl MainWorker { pub fn from_options( main_module: ModuleSpecifier, permissions: Permissions, - options: WorkerOptions, + mut options: WorkerOptions, ) -> Self { // Permissions: many ops depend on this let unstable = options.bootstrap.unstable; @@ -92,7 +93,7 @@ impl MainWorker { .build(); // Internal modules - let extensions: Vec<Extension> = vec![ + let mut extensions: Vec<Extension> = vec![ // Web APIs deno_webidl::init(), deno_console::init(), @@ -146,6 +147,7 @@ impl MainWorker { // Permissions ext (worker specific state) perm_ext, ]; + extensions.extend(std::mem::take(&mut options.extensions)); let mut js_runtime = JsRuntime::new(RuntimeOptions { module_loader: Some(options.module_loader.clone()), @@ -313,6 +315,7 @@ mod tests { ts_version: "x".to_string(), unstable: false, }, + extensions: vec![], user_agent: "x".to_string(), unsafely_ignore_certificate_errors: None, root_cert_store: None, |