summaryrefslogtreecommitdiff
path: root/cli/js/lib.deno.shared_globals.d.ts
diff options
context:
space:
mode:
authorKitson Kelly <me@kitsonkelly.com>2020-04-12 01:42:02 +1000
committerGitHub <noreply@github.com>2020-04-11 11:42:02 -0400
commitfc4819e1e0624b9377913932202bc31f5a25bab4 (patch)
tree98604a5ce1ff29c1a900c0c37b7307072a48fa6a /cli/js/lib.deno.shared_globals.d.ts
parent2b362bef8523f3d8c05ce5d3d4b4a839b669568d (diff)
refactor: Event and EventTarget implementations (#4707)
Refactors Event and EventTarget so that they better encapsulate their non-public data as well as are more forward compatible with things like DOM Nodes. Moves `dom_types.ts` -> `dom_types.d.ts` which was always the intention, it was a legacy of when we used to build the types from the code and the limitations of the compiler. There was a lot of cruft in `dom_types` which shouldn't have been there, and mis-alignment to the DOM standards. This generally has been eliminated, though we still have some minor differences from the DOM (like the removal of some deprecated methods/properties). Adds `DOMException`. Strictly it shouldn't inherit from `Error`, but most browsers provide a stack trace when one is thrown, so the behaviour in Deno actually better matches the browser. `Event` still doesn't log to console like it does in the browser. I wanted to get this raised and that could be an enhancement later on (it currently doesn't either).
Diffstat (limited to 'cli/js/lib.deno.shared_globals.d.ts')
-rw-r--r--cli/js/lib.deno.shared_globals.d.ts192
1 files changed, 67 insertions, 125 deletions
diff --git a/cli/js/lib.deno.shared_globals.d.ts b/cli/js/lib.deno.shared_globals.d.ts
index 2027686a9..a1e834cc4 100644
--- a/cli/js/lib.deno.shared_globals.d.ts
+++ b/cli/js/lib.deno.shared_globals.d.ts
@@ -1,12 +1,8 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any */
+/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, no-var */
/// <reference no-default-lib="true" />
-// TODO: we need to remove this, but Fetch::Response::Body implements Reader
-// which requires Deno.EOF, and we shouldn't be leaking that, but https_proxy
-// at the least requires the Reader interface on Body, which it shouldn't
-/// <reference lib="deno.ns" />
/// <reference lib="esnext" />
// This follows the WebIDL at: https://webassembly.github.io/spec/js-api/
@@ -184,6 +180,7 @@ declare function setTimeout(
delay?: number,
...args: unknown[]
): number;
+
/** Repeatedly calls a function , with a fixed time delay between each call. */
declare function setInterval(
cb: (...args: unknown[]) => void,
@@ -194,8 +191,8 @@ declare function clearTimeout(id?: number): void;
declare function clearInterval(id?: number): void;
declare function queueMicrotask(func: Function): void;
-declare const console: Console;
-declare const location: Location;
+declare var console: Console;
+declare var location: Location;
declare function addEventListener(
type: string,
@@ -315,6 +312,12 @@ interface DOMStringList {
[index: number]: string;
}
+declare class DOMException extends Error {
+ constructor(message?: string, name?: string);
+ readonly name: string;
+ readonly message: string;
+}
+
/** The location (URL) of the object it is linked to. Changes done on it are
* reflected on the object it relates to. Both the Document and Window
* interface have such a linked Location, accessible via Document.location and
@@ -1060,122 +1063,81 @@ declare namespace performance {
export function now(): number;
}
+interface EventInit {
+ bubbles?: boolean;
+ cancelable?: boolean;
+ composed?: boolean;
+}
+
/** An event which takes place in the DOM. */
-interface Event {
- /**
- * Returns true or false depending on how event was initialized. True if
+declare class Event {
+ constructor(type: string, eventInitDict?: EventInit);
+ /** Returns true or false depending on how event was initialized. True if
* event goes through its target's ancestors in reverse tree order, and
- * false otherwise.
- */
+ * false otherwise. */
readonly bubbles: boolean;
-
- // TODO(ry) Remove cancelBubbleImmediately - non-standard extension.
- cancelBubbleImmediately: boolean;
-
cancelBubble: boolean;
- /**
- * Returns true or false depending on how event was initialized. Its return
- * value does not always carry meaning, but true can indicate that part of
- * the operation during which event was dispatched, can be canceled by
- * invoking the preventDefault() method.
- */
+ /** Returns true or false depending on how event was initialized. Its return
+ * value does not always carry meaning, but true can indicate that part of the
+ * operation during which event was dispatched, can be canceled by invoking
+ * the preventDefault() method. */
readonly cancelable: boolean;
- /**
- * Returns true or false depending on how event was initialized. True if
+ /** Returns true or false depending on how event was initialized. True if
* event invokes listeners past a ShadowRoot node that is the root of its
- * target, and false otherwise.
- */
+ * target, and false otherwise. */
readonly composed: boolean;
- /**
- * Returns the object whose event listener's callback is currently being
- * invoked.
- */
+ /** Returns the object whose event listener's callback is currently being
+ * invoked. */
readonly currentTarget: EventTarget | null;
- /**
- * Returns true if preventDefault() was invoked successfully to indicate
- * cancelation, and false otherwise.
- */
+ /** Returns true if preventDefault() was invoked successfully to indicate
+ * cancellation, and false otherwise. */
readonly defaultPrevented: boolean;
- /**
- * Returns the event's phase, which is one of NONE, CAPTURING_PHASE,
- * AT_TARGET, and BUBBLING_PHASE.
- */
+ /** Returns the event's phase, which is one of NONE, CAPTURING_PHASE,
+ * AT_TARGET, and BUBBLING_PHASE. */
readonly eventPhase: number;
- /**
- * Returns true if event was dispatched by the user agent, and false
- * otherwise.
- */
+ /** Returns true if event was dispatched by the user agent, and false
+ * otherwise. */
readonly isTrusted: boolean;
- returnValue: boolean;
- /** @deprecated */
- readonly srcElement: EventTarget | null;
- /**
- * Returns the object to which event is dispatched (its target).
- */
+ /** Returns the object to which event is dispatched (its target). */
readonly target: EventTarget | null;
- /**
- * Returns the event's timestamp as the number of milliseconds measured
- * relative to the time origin.
- */
+ /** Returns the event's timestamp as the number of milliseconds measured
+ * relative to the time origin. */
readonly timeStamp: number;
- /**
- * Returns the type of event, e.g. "click", "hashchange", or "submit".
- */
+ /** Returns the type of event, e.g. "click", "hashchange", or "submit". */
readonly type: string;
- /**
- * Returns the invocation target objects of event's path (objects on which
+ /** Returns the invocation target objects of event's path (objects on which
* listeners will be invoked), except for any nodes in shadow trees of which
* the shadow root's mode is "closed" that are not reachable from event's
- * currentTarget.
- */
+ * currentTarget. */
composedPath(): EventTarget[];
- initEvent(type: string, bubbles?: boolean, cancelable?: boolean): void;
- /**
- * If invoked when the cancelable attribute value is true, and while
+ /** If invoked when the cancelable attribute value is true, and while
* executing a listener for the event with passive set to false, signals to
* the operation that caused event to be dispatched that it needs to be
- * canceled.
- */
+ * canceled. */
preventDefault(): void;
- /**
- * Invoking this method prevents event from reaching any registered event
- * listeners after the current one finishes running and, when dispatched in
- * a tree, also prevents event from reaching any other objects.
- */
+ /** Invoking this method prevents event from reaching any registered event
+ * listeners after the current one finishes running and, when dispatched in a
+ * tree, also prevents event from reaching any other objects. */
stopImmediatePropagation(): void;
- /**
- * When dispatched in a tree, invoking this method prevents event from
- * reaching any objects other than the current object.
- */
+ /** When dispatched in a tree, invoking this method prevents event from
+ * reaching any objects other than the current object. */
stopPropagation(): void;
readonly AT_TARGET: number;
readonly BUBBLING_PHASE: number;
readonly CAPTURING_PHASE: number;
readonly NONE: number;
+ static readonly AT_TARGET: number;
+ static readonly BUBBLING_PHASE: number;
+ static readonly CAPTURING_PHASE: number;
+ static readonly NONE: number;
}
-interface EventInit {
- bubbles?: boolean;
- cancelable?: boolean;
- composed?: boolean;
-}
-
-declare const Event: {
- prototype: Event;
- new (type: string, eventInitDict?: EventInit): Event;
- readonly AT_TARGET: number;
- readonly BUBBLING_PHASE: number;
- readonly CAPTURING_PHASE: number;
- readonly NONE: number;
-};
-
/**
* EventTarget is a DOM interface implemented by objects that can receive events
* and may have listeners for them.
*/
-interface EventTarget {
- /**
- * Appends an event listener for events whose type attribute value is type.
+declare class EventTarget {
+ /** Appends an event listener for events whose type attribute value is type.
* The callback argument sets the callback that will be invoked when the event
* is dispatched.
*
@@ -1197,41 +1159,32 @@ interface EventTarget {
* invoked once after which the event listener will be removed.
*
* The event listener is appended to target's event listener list and is not
- * appended if it has the same type, callback, and capture.
- */
+ * appended if it has the same type, callback, and capture. */
addEventListener(
type: string,
listener: EventListenerOrEventListenerObject | null,
options?: boolean | AddEventListenerOptions
): void;
- /**
- * Dispatches a synthetic event event to target and returns true if either
+ /** Dispatches a synthetic event event to target and returns true if either
* event's cancelable attribute value is false or its preventDefault() method
- * was not invoked, and false otherwise.
- */
+ * was not invoked, and false otherwise. */
dispatchEvent(event: Event): boolean;
- /**
- * Removes the event listener in target's event listener list with the same
- * type, callback, and options.
- */
+ /** Removes the event listener in target's event listener list with the same
+ * type, callback, and options. */
removeEventListener(
type: string,
callback: EventListenerOrEventListenerObject | null,
options?: EventListenerOptions | boolean
): void;
+ [Symbol.toStringTag]: string;
}
-declare const EventTarget: {
- prototype: EventTarget;
- new (): EventTarget;
-};
-
interface EventListener {
- (evt: Event): void;
+ (evt: Event): void | Promise<void>;
}
interface EventListenerObject {
- handleEvent(evt: Event): void;
+ handleEvent(evt: Event): void | Promise<void>;
}
declare type EventListenerOrEventListenerObject =
@@ -1257,27 +1210,16 @@ interface ProgressEvent<T extends EventTarget = EventTarget> extends Event {
readonly total: number;
}
-interface CustomEvent<T = any> extends Event {
- /**
- * Returns any custom data event was created with. Typically used for synthetic events.
- */
- readonly detail: T;
- initCustomEvent(
- typeArg: string,
- canBubbleArg: boolean,
- cancelableArg: boolean,
- detailArg: T
- ): void;
-}
-
interface CustomEventInit<T = any> extends EventInit {
detail?: T;
}
-declare const CustomEvent: {
- prototype: CustomEvent;
- new <T>(typeArg: string, eventInitDict?: CustomEventInit<T>): CustomEvent<T>;
-};
+declare class CustomEvent<T = any> extends Event {
+ constructor(typeArg: string, eventInitDict?: CustomEventInit<T>);
+ /** Returns any custom data event was created with. Typically used for
+ * synthetic events. */
+ readonly detail: T;
+}
interface AbortSignalEventMap {
abort: Event;