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
|
|
|
|
// Deno, and therefore it defines a lot of the runtime environemnt that code
|
|
|
|
// 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
|
|
|
|
// imported as namespaces, so when the runtime tpye library is generated they
|
|
|
|
// can be expressed as a namespace in the type library.
|
2019-02-19 21:42:19 -05:00
|
|
|
import { window } from "./window";
|
2018-10-11 17:23:13 -04:00
|
|
|
import * as blob from "./blob";
|
2018-11-08 19:09:18 -05:00
|
|
|
import * as consoleTypes from "./console";
|
2019-01-23 07:20:53 -05:00
|
|
|
import * as customEvent from "./custom_event";
|
2019-02-12 10:08:56 -05:00
|
|
|
import * as deno from "./deno";
|
2018-11-08 19:09:18 -05:00
|
|
|
import * as domTypes from "./dom_types";
|
2019-01-05 10:02:44 -05:00
|
|
|
import * as event from "./event";
|
|
|
|
import * as eventTarget from "./event_target";
|
2018-11-08 19:09:18 -05:00
|
|
|
import * as formData from "./form_data";
|
|
|
|
import * as fetchTypes from "./fetch";
|
|
|
|
import * as headers from "./headers";
|
2018-10-11 17:23:13 -04:00
|
|
|
import * as textEncoding from "./text_encoding";
|
|
|
|
import * as timers from "./timers";
|
2018-12-17 20:07:47 -05:00
|
|
|
import * as url from "./url";
|
2018-10-22 01:08:14 -04:00
|
|
|
import * as urlSearchParams from "./url_search_params";
|
2019-01-08 14:44:06 -05:00
|
|
|
import * as workers from "./workers";
|
2019-02-02 01:27:42 -05:00
|
|
|
import * as performanceUtil from "./performance";
|
2018-11-08 19:09:18 -05:00
|
|
|
|
|
|
|
// These imports are not exposed and therefore are fine to just import the
|
|
|
|
// symbols required.
|
|
|
|
import { libdeno } from "./libdeno";
|
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 {
|
2018-11-08 19:09:18 -05:00
|
|
|
const console: consoleTypes.Console;
|
2018-08-09 15:17:08 -04:00
|
|
|
const setTimeout: typeof timers.setTimeout;
|
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.
|
|
|
|
|
|
|
|
window.Deno = deno;
|
|
|
|
Object.freeze(window.Deno);
|
|
|
|
|
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;
|
|
|
|
window.clearTimeout = timers.clearTimer;
|
|
|
|
window.clearInterval = timers.clearTimer;
|
|
|
|
window.console = new consoleTypes.Console(libdeno.print);
|
|
|
|
window.setTimeout = timers.setTimeout;
|
|
|
|
window.setInterval = timers.setInterval;
|
2019-02-12 21:14:02 -05:00
|
|
|
window.location = (undefined as unknown) as domTypes.Location;
|
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;
|
|
|
|
export type Blob = blob.DenoBlob;
|
2018-12-23 11:44:08 -05:00
|
|
|
|
|
|
|
// TODO(ry) Do not export a class implementing the DOM, export the DOM
|
|
|
|
// interface. See this comment for implementation hint:
|
|
|
|
// https://github.com/denoland/deno/pull/1396#discussion_r243711502
|
|
|
|
// window.File = file.DenoFile;
|
|
|
|
// export type File = file.DenoFile;
|
|
|
|
|
2019-01-23 07:20:53 -05:00
|
|
|
window.CustomEventInit = customEvent.CustomEventInit;
|
|
|
|
export type CustomEventInit = customEvent.CustomEventInit;
|
|
|
|
window.CustomEvent = customEvent.CustomEvent;
|
|
|
|
export type CustomEvent = customEvent.CustomEvent;
|
2019-01-05 10:02:44 -05:00
|
|
|
window.EventInit = event.EventInit;
|
|
|
|
export type EventInit = event.EventInit;
|
|
|
|
window.Event = event.Event;
|
|
|
|
export type Event = event.Event;
|
|
|
|
window.EventTarget = eventTarget.EventTarget;
|
|
|
|
export type EventTarget = eventTarget.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;
|
2018-11-08 19:09:18 -05:00
|
|
|
export type URLSearchParams = urlSearchParams.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-02-02 01:27:42 -05:00
|
|
|
window.performance = new performanceUtil.Performance();
|
|
|
|
|
2019-01-08 14:44:06 -05:00
|
|
|
window.workerMain = workers.workerMain;
|