diff options
author | Andreu Botella <abb@randomunok.com> | 2021-08-16 14:29:54 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-16 14:29:54 +0200 |
commit | ddbb7b83f2c483e354f425dfb70dbab494b05ea5 (patch) | |
tree | fa84f5607395773284e331fe32f2b86b59f02a5d /runtime/ops/worker_host.rs | |
parent | d1d2388d7f1a09fd2469b356f00b6b361269a0b7 (diff) |
feat(runtime): support classic workers for internal testing (#11338)
This commit implements classic workers, but only when the `--enable-testing-features-do-not-use` flag is provided. This change is not user facing. Classic workers are used extensively in WPT tests. The classic workers do not support loading from disk, and do not support TypeScript.
Co-authored-by: Luca Casonato <hello@lcas.dev>
Diffstat (limited to 'runtime/ops/worker_host.rs')
-rw-r--r-- | runtime/ops/worker_host.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/runtime/ops/worker_host.rs b/runtime/ops/worker_host.rs index 5315ff5c7..d80a39502 100644 --- a/runtime/ops/worker_host.rs +++ b/runtime/ops/worker_host.rs @@ -1,5 +1,6 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +use crate::ops::TestingFeaturesEnabled; use crate::permissions::resolve_read_allowlist; use crate::permissions::resolve_write_allowlist; use crate::permissions::EnvDescriptor; @@ -16,6 +17,7 @@ use crate::web_worker::run_web_worker; use crate::web_worker::SendableWebWorkerHandle; use crate::web_worker::WebWorker; use crate::web_worker::WebWorkerHandle; +use crate::web_worker::WebWorkerType; use crate::web_worker::WorkerControlEvent; use crate::web_worker::WorkerId; use deno_core::error::custom_error; @@ -48,6 +50,7 @@ pub struct CreateWebWorkerArgs { pub permissions: Permissions, pub main_module: ModuleSpecifier, pub use_deno_namespace: bool, + pub worker_type: WebWorkerType, } pub type CreateWebWorkerCb = dyn Fn(CreateWebWorkerArgs) -> (WebWorker, SendableWebWorkerHandle) @@ -460,6 +463,7 @@ pub struct CreateWorkerArgs { source_code: String, specifier: String, use_deno_namespace: bool, + worker_type: WebWorkerType, } /// Create worker as the host @@ -479,6 +483,17 @@ fn op_create_worker( if use_deno_namespace { super::check_unstable(state, "Worker.deno.namespace"); } + let worker_type = args.worker_type; + if let WebWorkerType::Classic = worker_type { + if let TestingFeaturesEnabled(false) = state.borrow() { + return Err( + deno_webstorage::DomExceptionNotSupportedError::new( + "Classic workers are not supported.", + ) + .into(), + ); + } + } let parent_permissions = state.borrow::<Permissions>().clone(); let worker_permissions = if let Some(permissions) = args.permissions { super::check_unstable(state, "Worker.deno.permissions"); @@ -518,6 +533,7 @@ fn op_create_worker( permissions: worker_permissions, main_module: module_specifier.clone(), use_deno_namespace, + worker_type, }); // Send thread safe handle from newly created worker to host thread |