From 247b8cec6a96266cc4133c48f8df422010c1efee Mon Sep 17 00:00:00 2001 From: Aaron O'Mullan Date: Thu, 7 Oct 2021 23:05:00 +0200 Subject: [PATCH 1/3] feat(runtime): allow passing extensions via Worker options --- cli/main.rs | 2 ++ cli/standalone.rs | 1 + runtime/examples/hello_runtime.rs | 1 + runtime/web_worker.rs | 4 +++- runtime/worker.rs | 7 +++++-- 5 files changed, 12 insertions(+), 3 deletions(-) diff --git a/cli/main.rs b/cli/main.rs index f94e329e2251c1..7c6265fb40bf23 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -127,6 +127,7 @@ fn create_web_worker_callback(ps: ProcState) -> Arc { ts_version: version::TYPESCRIPT.to_string(), unstable: ps.flags.unstable, }, + extensions: vec![], unsafely_ignore_certificate_errors: ps .flags .unsafely_ignore_certificate_errors @@ -216,6 +217,7 @@ pub fn create_main_worker( ts_version: version::TYPESCRIPT.to_string(), unstable: ps.flags.unstable, }, + extensions: vec![], unsafely_ignore_certificate_errors: ps .flags .unsafely_ignore_certificate_errors diff --git a/cli/standalone.rs b/cli/standalone.rs index 2e4704ea9c17c0..819ba10a4984c6 100644 --- a/cli/standalone.rs +++ b/cli/standalone.rs @@ -241,6 +241,7 @@ pub async fn run( ts_version: version::TYPESCRIPT.to_string(), unstable: metadata.unstable, }, + extensions: vec![], user_agent: version::get_user_agent(), unsafely_ignore_certificate_errors: metadata .unsafely_ignore_certificate_errors, diff --git a/runtime/examples/hello_runtime.rs b/runtime/examples/hello_runtime.rs index eb4557c049a81e..5ff482c5641c93 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 3db74dc578fa47..a439fcebb11a1a 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, pub unsafely_ignore_certificate_errors: Option>, pub root_cert_store: Option, 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(options.extensions.drain(..)); 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 8327c0dd9467c9..6144ad2846781e 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, pub unsafely_ignore_certificate_errors: Option>, pub root_cert_store: Option, 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 = vec![ + let mut extensions: Vec = vec![ // Web APIs deno_webidl::init(), deno_console::init(), @@ -146,6 +147,7 @@ impl MainWorker { // Permissions ext (worker specific state) perm_ext, ]; + extensions.extend(options.extensions.drain(..)); 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, From 7ae549dc2badbb115896262ccadf2d5cbe1f1f55 Mon Sep 17 00:00:00 2001 From: Aaron O'Mullan Date: Thu, 7 Oct 2021 23:18:47 +0200 Subject: [PATCH 2/3] lint std::mem::take instead of drain(..) --- runtime/web_worker.rs | 2 +- runtime/worker.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime/web_worker.rs b/runtime/web_worker.rs index a439fcebb11a1a..e269110de9da02 100644 --- a/runtime/web_worker.rs +++ b/runtime/web_worker.rs @@ -378,7 +378,7 @@ impl WebWorker { // Append exts extensions.extend(runtime_exts); extensions.extend(deno_ns_exts); // May be empty - extensions.extend(options.extensions.drain(..)); + 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 6144ad2846781e..e1b9599a381da8 100644 --- a/runtime/worker.rs +++ b/runtime/worker.rs @@ -147,7 +147,7 @@ impl MainWorker { // Permissions ext (worker specific state) perm_ext, ]; - extensions.extend(options.extensions.drain(..)); + extensions.extend(std::mem::take(&mut options.extensions)); let mut js_runtime = JsRuntime::new(RuntimeOptions { module_loader: Some(options.module_loader.clone()), From fbebe2a511d7707f28f6d095f1cec58305f443f3 Mon Sep 17 00:00:00 2001 From: Aaron O'Mullan Date: Thu, 7 Oct 2021 23:49:12 +0200 Subject: [PATCH 3/3] reset CI