Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dts): make globals available on globalThis #19438

Merged
merged 3 commits into from
Jul 3, 2023

Conversation

0f-0b
Copy link
Contributor

@0f-0b 0f-0b commented Jun 9, 2023

This PR changes Web IDL interfaces to be declared with var instead of class, so that accessing them via globalThis does not raise type errors.

deno doc --builtin Request output (#7514)
Defined in internal:https://lib.deno.d.ts:7667:0

var Request: { new(input: RequestInfo | URL, init?: RequestInit): Request; prototype: Request; }
  This Fetch API interface represents a resource request.

  @category
      Fetch API


Defined in internal:https://lib.deno.d.ts:7577:0

interface Request extends Body
  This Fetch API interface represents a resource request.

  @category
      Fetch API


  readonly cache: RequestCache
    Returns the cache mode associated with request, which is a string
    indicating how the request will interact with the browser's cache when
    fetching.
  readonly credentials: RequestCredentials
    Returns the credentials mode associated with request, which is a string
    indicating whether credentials will be sent with the request always, never,
    or only when sent to a same-origin URL.
  readonly destination: RequestDestination
    Returns the kind of resource requested by request, e.g., "document" or "script".
  readonly headers: Headers
    Returns a Headers object consisting of the headers associated with request.
    Note that headers added in the network layer by the user agent will not be
    accounted for in this object, e.g., the "Host" header.
  readonly integrity: string
    Returns request's subresource integrity metadata, which is a cryptographic
    hash of the resource being fetched. Its value consists of multiple hashes
    separated by whitespace. [SRI]
  readonly isHistoryNavigation: boolean
    Returns a boolean indicating whether or not request is for a history
    navigation (a.k.a. back-forward navigation).
  readonly isReloadNavigation: boolean
    Returns a boolean indicating whether or not request is for a reload
    navigation.
  readonly keepalive: boolean
    Returns a boolean indicating whether or not request can outlive the global
    in which it was created.
  readonly method: string
    Returns request's HTTP method, which is "GET" by default.
  readonly mode: RequestMode
    Returns the mode associated with request, which is a string indicating
    whether the request will use CORS, or will be restricted to same-origin
    URLs.
  readonly redirect: RequestRedirect
    Returns the redirect mode associated with request, which is a string
    indicating how redirects for the request will be handled during fetching. A
    request will follow redirects by default.
  readonly referrer: string
    Returns the referrer of request. Its value can be a same-origin URL if
    explicitly set in init, the empty string to indicate no referrer, and
    "about:client" when defaulting to the global's default. This is used during
    fetching to determine the value of the `Referer` header of the request
    being made.
  readonly referrerPolicy: ReferrerPolicy
    Returns the referrer policy associated with request. This is used during
    fetching to compute the value of the request's referrer.
  readonly signal: AbortSignal
    Returns the signal associated with request, which is an AbortSignal object
    indicating whether or not request has been aborted, and its abort event
    handler.
  readonly url: string
    Returns the URL of request as a string.
  clone(): Request

Also adds type declarations for missing Web APIs, except deprecated or non-standard ones.

List of added APIs
globalThis.Crypto;
globalThis.DOMException.ABORT_ERR;
globalThis.DOMException.DATA_CLONE_ERR;
globalThis.DOMException.DOMSTRING_SIZE_ERR;
globalThis.DOMException.HIERARCHY_REQUEST_ERR;
globalThis.DOMException.INDEX_SIZE_ERR;
globalThis.DOMException.INUSE_ATTRIBUTE_ERR;
globalThis.DOMException.INVALID_ACCESS_ERR;
globalThis.DOMException.INVALID_CHARACTER_ERR;
globalThis.DOMException.INVALID_MODIFICATION_ERR;
globalThis.DOMException.INVALID_NODE_TYPE_ERR;
globalThis.DOMException.INVALID_STATE_ERR;
globalThis.DOMException.NAMESPACE_ERR;
globalThis.DOMException.NETWORK_ERR;
globalThis.DOMException.NOT_FOUND_ERR;
globalThis.DOMException.NOT_SUPPORTED_ERR;
globalThis.DOMException.NO_DATA_ALLOWED_ERR;
globalThis.DOMException.NO_MODIFICATION_ALLOWED_ERR;
globalThis.DOMException.QUOTA_EXCEEDED_ERR;
globalThis.DOMException.SECURITY_ERR;
globalThis.DOMException.SYNTAX_ERR;
globalThis.DOMException.TIMEOUT_ERR;
globalThis.DOMException.TYPE_MISMATCH_ERR;
globalThis.DOMException.URL_MISMATCH_ERR;
globalThis.DOMException.VALIDATION_ERR;
globalThis.DOMException.WRONG_DOCUMENT_ERR;
globalThis.DOMException.prototype.ABORT_ERR;
globalThis.DOMException.prototype.DATA_CLONE_ERR;
globalThis.DOMException.prototype.DOMSTRING_SIZE_ERR;
globalThis.DOMException.prototype.HIERARCHY_REQUEST_ERR;
globalThis.DOMException.prototype.INDEX_SIZE_ERR;
globalThis.DOMException.prototype.INUSE_ATTRIBUTE_ERR;
globalThis.DOMException.prototype.INVALID_ACCESS_ERR;
globalThis.DOMException.prototype.INVALID_CHARACTER_ERR;
globalThis.DOMException.prototype.INVALID_MODIFICATION_ERR;
globalThis.DOMException.prototype.INVALID_NODE_TYPE_ERR;
globalThis.DOMException.prototype.INVALID_STATE_ERR;
globalThis.DOMException.prototype.NAMESPACE_ERR;
globalThis.DOMException.prototype.NETWORK_ERR;
globalThis.DOMException.prototype.NOT_FOUND_ERR;
globalThis.DOMException.prototype.NOT_SUPPORTED_ERR;
globalThis.DOMException.prototype.NO_DATA_ALLOWED_ERR;
globalThis.DOMException.prototype.NO_MODIFICATION_ALLOWED_ERR;
globalThis.DOMException.prototype.QUOTA_EXCEEDED_ERR;
globalThis.DOMException.prototype.SECURITY_ERR;
globalThis.DOMException.prototype.SYNTAX_ERR;
globalThis.DOMException.prototype.TIMEOUT_ERR;
globalThis.DOMException.prototype.TYPE_MISMATCH_ERR;
globalThis.DOMException.prototype.URL_MISMATCH_ERR;
globalThis.DOMException.prototype.VALIDATION_ERR;
globalThis.DOMException.prototype.WRONG_DOCUMENT_ERR;
globalThis.Headers.prototype.getSetCookie;
globalThis.MessageEvent.prototype.source;
globalThis.ReadableStream.from;
globalThis.ReadableStream.prototype.values;
globalThis.ReadableStreamBYOBRequest;
globalThis.TransformStreamDefaultController.prototype;
globalThis.WritableStreamDefaultController.prototype;
globalThis.close;
globalThis.closed;
List of excluded APIs
// non-standard
globalThis.Event.prototype.initialized;
globalThis.EventTarget.prototype.getParent;
globalThis.console.indentLevel;

// deprecated
globalThis.Event.prototype.returnValue;
globalThis.Event.prototype.srcElement;

Closes #13390.

Copy link
Member

@dsherret dsherret left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice change. Thank you!

This PR changes Web IDL interfaces to be declared with var instead of class, so that accessing them via globalThis does not raise type errors.

Yes, this is correct. Thanks for doing this.

@dsherret dsherret merged commit d632cce into denoland:main Jul 3, 2023
10 checks passed
@0f-0b 0f-0b deleted the fix-global-types branch July 3, 2023 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Some global variables are not available on globalThis
2 participants