summaryrefslogtreecommitdiff
path: root/cli/js
diff options
context:
space:
mode:
Diffstat (limited to 'cli/js')
-rw-r--r--cli/js/compiler.ts4
-rw-r--r--cli/js/compiler_bootstrap.ts24
-rw-r--r--cli/js/compiler_host.ts4
-rw-r--r--cli/js/globals.ts2
-rw-r--r--cli/js/lib.deno.ns.d.ts (renamed from cli/js/lib.deno.d.ts)0
-rw-r--r--cli/js/lib.deno.shared_globals.d.ts (renamed from cli/js/lib.deno_main.d.ts)260
-rw-r--r--cli/js/lib.deno.window.d.ts214
-rw-r--r--cli/js/lib.deno.worker.d.ts45
-rw-r--r--cli/js/lib.deno_worker.d.ts5
-rw-r--r--cli/js/runtime_worker.ts5
-rw-r--r--cli/js/workers.ts19
11 files changed, 323 insertions, 259 deletions
diff --git a/cli/js/compiler.ts b/cli/js/compiler.ts
index 394c6cf52..f003d7d0b 100644
--- a/cli/js/compiler.ts
+++ b/cli/js/compiler.ts
@@ -304,7 +304,7 @@ async function tsCompilerOnMessage({
}
// The compiler isolate exits after a single message.
- globalThis.workerClose();
+ globalThis.close();
}
async function wasmCompilerOnMessage({
@@ -332,7 +332,7 @@ async function wasmCompilerOnMessage({
util.log("<<< WASM compile end");
// The compiler isolate exits after a single message.
- globalThis.workerClose();
+ globalThis.close();
}
function bootstrapTsCompilerRuntime(): void {
diff --git a/cli/js/compiler_bootstrap.ts b/cli/js/compiler_bootstrap.ts
index afb3d2be5..585aec016 100644
--- a/cli/js/compiler_bootstrap.ts
+++ b/cli/js/compiler_bootstrap.ts
@@ -15,17 +15,27 @@ const options = host.getCompilationSettings();
// This is a hacky way of adding our libs to the libs available in TypeScript()
// as these are internal APIs of TypeScript which maintain valid libs
/* eslint-disable @typescript-eslint/no-explicit-any */
-(ts as any).libs.push("deno_main", "deno_worker", "deno");
-(ts as any).libMap.set("deno_main", "lib.deno_main.d.ts");
-(ts as any).libMap.set("deno_worker", "lib.deno_worker.d.ts");
-(ts as any).libMap.set("deno", "lib.deno.d.ts");
+(ts as any).libs.push(
+ "deno_ns",
+ "deno_window",
+ "deno_worker",
+ "deno_shared_globals"
+);
+(ts as any).libMap.set("deno_ns", "lib.deno.ns.d.ts");
+(ts as any).libMap.set("deno_window", "lib.deno.window.d.ts");
+(ts as any).libMap.set("deno_worker", "lib.deno.worker.d.ts");
+(ts as any).libMap.set("deno_shared_globals", "lib.deno.shared_globals.d.ts");
/* eslint-enable @typescript-eslint/no-explicit-any */
// this pre-populates the cache at snapshot time of our library files, so they
// are available in the future when needed.
-host.getSourceFile(`${ASSETS}/lib.deno_main.d.ts`, ts.ScriptTarget.ESNext);
-host.getSourceFile(`${ASSETS}/lib.deno_worker.d.ts`, ts.ScriptTarget.ESNext);
-host.getSourceFile(`${ASSETS}/lib.deno.d.ts`, ts.ScriptTarget.ESNext);
+host.getSourceFile(`${ASSETS}/lib.deno.ns.d.ts`, ts.ScriptTarget.ESNext);
+host.getSourceFile(`${ASSETS}/lib.deno.window.d.ts`, ts.ScriptTarget.ESNext);
+host.getSourceFile(`${ASSETS}/lib.deno.worker.d.ts`, ts.ScriptTarget.ESNext);
+host.getSourceFile(
+ `${ASSETS}/lib.deno.shared_globals.d.ts`,
+ ts.ScriptTarget.ESNext
+);
/**
* This function spins up TS compiler and loads all available libraries
diff --git a/cli/js/compiler_host.ts b/cli/js/compiler_host.ts
index 619ce702a..291f6fbc5 100644
--- a/cli/js/compiler_host.ts
+++ b/cli/js/compiler_host.ts
@@ -233,9 +233,9 @@ export class Host implements ts.CompilerHost {
switch (this._target) {
case CompilerHostTarget.Main:
case CompilerHostTarget.Runtime:
- return `${ASSETS}/lib.deno_main.d.ts`;
+ return `${ASSETS}/lib.deno.window.d.ts`;
case CompilerHostTarget.Worker:
- return `${ASSETS}/lib.deno_worker.d.ts`;
+ return `${ASSETS}/lib.deno.worker.d.ts`;
}
}
diff --git a/cli/js/globals.ts b/cli/js/globals.ts
index e6c1e855c..7cce739d5 100644
--- a/cli/js/globals.ts
+++ b/cli/js/globals.ts
@@ -132,7 +132,7 @@ declare global {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
var onmessage: ((e: { data: any }) => Promise<void> | void) | undefined;
// Called in compiler
- var workerClose: () => void;
+ var close: () => void;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
var postMessage: (msg: any) => void;
// Assigned to `self` global - compiler
diff --git a/cli/js/lib.deno.d.ts b/cli/js/lib.deno.ns.d.ts
index 0fa6f008c..0fa6f008c 100644
--- a/cli/js/lib.deno.d.ts
+++ b/cli/js/lib.deno.ns.d.ts
diff --git a/cli/js/lib.deno_main.d.ts b/cli/js/lib.deno.shared_globals.d.ts
index 52b6fb7f5..c8dfc833d 100644
--- a/cli/js/lib.deno_main.d.ts
+++ b/cli/js/lib.deno.shared_globals.d.ts
@@ -3,23 +3,23 @@
/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-interface, @typescript-eslint/no-explicit-any */
/// <reference no-default-lib="true" />
-/// <reference lib="deno" />
+/// <reference lib="deno_ns" />
/// <reference lib="esnext" />
-declare interface Window {
- window: Window & typeof globalThis;
+// https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope
+
+declare interface WindowOrWorkerGlobalScope {
+ // methods
atob: typeof __textEncoding.atob;
btoa: typeof __textEncoding.btoa;
- fetch: typeof __fetch.fetch;
- clearTimeout: typeof __timers.clearTimeout;
clearInterval: typeof __timers.clearInterval;
- console: __console.Console;
- setTimeout: typeof __timers.setTimeout;
+ clearTimeout: typeof __timers.clearTimeout;
+ fetch: typeof __fetch.fetch;
+ queueMicrotask: (task: () => void) => void;
setInterval: typeof __timers.setInterval;
- location: __domTypes.Location;
- onload: Function | undefined;
- onunload: Function | undefined;
- crypto: Crypto;
+ setTimeout: typeof __timers.setTimeout;
+ // properties
+ console: __console.Console;
Blob: typeof __blob.DenoBlob;
File: __domTypes.DomFileConstructor;
CustomEvent: typeof __customEvent.CustomEvent;
@@ -34,11 +34,9 @@ declare interface Window {
Request: __domTypes.RequestConstructor;
Response: typeof __fetch.Response;
performance: __performanceUtil.Performance;
- onmessage: (e: { data: any }) => void;
- onerror: undefined | typeof onerror;
- workerClose: typeof __workerMain.workerClose;
- postMessage: typeof __workerMain.postMessage;
Worker: typeof __workers.WorkerImpl;
+ location: __domTypes.Location;
+
addEventListener: (
type: string,
callback: (event: __domTypes.Event) => void | null,
@@ -50,23 +48,17 @@ declare interface Window {
callback: (event: __domTypes.Event) => void | null,
options?: boolean | __domTypes.EventListenerOptions | undefined
) => void;
- queueMicrotask: (task: () => void) => void;
- Deno: typeof Deno;
}
-declare const window: Window & typeof globalThis;
declare const atob: typeof __textEncoding.atob;
declare const btoa: typeof __textEncoding.btoa;
-declare const fetch: typeof __fetch.fetch;
-declare const clearTimeout: typeof __timers.clearTimeout;
declare const clearInterval: typeof __timers.clearInterval;
-declare const console: __console.Console;
-declare const setTimeout: typeof __timers.setTimeout;
+declare const clearTimeout: typeof __timers.clearTimeout;
+declare const fetch: typeof __fetch.fetch;
declare const setInterval: typeof __timers.setInterval;
-declare const location: __domTypes.Location;
-declare const onload: Function | undefined;
-declare const onunload: Function | undefined;
-declare const crypto: Crypto;
+declare const setTimeout: typeof __timers.setTimeout;
+
+declare const console: __console.Console;
declare const Blob: typeof __blob.DenoBlob;
declare const File: __domTypes.DomFileConstructor;
declare const CustomEventInit: typeof __customEvent.CustomEventInit;
@@ -78,25 +70,15 @@ declare const EventTarget: typeof __eventTarget.EventTarget;
declare const URL: typeof __url.URL;
declare const URLSearchParams: typeof __urlSearchParams.URLSearchParams;
declare const Headers: __domTypes.HeadersConstructor;
+declare const location: __domTypes.Location;
declare const FormData: __domTypes.FormDataConstructor;
declare const TextEncoder: typeof __textEncoding.TextEncoder;
declare const TextDecoder: typeof __textEncoding.TextDecoder;
declare const Request: __domTypes.RequestConstructor;
declare const Response: typeof __fetch.Response;
declare const performance: __performanceUtil.Performance;
-declare let onmessage: ((e: { data: any }) => Promise<void> | void) | undefined;
-declare let onerror:
- | ((
- msg: string,
- source: string,
- lineno: number,
- colno: number,
- e: Event
- ) => boolean | void)
- | undefined;
-declare const workerClose: typeof __workerMain.workerClose;
-declare const postMessage: typeof __workerMain.postMessage;
declare const Worker: typeof __workers.WorkerImpl;
+
declare const addEventListener: (
type: string,
callback: (event: __domTypes.Event) => void | null,
@@ -133,198 +115,6 @@ declare interface ImportMeta {
main: boolean;
}
-declare interface Crypto {
- readonly subtle: null;
- getRandomValues<
- T extends
- | Int8Array
- | Int16Array
- | Int32Array
- | Uint8Array
- | Uint16Array
- | Uint32Array
- | Uint8ClampedArray
- | Float32Array
- | Float64Array
- | DataView
- | null
- >(
- array: T
- ): T;
-}
-
-// This follows the WebIDL at: https://webassembly.github.io/spec/js-api/
-// and: https://webassembly.github.io/spec/web-api/
-
-declare namespace WebAssembly {
- interface WebAssemblyInstantiatedSource {
- module: Module;
- instance: Instance;
- }
-
- /** Compiles a `WebAssembly.Module` from WebAssembly binary code. This
- * function is useful if it is necessary to a compile a module before it can
- * be instantiated (otherwise, the `WebAssembly.instantiate()` function
- * should be used). */
- function compile(bufferSource: __domTypes.BufferSource): Promise<Module>;
-
- /** Compiles a `WebAssembly.Module` directly from a streamed underlying
- * source. This function is useful if it is necessary to a compile a module
- * before it can be instantiated (otherwise, the
- * `WebAssembly.instantiateStreaming()` function should be used). */
- function compileStreaming(
- source: Promise<__domTypes.Response>
- ): Promise<Module>;
-
- /** Takes the WebAssembly binary code, in the form of a typed array or
- * `ArrayBuffer`, and performs both compilation and instantiation in one step.
- * The returned `Promise` resolves to both a compiled `WebAssembly.Module` and
- * its first `WebAssembly.Instance`. */
- function instantiate(
- bufferSource: __domTypes.BufferSource,
- importObject?: object
- ): Promise<WebAssemblyInstantiatedSource>;
-
- /** Takes an already-compiled `WebAssembly.Module` and returns a `Promise`
- * that resolves to an `Instance` of that `Module`. This overload is useful if
- * the `Module` has already been compiled. */
- function instantiate(
- module: Module,
- importObject?: object
- ): Promise<Instance>;
-
- /** Compiles and instantiates a WebAssembly module directly from a streamed
- * underlying source. This is the most efficient, optimized way to load wasm
- * code. */
- function instantiateStreaming(
- source: Promise<__domTypes.Response>,
- importObject?: object
- ): Promise<WebAssemblyInstantiatedSource>;
-
- /** Validates a given typed array of WebAssembly binary code, returning
- * whether the bytes form a valid wasm module (`true`) or not (`false`). */
- function validate(bufferSource: __domTypes.BufferSource): boolean;
-
- type ImportExportKind = "function" | "table" | "memory" | "global";
-
- interface ModuleExportDescriptor {
- name: string;
- kind: ImportExportKind;
- }
- interface ModuleImportDescriptor {
- module: string;
- name: string;
- kind: ImportExportKind;
- }
-
- class Module {
- constructor(bufferSource: __domTypes.BufferSource);
-
- /** Given a `Module` and string, returns a copy of the contents of all
- * custom sections in the module with the given string name. */
- static customSections(
- moduleObject: Module,
- sectionName: string
- ): ArrayBuffer;
-
- /** Given a `Module`, returns an array containing descriptions of all the
- * declared exports. */
- static exports(moduleObject: Module): ModuleExportDescriptor[];
-
- /** Given a `Module`, returns an array containing descriptions of all the
- * declared imports. */
- static imports(moduleObject: Module): ModuleImportDescriptor[];
- }
-
- class Instance<T extends object = { [key: string]: any }> {
- constructor(module: Module, importObject?: object);
-
- /** An object containing as its members all the functions exported from the
- * WebAssembly module instance, to allow them to be accessed and used by
- * JavaScript. */
- readonly exports: T;
- }
-
- interface MemoryDescriptor {
- initial: number;
- maximum?: number;
- }
-
- class Memory {
- constructor(descriptor: MemoryDescriptor);
-
- /** An accessor property that returns the buffer contained in the memory. */
- readonly buffer: ArrayBuffer;
-
- /** Increases the size of the memory instance by a specified number of
- * WebAssembly pages (each one is 64KB in size). */
- grow(delta: number): number;
- }
-
- type TableKind = "anyfunc";
-
- interface TableDescriptor {
- element: TableKind;
- initial: number;
- maximum?: number;
- }
-
- class Table {
- constructor(descriptor: TableDescriptor);
-
- /** Returns the length of the table, i.e. the number of elements. */
- readonly length: number;
-
- /** Accessor function — gets the element stored at a given index. */
- get(index: number): (...args: any[]) => any;
-
- /** Increases the size of the Table instance by a specified number of
- * elements. */
- grow(delta: number): number;
-
- /** Sets an element stored at a given index to a given value. */
- set(index: number, value: (...args: any[]) => any): void;
- }
-
- type ValueType = "i32" | "i64" | "f32" | "f64";
-
- interface GlobalDescriptor {
- value: ValueType;
- mutable?: boolean;
- }
-
- /** Represents a global variable instance, accessible from both JavaScript and
- * importable/exportable across one or more `WebAssembly.Module` instances.
- * This allows dynamic linking of multiple modules. */
- class Global {
- constructor(descriptor: GlobalDescriptor, value?: any);
-
- /** Old-style method that returns the value contained inside the global
- * variable. */
- valueOf(): any;
-
- /** The value contained inside the global variable — this can be used to
- * directly set and get the global's value. */
- value: any;
- }
-
- /** Indicates an error during WebAssembly decoding or validation */
- class CompileError extends Error {
- constructor(message: string, fileName?: string, lineNumber?: string);
- }
-
- /** Indicates an error during module instantiation (besides traps from the
- * start function). */
- class LinkError extends Error {
- constructor(message: string, fileName?: string, lineNumber?: string);
- }
-
- /** Is thrown whenever WebAssembly specifies a trap. */
- class RuntimeError extends Error {
- constructor(message: string, fileName?: string, lineNumber?: string);
- }
-}
-
declare namespace __domTypes {
// @url js/dom_types.d.ts
@@ -1519,13 +1309,6 @@ declare namespace __url {
};
}
-declare namespace __workerMain {
- export let onmessage: (e: { data: any }) => void;
- export function postMessage(data: any): void;
- export function getMessage(): Promise<any>;
- export function workerClose(): void;
-}
-
declare namespace __workers {
// @url js/workers.d.ts
export interface Worker {
@@ -1533,9 +1316,11 @@ declare namespace __workers {
onmessage?: (e: { data: any }) => void;
onmessageerror?: () => void;
postMessage(data: any): void;
+ terminate(): void;
}
export interface WorkerOptions {
type?: "classic" | "module";
+ name?: string;
}
export class WorkerImpl implements Worker {
private readonly id;
@@ -1546,6 +1331,7 @@ declare namespace __workers {
onmessageerror?: () => void;
constructor(specifier: string, options?: WorkerOptions);
postMessage(data: any): void;
+ terminate(): void;
private run;
}
}
diff --git a/cli/js/lib.deno.window.d.ts b/cli/js/lib.deno.window.d.ts
new file mode 100644
index 000000000..d4dc08acb
--- /dev/null
+++ b/cli/js/lib.deno.window.d.ts
@@ -0,0 +1,214 @@
+// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
+
+/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-interface, @typescript-eslint/no-explicit-any */
+
+/// <reference no-default-lib="true" />
+/// <reference lib="deno_ns" />
+/// <reference lib="deno_shared_globals" />
+/// <reference lib="esnext" />
+
+declare interface Window extends WindowOrWorkerGlobalScope {
+ window: Window & WindowOrWorkerGlobalScope & typeof globalThis;
+ onload: Function | undefined;
+ onunload: Function | undefined;
+ crypto: Crypto;
+ Deno: typeof Deno;
+}
+
+declare const window: Window & WindowOrWorkerGlobalScope & typeof globalThis;
+declare const onload: Function | undefined;
+declare const onunload: Function | undefined;
+declare const crypto: Crypto;
+
+declare interface Crypto {
+ readonly subtle: null;
+ getRandomValues<
+ T extends
+ | Int8Array
+ | Int16Array
+ | Int32Array
+ | Uint8Array
+ | Uint16Array
+ | Uint32Array
+ | Uint8ClampedArray
+ | Float32Array
+ | Float64Array
+ | DataView
+ | null
+ >(
+ array: T
+ ): T;
+}
+
+// This follows the WebIDL at: https://webassembly.github.io/spec/js-api/
+// and: https://webassembly.github.io/spec/web-api/
+
+declare namespace WebAssembly {
+ interface WebAssemblyInstantiatedSource {
+ module: Module;
+ instance: Instance;
+ }
+
+ /** Compiles a `WebAssembly.Module` from WebAssembly binary code. This
+ * function is useful if it is necessary to a compile a module before it can
+ * be instantiated (otherwise, the `WebAssembly.instantiate()` function
+ * should be used). */
+ function compile(bufferSource: __domTypes.BufferSource): Promise<Module>;
+
+ /** Compiles a `WebAssembly.Module` directly from a streamed underlying
+ * source. This function is useful if it is necessary to a compile a module
+ * before it can be instantiated (otherwise, the
+ * `WebAssembly.instantiateStreaming()` function should be used). */
+ function compileStreaming(
+ source: Promise<__domTypes.Response>
+ ): Promise<Module>;
+
+ /** Takes the WebAssembly binary code, in the form of a typed array or
+ * `ArrayBuffer`, and performs both compilation and instantiation in one step.
+ * The returned `Promise` resolves to both a compiled `WebAssembly.Module` and
+ * its first `WebAssembly.Instance`. */
+ function instantiate(
+ bufferSource: __domTypes.BufferSource,
+ importObject?: object
+ ): Promise<WebAssemblyInstantiatedSource>;
+
+ /** Takes an already-compiled `WebAssembly.Module` and returns a `Promise`
+ * that resolves to an `Instance` of that `Module`. This overload is useful if
+ * the `Module` has already been compiled. */
+ function instantiate(
+ module: Module,
+ importObject?: object
+ ): Promise<Instance>;
+
+ /** Compiles and instantiates a WebAssembly module directly from a streamed
+ * underlying source. This is the most efficient, optimized way to load wasm
+ * code. */
+ function instantiateStreaming(
+ source: Promise<__domTypes.Response>,
+ importObject?: object
+ ): Promise<WebAssemblyInstantiatedSource>;
+
+ /** Validates a given typed array of WebAssembly binary code, returning
+ * whether the bytes form a valid wasm module (`true`) or not (`false`). */
+ function validate(bufferSource: __domTypes.BufferSource): boolean;
+
+ type ImportExportKind = "function" | "table" | "memory" | "global";
+
+ interface ModuleExportDescriptor {
+ name: string;
+ kind: ImportExportKind;
+ }
+ interface ModuleImportDescriptor {
+ module: string;
+ name: string;
+ kind: ImportExportKind;
+ }
+
+ class Module {
+ constructor(bufferSource: __domTypes.BufferSource);
+
+ /** Given a `Module` and string, returns a copy of the contents of all
+ * custom sections in the module with the given string name. */
+ static customSections(
+ moduleObject: Module,
+ sectionName: string
+ ): ArrayBuffer;
+
+ /** Given a `Module`, returns an array containing descriptions of all the
+ * declared exports. */
+ static exports(moduleObject: Module): ModuleExportDescriptor[];
+
+ /** Given a `Module`, returns an array containing descriptions of all the
+ * declared imports. */
+ static imports(moduleObject: Module): ModuleImportDescriptor[];
+ }
+
+ class Instance<T extends object = { [key: string]: any }> {
+ constructor(module: Module, importObject?: object);
+
+ /** An object containing as its members all the functions exported from the
+ * WebAssembly module instance, to allow them to be accessed and used by
+ * JavaScript. */
+ readonly exports: T;
+ }
+
+ interface MemoryDescriptor {
+ initial: number;
+ maximum?: number;
+ }
+
+ class Memory {
+ constructor(descriptor: MemoryDescriptor);
+
+ /** An accessor property that returns the buffer contained in the memory. */
+ readonly buffer: ArrayBuffer;
+
+ /** Increases the size of the memory instance by a specified number of
+ * WebAssembly pages (each one is 64KB in size). */
+ grow(delta: number): number;
+ }
+
+ type TableKind = "anyfunc";
+
+ interface TableDescriptor {
+ element: TableKind;
+ initial: number;
+ maximum?: number;
+ }
+
+ class Table {
+ constructor(descriptor: TableDescriptor);
+
+ /** Returns the length of the table, i.e. the number of elements. */
+ readonly length: number;
+
+ /** Accessor function — gets the element stored at a given index. */
+ get(index: number): (...args: any[]) => any;
+
+ /** Increases the size of the Table instance by a specified number of
+ * elements. */
+ grow(delta: number): number;
+
+ /** Sets an element stored at a given index to a given value. */
+ set(index: number, value: (...args: any[]) => any): void;
+ }
+
+ type ValueType = "i32" | "i64" | "f32" | "f64";
+
+ interface GlobalDescriptor {
+ value: ValueType;
+ mutable?: boolean;
+ }
+
+ /** Represents a global variable instance, accessible from both JavaScript and
+ * importable/exportable across one or more `WebAssembly.Module` instances.
+ * This allows dynamic linking of multiple modules. */
+ class Global {
+ constructor(descriptor: GlobalDescriptor, value?: any);
+
+ /** Old-style method that returns the value contained inside the global
+ * variable. */
+ valueOf(): any;
+
+ /** The value contained inside the global variable — this can be used to
+ * directly set and get the global's value. */
+ value: any;
+ }
+
+ /** Indicates an error during WebAssembly decoding or validation */
+ class CompileError extends Error {
+ constructor(message: string, fileName?: string, lineNumber?: string);
+ }
+
+ /** Indicates an error during module instantiation (besides traps from the
+ * start function). */
+ class LinkError extends Error {
+ constructor(message: string, fileName?: string, lineNumber?: string);
+ }
+
+ /** Is thrown whenever WebAssembly specifies a trap. */
+ class RuntimeError extends Error {
+ constructor(message: string, fileName?: string, lineNumber?: string);
+ }
+}
+/* eslint-enable @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-interface, @typescript-eslint/no-explicit-any */
diff --git a/cli/js/lib.deno.worker.d.ts b/cli/js/lib.deno.worker.d.ts
new file mode 100644
index 000000000..07955345c
--- /dev/null
+++ b/cli/js/lib.deno.worker.d.ts
@@ -0,0 +1,45 @@
+// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
+
+/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-interface, @typescript-eslint/no-explicit-any */
+
+/// <reference no-default-lib="true" />
+/// <reference lib="deno_shared_globals" />
+/// <reference lib="esnext" />
+
+declare interface DedicatedWorkerGlobalScope extends WindowOrWorkerGlobalScope {
+ self: DedicatedWorkerGlobalScope &
+ WindowOrWorkerGlobalScope &
+ typeof globalThis;
+ onmessage: (e: { data: any }) => void;
+ onerror: undefined | typeof onerror;
+ name: typeof __workerMain.name;
+ close: typeof __workerMain.close;
+ postMessage: typeof __workerMain.postMessage;
+}
+
+declare const self: DedicatedWorkerGlobalScope &
+ WindowOrWorkerGlobalScope &
+ typeof globalThis;
+declare let onmessage: ((e: { data: any }) => Promise<void> | void) | undefined;
+declare let onerror:
+ | ((
+ msg: string,
+ source: string,
+ lineno: number,
+ colno: number,
+ e: Event
+ ) => boolean | void)
+ | undefined;
+declare const close: typeof __workerMain.close;
+declare const name: typeof __workerMain.name;
+declare const postMessage: typeof __workerMain.postMessage;
+
+declare namespace __workerMain {
+ export let onmessage: (e: { data: any }) => void;
+ export function postMessage(data: any): void;
+ export function getMessage(): Promise<any>;
+ export function close(): void;
+ export const name: string;
+}
+
+/* eslint-enable @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-interface, @typescript-eslint/no-explicit-any */
diff --git a/cli/js/lib.deno_worker.d.ts b/cli/js/lib.deno_worker.d.ts
deleted file mode 100644
index d7652807d..000000000
--- a/cli/js/lib.deno_worker.d.ts
+++ /dev/null
@@ -1,5 +0,0 @@
-// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-
-/// <reference no-default-lib="true" />
-/// <reference lib="deno" />
-/// <reference lib="webworker" />
diff --git a/cli/js/runtime_worker.ts b/cli/js/runtime_worker.ts
index 7f1d1b69c..0dc65fdb6 100644
--- a/cli/js/runtime_worker.ts
+++ b/cli/js/runtime_worker.ts
@@ -54,7 +54,7 @@ export async function getMessage(): Promise<any> {
let isClosing = false;
let hasBootstrapped = false;
-export function workerClose(): void {
+export function close(): void {
isClosing = true;
}
@@ -102,7 +102,7 @@ export const workerRuntimeGlobalProperties = {
self: readOnly(globalThis),
onmessage: writable(onmessage),
onerror: writable(onerror),
- workerClose: nonEnumerable(workerClose),
+ close: nonEnumerable(close),
postMessage: writable(postMessage)
};
@@ -122,5 +122,6 @@ export function bootstrapWorkerRuntime(name: string): void {
Object.defineProperties(globalThis, windowOrWorkerGlobalScopeProperties);
Object.defineProperties(globalThis, workerRuntimeGlobalProperties);
Object.defineProperties(globalThis, eventTargetProperties);
+ Object.defineProperties(globalThis, { name: readOnly(name) });
runtime.start(false, name);
}
diff --git a/cli/js/workers.ts b/cli/js/workers.ts
index 60ef73da0..2a5d4d190 100644
--- a/cli/js/workers.ts
+++ b/cli/js/workers.ts
@@ -27,12 +27,14 @@ function decodeMessage(dataIntArray: Uint8Array): any {
function createWorker(
specifier: string,
hasSourceCode: boolean,
- sourceCode: Uint8Array
+ sourceCode: Uint8Array,
+ name?: string
): { id: number; loaded: boolean } {
return sendSync(dispatch.OP_CREATE_WORKER, {
specifier,
hasSourceCode,
- sourceCode: new TextDecoder().decode(sourceCode)
+ sourceCode: new TextDecoder().decode(sourceCode),
+ name
});
}
@@ -72,10 +74,12 @@ export interface Worker {
onmessage?: (e: { data: any }) => void;
onmessageerror?: () => void;
postMessage(data: any): void;
+ terminate(): void;
}
export interface WorkerOptions {
type?: "classic" | "module";
+ name?: string;
}
export class WorkerImpl extends EventTarget implements Worker {
@@ -121,7 +125,12 @@ export class WorkerImpl extends EventTarget implements Worker {
}
*/
- const { id, loaded } = createWorker(specifier, hasSourceCode, sourceCode);
+ const { id, loaded } = createWorker(
+ specifier,
+ hasSourceCode,
+ sourceCode,
+ options?.name
+ );
this.id = id;
this.ready = loaded;
this.poll();
@@ -196,6 +205,10 @@ export class WorkerImpl extends EventTarget implements Worker {
hostPostMessage(this.id, data);
}
+ terminate(): void {
+ throw new Error("Not yet implemented");
+ }
+
private async run(): Promise<void> {
while (!this.isClosing) {
const data = await hostGetMessage(this.id);