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

Implement ResponseConstructor to allow overrides from other runtimes #1941

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions baselines/audioworklet.generated.d.ts
Original file line number Diff line number Diff line change
@@ -862,6 +862,9 @@ interface ReadableStreamGenericReader {
cancel(reason?: any): Promise<void>;
}

interface ResponseConstructor {
}
Comment on lines +865 to +866
Copy link
Contributor

Choose a reason for hiding this comment

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

The Audio Worklet type has been affected.

Copy link
Author

Choose a reason for hiding this comment

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

Why is this the case? Because Response was declared as exposed in Worker?


/**
* A decoder for a specific method, that is a specific character encoding, like utf-8, iso-8859-2, koi8, cp1261, gbk, etc. A decoder takes a stream of bytes as input and emits a stream of code points. For a more scalable, non-native library, see StringView – a C-like representation of strings based on typed arrays.
*
15 changes: 10 additions & 5 deletions baselines/dom.generated.d.ts
Original file line number Diff line number Diff line change
@@ -20043,20 +20043,21 @@ interface Response extends Body {
readonly type: ResponseType;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/url) */
readonly url: string;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/clone) */
clone(): Response;
}

declare var Response: {
interface ResponseConstructor {
prototype: Response;
new(body?: BodyInit | null, init?: ResponseInit): Response;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/clone) */
clone(): Response;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/error_static) */
error(): Response;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/json_static) */
json(data: any, init?: ResponseInit): Response;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/Response) */
new(body?: BodyInit | null, init?: ResponseInit): Response;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/redirect_static) */
redirect(url: string | URL, status?: number): Response;
};
}

/**
* Provides access to the properties of <a> element, as well as methods to manipulate them.
@@ -27183,6 +27184,8 @@ interface WindowEventMap extends GlobalEventHandlersEventMap, WindowEventHandler
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window)
*/
interface Window extends EventTarget, AnimationFrameProvider, GlobalEventHandlers, WindowEventHandlers, WindowLocalStorage, WindowOrWorkerGlobalScope, WindowSessionStorage {
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/Response) */
readonly Response: ResponseConstructor;
/**
* @deprecated This is a legacy alias of `navigator`.
*
@@ -28820,6 +28823,8 @@ declare var Image: {
declare var Option: {
new(text?: string, value?: string, defaultSelected?: boolean, selected?: boolean): HTMLOptionElement;
};
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/Response) */
declare var Response: ResponseConstructor;
/**
* @deprecated This is a legacy alias of `navigator`.
*
11 changes: 6 additions & 5 deletions baselines/serviceworker.generated.d.ts
Original file line number Diff line number Diff line change
@@ -4896,20 +4896,21 @@ interface Response extends Body {
readonly type: ResponseType;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/url) */
readonly url: string;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/clone) */
clone(): Response;
}

declare var Response: {
interface ResponseConstructor {
prototype: Response;
new(body?: BodyInit | null, init?: ResponseInit): Response;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/clone) */
clone(): Response;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/error_static) */
error(): Response;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/json_static) */
json(data: any, init?: ResponseInit): Response;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/Response) */
new(body?: BodyInit | null, init?: ResponseInit): Response;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/redirect_static) */
redirect(url: string | URL, status?: number): Response;
};
}

/**
* Inherits from Event, and represents the event object of an event sent on a document or worker when its content security policy is violated.
11 changes: 6 additions & 5 deletions baselines/sharedworker.generated.d.ts
Original file line number Diff line number Diff line change
@@ -4658,20 +4658,21 @@ interface Response extends Body {
readonly type: ResponseType;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/url) */
readonly url: string;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/clone) */
clone(): Response;
}

declare var Response: {
interface ResponseConstructor {
prototype: Response;
new(body?: BodyInit | null, init?: ResponseInit): Response;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/clone) */
clone(): Response;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/error_static) */
error(): Response;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/json_static) */
json(data: any, init?: ResponseInit): Response;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/Response) */
new(body?: BodyInit | null, init?: ResponseInit): Response;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/redirect_static) */
redirect(url: string | URL, status?: number): Response;
};
}

