2019-01-21 14:03:30 -05:00
|
|
|
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
2018-11-08 19:09:18 -05:00
|
|
|
// This is a "special" module, in that it define the global runtime scope of
|
2019-08-19 11:35:43 -04:00
|
|
|
// Deno, and therefore it defines a lot of the runtime environment that code
|
2018-11-08 19:09:18 -05:00
|
|
|
// is evaluated in. We use this file to automatically build the runtime type
|
|
|
|
// library.
|
|
|
|
|
|
|
|
// Modules which will make up part of the global public API surface should be
|
2019-04-19 20:39:54 -04:00
|
|
|
// imported as namespaces, so when the runtime type library is generated they
|
2018-11-08 19:09:18 -05:00
|
|
|
// can be expressed as a namespace in the type library.
|
2019-09-02 17:07:11 -04:00
|
|
|
import { window } from "./window.ts";
|
|
|
|
import * as blob from "./blob.ts";
|
|
|
|
import * as consoleTypes from "./console.ts";
|
|
|
|
import * as csprng from "./get_random_values.ts";
|
|
|
|
import * as customEvent from "./custom_event.ts";
|
|
|
|
import * as Deno from "./deno.ts";
|
|
|
|
import * as domTypes from "./dom_types.ts";
|
|
|
|
import * as domFile from "./dom_file.ts";
|
|
|
|
import * as event from "./event.ts";
|
|
|
|
import * as eventTarget from "./event_target.ts";
|
|
|
|
import * as formData from "./form_data.ts";
|
|
|
|
import * as fetchTypes from "./fetch.ts";
|
|
|
|
import * as headers from "./headers.ts";
|
|
|
|
import * as textEncoding from "./text_encoding.ts";
|
|
|
|
import * as timers from "./timers.ts";
|
|
|
|
import * as url from "./url.ts";
|
|
|
|
import * as urlSearchParams from "./url_search_params.ts";
|
|
|
|
import * as workers from "./workers.ts";
|
|
|
|
import * as performanceUtil from "./performance.ts";
|
|
|
|
import * as request from "./request.ts";
|
2019-05-01 23:56:42 -04:00
|
|
|
|
2018-11-08 19:09:18 -05:00
|
|
|
// These imports are not exposed and therefore are fine to just import the
|
|
|
|
// symbols required.
|
2019-09-02 17:07:11 -04:00
|
|
|
import { core } from "./core.ts";
|
2018-09-12 15:16:42 -04:00
|
|
|
|
2018-10-11 17:23:13 -04:00
|
|
|
// During the build process, augmentations to the variable `window` in this
|
|
|
|
// file are tracked and created as part of default library that is built into
|
2018-11-08 19:09:18 -05:00
|
|
|
// Deno, we only need to declare the enough to compile Deno.
|
2018-10-11 17:23:13 -04:00
|
|
|
declare global {
|
2019-07-29 05:11:08 -04:00
|
|
|
interface CallSite {
|
|
|
|
getThis(): unknown;
|
|
|
|
getTypeName(): string;
|
|
|
|
getFunction(): Function;
|
|
|
|
getFunctionName(): string;
|
|
|
|
getMethodName(): string;
|
|
|
|
getFileName(): string;
|
|
|
|
getLineNumber(): number | null;
|
|
|
|
getColumnNumber(): number | null;
|
|
|
|
getEvalOrigin(): string | null;
|
|
|
|
isToplevel(): boolean;
|
|
|
|
isEval(): boolean;
|
|
|
|
isNative(): boolean;
|
|
|
|
isConstructor(): boolean;
|
|
|
|
isAsync(): boolean;
|
|
|
|
isPromiseAll(): boolean;
|
|
|
|
getPromiseIndex(): number | null;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface ErrorConstructor {
|
|
|
|
prepareStackTrace(error: Error, structuredStackTrace: CallSite[]): string;
|
|
|
|
}
|
2019-08-19 11:35:43 -04:00
|
|
|
|
|
|
|
interface Object {
|
|
|
|
[consoleTypes.customInspect]?(): string;
|
|
|
|
}
|
2018-08-07 16:27:31 -04:00
|
|
|
}
|
|
|
|
|
2018-11-08 19:09:18 -05:00
|
|
|
// A self reference to the global object.
|
2018-08-06 18:37:32 -04:00
|
|
|
window.window = window;
|
|
|
|
|
2019-02-12 10:08:56 -05:00
|
|
|
// This is the Deno namespace, it is handled differently from other window
|
|
|
|
// properties when building the runtime type library, as the whole module
|
|
|
|
// is flattened into a single namespace.
|
2019-08-19 11:35:43 -04:00
|
|
|
window.Deno = Deno;
|
2019-02-12 10:08:56 -05:00
|
|
|
|
2018-11-08 19:09:18 -05:00
|
|
|
// Globally available functions and object instances.
|
2018-09-20 18:53:29 -04:00
|
|
|
window.atob = textEncoding.atob;
|
|
|
|
window.btoa = textEncoding.btoa;
|
2018-11-08 19:09:18 -05:00
|
|
|
window.fetch = fetchTypes.fetch;
|
2019-06-18 09:24:20 -04:00
|
|
|
window.clearTimeout = timers.clearTimeout;
|
|
|
|
window.clearInterval = timers.clearInterval;
|
2019-07-17 09:42:04 -04:00
|
|
|
window.console = new consoleTypes.Console(core.print);
|
2018-11-08 19:09:18 -05:00
|
|
|
window.setTimeout = timers.setTimeout;
|
|
|
|
window.setInterval = timers.setInterval;
|
2019-02-12 21:14:02 -05:00
|
|
|
window.location = (undefined as unknown) as domTypes.Location;
|
2019-07-16 00:19:26 -04:00
|
|
|
window.onload = undefined as undefined | Function;
|
2019-10-02 11:32:51 -04:00
|
|
|
window.onunload = undefined as undefined | Function;
|
2019-05-17 14:03:01 -04:00
|
|
|
// The following Crypto interface implementation is not up to par with the
|
|
|
|
// standard https://www.w3.org/TR/WebCryptoAPI/#crypto-interface as it does not
|
|
|
|
// yet incorporate the SubtleCrypto interface as its "subtle" property.
|
|
|
|
window.crypto = (csprng as unknown) as Crypto;
|
2019-08-31 15:16:30 -04:00
|
|
|
// window.queueMicrotask added by hand to self-maintained lib.deno_runtime.d.ts
|
2018-07-06 11:20:35 -04:00
|
|
|
|
2018-11-08 19:09:18 -05:00
|
|
|
// When creating the runtime type library, we use modifications to `window` to
|
|
|
|
// determine what is in the global namespace. When we put a class in the
|
|
|
|
// namespace, we also need its global instance type as well, otherwise users
|
|
|
|
// won't be able to refer to instances.
|
|
|
|
// We have to export the type aliases, so that TypeScript _knows_ they are
|
|
|
|
// being used, which it cannot statically determine within this module.
|
|
|
|
window.Blob = blob.DenoBlob;
|
2019-09-17 12:17:12 -04:00
|
|
|
export type Blob = domTypes.Blob;
|
2018-12-23 11:44:08 -05:00
|
|
|
|
2019-09-10 10:57:17 -04:00
|
|
|
export type Body = domTypes.Body;
|
|
|
|
|
2019-09-23 11:07:13 -04:00
|
|
|
window.File = domFile.DomFileImpl as domTypes.DomFileConstructor;
|
2019-04-12 14:54:13 -04:00
|
|
|
export type File = domTypes.DomFile;
|
2018-12-23 11:44:08 -05:00
|
|
|
|
2019-09-17 12:17:12 -04:00
|
|
|
export type CustomEventInit = domTypes.CustomEventInit;
|
2019-01-23 07:20:53 -05:00
|
|
|
window.CustomEvent = customEvent.CustomEvent;
|
2019-09-17 12:17:12 -04:00
|
|
|
export type CustomEvent = domTypes.CustomEvent;
|
|
|
|
export type EventInit = domTypes.EventInit;
|
2019-01-05 10:02:44 -05:00
|
|
|
window.Event = event.Event;
|
2019-09-17 12:17:12 -04:00
|
|
|
export type Event = domTypes.Event;
|
|
|
|
export type EventListener = domTypes.EventListener;
|
2019-01-05 10:02:44 -05:00
|
|
|
window.EventTarget = eventTarget.EventTarget;
|
2019-09-17 12:17:12 -04:00
|
|
|
export type EventTarget = domTypes.EventTarget;
|
2018-12-17 20:07:47 -05:00
|
|
|
window.URL = url.URL;
|
|
|
|
export type URL = url.URL;
|
2018-10-22 01:08:14 -04:00
|
|
|
window.URLSearchParams = urlSearchParams.URLSearchParams;
|
2019-09-17 12:17:12 -04:00
|
|
|
export type URLSearchParams = domTypes.URLSearchParams;
|
2018-10-21 11:07:29 -04:00
|
|
|
|
2018-11-08 19:09:18 -05:00
|
|
|
// Using the `as` keyword to use standard compliant interfaces as the Deno
|
|
|
|
// implementations contain some implementation details we wouldn't want to
|
|
|
|
// expose in the runtime type library.
|
|
|
|
window.Headers = headers.Headers as domTypes.HeadersConstructor;
|
|
|
|
export type Headers = domTypes.Headers;
|
|
|
|
window.FormData = formData.FormData as domTypes.FormDataConstructor;
|
|
|
|
export type FormData = domTypes.FormData;
|
2018-09-12 15:16:42 -04:00
|
|
|
|
2018-11-08 19:09:18 -05:00
|
|
|
window.TextEncoder = textEncoding.TextEncoder;
|
2018-12-06 13:01:15 -05:00
|
|
|
export type TextEncoder = textEncoding.TextEncoder;
|
2018-11-08 19:09:18 -05:00
|
|
|
window.TextDecoder = textEncoding.TextDecoder;
|
2018-12-06 13:01:15 -05:00
|
|
|
export type TextDecoder = textEncoding.TextDecoder;
|
2019-01-08 14:44:06 -05:00
|
|
|
|
2019-06-11 21:32:49 -04:00
|
|
|
window.Request = request.Request as domTypes.RequestConstructor;
|
|
|
|
export type Request = domTypes.Request;
|
2019-05-01 23:56:42 -04:00
|
|
|
|
2019-06-13 22:53:30 -04:00
|
|
|
window.Response = fetchTypes.Response;
|
|
|
|
export type Response = domTypes.Response;
|
2019-05-01 23:56:42 -04:00
|
|
|
|
2019-02-02 01:27:42 -05:00
|
|
|
window.performance = new performanceUtil.Performance();
|
|
|
|
|
2019-04-01 15:09:59 -04:00
|
|
|
// This variable functioning correctly depends on `declareAsLet`
|
|
|
|
// in //tools/ts_library_builder/main.ts
|
|
|
|
window.onmessage = workers.onmessage;
|
|
|
|
|
2019-01-08 14:44:06 -05:00
|
|
|
window.workerMain = workers.workerMain;
|
2019-04-01 15:09:59 -04:00
|
|
|
window.workerClose = workers.workerClose;
|
|
|
|
window.postMessage = workers.postMessage;
|
|
|
|
|
|
|
|
window.Worker = workers.WorkerImpl;
|
|
|
|
export type Worker = workers.Worker;
|
2019-03-25 00:23:24 -04:00
|
|
|
|
2019-07-16 00:19:26 -04:00
|
|
|
window[domTypes.eventTargetHost] = null;
|
|
|
|
window[domTypes.eventTargetListeners] = {};
|
|
|
|
window[domTypes.eventTargetMode] = "";
|
|
|
|
window[domTypes.eventTargetNodeType] = 0;
|
|
|
|
window[eventTarget.eventTargetAssignedSlot] = false;
|
|
|
|
window[eventTarget.eventTargetHasActivationBehavior] = false;
|
|
|
|
window.addEventListener = eventTarget.EventTarget.prototype.addEventListener;
|
|
|
|
window.dispatchEvent = eventTarget.EventTarget.prototype.dispatchEvent;
|
|
|
|
window.removeEventListener =
|
|
|
|
eventTarget.EventTarget.prototype.removeEventListener;
|
|
|
|
|
|
|
|
// Registers the handler for window.onload function.
|
|
|
|
window.addEventListener(
|
|
|
|
"load",
|
|
|
|
(e: domTypes.Event): void => {
|
|
|
|
const onload = window.onload;
|
|
|
|
if (typeof onload === "function") {
|
|
|
|
onload(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2019-10-02 11:32:51 -04:00
|
|
|
// Registers the handler for window.onunload function.
|
|
|
|
window.addEventListener(
|
|
|
|
"unload",
|
|
|
|
(e: domTypes.Event): void => {
|
|
|
|
const onunload = window.onunload;
|
|
|
|
if (typeof onunload === "function") {
|
|
|
|
onunload(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2019-07-16 00:19:26 -04:00
|
|
|
|
2019-03-25 00:23:24 -04:00
|
|
|
// below are interfaces that are available in TypeScript but
|
|
|
|
// have different signatures
|
|
|
|
export interface ImportMeta {
|
|
|
|
url: string;
|
|
|
|
main: boolean;
|
|
|
|
}
|
2019-05-17 14:03:01 -04:00
|
|
|
|
|
|
|
export interface Crypto {
|
|
|
|
readonly subtle: null;
|
|
|
|
getRandomValues: <
|
|
|
|
T extends
|
|
|
|
| Int8Array
|
|
|
|
| Uint8Array
|
|
|
|
| Uint8ClampedArray
|
|
|
|
| Int16Array
|
|
|
|
| Uint16Array
|
|
|
|
| Int32Array
|
|
|
|
| Uint32Array
|
|
|
|
>(
|
|
|
|
typedArray: T
|
|
|
|
) => T;
|
|
|
|
}
|