summaryrefslogtreecommitdiff
path: root/runtime/web_worker.rs
diff options
context:
space:
mode:
authorAndreu Botella <abb@randomunok.com>2021-08-16 14:29:54 +0200
committerGitHub <noreply@github.com>2021-08-16 14:29:54 +0200
commitddbb7b83f2c483e354f425dfb70dbab494b05ea5 (patch)
treefa84f5607395773284e331fe32f2b86b59f02a5d /runtime/web_worker.rs
parentd1d2388d7f1a09fd2469b356f00b6b361269a0b7 (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/web_worker.rs')
-rw-r--r--runtime/web_worker.rs20
1 files changed, 19 insertions, 1 deletions
diff --git a/runtime/web_worker.rs b/runtime/web_worker.rs
index 495fedb81..240d79d1f 100644
--- a/runtime/web_worker.rs
+++ b/runtime/web_worker.rs
@@ -44,6 +44,13 @@ use std::sync::Arc;
use std::task::Context;
use std::task::Poll;
+#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
+#[serde(rename_all = "lowercase")]
+pub enum WebWorkerType {
+ Classic,
+ Module,
+}
+
#[derive(
Debug, Default, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize,
)]
@@ -110,6 +117,7 @@ pub struct WebWorkerInternalHandle {
pub cancel: Rc<CancelHandle>,
terminated: Arc<AtomicBool>,
isolate_handle: v8::IsolateHandle,
+ pub worker_type: WebWorkerType,
}
impl WebWorkerInternalHandle {
@@ -215,6 +223,7 @@ impl WebWorkerHandle {
fn create_handles(
isolate_handle: v8::IsolateHandle,
+ worker_type: WebWorkerType,
) -> (WebWorkerInternalHandle, SendableWebWorkerHandle) {
let (parent_port, worker_port) = create_entangled_message_port();
let (ctrl_tx, ctrl_rx) = mpsc::channel::<WorkerControlEvent>(1);
@@ -225,6 +234,7 @@ fn create_handles(
terminated: terminated.clone(),
isolate_handle: isolate_handle.clone(),
cancel: CancelHandle::new_rc(),
+ worker_type,
};
let external_handle = SendableWebWorkerHandle {
receiver: ctrl_rx,
@@ -245,6 +255,7 @@ pub struct WebWorker {
pub name: String,
internal_handle: WebWorkerInternalHandle,
pub use_deno_namespace: bool,
+ pub worker_type: WebWorkerType,
pub main_module: ModuleSpecifier,
}
@@ -253,6 +264,7 @@ pub struct WebWorkerOptions {
pub args: Vec<String>,
pub debug_flag: bool,
pub unstable: bool,
+ pub enable_testing_features: bool,
pub unsafely_ignore_certificate_errors: Option<Vec<String>>,
pub root_cert_store: Option<RootCertStore>,
pub user_agent: String,
@@ -261,6 +273,7 @@ pub struct WebWorkerOptions {
pub create_web_worker_cb: Arc<ops::worker_host::CreateWebWorkerCb>,
pub js_error_create_fn: Option<Rc<JsErrorCreateFn>>,
pub use_deno_namespace: bool,
+ pub worker_type: WebWorkerType,
pub maybe_inspector_server: Option<Arc<InspectorServer>>,
pub apply_source_maps: bool,
/// Sets `Deno.version.deno` in JS runtime.
@@ -286,10 +299,12 @@ impl WebWorker {
) -> (Self, SendableWebWorkerHandle) {
// Permissions: many ops depend on this
let unstable = options.unstable;
+ let enable_testing_features = options.enable_testing_features;
let perm_ext = Extension::builder()
.state(move |state| {
state.put::<Permissions>(permissions.clone());
state.put(ops::UnstableChecker { unstable });
+ state.put(ops::TestingFeaturesEnabled(enable_testing_features));
Ok(())
})
.build();
@@ -386,7 +401,8 @@ impl WebWorker {
let (internal_handle, external_handle) = {
let handle = js_runtime.v8_isolate().thread_safe_handle();
- let (internal_handle, external_handle) = create_handles(handle);
+ let (internal_handle, external_handle) =
+ create_handles(handle, options.worker_type);
let op_state = js_runtime.op_state();
let mut op_state = op_state.borrow_mut();
op_state.put(internal_handle.clone());
@@ -400,6 +416,7 @@ impl WebWorker {
name,
internal_handle,
use_deno_namespace: options.use_deno_namespace,
+ worker_type: options.worker_type,
main_module,
},
external_handle,
@@ -418,6 +435,7 @@ impl WebWorker {
"target": env!("TARGET"),
"tsVersion": options.ts_version,
"unstableFlag": options.unstable,
+ "enableTestingFeaturesFlag": options.enable_testing_features,
"v8Version": deno_core::v8_version(),
"location": self.main_module,
"cpuCount": options.cpu_count,