/**
* Inherits from Event, and represents the event object of an event sent on a document or worker when its content security policy is violated.
3 changes: 3 additions & 0 deletions baselines/ts5.5/audioworklet.generated.d.ts
Original file line number Diff line number Diff line change
@@ -862,6 +862,9 @@ interface ReadableStreamGenericReader {
cancel(reason?: any): Promise<void>;
}

interface ResponseConstructor {
}

/**
* A decoder for a specific method, that is a specific character encoding, like utf-8, iso-8859-2, koi8, cp1261, gbk, etc. A decoder takes a stream of bytes as input and emits a stream of code points. For a more scalable, non-native library, see StringView – a C-like representation of strings based on typed arrays.
*
15 changes: 10 additions & 5 deletions baselines/ts5.5/dom.generated.d.ts
Original file line number Diff line number Diff line change
@@ -20023,20 +20023,21 @@ interface Response extends Body {
readonly type: ResponseType;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/url) */
readonly url: string;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/clone) */
clone(): Response;
}

declare var Response: {
interface ResponseConstructor {
prototype: Response;
new(body?: BodyInit | null, init?: ResponseInit): Response;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/clone) */
clone(): Response;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/error_static) */
error(): Response;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/json_static) */
json(data: any, init?: ResponseInit): Response;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/Response) */
new(body?: BodyInit | null, init?: ResponseInit): Response;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/redirect_static) */
redirect(url: string | URL, status?: number): Response;
};
}

/**
* Provides access to the properties of <a> element, as well as methods to manipulate them.
@@ -27161,6 +27162,8 @@ interface WindowEventMap extends GlobalEventHandlersEventMap, WindowEventHandler
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window)
*/
interface Window extends EventTarget, AnimationFrameProvider, GlobalEventHandlers, WindowEventHandlers, WindowLocalStorage, WindowOrWorkerGlobalScope, WindowSessionStorage {
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/Response) */
readonly Response: ResponseConstructor;
/**
* @deprecated This is a legacy alias of `navigator`.
*
@@ -28798,6 +28801,8 @@ declare var Image: {
declare var Option: {
new(text?: string, value?: string, defaultSelected?: boolean, selected?: boolean): HTMLOptionElement;
};
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/Response) */
declare var Response: ResponseConstructor;
/**
* @deprecated This is a legacy alias of `navigator`.
*
11 changes: 6 additions & 5 deletions baselines/ts5.5/serviceworker.generated.d.ts
Original file line number Diff line number Diff line change
@@ -4896,20 +4896,21 @@ interface Response extends Body {
readonly type: ResponseType;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/url) */
readonly url: string;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/clone) */
clone(): Response;
}

declare var Response: {
interface ResponseConstructor {
prototype: Response;
new(body?: BodyInit | null, init?: ResponseInit): Response;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/clone) */
clone(): Response;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/error_static) */
error(): Response;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/json_static) */
json(data: any, init?: ResponseInit): Response;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/Response) */
new(body?: BodyInit | null, init?: ResponseInit): Response;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/redirect_static) */
redirect(url: string | URL, status?: number): Response;
};
}

/**
* Inherits from Event, and represents the event object of an event sent on a document or worker when its content security policy is violated.
11 changes: 6 additions & 5 deletions baselines/ts5.5/sharedworker.generated.d.ts
Original file line number Diff line number Diff line change
@@ -4658,20 +4658,21 @@ interface Response extends Body {
readonly type: ResponseType;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/url) */
readonly url: string;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/clone) */
clone(): Response;
}

