summaryrefslogtreecommitdiff
path: root/runtime/ops/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/ops/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/ops/web_worker.rs')
-rw-r--r--runtime/ops/web_worker.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/runtime/ops/web_worker.rs b/runtime/ops/web_worker.rs
index 026e38157..8439e4384 100644
--- a/runtime/ops/web_worker.rs
+++ b/runtime/ops/web_worker.rs
@@ -1,6 +1,9 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
+mod sync_fetch;
+
use crate::web_worker::WebWorkerInternalHandle;
+use crate::web_worker::WebWorkerType;
use crate::web_worker::WorkerControlEvent;
use deno_core::error::generic_error;
use deno_core::error::AnyError;
@@ -13,6 +16,8 @@ use deno_web::JsMessageData;
use std::cell::RefCell;
use std::rc::Rc;
+use self::sync_fetch::op_worker_sync_fetch;
+
pub fn init() -> Extension {
Extension::builder()
.ops(vec![
@@ -25,6 +30,8 @@ pub fn init() -> Extension {
"op_worker_unhandled_error",
op_sync(op_worker_unhandled_error),
),
+ ("op_worker_get_type", op_sync(op_worker_get_type)),
+ ("op_worker_sync_fetch", op_sync(op_worker_sync_fetch)),
])
.build()
}
@@ -79,3 +86,12 @@ fn op_worker_unhandled_error(
.expect("Failed to propagate error event to parent worker");
Ok(())
}
+
+fn op_worker_get_type(
+ state: &mut OpState,
+ _: (),
+ _: (),
+) -> Result<WebWorkerType, AnyError> {
+ let handle = state.borrow::<WebWorkerInternalHandle>().clone();
+ Ok(handle.worker_type)
+}