summaryrefslogtreecommitdiff
path: root/runtime/js/11_workers.js
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/js/11_workers.js
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/js/11_workers.js')
-rw-r--r--runtime/js/11_workers.js31
1 files changed, 20 insertions, 11 deletions
diff --git a/runtime/js/11_workers.js b/runtime/js/11_workers.js
index b5a8a9d0c..2f9413119 100644
--- a/runtime/js/11_workers.js
+++ b/runtime/js/11_workers.js
@@ -7,7 +7,6 @@
ArrayIsArray,
ArrayPrototypeMap,
Error,
- Uint8Array,
StringPrototypeStartsWith,
String,
SymbolIterator,
@@ -28,6 +27,7 @@
useDenoNamespace,
permissions,
name,
+ workerType,
) {
return core.opSync("op_create_worker", {
hasSourceCode,
@@ -36,6 +36,7 @@
sourceCode,
specifier,
useDenoNamespace,
+ workerType,
});
}
@@ -183,20 +184,12 @@
}
}
- if (type !== "module") {
- throw new Error(
- 'Not yet implemented: only "module" type workers are supported',
- );
- }
-
- this.#name = name;
- const hasSourceCode = false;
- const sourceCode = core.decode(new Uint8Array());
+ const workerType = webidl.converters["WorkerType"](type);
if (
StringPrototypeStartsWith(specifier, "./") ||
StringPrototypeStartsWith(specifier, "../") ||
- StringPrototypeStartsWith(specifier, "/") || type == "classic"
+ StringPrototypeStartsWith(specifier, "/") || workerType === "classic"
) {
const baseUrl = getLocationHref();
if (baseUrl != null) {
@@ -204,6 +197,16 @@
}
}
+ this.#name = name;
+ let hasSourceCode, sourceCode;
+ if (workerType === "classic") {
+ hasSourceCode = true;
+ sourceCode = `importScripts("#");`;
+ } else {
+ hasSourceCode = false;
+ sourceCode = "";
+ }
+
const id = createWorker(
specifier,
hasSourceCode,
@@ -213,6 +216,7 @@
? null
: parsePermissions(workerDenoAttributes.permissions),
options?.name,
+ workerType,
);
this.#id = id;
this.#pollControl();
@@ -344,6 +348,11 @@
defineEventHandler(Worker.prototype, "message");
defineEventHandler(Worker.prototype, "messageerror");
+ webidl.converters["WorkerType"] = webidl.createEnumConverter("WorkerType", [
+ "classic",
+ "module",
+ ]);
+
window.__bootstrap.worker = {
parsePermissions,
Worker,