declare var Response: {
interface ResponseConstructor {
prototype: Response;
new(body?: BodyInit | null, init?: ResponseInit): Response;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/clone) */
clone(): Response;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/error_static) */
error(): Response;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/json_static) */
json(data: any, init?: ResponseInit): Response;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/Response) */
new(body?: BodyInit | null, init?: ResponseInit): Response;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/redirect_static) */
redirect(url: string | URL, status?: number): Response;
};
}

/**
* Inherits from Event, and represents the event object of an event sent on a document or worker when its content security policy is violated.
11 changes: 6 additions & 5 deletions baselines/ts5.5/webworker.generated.d.ts
Original file line number Diff line number Diff line change
@@ -5595,20 +5595,21 @@ interface Response extends Body {
readonly type: ResponseType;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/url) */
readonly url: string;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/clone) */
clone(): Response;
}

declare var Response: {
interface ResponseConstructor {
prototype: Response;
new(body?: BodyInit | null, init?: ResponseInit): Response;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/clone) */
clone(): Response;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/error_static) */
error(): Response;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/json_static) */
json(data: any, init?: ResponseInit): Response;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/Response) */
new(body?: BodyInit | null, init?: ResponseInit): Response;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/redirect_static) */
redirect(url: string | URL, status?: number): Response;
};
}

/**
* Inherits from Event, and represents the event object of an event sent on a document or worker when its content security policy is violated.
11 changes: 6 additions & 5 deletions baselines/webworker.generated.d.ts
Original file line number Diff line number Diff line change
@@ -5595,20 +5595,21 @@ interface Response extends Body {
readonly type: ResponseType;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/url) */
readonly url: string;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/clone) */
clone(): Response;
}

declare var Response: {
interface ResponseConstructor {
prototype: Response;
new(body?: BodyInit | null, init?: ResponseInit): Response;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/clone) */
clone(): Response;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/error_static) */
error(): Response;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/json_static) */
json(data: any, init?: ResponseInit): Response;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/Response) */
new(body?: BodyInit | null, init?: ResponseInit): Response;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/redirect_static) */
redirect(url: string | URL, status?: number): Response;
};
}

