summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--runtime/js/99_main.js20
-rw-r--r--runtime/snapshot.rs1
-rw-r--r--runtime/worker.rs5
3 files changed, 15 insertions, 11 deletions
diff --git a/runtime/js/99_main.js b/runtime/js/99_main.js
index ad2a373cd..d18527865 100644
--- a/runtime/js/99_main.js
+++ b/runtime/js/99_main.js
@@ -14,6 +14,11 @@ import {
op_ppid,
op_set_format_exception_callback,
op_snapshot_options,
+ op_worker_close,
+ op_worker_get_type,
+ op_worker_post_message,
+ op_worker_recv_message,
+ op_worker_sync_fetch,
} from "ext:core/ops";
const {
ArrayPrototypeFilter,
@@ -223,7 +228,7 @@ function workerClose() {
}
isClosing = true;
- ops.op_worker_close();
+ op_worker_close();
}
function postMessage(message, transferOrOptions = {}) {
@@ -252,15 +257,13 @@ function postMessage(message, transferOrOptions = {}) {
}
const { transfer } = options;
const data = messagePort.serializeJsMessageData(message, transfer);
- ops.op_worker_post_message(data);
+ op_worker_post_message(data);
}
let isClosing = false;
let globalDispatchEvent;
async function pollForMessages() {
- const { op_worker_recv_message } = core.ensureFastOps();
-
if (!globalDispatchEvent) {
globalDispatchEvent = FunctionPrototypeBind(
globalThis.dispatchEvent,
@@ -309,7 +312,7 @@ async function pollForMessages() {
let loadedMainWorkerScript = false;
function importScripts(...urls) {
- if (ops.op_worker_get_type() === "module") {
+ if (op_worker_get_type() === "module") {
throw new TypeError("Can't import scripts in a module worker.");
}
@@ -329,7 +332,7 @@ function importScripts(...urls) {
// imported scripts, so we use `loadedMainWorkerScript` to distinguish them.
// TODO(andreubotella) Refactor worker creation so the main script isn't
// loaded with `importScripts()`.
- const scripts = ops.op_worker_sync_fetch(
+ const scripts = op_worker_sync_fetch(
parsedUrls,
!loadedMainWorkerScript,
);
@@ -595,11 +598,6 @@ const NOT_IMPORTED_OPS = [
"op_test_op_sanitizer_report",
"op_void_async",
"op_void_sync",
- "op_worker_close",
- "op_worker_get_type",
- "op_worker_post_message",
- "op_worker_recv_message",
- "op_worker_sync_fetch",
"op_ws_send_pong",
"op_jupyter_broadcast",
"op_format_file_name",
diff --git a/runtime/snapshot.rs b/runtime/snapshot.rs
index 794de14d9..b23b024ee 100644
--- a/runtime/snapshot.rs
+++ b/runtime/snapshot.rs
@@ -253,6 +253,7 @@ pub fn create_runtime_snapshot(
ops::tty::deno_tty::init_ops(),
ops::http::deno_http_runtime::init_ops(),
ops::bootstrap::deno_bootstrap::init_ops(Some(snapshot_options)),
+ ops::web_worker::deno_web_worker::init_ops(),
];
for extension in &mut extensions {
diff --git a/runtime/worker.rs b/runtime/worker.rs
index e6da93d78..449c50e10 100644
--- a/runtime/worker.rs
+++ b/runtime/worker.rs
@@ -430,6 +430,11 @@ impl MainWorker {
enable_testing_features,
),
runtime::init_ops_and_esm(),
+ // NOTE(bartlomieju): this is done, just so that ops from this extension
+ // are available and importing them in `99_main.js` doesn't cause an
+ // error because they're not defined. Trying to use these ops in non-worker
+ // context will cause a panic.
+ ops::web_worker::deno_web_worker::init_ops_and_esm().disable(),
];
#[cfg(__runtime_js_sources)]