/**
* Inherits from Event, and represents the event object of an event sent on a document or worker when its content security policy is violated.
234 changes: 234 additions & 0 deletions inputfiles/addedTypes.jsonc
Original file line number Diff line number Diff line change
@@ -454,6 +454,227 @@
},
"interfaces": {
"interface": {
"Response": {
"name": "Response",
"noInterfaceObject": true,

"properties": {
"property": {
"type": {
"name": "type",
"type": "ResponseType",
"readonly": true,
"exposed": "Window Worker",
"mdnUrl": "https://developer.mozilla.org/docs/Web/API/Response/type"
},
"url": {
"name": "url",
"type": "USVString",
"readonly": true,
"exposed": "Window Worker",
"mdnUrl": "https://developer.mozilla.org/docs/Web/API/Response/url"
},
"redirected": {
"name": "redirected",
"type": "boolean",
"readonly": true,
"exposed": "Window Worker",
"mdnUrl": "https://developer.mozilla.org/docs/Web/API/Response/redirected"
},
"status": {
"name": "status",
"type": "unsigned short",
"readonly": true,
"exposed": "Window Worker",
"mdnUrl": "https://developer.mozilla.org/docs/Web/API/Response/status"
},
"ok": {
"name": "ok",
"type": "boolean",
"readonly": true,
"exposed": "Window Worker",
"mdnUrl": "https://developer.mozilla.org/docs/Web/API/Response/ok"
},
"statusText": {
"name": "statusText",
"type": "ByteString",
"readonly": true,
"exposed": "Window Worker",
"mdnUrl": "https://developer.mozilla.org/docs/Web/API/Response/statusText"
},
"headers": {
"name": "headers",
"type": "Headers",
"readonly": true,
"exposed": "Window Worker",
"mdnUrl": "https://developer.mozilla.org/docs/Web/API/Response/headers"
}
},
"namesakes": {}
},
"constructor": {
"signature": [
{
"type": "Response",
"param": [
{
"name": "body",
"type": "BodyInit",
"nullable": true,
"optional": true,
"variadic": false
},
{
"name": "init",
"type": "ResponseInit",
"nullable": false,
"optional": true,
"variadic": false
}
]
}
]
},
"exposed": "Window Worker",
"legacyWindowAlias": [],
"secureContext": false,
"transferable": false,
"implements": ["Body"],
"mdnUrl": "https://developer.mozilla.org/docs/Web/API/Response",
"comment": "This Fetch API interface represents the response to a request."
},
"ResponseConstructor": {
"name": "ResponseConstructor",
"noInterfaceObject": true,

"properties": {
"property": {
"prototype": {
"name": "prototype",
"type": "Response",
"exposed": "Window Worker"
}
}
},

"methods": {
"method": {
"new": {
"mdnUrl": "https://developer.mozilla.org/docs/Web/API/Response/Response",
"name": "new",
"exposed": "Window Worker",
"signature": [
{
"type": "Response",
"param": [
{
"name": "body",
"type": "BodyInit",
"nullable": true,
"optional": true,
"variadic": false
},
{
"name": "init",
"type": "ResponseInit",
"nullable": false,
"optional": true,
"variadic": false
}
]
}
]
},
"error": {
"name": "error",
"signature": [
{
"type": "Response",
"nullable": false,
"param": []
}
],
"getter": false,
"stringifier": false,
"exposed": "Window Worker",
"mdnUrl": "https://developer.mozilla.org/docs/Web/API/Response/error_static"
},
"redirect": {
"name": "redirect",
"signature": [
{
"type": "Response",
"nullable": false,
"param": [
{
"name": "url",
"type": "USVString",
"nullable": false,
"optional": false,
"variadic": false
},
{
"name": "status",
"type": "unsigned short",
"nullable": false,
"optional": true,
"variadic": false
}
]
}
],
"getter": false,
"stringifier": false,
"exposed": "Window Worker",
"mdnUrl": "https://developer.mozilla.org/docs/Web/API/Response/redirect_static"
},
"json": {
"name": "json",
"signature": [
{
"type": "Response",
"nullable": false,
"param": [
{
"name": "data",
"type": "any",
"nullable": false,
"optional": false,
"variadic": false
},
{
"name": "init",
"type": "ResponseInit",
"nullable": false,
"optional": true,
"variadic": false
}
]
}
],
"getter": false,
"stringifier": false,
"exposed": "Window Worker",
"mdnUrl": "https://developer.mozilla.org/docs/Web/API/Response/json_static"
},
"clone": {
"name": "clone",
"signature": [
{
"type": "Response",
"nullable": false,
"param": []
}
],
"getter": false,
"static": false,
"stringifier": false,
"exposed": "Window Worker",
"mdnUrl": "https://developer.mozilla.org/docs/Web/API/Response/clone"
}
}
}
},
// ImportMeta is not a true DOM interface, but we are forced to declare it as one in order to emit method definitions.
// We cannot define methods as dictionary properties with function types,
// as this would cause conflicts with ImportMeta method overrides in places like @types/node.
@@ -604,6 +825,19 @@
"overrideIndexSignatures": [
"[index: number]: Window"
],
"properties": {
"property": {
"Response": {
"name": "Response",
"type": "ResponseConstructor",
"nullable": false,
"readonly": true,
"exposed": "Window",
"secureContext": false,
"mdnUrl": "https://developer.mozilla.org/docs/Web/API/Response/Response"
}
}
},
"events": {
"event": [
{
1 change: 1 addition & 0 deletions inputfiles/removedTypes.jsonc
Original file line number Diff line number Diff line change
@@ -109,6 +109,7 @@
},
"interfaces": {
"interface": {
"Response": null,
"Clipboard": {
"methods": {
"method": {