From 48b7d783ee9b32651e0d3e275cd3d65f7607204d Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Sat, 19 Jul 2025 19:20:07 +0200 Subject: [PATCH 1/3] Restore Trusted Types from BCD 6.0.24 --- baselines/dom.generated.d.ts | 218 +++++++++++++++++-- baselines/serviceworker.generated.d.ts | 194 ++++++++++++++++- baselines/sharedworker.generated.d.ts | 196 ++++++++++++++++- baselines/ts5.5/dom.generated.d.ts | 218 +++++++++++++++++-- baselines/ts5.5/serviceworker.generated.d.ts | 194 ++++++++++++++++- baselines/ts5.5/sharedworker.generated.d.ts | 196 ++++++++++++++++- baselines/ts5.5/webworker.generated.d.ts | 196 ++++++++++++++++- baselines/ts5.6/dom.generated.d.ts | 218 +++++++++++++++++-- baselines/ts5.6/serviceworker.generated.d.ts | 194 ++++++++++++++++- baselines/ts5.6/sharedworker.generated.d.ts | 196 ++++++++++++++++- baselines/ts5.6/webworker.generated.d.ts | 196 ++++++++++++++++- baselines/webworker.generated.d.ts | 196 ++++++++++++++++- inputfiles/overridingTypes.jsonc | 23 -- 13 files changed, 2322 insertions(+), 113 deletions(-) diff --git a/baselines/dom.generated.d.ts b/baselines/dom.generated.d.ts index 76130d49d..34387fd4c 100644 --- a/baselines/dom.generated.d.ts +++ b/baselines/dom.generated.d.ts @@ -2322,6 +2322,12 @@ interface TransitionEventInit extends EventInit { pseudoElement?: string; } +interface TrustedTypePolicyOptions { + createHTML?: CreateHTMLCallback; + createScript?: CreateScriptCallback; + createScriptURL?: CreateScriptURLCallback; +} + interface UIEventInit extends EventInit { detail?: number; view?: Window | null; @@ -9259,7 +9265,7 @@ interface DOMParser { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/DOMParser/parseFromString) */ - parseFromString(string: string, type: DOMParserSupportedType): Document; + parseFromString(string: TrustedHTML | string, type: DOMParserSupportedType): Document; } declare var DOMParser: { @@ -10628,14 +10634,14 @@ interface Document extends Node, DocumentOrShadowRoot, FontFaceSource, GlobalEve * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Document/write) */ - write(...text: string[]): void; + write(...text: (TrustedHTML | string)[]): void; /** * The **`writeln()`** method of the Document interface writes text in one or more TrustedHTML or string parameters to a document stream opened by document.open(), followed by a newline character. * @deprecated * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Document/writeln) */ - writeln(...text: string[]): void; + writeln(...text: (TrustedHTML | string)[]): void; /** [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent) */ get textContent(): null; addEventListener(type: K, listener: (this: Document, ev: DocumentEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; @@ -10652,7 +10658,7 @@ declare var Document: { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Document/parseHTMLUnsafe_static) */ - parseHTMLUnsafe(html: string): Document; + parseHTMLUnsafe(html: TrustedHTML | string): Document; }; /** @@ -11006,7 +11012,7 @@ interface Element extends Node, ARIAMixin, Animatable, ChildNode, NonDocumentTyp * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/innerHTML) */ - innerHTML: string; + innerHTML: TrustedHTML | string; /** * The **`Element.localName`** read-only property returns the local part of the qualified name of an element. * @@ -11028,7 +11034,7 @@ interface Element extends Node, ARIAMixin, Animatable, ChildNode, NonDocumentTyp * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/outerHTML) */ - outerHTML: string; + outerHTML: TrustedHTML | string; readonly ownerDocument: Document; /** * The **`part`** property of the Element interface represents the part identifier(s) of the element (i.e., set using the `part` attribute), returned as a DOMTokenList. @@ -11221,7 +11227,7 @@ interface Element extends Node, ARIAMixin, Animatable, ChildNode, NonDocumentTyp * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/insertAdjacentHTML) */ - insertAdjacentHTML(position: InsertPosition, string: string): void; + insertAdjacentHTML(position: InsertPosition, string: TrustedHTML | string): void; /** * The **`insertAdjacentText()`** method of the Element interface, given a relative position and a string, inserts a new text node at the given position relative to the element it is called from. * @@ -11326,7 +11332,7 @@ interface Element extends Node, ARIAMixin, Animatable, ChildNode, NonDocumentTyp * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/setHTMLUnsafe) */ - setHTMLUnsafe(html: string): void; + setHTMLUnsafe(html: TrustedHTML | string): void; /** * The **`setPointerCapture()`** method of the _capture target_ of future pointer events. * @@ -14747,7 +14753,7 @@ interface HTMLIFrameElement extends HTMLElement { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLIFrameElement/srcdoc) */ - srcdoc: string; + srcdoc: TrustedHTML | string; /** * The **`width`** property of the HTMLIFrameElement interface returns a string that reflects the `width` attribute of the iframe element, indicating the width of the frame in CSS pixels. * @@ -25943,7 +25949,7 @@ interface Range extends AbstractRange { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Range/createContextualFragment) */ - createContextualFragment(string: string): DocumentFragment; + createContextualFragment(string: TrustedHTML | string): DocumentFragment; /** * The **`Range.deleteContents()`** method removes all completely-selected Node within this range from the document. * @@ -30888,7 +30894,7 @@ interface ServiceWorkerContainer extends EventTarget { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/ServiceWorkerContainer/register) */ - register(scriptURL: string | URL, options?: RegistrationOptions): Promise; + register(scriptURL: TrustedScriptURL | string, options?: RegistrationOptions): Promise; /** * The **`startMessages()`** method of the ServiceWorkerContainer interface explicitly starts the flow of messages being dispatched from a service worker to pages under its control (e.g., sent via Client.postMessage()). * @@ -31035,7 +31041,7 @@ interface ShadowRoot extends DocumentFragment, DocumentOrShadowRoot { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/ShadowRoot/innerHTML) */ - innerHTML: string; + innerHTML: TrustedHTML | string; /** * The **`mode`** read-only property of the ShadowRoot specifies its mode — either `open` or `closed`. * @@ -31066,7 +31072,7 @@ interface ShadowRoot extends DocumentFragment, DocumentOrShadowRoot { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/ShadowRoot/setHTMLUnsafe) */ - setHTMLUnsafe(html: string): void; + setHTMLUnsafe(html: TrustedHTML | string): void; addEventListener(type: K, listener: (this: ShadowRoot, ev: ShadowRootEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void; removeEventListener(type: K, listener: (this: ShadowRoot, ev: ShadowRootEventMap[K]) => any, options?: boolean | EventListenerOptions): void; @@ -31098,7 +31104,7 @@ interface SharedWorker extends EventTarget, AbstractWorker { declare var SharedWorker: { prototype: SharedWorker; - new(scriptURL: string | URL, options?: string | WorkerOptions): SharedWorker; + new(scriptURL: TrustedScriptURL | string, options?: string | WorkerOptions): SharedWorker; }; interface Slottable { @@ -32925,6 +32931,170 @@ declare var TreeWalker: { new(): TreeWalker; }; +/** + * The **`TrustedHTML`** interface of the Trusted Types API represents a string that a developer can insert into an injection sink that will render it as HTML. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedHTML) + */ +interface TrustedHTML { + /** + * The **`toJSON()`** method of the TrustedHTML interface returns a JSON representation of the stored data. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedHTML/toJSON) + */ + toJSON(): string; + toString(): string; +} + +declare var TrustedHTML: { + prototype: TrustedHTML; + new(): TrustedHTML; +}; + +/** + * The **`TrustedScript`** interface of the Trusted Types API represents a string with an uncompiled script body that a developer can insert into an injection sink that might execute the script. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedScript) + */ +interface TrustedScript { + /** + * The **`toJSON()`** method of the TrustedScript interface returns a JSON representation of the stored data. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedScript/toJSON) + */ + toJSON(): string; + toString(): string; +} + +declare var TrustedScript: { + prototype: TrustedScript; + new(): TrustedScript; +}; + +/** + * The **`TrustedScriptURL`** interface of the Trusted Types API represents a string that a developer can insert into an injection sink that will parse it as a URL of an external script. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedScriptURL) + */ +interface TrustedScriptURL { + /** + * The **`toJSON()`** method of the TrustedScriptURL interface returns a JSON representation of the stored data. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedScriptURL/toJSON) + */ + toJSON(): string; + toString(): string; +} + +declare var TrustedScriptURL: { + prototype: TrustedScriptURL; + new(): TrustedScriptURL; +}; + +/** + * The **`TrustedTypePolicy`** interface of the Trusted Types API defines a group of functions which create `TrustedType` objects. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicy) + */ +interface TrustedTypePolicy { + /** + * The **`name`** read-only property of the TrustedTypePolicy interface returns the name of the policy. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicy/name) + */ + readonly name: string; + /** + * The **`createHTML()`** method of the TrustedTypePolicy interface creates a TrustedHTML object using a policy created by TrustedTypePolicyFactory.createPolicy(). + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicy/createHTML) + */ + createHTML(input: string, ...arguments: any[]): TrustedHTML; + /** + * The **`createScript()`** method of the TrustedTypePolicy interface creates a TrustedScript object using a policy created by TrustedTypePolicyFactory.createPolicy(). + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicy/createScript) + */ + createScript(input: string, ...arguments: any[]): TrustedScript; + /** + * The **`createScriptURL()`** method of the TrustedTypePolicy interface creates a TrustedScriptURL object using a policy created by TrustedTypePolicyFactory.createPolicy(). + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicy/createScriptURL) + */ + createScriptURL(input: string, ...arguments: any[]): TrustedScriptURL; +} + +declare var TrustedTypePolicy: { + prototype: TrustedTypePolicy; + new(): TrustedTypePolicy; +}; + +/** + * The **`TrustedTypePolicyFactory`** interface of the Trusted Types API creates policies and allows the verification of Trusted Type objects against created policies. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory) + */ +interface TrustedTypePolicyFactory { + /** + * The **`defaultPolicy`** read-only property of the TrustedTypePolicyFactory interface returns the default TrustedTypePolicy or null if this is empty. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/defaultPolicy) + */ + readonly defaultPolicy: TrustedTypePolicy | null; + /** + * The **`emptyHTML`** read-only property of the TrustedTypePolicyFactory interface returns a TrustedHTML object containing an empty string. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/emptyHTML) + */ + readonly emptyHTML: TrustedHTML; + /** + * The **`emptyScript`** read-only property of the TrustedTypePolicyFactory interface returns a TrustedScript object containing an empty string. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/emptyScript) + */ + readonly emptyScript: TrustedScript; + /** + * The **`createPolicy()`** method of the TrustedTypePolicyFactory interface creates a TrustedTypePolicy object that implements the rules passed as `policyOptions`. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/createPolicy) + */ + createPolicy(policyName: string, policyOptions?: TrustedTypePolicyOptions): TrustedTypePolicy; + /** + * The **`getAttributeType()`** method of the TrustedTypePolicyFactory interface allows web developers to check if a Trusted Type is required for an element, and if so which Trusted Type is used. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/getAttributeType) + */ + getAttributeType(tagName: string, attribute: string, elementNs?: string | null, attrNs?: string | null): string | null; + /** + * The **`getPropertyType()`** method of the TrustedTypePolicyFactory interface allows web developers to check if a Trusted Type is required for an element's property. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/getPropertyType) + */ + getPropertyType(tagName: string, property: string, elementNs?: string | null): string | null; + /** + * The **`isHTML()`** method of the TrustedTypePolicyFactory interface returns true if it is passed a valid TrustedHTML object. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/isHTML) + */ + isHTML(value: any): boolean; + /** + * The **`isScript()`** method of the TrustedTypePolicyFactory interface returns true if it is passed a valid TrustedScript object. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/isScript) + */ + isScript(value: any): boolean; + /** + * The **`isScriptURL()`** method of the TrustedTypePolicyFactory interface returns true if it is passed a valid TrustedScriptURL object. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/isScriptURL) + */ + isScriptURL(value: any): boolean; +} + +declare var TrustedTypePolicyFactory: { + prototype: TrustedTypePolicyFactory; + new(): TrustedTypePolicyFactory; +}; + /** * The **`UIEvent`** interface represents simple user interface events. * @@ -37345,6 +37515,8 @@ interface WindowOrWorkerGlobalScope { readonly origin: string; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/performance) */ readonly performance: Performance; + /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/trustedTypes) */ + readonly trustedTypes: TrustedTypePolicyFactory; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/atob) */ atob(data: string): string; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/btoa) */ @@ -37405,7 +37577,7 @@ interface Worker extends EventTarget, AbstractWorker, MessageEventTarget declare var Worker: { prototype: Worker; - new(scriptURL: string | URL, options?: WorkerOptions): Worker; + new(scriptURL: TrustedScriptURL | string, options?: WorkerOptions): Worker; }; /** @@ -38405,6 +38577,18 @@ interface BlobCallback { (blob: Blob | null): void; } +interface CreateHTMLCallback { + (input: string, ...arguments: any[]): string | null; +} + +interface CreateScriptCallback { + (input: string, ...arguments: any[]): string | null; +} + +interface CreateScriptURLCallback { + (input: string, ...arguments: any[]): string | null; +} + interface CustomElementConstructor { new (...params: any[]): HTMLElement; } @@ -39570,6 +39754,8 @@ declare var isSecureContext: boolean; declare var origin: string; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/performance) */ declare var performance: Performance; +/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/trustedTypes) */ +declare var trustedTypes: TrustedTypePolicyFactory; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/atob) */ declare function atob(data: string): string; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/btoa) */ @@ -39671,7 +39857,7 @@ type RenderingContext = CanvasRenderingContext2D | ImageBitmapRenderingContext | type ReportList = Report[]; type RequestInfo = Request | string; type TexImageSource = ImageBitmap | ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | OffscreenCanvas | VideoFrame; -type TimerHandler = string | Function; +type TimerHandler = string | Function | TrustedScript; type Transferable = OffscreenCanvas | ImageBitmap | MessagePort | MediaSourceHandle | ReadableStream | WritableStream | TransformStream | AudioData | VideoFrame | RTCDataChannel | ArrayBuffer; type URLPatternInput = string | URLPatternInit; type Uint32List = Uint32Array | GLuint[]; diff --git a/baselines/serviceworker.generated.d.ts b/baselines/serviceworker.generated.d.ts index 6430a4b66..b646ba82e 100644 --- a/baselines/serviceworker.generated.d.ts +++ b/baselines/serviceworker.generated.d.ts @@ -717,6 +717,12 @@ interface Transformer { writableType?: undefined; } +interface TrustedTypePolicyOptions { + createHTML?: CreateHTMLCallback; + createScript?: CreateScriptCallback; + createScriptURL?: CreateScriptURLCallback; +} + interface URLPatternComponentResult { groups?: Record; input?: string; @@ -6942,7 +6948,7 @@ interface ServiceWorkerContainer extends EventTarget { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/ServiceWorkerContainer/register) */ - register(scriptURL: string | URL, options?: RegistrationOptions): Promise; + register(scriptURL: TrustedScriptURL | string, options?: RegistrationOptions): Promise; /** * The **`startMessages()`** method of the ServiceWorkerContainer interface explicitly starts the flow of messages being dispatched from a service worker to pages under its control (e.g., sent via Client.postMessage()). * @@ -7550,6 +7556,170 @@ declare var TransformStreamDefaultController: { new(): TransformStreamDefaultController; }; +/** + * The **`TrustedHTML`** interface of the Trusted Types API represents a string that a developer can insert into an injection sink that will render it as HTML. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedHTML) + */ +interface TrustedHTML { + /** + * The **`toJSON()`** method of the TrustedHTML interface returns a JSON representation of the stored data. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedHTML/toJSON) + */ + toJSON(): string; + toString(): string; +} + +declare var TrustedHTML: { + prototype: TrustedHTML; + new(): TrustedHTML; +}; + +/** + * The **`TrustedScript`** interface of the Trusted Types API represents a string with an uncompiled script body that a developer can insert into an injection sink that might execute the script. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedScript) + */ +interface TrustedScript { + /** + * The **`toJSON()`** method of the TrustedScript interface returns a JSON representation of the stored data. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedScript/toJSON) + */ + toJSON(): string; + toString(): string; +} + +declare var TrustedScript: { + prototype: TrustedScript; + new(): TrustedScript; +}; + +/** + * The **`TrustedScriptURL`** interface of the Trusted Types API represents a string that a developer can insert into an injection sink that will parse it as a URL of an external script. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedScriptURL) + */ +interface TrustedScriptURL { + /** + * The **`toJSON()`** method of the TrustedScriptURL interface returns a JSON representation of the stored data. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedScriptURL/toJSON) + */ + toJSON(): string; + toString(): string; +} + +declare var TrustedScriptURL: { + prototype: TrustedScriptURL; + new(): TrustedScriptURL; +}; + +/** + * The **`TrustedTypePolicy`** interface of the Trusted Types API defines a group of functions which create `TrustedType` objects. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicy) + */ +interface TrustedTypePolicy { + /** + * The **`name`** read-only property of the TrustedTypePolicy interface returns the name of the policy. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicy/name) + */ + readonly name: string; + /** + * The **`createHTML()`** method of the TrustedTypePolicy interface creates a TrustedHTML object using a policy created by TrustedTypePolicyFactory.createPolicy(). + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicy/createHTML) + */ + createHTML(input: string, ...arguments: any[]): TrustedHTML; + /** + * The **`createScript()`** method of the TrustedTypePolicy interface creates a TrustedScript object using a policy created by TrustedTypePolicyFactory.createPolicy(). + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicy/createScript) + */ + createScript(input: string, ...arguments: any[]): TrustedScript; + /** + * The **`createScriptURL()`** method of the TrustedTypePolicy interface creates a TrustedScriptURL object using a policy created by TrustedTypePolicyFactory.createPolicy(). + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicy/createScriptURL) + */ + createScriptURL(input: string, ...arguments: any[]): TrustedScriptURL; +} + +declare var TrustedTypePolicy: { + prototype: TrustedTypePolicy; + new(): TrustedTypePolicy; +}; + +/** + * The **`TrustedTypePolicyFactory`** interface of the Trusted Types API creates policies and allows the verification of Trusted Type objects against created policies. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory) + */ +interface TrustedTypePolicyFactory { + /** + * The **`defaultPolicy`** read-only property of the TrustedTypePolicyFactory interface returns the default TrustedTypePolicy or null if this is empty. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/defaultPolicy) + */ + readonly defaultPolicy: TrustedTypePolicy | null; + /** + * The **`emptyHTML`** read-only property of the TrustedTypePolicyFactory interface returns a TrustedHTML object containing an empty string. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/emptyHTML) + */ + readonly emptyHTML: TrustedHTML; + /** + * The **`emptyScript`** read-only property of the TrustedTypePolicyFactory interface returns a TrustedScript object containing an empty string. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/emptyScript) + */ + readonly emptyScript: TrustedScript; + /** + * The **`createPolicy()`** method of the TrustedTypePolicyFactory interface creates a TrustedTypePolicy object that implements the rules passed as `policyOptions`. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/createPolicy) + */ + createPolicy(policyName: string, policyOptions?: TrustedTypePolicyOptions): TrustedTypePolicy; + /** + * The **`getAttributeType()`** method of the TrustedTypePolicyFactory interface allows web developers to check if a Trusted Type is required for an element, and if so which Trusted Type is used. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/getAttributeType) + */ + getAttributeType(tagName: string, attribute: string, elementNs?: string | null, attrNs?: string | null): string | null; + /** + * The **`getPropertyType()`** method of the TrustedTypePolicyFactory interface allows web developers to check if a Trusted Type is required for an element's property. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/getPropertyType) + */ + getPropertyType(tagName: string, property: string, elementNs?: string | null): string | null; + /** + * The **`isHTML()`** method of the TrustedTypePolicyFactory interface returns true if it is passed a valid TrustedHTML object. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/isHTML) + */ + isHTML(value: any): boolean; + /** + * The **`isScript()`** method of the TrustedTypePolicyFactory interface returns true if it is passed a valid TrustedScript object. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/isScript) + */ + isScript(value: any): boolean; + /** + * The **`isScriptURL()`** method of the TrustedTypePolicyFactory interface returns true if it is passed a valid TrustedScriptURL object. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/isScriptURL) + */ + isScriptURL(value: any): boolean; +} + +declare var TrustedTypePolicyFactory: { + prototype: TrustedTypePolicyFactory; + new(): TrustedTypePolicyFactory; +}; + /** * The **`URL`** interface is used to parse, construct, normalize, and encode URL. * @@ -10601,6 +10771,8 @@ interface WindowOrWorkerGlobalScope { readonly origin: string; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/performance) */ readonly performance: Performance; + /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/trustedTypes) */ + readonly trustedTypes: TrustedTypePolicyFactory; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/atob) */ atob(data: string): string; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/btoa) */ @@ -10676,7 +10848,7 @@ interface WorkerGlobalScope extends EventTarget, FontFaceSource, WindowOrWorkerG * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/WorkerGlobalScope/importScripts) */ - importScripts(...urls: (string | URL)[]): void; + importScripts(...urls: (TrustedScriptURL | string)[]): void; addEventListener(type: K, listener: (this: WorkerGlobalScope, ev: WorkerGlobalScopeEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void; removeEventListener(type: K, listener: (this: WorkerGlobalScope, ev: WorkerGlobalScopeEventMap[K]) => any, options?: boolean | EventListenerOptions): void; @@ -11190,6 +11362,18 @@ interface Console { declare var console: Console; +interface CreateHTMLCallback { + (input: string, ...arguments: any[]): string | null; +} + +interface CreateScriptCallback { + (input: string, ...arguments: any[]): string | null; +} + +interface CreateScriptURLCallback { + (input: string, ...arguments: any[]): string | null; +} + interface LockGrantedCallback { (lock: Lock | null): T; } @@ -11345,7 +11529,7 @@ declare var self: WorkerGlobalScope & typeof globalThis; * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/WorkerGlobalScope/importScripts) */ -declare function importScripts(...urls: (string | URL)[]): void; +declare function importScripts(...urls: (TrustedScriptURL | string)[]): void; /** * The **`dispatchEvent()`** method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order. * @@ -11372,6 +11556,8 @@ declare var isSecureContext: boolean; declare var origin: string; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/performance) */ declare var performance: Performance; +/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/trustedTypes) */ +declare var trustedTypes: TrustedTypePolicyFactory; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/atob) */ declare function atob(data: string): string; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/btoa) */ @@ -11447,7 +11633,7 @@ type ReadableStreamReader = ReadableStreamDefaultReader | ReadableStreamBY type ReportList = Report[]; type RequestInfo = Request | string; type TexImageSource = ImageBitmap | ImageData | OffscreenCanvas; -type TimerHandler = string | Function; +type TimerHandler = string | Function | TrustedScript; type Transferable = OffscreenCanvas | ImageBitmap | MessagePort | ReadableStream | WritableStream | TransformStream | ArrayBuffer; type URLPatternInput = string | URLPatternInit; type Uint32List = Uint32Array | GLuint[]; diff --git a/baselines/sharedworker.generated.d.ts b/baselines/sharedworker.generated.d.ts index 6ce6e8fb6..69e60e877 100644 --- a/baselines/sharedworker.generated.d.ts +++ b/baselines/sharedworker.generated.d.ts @@ -647,6 +647,12 @@ interface Transformer { writableType?: undefined; } +interface TrustedTypePolicyOptions { + createHTML?: CreateHTMLCallback; + createScript?: CreateScriptCallback; + createScriptURL?: CreateScriptURLCallback; +} + interface URLPatternComponentResult { groups?: Record; input?: string; @@ -6525,7 +6531,7 @@ interface ServiceWorkerContainer extends EventTarget { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/ServiceWorkerContainer/register) */ - register(scriptURL: string | URL, options?: RegistrationOptions): Promise; + register(scriptURL: TrustedScriptURL | string, options?: RegistrationOptions): Promise; /** * The **`startMessages()`** method of the ServiceWorkerContainer interface explicitly starts the flow of messages being dispatched from a service worker to pages under its control (e.g., sent via Client.postMessage()). * @@ -7081,6 +7087,170 @@ declare var TransformStreamDefaultController: { new(): TransformStreamDefaultController; }; +/** + * The **`TrustedHTML`** interface of the Trusted Types API represents a string that a developer can insert into an injection sink that will render it as HTML. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedHTML) + */ +interface TrustedHTML { + /** + * The **`toJSON()`** method of the TrustedHTML interface returns a JSON representation of the stored data. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedHTML/toJSON) + */ + toJSON(): string; + toString(): string; +} + +declare var TrustedHTML: { + prototype: TrustedHTML; + new(): TrustedHTML; +}; + +/** + * The **`TrustedScript`** interface of the Trusted Types API represents a string with an uncompiled script body that a developer can insert into an injection sink that might execute the script. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedScript) + */ +interface TrustedScript { + /** + * The **`toJSON()`** method of the TrustedScript interface returns a JSON representation of the stored data. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedScript/toJSON) + */ + toJSON(): string; + toString(): string; +} + +declare var TrustedScript: { + prototype: TrustedScript; + new(): TrustedScript; +}; + +/** + * The **`TrustedScriptURL`** interface of the Trusted Types API represents a string that a developer can insert into an injection sink that will parse it as a URL of an external script. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedScriptURL) + */ +interface TrustedScriptURL { + /** + * The **`toJSON()`** method of the TrustedScriptURL interface returns a JSON representation of the stored data. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedScriptURL/toJSON) + */ + toJSON(): string; + toString(): string; +} + +declare var TrustedScriptURL: { + prototype: TrustedScriptURL; + new(): TrustedScriptURL; +}; + +/** + * The **`TrustedTypePolicy`** interface of the Trusted Types API defines a group of functions which create `TrustedType` objects. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicy) + */ +interface TrustedTypePolicy { + /** + * The **`name`** read-only property of the TrustedTypePolicy interface returns the name of the policy. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicy/name) + */ + readonly name: string; + /** + * The **`createHTML()`** method of the TrustedTypePolicy interface creates a TrustedHTML object using a policy created by TrustedTypePolicyFactory.createPolicy(). + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicy/createHTML) + */ + createHTML(input: string, ...arguments: any[]): TrustedHTML; + /** + * The **`createScript()`** method of the TrustedTypePolicy interface creates a TrustedScript object using a policy created by TrustedTypePolicyFactory.createPolicy(). + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicy/createScript) + */ + createScript(input: string, ...arguments: any[]): TrustedScript; + /** + * The **`createScriptURL()`** method of the TrustedTypePolicy interface creates a TrustedScriptURL object using a policy created by TrustedTypePolicyFactory.createPolicy(). + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicy/createScriptURL) + */ + createScriptURL(input: string, ...arguments: any[]): TrustedScriptURL; +} + +declare var TrustedTypePolicy: { + prototype: TrustedTypePolicy; + new(): TrustedTypePolicy; +}; + +/** + * The **`TrustedTypePolicyFactory`** interface of the Trusted Types API creates policies and allows the verification of Trusted Type objects against created policies. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory) + */ +interface TrustedTypePolicyFactory { + /** + * The **`defaultPolicy`** read-only property of the TrustedTypePolicyFactory interface returns the default TrustedTypePolicy or null if this is empty. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/defaultPolicy) + */ + readonly defaultPolicy: TrustedTypePolicy | null; + /** + * The **`emptyHTML`** read-only property of the TrustedTypePolicyFactory interface returns a TrustedHTML object containing an empty string. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/emptyHTML) + */ + readonly emptyHTML: TrustedHTML; + /** + * The **`emptyScript`** read-only property of the TrustedTypePolicyFactory interface returns a TrustedScript object containing an empty string. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/emptyScript) + */ + readonly emptyScript: TrustedScript; + /** + * The **`createPolicy()`** method of the TrustedTypePolicyFactory interface creates a TrustedTypePolicy object that implements the rules passed as `policyOptions`. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/createPolicy) + */ + createPolicy(policyName: string, policyOptions?: TrustedTypePolicyOptions): TrustedTypePolicy; + /** + * The **`getAttributeType()`** method of the TrustedTypePolicyFactory interface allows web developers to check if a Trusted Type is required for an element, and if so which Trusted Type is used. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/getAttributeType) + */ + getAttributeType(tagName: string, attribute: string, elementNs?: string | null, attrNs?: string | null): string | null; + /** + * The **`getPropertyType()`** method of the TrustedTypePolicyFactory interface allows web developers to check if a Trusted Type is required for an element's property. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/getPropertyType) + */ + getPropertyType(tagName: string, property: string, elementNs?: string | null): string | null; + /** + * The **`isHTML()`** method of the TrustedTypePolicyFactory interface returns true if it is passed a valid TrustedHTML object. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/isHTML) + */ + isHTML(value: any): boolean; + /** + * The **`isScript()`** method of the TrustedTypePolicyFactory interface returns true if it is passed a valid TrustedScript object. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/isScript) + */ + isScript(value: any): boolean; + /** + * The **`isScriptURL()`** method of the TrustedTypePolicyFactory interface returns true if it is passed a valid TrustedScriptURL object. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/isScriptURL) + */ + isScriptURL(value: any): boolean; +} + +declare var TrustedTypePolicyFactory: { + prototype: TrustedTypePolicyFactory; + new(): TrustedTypePolicyFactory; +}; + /** * The **`URL`** interface is used to parse, construct, normalize, and encode URL. * @@ -10107,6 +10277,8 @@ interface WindowOrWorkerGlobalScope { readonly origin: string; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/performance) */ readonly performance: Performance; + /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/trustedTypes) */ + readonly trustedTypes: TrustedTypePolicyFactory; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/atob) */ atob(data: string): string; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/btoa) */ @@ -10162,7 +10334,7 @@ interface Worker extends EventTarget, AbstractWorker, MessageEventTarget declare var Worker: { prototype: Worker; - new(scriptURL: string | URL, options?: WorkerOptions): Worker; + new(scriptURL: TrustedScriptURL | string, options?: WorkerOptions): Worker; }; interface WorkerGlobalScopeEventMap { @@ -10215,7 +10387,7 @@ interface WorkerGlobalScope extends EventTarget, FontFaceSource, WindowOrWorkerG * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/WorkerGlobalScope/importScripts) */ - importScripts(...urls: (string | URL)[]): void; + importScripts(...urls: (TrustedScriptURL | string)[]): void; addEventListener(type: K, listener: (this: WorkerGlobalScope, ev: WorkerGlobalScopeEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void; removeEventListener(type: K, listener: (this: WorkerGlobalScope, ev: WorkerGlobalScopeEventMap[K]) => any, options?: boolean | EventListenerOptions): void; @@ -10916,6 +11088,18 @@ interface Console { declare var console: Console; +interface CreateHTMLCallback { + (input: string, ...arguments: any[]): string | null; +} + +interface CreateScriptCallback { + (input: string, ...arguments: any[]): string | null; +} + +interface CreateScriptURLCallback { + (input: string, ...arguments: any[]): string | null; +} + interface LockGrantedCallback { (lock: Lock | null): T; } @@ -11035,7 +11219,7 @@ declare var self: WorkerGlobalScope & typeof globalThis; * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/WorkerGlobalScope/importScripts) */ -declare function importScripts(...urls: (string | URL)[]): void; +declare function importScripts(...urls: (TrustedScriptURL | string)[]): void; /** * The **`dispatchEvent()`** method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order. * @@ -11062,6 +11246,8 @@ declare var isSecureContext: boolean; declare var origin: string; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/performance) */ declare var performance: Performance; +/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/trustedTypes) */ +declare var trustedTypes: TrustedTypePolicyFactory; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/atob) */ declare function atob(data: string): string; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/btoa) */ @@ -11135,7 +11321,7 @@ type ReadableStreamReader = ReadableStreamDefaultReader | ReadableStreamBY type ReportList = Report[]; type RequestInfo = Request | string; type TexImageSource = ImageBitmap | ImageData | OffscreenCanvas; -type TimerHandler = string | Function; +type TimerHandler = string | Function | TrustedScript; type Transferable = OffscreenCanvas | ImageBitmap | MessagePort | ReadableStream | WritableStream | TransformStream | ArrayBuffer; type URLPatternInput = string | URLPatternInit; type Uint32List = Uint32Array | GLuint[]; diff --git a/baselines/ts5.5/dom.generated.d.ts b/baselines/ts5.5/dom.generated.d.ts index 8026268fb..4169cbc6e 100644 --- a/baselines/ts5.5/dom.generated.d.ts +++ b/baselines/ts5.5/dom.generated.d.ts @@ -2322,6 +2322,12 @@ interface TransitionEventInit extends EventInit { pseudoElement?: string; } +interface TrustedTypePolicyOptions { + createHTML?: CreateHTMLCallback; + createScript?: CreateScriptCallback; + createScriptURL?: CreateScriptURLCallback; +} + interface UIEventInit extends EventInit { detail?: number; view?: Window | null; @@ -9251,7 +9257,7 @@ interface DOMParser { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/DOMParser/parseFromString) */ - parseFromString(string: string, type: DOMParserSupportedType): Document; + parseFromString(string: TrustedHTML | string, type: DOMParserSupportedType): Document; } declare var DOMParser: { @@ -10620,14 +10626,14 @@ interface Document extends Node, DocumentOrShadowRoot, FontFaceSource, GlobalEve * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Document/write) */ - write(...text: string[]): void; + write(...text: (TrustedHTML | string)[]): void; /** * The **`writeln()`** method of the Document interface writes text in one or more TrustedHTML or string parameters to a document stream opened by document.open(), followed by a newline character. * @deprecated * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Document/writeln) */ - writeln(...text: string[]): void; + writeln(...text: (TrustedHTML | string)[]): void; /** [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent) */ get textContent(): null; addEventListener(type: K, listener: (this: Document, ev: DocumentEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; @@ -10644,7 +10650,7 @@ declare var Document: { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Document/parseHTMLUnsafe_static) */ - parseHTMLUnsafe(html: string): Document; + parseHTMLUnsafe(html: TrustedHTML | string): Document; }; /** @@ -10997,7 +11003,7 @@ interface Element extends Node, ARIAMixin, Animatable, ChildNode, NonDocumentTyp * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/innerHTML) */ - innerHTML: string; + innerHTML: TrustedHTML | string; /** * The **`Element.localName`** read-only property returns the local part of the qualified name of an element. * @@ -11019,7 +11025,7 @@ interface Element extends Node, ARIAMixin, Animatable, ChildNode, NonDocumentTyp * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/outerHTML) */ - outerHTML: string; + outerHTML: TrustedHTML | string; readonly ownerDocument: Document; /** * The **`part`** property of the Element interface represents the part identifier(s) of the element (i.e., set using the `part` attribute), returned as a DOMTokenList. @@ -11211,7 +11217,7 @@ interface Element extends Node, ARIAMixin, Animatable, ChildNode, NonDocumentTyp * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/insertAdjacentHTML) */ - insertAdjacentHTML(position: InsertPosition, string: string): void; + insertAdjacentHTML(position: InsertPosition, string: TrustedHTML | string): void; /** * The **`insertAdjacentText()`** method of the Element interface, given a relative position and a string, inserts a new text node at the given position relative to the element it is called from. * @@ -11316,7 +11322,7 @@ interface Element extends Node, ARIAMixin, Animatable, ChildNode, NonDocumentTyp * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/setHTMLUnsafe) */ - setHTMLUnsafe(html: string): void; + setHTMLUnsafe(html: TrustedHTML | string): void; /** * The **`setPointerCapture()`** method of the _capture target_ of future pointer events. * @@ -14732,7 +14738,7 @@ interface HTMLIFrameElement extends HTMLElement { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLIFrameElement/srcdoc) */ - srcdoc: string; + srcdoc: TrustedHTML | string; /** * The **`width`** property of the HTMLIFrameElement interface returns a string that reflects the `width` attribute of the iframe element, indicating the width of the frame in CSS pixels. * @@ -25922,7 +25928,7 @@ interface Range extends AbstractRange { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Range/createContextualFragment) */ - createContextualFragment(string: string): DocumentFragment; + createContextualFragment(string: TrustedHTML | string): DocumentFragment; /** * The **`Range.deleteContents()`** method removes all completely-selected Node within this range from the document. * @@ -30866,7 +30872,7 @@ interface ServiceWorkerContainer extends EventTarget { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/ServiceWorkerContainer/register) */ - register(scriptURL: string | URL, options?: RegistrationOptions): Promise; + register(scriptURL: TrustedScriptURL | string, options?: RegistrationOptions): Promise; /** * The **`startMessages()`** method of the ServiceWorkerContainer interface explicitly starts the flow of messages being dispatched from a service worker to pages under its control (e.g., sent via Client.postMessage()). * @@ -31013,7 +31019,7 @@ interface ShadowRoot extends DocumentFragment, DocumentOrShadowRoot { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/ShadowRoot/innerHTML) */ - innerHTML: string; + innerHTML: TrustedHTML | string; /** * The **`mode`** read-only property of the ShadowRoot specifies its mode — either `open` or `closed`. * @@ -31044,7 +31050,7 @@ interface ShadowRoot extends DocumentFragment, DocumentOrShadowRoot { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/ShadowRoot/setHTMLUnsafe) */ - setHTMLUnsafe(html: string): void; + setHTMLUnsafe(html: TrustedHTML | string): void; addEventListener(type: K, listener: (this: ShadowRoot, ev: ShadowRootEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void; removeEventListener(type: K, listener: (this: ShadowRoot, ev: ShadowRootEventMap[K]) => any, options?: boolean | EventListenerOptions): void; @@ -31076,7 +31082,7 @@ interface SharedWorker extends EventTarget, AbstractWorker { declare var SharedWorker: { prototype: SharedWorker; - new(scriptURL: string | URL, options?: string | WorkerOptions): SharedWorker; + new(scriptURL: TrustedScriptURL | string, options?: string | WorkerOptions): SharedWorker; }; interface Slottable { @@ -32902,6 +32908,170 @@ declare var TreeWalker: { new(): TreeWalker; }; +/** + * The **`TrustedHTML`** interface of the Trusted Types API represents a string that a developer can insert into an injection sink that will render it as HTML. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedHTML) + */ +interface TrustedHTML { + /** + * The **`toJSON()`** method of the TrustedHTML interface returns a JSON representation of the stored data. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedHTML/toJSON) + */ + toJSON(): string; + toString(): string; +} + +declare var TrustedHTML: { + prototype: TrustedHTML; + new(): TrustedHTML; +}; + +/** + * The **`TrustedScript`** interface of the Trusted Types API represents a string with an uncompiled script body that a developer can insert into an injection sink that might execute the script. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedScript) + */ +interface TrustedScript { + /** + * The **`toJSON()`** method of the TrustedScript interface returns a JSON representation of the stored data. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedScript/toJSON) + */ + toJSON(): string; + toString(): string; +} + +declare var TrustedScript: { + prototype: TrustedScript; + new(): TrustedScript; +}; + +/** + * The **`TrustedScriptURL`** interface of the Trusted Types API represents a string that a developer can insert into an injection sink that will parse it as a URL of an external script. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedScriptURL) + */ +interface TrustedScriptURL { + /** + * The **`toJSON()`** method of the TrustedScriptURL interface returns a JSON representation of the stored data. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedScriptURL/toJSON) + */ + toJSON(): string; + toString(): string; +} + +declare var TrustedScriptURL: { + prototype: TrustedScriptURL; + new(): TrustedScriptURL; +}; + +/** + * The **`TrustedTypePolicy`** interface of the Trusted Types API defines a group of functions which create `TrustedType` objects. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicy) + */ +interface TrustedTypePolicy { + /** + * The **`name`** read-only property of the TrustedTypePolicy interface returns the name of the policy. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicy/name) + */ + readonly name: string; + /** + * The **`createHTML()`** method of the TrustedTypePolicy interface creates a TrustedHTML object using a policy created by TrustedTypePolicyFactory.createPolicy(). + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicy/createHTML) + */ + createHTML(input: string, ...arguments: any[]): TrustedHTML; + /** + * The **`createScript()`** method of the TrustedTypePolicy interface creates a TrustedScript object using a policy created by TrustedTypePolicyFactory.createPolicy(). + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicy/createScript) + */ + createScript(input: string, ...arguments: any[]): TrustedScript; + /** + * The **`createScriptURL()`** method of the TrustedTypePolicy interface creates a TrustedScriptURL object using a policy created by TrustedTypePolicyFactory.createPolicy(). + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicy/createScriptURL) + */ + createScriptURL(input: string, ...arguments: any[]): TrustedScriptURL; +} + +declare var TrustedTypePolicy: { + prototype: TrustedTypePolicy; + new(): TrustedTypePolicy; +}; + +/** + * The **`TrustedTypePolicyFactory`** interface of the Trusted Types API creates policies and allows the verification of Trusted Type objects against created policies. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory) + */ +interface TrustedTypePolicyFactory { + /** + * The **`defaultPolicy`** read-only property of the TrustedTypePolicyFactory interface returns the default TrustedTypePolicy or null if this is empty. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/defaultPolicy) + */ + readonly defaultPolicy: TrustedTypePolicy | null; + /** + * The **`emptyHTML`** read-only property of the TrustedTypePolicyFactory interface returns a TrustedHTML object containing an empty string. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/emptyHTML) + */ + readonly emptyHTML: TrustedHTML; + /** + * The **`emptyScript`** read-only property of the TrustedTypePolicyFactory interface returns a TrustedScript object containing an empty string. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/emptyScript) + */ + readonly emptyScript: TrustedScript; + /** + * The **`createPolicy()`** method of the TrustedTypePolicyFactory interface creates a TrustedTypePolicy object that implements the rules passed as `policyOptions`. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/createPolicy) + */ + createPolicy(policyName: string, policyOptions?: TrustedTypePolicyOptions): TrustedTypePolicy; + /** + * The **`getAttributeType()`** method of the TrustedTypePolicyFactory interface allows web developers to check if a Trusted Type is required for an element, and if so which Trusted Type is used. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/getAttributeType) + */ + getAttributeType(tagName: string, attribute: string, elementNs?: string | null, attrNs?: string | null): string | null; + /** + * The **`getPropertyType()`** method of the TrustedTypePolicyFactory interface allows web developers to check if a Trusted Type is required for an element's property. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/getPropertyType) + */ + getPropertyType(tagName: string, property: string, elementNs?: string | null): string | null; + /** + * The **`isHTML()`** method of the TrustedTypePolicyFactory interface returns true if it is passed a valid TrustedHTML object. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/isHTML) + */ + isHTML(value: any): boolean; + /** + * The **`isScript()`** method of the TrustedTypePolicyFactory interface returns true if it is passed a valid TrustedScript object. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/isScript) + */ + isScript(value: any): boolean; + /** + * The **`isScriptURL()`** method of the TrustedTypePolicyFactory interface returns true if it is passed a valid TrustedScriptURL object. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/isScriptURL) + */ + isScriptURL(value: any): boolean; +} + +declare var TrustedTypePolicyFactory: { + prototype: TrustedTypePolicyFactory; + new(): TrustedTypePolicyFactory; +}; + /** * The **`UIEvent`** interface represents simple user interface events. * @@ -37322,6 +37492,8 @@ interface WindowOrWorkerGlobalScope { readonly origin: string; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/performance) */ readonly performance: Performance; + /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/trustedTypes) */ + readonly trustedTypes: TrustedTypePolicyFactory; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/atob) */ atob(data: string): string; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/btoa) */ @@ -37382,7 +37554,7 @@ interface Worker extends EventTarget, AbstractWorker, MessageEventTarget declare var Worker: { prototype: Worker; - new(scriptURL: string | URL, options?: WorkerOptions): Worker; + new(scriptURL: TrustedScriptURL | string, options?: WorkerOptions): Worker; }; /** @@ -38382,6 +38554,18 @@ interface BlobCallback { (blob: Blob | null): void; } +interface CreateHTMLCallback { + (input: string, ...arguments: any[]): string | null; +} + +interface CreateScriptCallback { + (input: string, ...arguments: any[]): string | null; +} + +interface CreateScriptURLCallback { + (input: string, ...arguments: any[]): string | null; +} + interface CustomElementConstructor { new (...params: any[]): HTMLElement; } @@ -39547,6 +39731,8 @@ declare var isSecureContext: boolean; declare var origin: string; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/performance) */ declare var performance: Performance; +/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/trustedTypes) */ +declare var trustedTypes: TrustedTypePolicyFactory; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/atob) */ declare function atob(data: string): string; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/btoa) */ @@ -39648,7 +39834,7 @@ type RenderingContext = CanvasRenderingContext2D | ImageBitmapRenderingContext | type ReportList = Report[]; type RequestInfo = Request | string; type TexImageSource = ImageBitmap | ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | OffscreenCanvas | VideoFrame; -type TimerHandler = string | Function; +type TimerHandler = string | Function | TrustedScript; type Transferable = OffscreenCanvas | ImageBitmap | MessagePort | MediaSourceHandle | ReadableStream | WritableStream | TransformStream | AudioData | VideoFrame | RTCDataChannel | ArrayBuffer; type URLPatternInput = string | URLPatternInit; type Uint32List = Uint32Array | GLuint[]; diff --git a/baselines/ts5.5/serviceworker.generated.d.ts b/baselines/ts5.5/serviceworker.generated.d.ts index 6847b2bec..39f7a37ef 100644 --- a/baselines/ts5.5/serviceworker.generated.d.ts +++ b/baselines/ts5.5/serviceworker.generated.d.ts @@ -717,6 +717,12 @@ interface Transformer { writableType?: undefined; } +interface TrustedTypePolicyOptions { + createHTML?: CreateHTMLCallback; + createScript?: CreateScriptCallback; + createScriptURL?: CreateScriptURLCallback; +} + interface URLPatternComponentResult { groups?: Record; input?: string; @@ -6942,7 +6948,7 @@ interface ServiceWorkerContainer extends EventTarget { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/ServiceWorkerContainer/register) */ - register(scriptURL: string | URL, options?: RegistrationOptions): Promise; + register(scriptURL: TrustedScriptURL | string, options?: RegistrationOptions): Promise; /** * The **`startMessages()`** method of the ServiceWorkerContainer interface explicitly starts the flow of messages being dispatched from a service worker to pages under its control (e.g., sent via Client.postMessage()). * @@ -7550,6 +7556,170 @@ declare var TransformStreamDefaultController: { new(): TransformStreamDefaultController; }; +/** + * The **`TrustedHTML`** interface of the Trusted Types API represents a string that a developer can insert into an injection sink that will render it as HTML. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedHTML) + */ +interface TrustedHTML { + /** + * The **`toJSON()`** method of the TrustedHTML interface returns a JSON representation of the stored data. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedHTML/toJSON) + */ + toJSON(): string; + toString(): string; +} + +declare var TrustedHTML: { + prototype: TrustedHTML; + new(): TrustedHTML; +}; + +/** + * The **`TrustedScript`** interface of the Trusted Types API represents a string with an uncompiled script body that a developer can insert into an injection sink that might execute the script. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedScript) + */ +interface TrustedScript { + /** + * The **`toJSON()`** method of the TrustedScript interface returns a JSON representation of the stored data. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedScript/toJSON) + */ + toJSON(): string; + toString(): string; +} + +declare var TrustedScript: { + prototype: TrustedScript; + new(): TrustedScript; +}; + +/** + * The **`TrustedScriptURL`** interface of the Trusted Types API represents a string that a developer can insert into an injection sink that will parse it as a URL of an external script. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedScriptURL) + */ +interface TrustedScriptURL { + /** + * The **`toJSON()`** method of the TrustedScriptURL interface returns a JSON representation of the stored data. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedScriptURL/toJSON) + */ + toJSON(): string; + toString(): string; +} + +declare var TrustedScriptURL: { + prototype: TrustedScriptURL; + new(): TrustedScriptURL; +}; + +/** + * The **`TrustedTypePolicy`** interface of the Trusted Types API defines a group of functions which create `TrustedType` objects. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicy) + */ +interface TrustedTypePolicy { + /** + * The **`name`** read-only property of the TrustedTypePolicy interface returns the name of the policy. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicy/name) + */ + readonly name: string; + /** + * The **`createHTML()`** method of the TrustedTypePolicy interface creates a TrustedHTML object using a policy created by TrustedTypePolicyFactory.createPolicy(). + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicy/createHTML) + */ + createHTML(input: string, ...arguments: any[]): TrustedHTML; + /** + * The **`createScript()`** method of the TrustedTypePolicy interface creates a TrustedScript object using a policy created by TrustedTypePolicyFactory.createPolicy(). + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicy/createScript) + */ + createScript(input: string, ...arguments: any[]): TrustedScript; + /** + * The **`createScriptURL()`** method of the TrustedTypePolicy interface creates a TrustedScriptURL object using a policy created by TrustedTypePolicyFactory.createPolicy(). + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicy/createScriptURL) + */ + createScriptURL(input: string, ...arguments: any[]): TrustedScriptURL; +} + +declare var TrustedTypePolicy: { + prototype: TrustedTypePolicy; + new(): TrustedTypePolicy; +}; + +/** + * The **`TrustedTypePolicyFactory`** interface of the Trusted Types API creates policies and allows the verification of Trusted Type objects against created policies. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory) + */ +interface TrustedTypePolicyFactory { + /** + * The **`defaultPolicy`** read-only property of the TrustedTypePolicyFactory interface returns the default TrustedTypePolicy or null if this is empty. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/defaultPolicy) + */ + readonly defaultPolicy: TrustedTypePolicy | null; + /** + * The **`emptyHTML`** read-only property of the TrustedTypePolicyFactory interface returns a TrustedHTML object containing an empty string. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/emptyHTML) + */ + readonly emptyHTML: TrustedHTML; + /** + * The **`emptyScript`** read-only property of the TrustedTypePolicyFactory interface returns a TrustedScript object containing an empty string. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/emptyScript) + */ + readonly emptyScript: TrustedScript; + /** + * The **`createPolicy()`** method of the TrustedTypePolicyFactory interface creates a TrustedTypePolicy object that implements the rules passed as `policyOptions`. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/createPolicy) + */ + createPolicy(policyName: string, policyOptions?: TrustedTypePolicyOptions): TrustedTypePolicy; + /** + * The **`getAttributeType()`** method of the TrustedTypePolicyFactory interface allows web developers to check if a Trusted Type is required for an element, and if so which Trusted Type is used. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/getAttributeType) + */ + getAttributeType(tagName: string, attribute: string, elementNs?: string | null, attrNs?: string | null): string | null; + /** + * The **`getPropertyType()`** method of the TrustedTypePolicyFactory interface allows web developers to check if a Trusted Type is required for an element's property. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/getPropertyType) + */ + getPropertyType(tagName: string, property: string, elementNs?: string | null): string | null; + /** + * The **`isHTML()`** method of the TrustedTypePolicyFactory interface returns true if it is passed a valid TrustedHTML object. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/isHTML) + */ + isHTML(value: any): boolean; + /** + * The **`isScript()`** method of the TrustedTypePolicyFactory interface returns true if it is passed a valid TrustedScript object. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/isScript) + */ + isScript(value: any): boolean; + /** + * The **`isScriptURL()`** method of the TrustedTypePolicyFactory interface returns true if it is passed a valid TrustedScriptURL object. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/isScriptURL) + */ + isScriptURL(value: any): boolean; +} + +declare var TrustedTypePolicyFactory: { + prototype: TrustedTypePolicyFactory; + new(): TrustedTypePolicyFactory; +}; + /** * The **`URL`** interface is used to parse, construct, normalize, and encode URL. * @@ -10601,6 +10771,8 @@ interface WindowOrWorkerGlobalScope { readonly origin: string; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/performance) */ readonly performance: Performance; + /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/trustedTypes) */ + readonly trustedTypes: TrustedTypePolicyFactory; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/atob) */ atob(data: string): string; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/btoa) */ @@ -10676,7 +10848,7 @@ interface WorkerGlobalScope extends EventTarget, FontFaceSource, WindowOrWorkerG * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/WorkerGlobalScope/importScripts) */ - importScripts(...urls: (string | URL)[]): void; + importScripts(...urls: (TrustedScriptURL | string)[]): void; addEventListener(type: K, listener: (this: WorkerGlobalScope, ev: WorkerGlobalScopeEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void; removeEventListener(type: K, listener: (this: WorkerGlobalScope, ev: WorkerGlobalScopeEventMap[K]) => any, options?: boolean | EventListenerOptions): void; @@ -11190,6 +11362,18 @@ interface Console { declare var console: Console; +interface CreateHTMLCallback { + (input: string, ...arguments: any[]): string | null; +} + +interface CreateScriptCallback { + (input: string, ...arguments: any[]): string | null; +} + +interface CreateScriptURLCallback { + (input: string, ...arguments: any[]): string | null; +} + interface LockGrantedCallback { (lock: Lock | null): T; } @@ -11345,7 +11529,7 @@ declare var self: WorkerGlobalScope & typeof globalThis; * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/WorkerGlobalScope/importScripts) */ -declare function importScripts(...urls: (string | URL)[]): void; +declare function importScripts(...urls: (TrustedScriptURL | string)[]): void; /** * The **`dispatchEvent()`** method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order. * @@ -11372,6 +11556,8 @@ declare var isSecureContext: boolean; declare var origin: string; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/performance) */ declare var performance: Performance; +/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/trustedTypes) */ +declare var trustedTypes: TrustedTypePolicyFactory; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/atob) */ declare function atob(data: string): string; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/btoa) */ @@ -11447,7 +11633,7 @@ type ReadableStreamReader = ReadableStreamDefaultReader | ReadableStreamBY type ReportList = Report[]; type RequestInfo = Request | string; type TexImageSource = ImageBitmap | ImageData | OffscreenCanvas; -type TimerHandler = string | Function; +type TimerHandler = string | Function | TrustedScript; type Transferable = OffscreenCanvas | ImageBitmap | MessagePort | ReadableStream | WritableStream | TransformStream | ArrayBuffer; type URLPatternInput = string | URLPatternInit; type Uint32List = Uint32Array | GLuint[]; diff --git a/baselines/ts5.5/sharedworker.generated.d.ts b/baselines/ts5.5/sharedworker.generated.d.ts index de00fa37c..b94e27189 100644 --- a/baselines/ts5.5/sharedworker.generated.d.ts +++ b/baselines/ts5.5/sharedworker.generated.d.ts @@ -647,6 +647,12 @@ interface Transformer { writableType?: undefined; } +interface TrustedTypePolicyOptions { + createHTML?: CreateHTMLCallback; + createScript?: CreateScriptCallback; + createScriptURL?: CreateScriptURLCallback; +} + interface URLPatternComponentResult { groups?: Record; input?: string; @@ -6525,7 +6531,7 @@ interface ServiceWorkerContainer extends EventTarget { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/ServiceWorkerContainer/register) */ - register(scriptURL: string | URL, options?: RegistrationOptions): Promise; + register(scriptURL: TrustedScriptURL | string, options?: RegistrationOptions): Promise; /** * The **`startMessages()`** method of the ServiceWorkerContainer interface explicitly starts the flow of messages being dispatched from a service worker to pages under its control (e.g., sent via Client.postMessage()). * @@ -7081,6 +7087,170 @@ declare var TransformStreamDefaultController: { new(): TransformStreamDefaultController; }; +/** + * The **`TrustedHTML`** interface of the Trusted Types API represents a string that a developer can insert into an injection sink that will render it as HTML. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedHTML) + */ +interface TrustedHTML { + /** + * The **`toJSON()`** method of the TrustedHTML interface returns a JSON representation of the stored data. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedHTML/toJSON) + */ + toJSON(): string; + toString(): string; +} + +declare var TrustedHTML: { + prototype: TrustedHTML; + new(): TrustedHTML; +}; + +/** + * The **`TrustedScript`** interface of the Trusted Types API represents a string with an uncompiled script body that a developer can insert into an injection sink that might execute the script. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedScript) + */ +interface TrustedScript { + /** + * The **`toJSON()`** method of the TrustedScript interface returns a JSON representation of the stored data. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedScript/toJSON) + */ + toJSON(): string; + toString(): string; +} + +declare var TrustedScript: { + prototype: TrustedScript; + new(): TrustedScript; +}; + +/** + * The **`TrustedScriptURL`** interface of the Trusted Types API represents a string that a developer can insert into an injection sink that will parse it as a URL of an external script. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedScriptURL) + */ +interface TrustedScriptURL { + /** + * The **`toJSON()`** method of the TrustedScriptURL interface returns a JSON representation of the stored data. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedScriptURL/toJSON) + */ + toJSON(): string; + toString(): string; +} + +declare var TrustedScriptURL: { + prototype: TrustedScriptURL; + new(): TrustedScriptURL; +}; + +/** + * The **`TrustedTypePolicy`** interface of the Trusted Types API defines a group of functions which create `TrustedType` objects. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicy) + */ +interface TrustedTypePolicy { + /** + * The **`name`** read-only property of the TrustedTypePolicy interface returns the name of the policy. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicy/name) + */ + readonly name: string; + /** + * The **`createHTML()`** method of the TrustedTypePolicy interface creates a TrustedHTML object using a policy created by TrustedTypePolicyFactory.createPolicy(). + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicy/createHTML) + */ + createHTML(input: string, ...arguments: any[]): TrustedHTML; + /** + * The **`createScript()`** method of the TrustedTypePolicy interface creates a TrustedScript object using a policy created by TrustedTypePolicyFactory.createPolicy(). + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicy/createScript) + */ + createScript(input: string, ...arguments: any[]): TrustedScript; + /** + * The **`createScriptURL()`** method of the TrustedTypePolicy interface creates a TrustedScriptURL object using a policy created by TrustedTypePolicyFactory.createPolicy(). + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicy/createScriptURL) + */ + createScriptURL(input: string, ...arguments: any[]): TrustedScriptURL; +} + +declare var TrustedTypePolicy: { + prototype: TrustedTypePolicy; + new(): TrustedTypePolicy; +}; + +/** + * The **`TrustedTypePolicyFactory`** interface of the Trusted Types API creates policies and allows the verification of Trusted Type objects against created policies. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory) + */ +interface TrustedTypePolicyFactory { + /** + * The **`defaultPolicy`** read-only property of the TrustedTypePolicyFactory interface returns the default TrustedTypePolicy or null if this is empty. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/defaultPolicy) + */ + readonly defaultPolicy: TrustedTypePolicy | null; + /** + * The **`emptyHTML`** read-only property of the TrustedTypePolicyFactory interface returns a TrustedHTML object containing an empty string. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/emptyHTML) + */ + readonly emptyHTML: TrustedHTML; + /** + * The **`emptyScript`** read-only property of the TrustedTypePolicyFactory interface returns a TrustedScript object containing an empty string. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/emptyScript) + */ + readonly emptyScript: TrustedScript; + /** + * The **`createPolicy()`** method of the TrustedTypePolicyFactory interface creates a TrustedTypePolicy object that implements the rules passed as `policyOptions`. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/createPolicy) + */ + createPolicy(policyName: string, policyOptions?: TrustedTypePolicyOptions): TrustedTypePolicy; + /** + * The **`getAttributeType()`** method of the TrustedTypePolicyFactory interface allows web developers to check if a Trusted Type is required for an element, and if so which Trusted Type is used. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/getAttributeType) + */ + getAttributeType(tagName: string, attribute: string, elementNs?: string | null, attrNs?: string | null): string | null; + /** + * The **`getPropertyType()`** method of the TrustedTypePolicyFactory interface allows web developers to check if a Trusted Type is required for an element's property. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/getPropertyType) + */ + getPropertyType(tagName: string, property: string, elementNs?: string | null): string | null; + /** + * The **`isHTML()`** method of the TrustedTypePolicyFactory interface returns true if it is passed a valid TrustedHTML object. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/isHTML) + */ + isHTML(value: any): boolean; + /** + * The **`isScript()`** method of the TrustedTypePolicyFactory interface returns true if it is passed a valid TrustedScript object. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/isScript) + */ + isScript(value: any): boolean; + /** + * The **`isScriptURL()`** method of the TrustedTypePolicyFactory interface returns true if it is passed a valid TrustedScriptURL object. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/isScriptURL) + */ + isScriptURL(value: any): boolean; +} + +declare var TrustedTypePolicyFactory: { + prototype: TrustedTypePolicyFactory; + new(): TrustedTypePolicyFactory; +}; + /** * The **`URL`** interface is used to parse, construct, normalize, and encode URL. * @@ -10107,6 +10277,8 @@ interface WindowOrWorkerGlobalScope { readonly origin: string; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/performance) */ readonly performance: Performance; + /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/trustedTypes) */ + readonly trustedTypes: TrustedTypePolicyFactory; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/atob) */ atob(data: string): string; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/btoa) */ @@ -10162,7 +10334,7 @@ interface Worker extends EventTarget, AbstractWorker, MessageEventTarget declare var Worker: { prototype: Worker; - new(scriptURL: string | URL, options?: WorkerOptions): Worker; + new(scriptURL: TrustedScriptURL | string, options?: WorkerOptions): Worker; }; interface WorkerGlobalScopeEventMap { @@ -10215,7 +10387,7 @@ interface WorkerGlobalScope extends EventTarget, FontFaceSource, WindowOrWorkerG * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/WorkerGlobalScope/importScripts) */ - importScripts(...urls: (string | URL)[]): void; + importScripts(...urls: (TrustedScriptURL | string)[]): void; addEventListener(type: K, listener: (this: WorkerGlobalScope, ev: WorkerGlobalScopeEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void; removeEventListener(type: K, listener: (this: WorkerGlobalScope, ev: WorkerGlobalScopeEventMap[K]) => any, options?: boolean | EventListenerOptions): void; @@ -10916,6 +11088,18 @@ interface Console { declare var console: Console; +interface CreateHTMLCallback { + (input: string, ...arguments: any[]): string | null; +} + +interface CreateScriptCallback { + (input: string, ...arguments: any[]): string | null; +} + +interface CreateScriptURLCallback { + (input: string, ...arguments: any[]): string | null; +} + interface LockGrantedCallback { (lock: Lock | null): T; } @@ -11035,7 +11219,7 @@ declare var self: WorkerGlobalScope & typeof globalThis; * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/WorkerGlobalScope/importScripts) */ -declare function importScripts(...urls: (string | URL)[]): void; +declare function importScripts(...urls: (TrustedScriptURL | string)[]): void; /** * The **`dispatchEvent()`** method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order. * @@ -11062,6 +11246,8 @@ declare var isSecureContext: boolean; declare var origin: string; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/performance) */ declare var performance: Performance; +/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/trustedTypes) */ +declare var trustedTypes: TrustedTypePolicyFactory; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/atob) */ declare function atob(data: string): string; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/btoa) */ @@ -11135,7 +11321,7 @@ type ReadableStreamReader = ReadableStreamDefaultReader | ReadableStreamBY type ReportList = Report[]; type RequestInfo = Request | string; type TexImageSource = ImageBitmap | ImageData | OffscreenCanvas; -type TimerHandler = string | Function; +type TimerHandler = string | Function | TrustedScript; type Transferable = OffscreenCanvas | ImageBitmap | MessagePort | ReadableStream | WritableStream | TransformStream | ArrayBuffer; type URLPatternInput = string | URLPatternInit; type Uint32List = Uint32Array | GLuint[]; diff --git a/baselines/ts5.5/webworker.generated.d.ts b/baselines/ts5.5/webworker.generated.d.ts index cdaec1532..bc86de286 100644 --- a/baselines/ts5.5/webworker.generated.d.ts +++ b/baselines/ts5.5/webworker.generated.d.ts @@ -861,6 +861,12 @@ interface Transformer { writableType?: undefined; } +interface TrustedTypePolicyOptions { + createHTML?: CreateHTMLCallback; + createScript?: CreateScriptCallback; + createScriptURL?: CreateScriptURLCallback; +} + interface URLPatternComponentResult { groups?: Record; input?: string; @@ -8044,7 +8050,7 @@ interface ServiceWorkerContainer extends EventTarget { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/ServiceWorkerContainer/register) */ - register(scriptURL: string | URL, options?: RegistrationOptions): Promise; + register(scriptURL: TrustedScriptURL | string, options?: RegistrationOptions): Promise; /** * The **`startMessages()`** method of the ServiceWorkerContainer interface explicitly starts the flow of messages being dispatched from a service worker to pages under its control (e.g., sent via Client.postMessage()). * @@ -8687,6 +8693,170 @@ declare var TransformStreamDefaultController: { new(): TransformStreamDefaultController; }; +/** + * The **`TrustedHTML`** interface of the Trusted Types API represents a string that a developer can insert into an injection sink that will render it as HTML. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedHTML) + */ +interface TrustedHTML { + /** + * The **`toJSON()`** method of the TrustedHTML interface returns a JSON representation of the stored data. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedHTML/toJSON) + */ + toJSON(): string; + toString(): string; +} + +declare var TrustedHTML: { + prototype: TrustedHTML; + new(): TrustedHTML; +}; + +/** + * The **`TrustedScript`** interface of the Trusted Types API represents a string with an uncompiled script body that a developer can insert into an injection sink that might execute the script. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedScript) + */ +interface TrustedScript { + /** + * The **`toJSON()`** method of the TrustedScript interface returns a JSON representation of the stored data. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedScript/toJSON) + */ + toJSON(): string; + toString(): string; +} + +declare var TrustedScript: { + prototype: TrustedScript; + new(): TrustedScript; +}; + +/** + * The **`TrustedScriptURL`** interface of the Trusted Types API represents a string that a developer can insert into an injection sink that will parse it as a URL of an external script. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedScriptURL) + */ +interface TrustedScriptURL { + /** + * The **`toJSON()`** method of the TrustedScriptURL interface returns a JSON representation of the stored data. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedScriptURL/toJSON) + */ + toJSON(): string; + toString(): string; +} + +declare var TrustedScriptURL: { + prototype: TrustedScriptURL; + new(): TrustedScriptURL; +}; + +/** + * The **`TrustedTypePolicy`** interface of the Trusted Types API defines a group of functions which create `TrustedType` objects. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicy) + */ +interface TrustedTypePolicy { + /** + * The **`name`** read-only property of the TrustedTypePolicy interface returns the name of the policy. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicy/name) + */ + readonly name: string; + /** + * The **`createHTML()`** method of the TrustedTypePolicy interface creates a TrustedHTML object using a policy created by TrustedTypePolicyFactory.createPolicy(). + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicy/createHTML) + */ + createHTML(input: string, ...arguments: any[]): TrustedHTML; + /** + * The **`createScript()`** method of the TrustedTypePolicy interface creates a TrustedScript object using a policy created by TrustedTypePolicyFactory.createPolicy(). + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicy/createScript) + */ + createScript(input: string, ...arguments: any[]): TrustedScript; + /** + * The **`createScriptURL()`** method of the TrustedTypePolicy interface creates a TrustedScriptURL object using a policy created by TrustedTypePolicyFactory.createPolicy(). + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicy/createScriptURL) + */ + createScriptURL(input: string, ...arguments: any[]): TrustedScriptURL; +} + +declare var TrustedTypePolicy: { + prototype: TrustedTypePolicy; + new(): TrustedTypePolicy; +}; + +/** + * The **`TrustedTypePolicyFactory`** interface of the Trusted Types API creates policies and allows the verification of Trusted Type objects against created policies. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory) + */ +interface TrustedTypePolicyFactory { + /** + * The **`defaultPolicy`** read-only property of the TrustedTypePolicyFactory interface returns the default TrustedTypePolicy or null if this is empty. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/defaultPolicy) + */ + readonly defaultPolicy: TrustedTypePolicy | null; + /** + * The **`emptyHTML`** read-only property of the TrustedTypePolicyFactory interface returns a TrustedHTML object containing an empty string. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/emptyHTML) + */ + readonly emptyHTML: TrustedHTML; + /** + * The **`emptyScript`** read-only property of the TrustedTypePolicyFactory interface returns a TrustedScript object containing an empty string. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/emptyScript) + */ + readonly emptyScript: TrustedScript; + /** + * The **`createPolicy()`** method of the TrustedTypePolicyFactory interface creates a TrustedTypePolicy object that implements the rules passed as `policyOptions`. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/createPolicy) + */ + createPolicy(policyName: string, policyOptions?: TrustedTypePolicyOptions): TrustedTypePolicy; + /** + * The **`getAttributeType()`** method of the TrustedTypePolicyFactory interface allows web developers to check if a Trusted Type is required for an element, and if so which Trusted Type is used. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/getAttributeType) + */ + getAttributeType(tagName: string, attribute: string, elementNs?: string | null, attrNs?: string | null): string | null; + /** + * The **`getPropertyType()`** method of the TrustedTypePolicyFactory interface allows web developers to check if a Trusted Type is required for an element's property. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/getPropertyType) + */ + getPropertyType(tagName: string, property: string, elementNs?: string | null): string | null; + /** + * The **`isHTML()`** method of the TrustedTypePolicyFactory interface returns true if it is passed a valid TrustedHTML object. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/isHTML) + */ + isHTML(value: any): boolean; + /** + * The **`isScript()`** method of the TrustedTypePolicyFactory interface returns true if it is passed a valid TrustedScript object. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/isScript) + */ + isScript(value: any): boolean; + /** + * The **`isScriptURL()`** method of the TrustedTypePolicyFactory interface returns true if it is passed a valid TrustedScriptURL object. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/isScriptURL) + */ + isScriptURL(value: any): boolean; +} + +declare var TrustedTypePolicyFactory: { + prototype: TrustedTypePolicyFactory; + new(): TrustedTypePolicyFactory; +}; + /** * The **`URL`** interface is used to parse, construct, normalize, and encode URL. * @@ -12035,6 +12205,8 @@ interface WindowOrWorkerGlobalScope { readonly origin: string; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/performance) */ readonly performance: Performance; + /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/trustedTypes) */ + readonly trustedTypes: TrustedTypePolicyFactory; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/atob) */ atob(data: string): string; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/btoa) */ @@ -12090,7 +12262,7 @@ interface Worker extends EventTarget, AbstractWorker, MessageEventTarget declare var Worker: { prototype: Worker; - new(scriptURL: string | URL, options?: WorkerOptions): Worker; + new(scriptURL: TrustedScriptURL | string, options?: WorkerOptions): Worker; }; interface WorkerGlobalScopeEventMap { @@ -12143,7 +12315,7 @@ interface WorkerGlobalScope extends EventTarget, FontFaceSource, WindowOrWorkerG * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/WorkerGlobalScope/importScripts) */ - importScripts(...urls: (string | URL)[]): void; + importScripts(...urls: (TrustedScriptURL | string)[]): void; addEventListener(type: K, listener: (this: WorkerGlobalScope, ev: WorkerGlobalScopeEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void; removeEventListener(type: K, listener: (this: WorkerGlobalScope, ev: WorkerGlobalScopeEventMap[K]) => any, options?: boolean | EventListenerOptions): void; @@ -12848,6 +13020,18 @@ interface AudioDataOutputCallback { (output: AudioData): void; } +interface CreateHTMLCallback { + (input: string, ...arguments: any[]): string | null; +} + +interface CreateScriptCallback { + (input: string, ...arguments: any[]): string | null; +} + +interface CreateScriptURLCallback { + (input: string, ...arguments: any[]): string | null; +} + interface EncodedAudioChunkOutputCallback { (output: EncodedAudioChunk, metadata?: EncodedAudioChunkMetadata): void; } @@ -12994,7 +13178,7 @@ declare var self: WorkerGlobalScope & typeof globalThis; * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/WorkerGlobalScope/importScripts) */ -declare function importScripts(...urls: (string | URL)[]): void; +declare function importScripts(...urls: (TrustedScriptURL | string)[]): void; /** * The **`dispatchEvent()`** method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order. * @@ -13021,6 +13205,8 @@ declare var isSecureContext: boolean; declare var origin: string; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/performance) */ declare var performance: Performance; +/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/trustedTypes) */ +declare var trustedTypes: TrustedTypePolicyFactory; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/atob) */ declare function atob(data: string): string; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/btoa) */ @@ -13105,7 +13291,7 @@ type ReadableStreamReader = ReadableStreamDefaultReader | ReadableStreamBY type ReportList = Report[]; type RequestInfo = Request | string; type TexImageSource = ImageBitmap | ImageData | OffscreenCanvas | VideoFrame; -type TimerHandler = string | Function; +type TimerHandler = string | Function | TrustedScript; type Transferable = OffscreenCanvas | ImageBitmap | MessagePort | MediaSourceHandle | ReadableStream | WritableStream | TransformStream | AudioData | VideoFrame | RTCDataChannel | ArrayBuffer; type URLPatternInput = string | URLPatternInit; type Uint32List = Uint32Array | GLuint[]; diff --git a/baselines/ts5.6/dom.generated.d.ts b/baselines/ts5.6/dom.generated.d.ts index 6e5cae9e1..b84f4f85f 100644 --- a/baselines/ts5.6/dom.generated.d.ts +++ b/baselines/ts5.6/dom.generated.d.ts @@ -2322,6 +2322,12 @@ interface TransitionEventInit extends EventInit { pseudoElement?: string; } +interface TrustedTypePolicyOptions { + createHTML?: CreateHTMLCallback; + createScript?: CreateScriptCallback; + createScriptURL?: CreateScriptURLCallback; +} + interface UIEventInit extends EventInit { detail?: number; view?: Window | null; @@ -9259,7 +9265,7 @@ interface DOMParser { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/DOMParser/parseFromString) */ - parseFromString(string: string, type: DOMParserSupportedType): Document; + parseFromString(string: TrustedHTML | string, type: DOMParserSupportedType): Document; } declare var DOMParser: { @@ -10628,14 +10634,14 @@ interface Document extends Node, DocumentOrShadowRoot, FontFaceSource, GlobalEve * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Document/write) */ - write(...text: string[]): void; + write(...text: (TrustedHTML | string)[]): void; /** * The **`writeln()`** method of the Document interface writes text in one or more TrustedHTML or string parameters to a document stream opened by document.open(), followed by a newline character. * @deprecated * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Document/writeln) */ - writeln(...text: string[]): void; + writeln(...text: (TrustedHTML | string)[]): void; /** [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent) */ get textContent(): null; addEventListener(type: K, listener: (this: Document, ev: DocumentEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; @@ -10652,7 +10658,7 @@ declare var Document: { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Document/parseHTMLUnsafe_static) */ - parseHTMLUnsafe(html: string): Document; + parseHTMLUnsafe(html: TrustedHTML | string): Document; }; /** @@ -11006,7 +11012,7 @@ interface Element extends Node, ARIAMixin, Animatable, ChildNode, NonDocumentTyp * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/innerHTML) */ - innerHTML: string; + innerHTML: TrustedHTML | string; /** * The **`Element.localName`** read-only property returns the local part of the qualified name of an element. * @@ -11028,7 +11034,7 @@ interface Element extends Node, ARIAMixin, Animatable, ChildNode, NonDocumentTyp * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/outerHTML) */ - outerHTML: string; + outerHTML: TrustedHTML | string; readonly ownerDocument: Document; /** * The **`part`** property of the Element interface represents the part identifier(s) of the element (i.e., set using the `part` attribute), returned as a DOMTokenList. @@ -11221,7 +11227,7 @@ interface Element extends Node, ARIAMixin, Animatable, ChildNode, NonDocumentTyp * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/insertAdjacentHTML) */ - insertAdjacentHTML(position: InsertPosition, string: string): void; + insertAdjacentHTML(position: InsertPosition, string: TrustedHTML | string): void; /** * The **`insertAdjacentText()`** method of the Element interface, given a relative position and a string, inserts a new text node at the given position relative to the element it is called from. * @@ -11326,7 +11332,7 @@ interface Element extends Node, ARIAMixin, Animatable, ChildNode, NonDocumentTyp * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/setHTMLUnsafe) */ - setHTMLUnsafe(html: string): void; + setHTMLUnsafe(html: TrustedHTML | string): void; /** * The **`setPointerCapture()`** method of the _capture target_ of future pointer events. * @@ -14747,7 +14753,7 @@ interface HTMLIFrameElement extends HTMLElement { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLIFrameElement/srcdoc) */ - srcdoc: string; + srcdoc: TrustedHTML | string; /** * The **`width`** property of the HTMLIFrameElement interface returns a string that reflects the `width` attribute of the iframe element, indicating the width of the frame in CSS pixels. * @@ -25943,7 +25949,7 @@ interface Range extends AbstractRange { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Range/createContextualFragment) */ - createContextualFragment(string: string): DocumentFragment; + createContextualFragment(string: TrustedHTML | string): DocumentFragment; /** * The **`Range.deleteContents()`** method removes all completely-selected Node within this range from the document. * @@ -30888,7 +30894,7 @@ interface ServiceWorkerContainer extends EventTarget { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/ServiceWorkerContainer/register) */ - register(scriptURL: string | URL, options?: RegistrationOptions): Promise; + register(scriptURL: TrustedScriptURL | string, options?: RegistrationOptions): Promise; /** * The **`startMessages()`** method of the ServiceWorkerContainer interface explicitly starts the flow of messages being dispatched from a service worker to pages under its control (e.g., sent via Client.postMessage()). * @@ -31035,7 +31041,7 @@ interface ShadowRoot extends DocumentFragment, DocumentOrShadowRoot { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/ShadowRoot/innerHTML) */ - innerHTML: string; + innerHTML: TrustedHTML | string; /** * The **`mode`** read-only property of the ShadowRoot specifies its mode — either `open` or `closed`. * @@ -31066,7 +31072,7 @@ interface ShadowRoot extends DocumentFragment, DocumentOrShadowRoot { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/ShadowRoot/setHTMLUnsafe) */ - setHTMLUnsafe(html: string): void; + setHTMLUnsafe(html: TrustedHTML | string): void; addEventListener(type: K, listener: (this: ShadowRoot, ev: ShadowRootEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void; removeEventListener(type: K, listener: (this: ShadowRoot, ev: ShadowRootEventMap[K]) => any, options?: boolean | EventListenerOptions): void; @@ -31098,7 +31104,7 @@ interface SharedWorker extends EventTarget, AbstractWorker { declare var SharedWorker: { prototype: SharedWorker; - new(scriptURL: string | URL, options?: string | WorkerOptions): SharedWorker; + new(scriptURL: TrustedScriptURL | string, options?: string | WorkerOptions): SharedWorker; }; interface Slottable { @@ -32925,6 +32931,170 @@ declare var TreeWalker: { new(): TreeWalker; }; +/** + * The **`TrustedHTML`** interface of the Trusted Types API represents a string that a developer can insert into an injection sink that will render it as HTML. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedHTML) + */ +interface TrustedHTML { + /** + * The **`toJSON()`** method of the TrustedHTML interface returns a JSON representation of the stored data. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedHTML/toJSON) + */ + toJSON(): string; + toString(): string; +} + +declare var TrustedHTML: { + prototype: TrustedHTML; + new(): TrustedHTML; +}; + +/** + * The **`TrustedScript`** interface of the Trusted Types API represents a string with an uncompiled script body that a developer can insert into an injection sink that might execute the script. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedScript) + */ +interface TrustedScript { + /** + * The **`toJSON()`** method of the TrustedScript interface returns a JSON representation of the stored data. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedScript/toJSON) + */ + toJSON(): string; + toString(): string; +} + +declare var TrustedScript: { + prototype: TrustedScript; + new(): TrustedScript; +}; + +/** + * The **`TrustedScriptURL`** interface of the Trusted Types API represents a string that a developer can insert into an injection sink that will parse it as a URL of an external script. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedScriptURL) + */ +interface TrustedScriptURL { + /** + * The **`toJSON()`** method of the TrustedScriptURL interface returns a JSON representation of the stored data. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedScriptURL/toJSON) + */ + toJSON(): string; + toString(): string; +} + +declare var TrustedScriptURL: { + prototype: TrustedScriptURL; + new(): TrustedScriptURL; +}; + +/** + * The **`TrustedTypePolicy`** interface of the Trusted Types API defines a group of functions which create `TrustedType` objects. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicy) + */ +interface TrustedTypePolicy { + /** + * The **`name`** read-only property of the TrustedTypePolicy interface returns the name of the policy. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicy/name) + */ + readonly name: string; + /** + * The **`createHTML()`** method of the TrustedTypePolicy interface creates a TrustedHTML object using a policy created by TrustedTypePolicyFactory.createPolicy(). + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicy/createHTML) + */ + createHTML(input: string, ...arguments: any[]): TrustedHTML; + /** + * The **`createScript()`** method of the TrustedTypePolicy interface creates a TrustedScript object using a policy created by TrustedTypePolicyFactory.createPolicy(). + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicy/createScript) + */ + createScript(input: string, ...arguments: any[]): TrustedScript; + /** + * The **`createScriptURL()`** method of the TrustedTypePolicy interface creates a TrustedScriptURL object using a policy created by TrustedTypePolicyFactory.createPolicy(). + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicy/createScriptURL) + */ + createScriptURL(input: string, ...arguments: any[]): TrustedScriptURL; +} + +declare var TrustedTypePolicy: { + prototype: TrustedTypePolicy; + new(): TrustedTypePolicy; +}; + +/** + * The **`TrustedTypePolicyFactory`** interface of the Trusted Types API creates policies and allows the verification of Trusted Type objects against created policies. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory) + */ +interface TrustedTypePolicyFactory { + /** + * The **`defaultPolicy`** read-only property of the TrustedTypePolicyFactory interface returns the default TrustedTypePolicy or null if this is empty. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/defaultPolicy) + */ + readonly defaultPolicy: TrustedTypePolicy | null; + /** + * The **`emptyHTML`** read-only property of the TrustedTypePolicyFactory interface returns a TrustedHTML object containing an empty string. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/emptyHTML) + */ + readonly emptyHTML: TrustedHTML; + /** + * The **`emptyScript`** read-only property of the TrustedTypePolicyFactory interface returns a TrustedScript object containing an empty string. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/emptyScript) + */ + readonly emptyScript: TrustedScript; + /** + * The **`createPolicy()`** method of the TrustedTypePolicyFactory interface creates a TrustedTypePolicy object that implements the rules passed as `policyOptions`. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/createPolicy) + */ + createPolicy(policyName: string, policyOptions?: TrustedTypePolicyOptions): TrustedTypePolicy; + /** + * The **`getAttributeType()`** method of the TrustedTypePolicyFactory interface allows web developers to check if a Trusted Type is required for an element, and if so which Trusted Type is used. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/getAttributeType) + */ + getAttributeType(tagName: string, attribute: string, elementNs?: string | null, attrNs?: string | null): string | null; + /** + * The **`getPropertyType()`** method of the TrustedTypePolicyFactory interface allows web developers to check if a Trusted Type is required for an element's property. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/getPropertyType) + */ + getPropertyType(tagName: string, property: string, elementNs?: string | null): string | null; + /** + * The **`isHTML()`** method of the TrustedTypePolicyFactory interface returns true if it is passed a valid TrustedHTML object. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/isHTML) + */ + isHTML(value: any): boolean; + /** + * The **`isScript()`** method of the TrustedTypePolicyFactory interface returns true if it is passed a valid TrustedScript object. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/isScript) + */ + isScript(value: any): boolean; + /** + * The **`isScriptURL()`** method of the TrustedTypePolicyFactory interface returns true if it is passed a valid TrustedScriptURL object. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/isScriptURL) + */ + isScriptURL(value: any): boolean; +} + +declare var TrustedTypePolicyFactory: { + prototype: TrustedTypePolicyFactory; + new(): TrustedTypePolicyFactory; +}; + /** * The **`UIEvent`** interface represents simple user interface events. * @@ -37345,6 +37515,8 @@ interface WindowOrWorkerGlobalScope { readonly origin: string; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/performance) */ readonly performance: Performance; + /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/trustedTypes) */ + readonly trustedTypes: TrustedTypePolicyFactory; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/atob) */ atob(data: string): string; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/btoa) */ @@ -37405,7 +37577,7 @@ interface Worker extends EventTarget, AbstractWorker, MessageEventTarget declare var Worker: { prototype: Worker; - new(scriptURL: string | URL, options?: WorkerOptions): Worker; + new(scriptURL: TrustedScriptURL | string, options?: WorkerOptions): Worker; }; /** @@ -38405,6 +38577,18 @@ interface BlobCallback { (blob: Blob | null): void; } +interface CreateHTMLCallback { + (input: string, ...arguments: any[]): string | null; +} + +interface CreateScriptCallback { + (input: string, ...arguments: any[]): string | null; +} + +interface CreateScriptURLCallback { + (input: string, ...arguments: any[]): string | null; +} + interface CustomElementConstructor { new (...params: any[]): HTMLElement; } @@ -39570,6 +39754,8 @@ declare var isSecureContext: boolean; declare var origin: string; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/performance) */ declare var performance: Performance; +/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/trustedTypes) */ +declare var trustedTypes: TrustedTypePolicyFactory; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/atob) */ declare function atob(data: string): string; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/btoa) */ @@ -39671,7 +39857,7 @@ type RenderingContext = CanvasRenderingContext2D | ImageBitmapRenderingContext | type ReportList = Report[]; type RequestInfo = Request | string; type TexImageSource = ImageBitmap | ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | OffscreenCanvas | VideoFrame; -type TimerHandler = string | Function; +type TimerHandler = string | Function | TrustedScript; type Transferable = OffscreenCanvas | ImageBitmap | MessagePort | MediaSourceHandle | ReadableStream | WritableStream | TransformStream | AudioData | VideoFrame | RTCDataChannel | ArrayBuffer; type URLPatternInput = string | URLPatternInit; type Uint32List = Uint32Array | GLuint[]; diff --git a/baselines/ts5.6/serviceworker.generated.d.ts b/baselines/ts5.6/serviceworker.generated.d.ts index 6847b2bec..39f7a37ef 100644 --- a/baselines/ts5.6/serviceworker.generated.d.ts +++ b/baselines/ts5.6/serviceworker.generated.d.ts @@ -717,6 +717,12 @@ interface Transformer { writableType?: undefined; } +interface TrustedTypePolicyOptions { + createHTML?: CreateHTMLCallback; + createScript?: CreateScriptCallback; + createScriptURL?: CreateScriptURLCallback; +} + interface URLPatternComponentResult { groups?: Record; input?: string; @@ -6942,7 +6948,7 @@ interface ServiceWorkerContainer extends EventTarget { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/ServiceWorkerContainer/register) */ - register(scriptURL: string | URL, options?: RegistrationOptions): Promise; + register(scriptURL: TrustedScriptURL | string, options?: RegistrationOptions): Promise; /** * The **`startMessages()`** method of the ServiceWorkerContainer interface explicitly starts the flow of messages being dispatched from a service worker to pages under its control (e.g., sent via Client.postMessage()). * @@ -7550,6 +7556,170 @@ declare var TransformStreamDefaultController: { new(): TransformStreamDefaultController; }; +/** + * The **`TrustedHTML`** interface of the Trusted Types API represents a string that a developer can insert into an injection sink that will render it as HTML. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedHTML) + */ +interface TrustedHTML { + /** + * The **`toJSON()`** method of the TrustedHTML interface returns a JSON representation of the stored data. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedHTML/toJSON) + */ + toJSON(): string; + toString(): string; +} + +declare var TrustedHTML: { + prototype: TrustedHTML; + new(): TrustedHTML; +}; + +/** + * The **`TrustedScript`** interface of the Trusted Types API represents a string with an uncompiled script body that a developer can insert into an injection sink that might execute the script. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedScript) + */ +interface TrustedScript { + /** + * The **`toJSON()`** method of the TrustedScript interface returns a JSON representation of the stored data. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedScript/toJSON) + */ + toJSON(): string; + toString(): string; +} + +declare var TrustedScript: { + prototype: TrustedScript; + new(): TrustedScript; +}; + +/** + * The **`TrustedScriptURL`** interface of the Trusted Types API represents a string that a developer can insert into an injection sink that will parse it as a URL of an external script. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedScriptURL) + */ +interface TrustedScriptURL { + /** + * The **`toJSON()`** method of the TrustedScriptURL interface returns a JSON representation of the stored data. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedScriptURL/toJSON) + */ + toJSON(): string; + toString(): string; +} + +declare var TrustedScriptURL: { + prototype: TrustedScriptURL; + new(): TrustedScriptURL; +}; + +/** + * The **`TrustedTypePolicy`** interface of the Trusted Types API defines a group of functions which create `TrustedType` objects. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicy) + */ +interface TrustedTypePolicy { + /** + * The **`name`** read-only property of the TrustedTypePolicy interface returns the name of the policy. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicy/name) + */ + readonly name: string; + /** + * The **`createHTML()`** method of the TrustedTypePolicy interface creates a TrustedHTML object using a policy created by TrustedTypePolicyFactory.createPolicy(). + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicy/createHTML) + */ + createHTML(input: string, ...arguments: any[]): TrustedHTML; + /** + * The **`createScript()`** method of the TrustedTypePolicy interface creates a TrustedScript object using a policy created by TrustedTypePolicyFactory.createPolicy(). + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicy/createScript) + */ + createScript(input: string, ...arguments: any[]): TrustedScript; + /** + * The **`createScriptURL()`** method of the TrustedTypePolicy interface creates a TrustedScriptURL object using a policy created by TrustedTypePolicyFactory.createPolicy(). + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicy/createScriptURL) + */ + createScriptURL(input: string, ...arguments: any[]): TrustedScriptURL; +} + +declare var TrustedTypePolicy: { + prototype: TrustedTypePolicy; + new(): TrustedTypePolicy; +}; + +/** + * The **`TrustedTypePolicyFactory`** interface of the Trusted Types API creates policies and allows the verification of Trusted Type objects against created policies. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory) + */ +interface TrustedTypePolicyFactory { + /** + * The **`defaultPolicy`** read-only property of the TrustedTypePolicyFactory interface returns the default TrustedTypePolicy or null if this is empty. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/defaultPolicy) + */ + readonly defaultPolicy: TrustedTypePolicy | null; + /** + * The **`emptyHTML`** read-only property of the TrustedTypePolicyFactory interface returns a TrustedHTML object containing an empty string. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/emptyHTML) + */ + readonly emptyHTML: TrustedHTML; + /** + * The **`emptyScript`** read-only property of the TrustedTypePolicyFactory interface returns a TrustedScript object containing an empty string. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/emptyScript) + */ + readonly emptyScript: TrustedScript; + /** + * The **`createPolicy()`** method of the TrustedTypePolicyFactory interface creates a TrustedTypePolicy object that implements the rules passed as `policyOptions`. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/createPolicy) + */ + createPolicy(policyName: string, policyOptions?: TrustedTypePolicyOptions): TrustedTypePolicy; + /** + * The **`getAttributeType()`** method of the TrustedTypePolicyFactory interface allows web developers to check if a Trusted Type is required for an element, and if so which Trusted Type is used. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/getAttributeType) + */ + getAttributeType(tagName: string, attribute: string, elementNs?: string | null, attrNs?: string | null): string | null; + /** + * The **`getPropertyType()`** method of the TrustedTypePolicyFactory interface allows web developers to check if a Trusted Type is required for an element's property. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/getPropertyType) + */ + getPropertyType(tagName: string, property: string, elementNs?: string | null): string | null; + /** + * The **`isHTML()`** method of the TrustedTypePolicyFactory interface returns true if it is passed a valid TrustedHTML object. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/isHTML) + */ + isHTML(value: any): boolean; + /** + * The **`isScript()`** method of the TrustedTypePolicyFactory interface returns true if it is passed a valid TrustedScript object. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/isScript) + */ + isScript(value: any): boolean; + /** + * The **`isScriptURL()`** method of the TrustedTypePolicyFactory interface returns true if it is passed a valid TrustedScriptURL object. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/isScriptURL) + */ + isScriptURL(value: any): boolean; +} + +declare var TrustedTypePolicyFactory: { + prototype: TrustedTypePolicyFactory; + new(): TrustedTypePolicyFactory; +}; + /** * The **`URL`** interface is used to parse, construct, normalize, and encode URL. * @@ -10601,6 +10771,8 @@ interface WindowOrWorkerGlobalScope { readonly origin: string; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/performance) */ readonly performance: Performance; + /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/trustedTypes) */ + readonly trustedTypes: TrustedTypePolicyFactory; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/atob) */ atob(data: string): string; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/btoa) */ @@ -10676,7 +10848,7 @@ interface WorkerGlobalScope extends EventTarget, FontFaceSource, WindowOrWorkerG * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/WorkerGlobalScope/importScripts) */ - importScripts(...urls: (string | URL)[]): void; + importScripts(...urls: (TrustedScriptURL | string)[]): void; addEventListener(type: K, listener: (this: WorkerGlobalScope, ev: WorkerGlobalScopeEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void; removeEventListener(type: K, listener: (this: WorkerGlobalScope, ev: WorkerGlobalScopeEventMap[K]) => any, options?: boolean | EventListenerOptions): void; @@ -11190,6 +11362,18 @@ interface Console { declare var console: Console; +interface CreateHTMLCallback { + (input: string, ...arguments: any[]): string | null; +} + +interface CreateScriptCallback { + (input: string, ...arguments: any[]): string | null; +} + +interface CreateScriptURLCallback { + (input: string, ...arguments: any[]): string | null; +} + interface LockGrantedCallback { (lock: Lock | null): T; } @@ -11345,7 +11529,7 @@ declare var self: WorkerGlobalScope & typeof globalThis; * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/WorkerGlobalScope/importScripts) */ -declare function importScripts(...urls: (string | URL)[]): void; +declare function importScripts(...urls: (TrustedScriptURL | string)[]): void; /** * The **`dispatchEvent()`** method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order. * @@ -11372,6 +11556,8 @@ declare var isSecureContext: boolean; declare var origin: string; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/performance) */ declare var performance: Performance; +/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/trustedTypes) */ +declare var trustedTypes: TrustedTypePolicyFactory; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/atob) */ declare function atob(data: string): string; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/btoa) */ @@ -11447,7 +11633,7 @@ type ReadableStreamReader = ReadableStreamDefaultReader | ReadableStreamBY type ReportList = Report[]; type RequestInfo = Request | string; type TexImageSource = ImageBitmap | ImageData | OffscreenCanvas; -type TimerHandler = string | Function; +type TimerHandler = string | Function | TrustedScript; type Transferable = OffscreenCanvas | ImageBitmap | MessagePort | ReadableStream | WritableStream | TransformStream | ArrayBuffer; type URLPatternInput = string | URLPatternInit; type Uint32List = Uint32Array | GLuint[]; diff --git a/baselines/ts5.6/sharedworker.generated.d.ts b/baselines/ts5.6/sharedworker.generated.d.ts index de00fa37c..b94e27189 100644 --- a/baselines/ts5.6/sharedworker.generated.d.ts +++ b/baselines/ts5.6/sharedworker.generated.d.ts @@ -647,6 +647,12 @@ interface Transformer { writableType?: undefined; } +interface TrustedTypePolicyOptions { + createHTML?: CreateHTMLCallback; + createScript?: CreateScriptCallback; + createScriptURL?: CreateScriptURLCallback; +} + interface URLPatternComponentResult { groups?: Record; input?: string; @@ -6525,7 +6531,7 @@ interface ServiceWorkerContainer extends EventTarget { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/ServiceWorkerContainer/register) */ - register(scriptURL: string | URL, options?: RegistrationOptions): Promise; + register(scriptURL: TrustedScriptURL | string, options?: RegistrationOptions): Promise; /** * The **`startMessages()`** method of the ServiceWorkerContainer interface explicitly starts the flow of messages being dispatched from a service worker to pages under its control (e.g., sent via Client.postMessage()). * @@ -7081,6 +7087,170 @@ declare var TransformStreamDefaultController: { new(): TransformStreamDefaultController; }; +/** + * The **`TrustedHTML`** interface of the Trusted Types API represents a string that a developer can insert into an injection sink that will render it as HTML. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedHTML) + */ +interface TrustedHTML { + /** + * The **`toJSON()`** method of the TrustedHTML interface returns a JSON representation of the stored data. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedHTML/toJSON) + */ + toJSON(): string; + toString(): string; +} + +declare var TrustedHTML: { + prototype: TrustedHTML; + new(): TrustedHTML; +}; + +/** + * The **`TrustedScript`** interface of the Trusted Types API represents a string with an uncompiled script body that a developer can insert into an injection sink that might execute the script. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedScript) + */ +interface TrustedScript { + /** + * The **`toJSON()`** method of the TrustedScript interface returns a JSON representation of the stored data. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedScript/toJSON) + */ + toJSON(): string; + toString(): string; +} + +declare var TrustedScript: { + prototype: TrustedScript; + new(): TrustedScript; +}; + +/** + * The **`TrustedScriptURL`** interface of the Trusted Types API represents a string that a developer can insert into an injection sink that will parse it as a URL of an external script. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedScriptURL) + */ +interface TrustedScriptURL { + /** + * The **`toJSON()`** method of the TrustedScriptURL interface returns a JSON representation of the stored data. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedScriptURL/toJSON) + */ + toJSON(): string; + toString(): string; +} + +declare var TrustedScriptURL: { + prototype: TrustedScriptURL; + new(): TrustedScriptURL; +}; + +/** + * The **`TrustedTypePolicy`** interface of the Trusted Types API defines a group of functions which create `TrustedType` objects. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicy) + */ +interface TrustedTypePolicy { + /** + * The **`name`** read-only property of the TrustedTypePolicy interface returns the name of the policy. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicy/name) + */ + readonly name: string; + /** + * The **`createHTML()`** method of the TrustedTypePolicy interface creates a TrustedHTML object using a policy created by TrustedTypePolicyFactory.createPolicy(). + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicy/createHTML) + */ + createHTML(input: string, ...arguments: any[]): TrustedHTML; + /** + * The **`createScript()`** method of the TrustedTypePolicy interface creates a TrustedScript object using a policy created by TrustedTypePolicyFactory.createPolicy(). + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicy/createScript) + */ + createScript(input: string, ...arguments: any[]): TrustedScript; + /** + * The **`createScriptURL()`** method of the TrustedTypePolicy interface creates a TrustedScriptURL object using a policy created by TrustedTypePolicyFactory.createPolicy(). + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicy/createScriptURL) + */ + createScriptURL(input: string, ...arguments: any[]): TrustedScriptURL; +} + +declare var TrustedTypePolicy: { + prototype: TrustedTypePolicy; + new(): TrustedTypePolicy; +}; + +/** + * The **`TrustedTypePolicyFactory`** interface of the Trusted Types API creates policies and allows the verification of Trusted Type objects against created policies. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory) + */ +interface TrustedTypePolicyFactory { + /** + * The **`defaultPolicy`** read-only property of the TrustedTypePolicyFactory interface returns the default TrustedTypePolicy or null if this is empty. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/defaultPolicy) + */ + readonly defaultPolicy: TrustedTypePolicy | null; + /** + * The **`emptyHTML`** read-only property of the TrustedTypePolicyFactory interface returns a TrustedHTML object containing an empty string. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/emptyHTML) + */ + readonly emptyHTML: TrustedHTML; + /** + * The **`emptyScript`** read-only property of the TrustedTypePolicyFactory interface returns a TrustedScript object containing an empty string. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/emptyScript) + */ + readonly emptyScript: TrustedScript; + /** + * The **`createPolicy()`** method of the TrustedTypePolicyFactory interface creates a TrustedTypePolicy object that implements the rules passed as `policyOptions`. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/createPolicy) + */ + createPolicy(policyName: string, policyOptions?: TrustedTypePolicyOptions): TrustedTypePolicy; + /** + * The **`getAttributeType()`** method of the TrustedTypePolicyFactory interface allows web developers to check if a Trusted Type is required for an element, and if so which Trusted Type is used. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/getAttributeType) + */ + getAttributeType(tagName: string, attribute: string, elementNs?: string | null, attrNs?: string | null): string | null; + /** + * The **`getPropertyType()`** method of the TrustedTypePolicyFactory interface allows web developers to check if a Trusted Type is required for an element's property. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/getPropertyType) + */ + getPropertyType(tagName: string, property: string, elementNs?: string | null): string | null; + /** + * The **`isHTML()`** method of the TrustedTypePolicyFactory interface returns true if it is passed a valid TrustedHTML object. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/isHTML) + */ + isHTML(value: any): boolean; + /** + * The **`isScript()`** method of the TrustedTypePolicyFactory interface returns true if it is passed a valid TrustedScript object. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/isScript) + */ + isScript(value: any): boolean; + /** + * The **`isScriptURL()`** method of the TrustedTypePolicyFactory interface returns true if it is passed a valid TrustedScriptURL object. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/isScriptURL) + */ + isScriptURL(value: any): boolean; +} + +declare var TrustedTypePolicyFactory: { + prototype: TrustedTypePolicyFactory; + new(): TrustedTypePolicyFactory; +}; + /** * The **`URL`** interface is used to parse, construct, normalize, and encode URL. * @@ -10107,6 +10277,8 @@ interface WindowOrWorkerGlobalScope { readonly origin: string; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/performance) */ readonly performance: Performance; + /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/trustedTypes) */ + readonly trustedTypes: TrustedTypePolicyFactory; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/atob) */ atob(data: string): string; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/btoa) */ @@ -10162,7 +10334,7 @@ interface Worker extends EventTarget, AbstractWorker, MessageEventTarget declare var Worker: { prototype: Worker; - new(scriptURL: string | URL, options?: WorkerOptions): Worker; + new(scriptURL: TrustedScriptURL | string, options?: WorkerOptions): Worker; }; interface WorkerGlobalScopeEventMap { @@ -10215,7 +10387,7 @@ interface WorkerGlobalScope extends EventTarget, FontFaceSource, WindowOrWorkerG * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/WorkerGlobalScope/importScripts) */ - importScripts(...urls: (string | URL)[]): void; + importScripts(...urls: (TrustedScriptURL | string)[]): void; addEventListener(type: K, listener: (this: WorkerGlobalScope, ev: WorkerGlobalScopeEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void; removeEventListener(type: K, listener: (this: WorkerGlobalScope, ev: WorkerGlobalScopeEventMap[K]) => any, options?: boolean | EventListenerOptions): void; @@ -10916,6 +11088,18 @@ interface Console { declare var console: Console; +interface CreateHTMLCallback { + (input: string, ...arguments: any[]): string | null; +} + +interface CreateScriptCallback { + (input: string, ...arguments: any[]): string | null; +} + +interface CreateScriptURLCallback { + (input: string, ...arguments: any[]): string | null; +} + interface LockGrantedCallback { (lock: Lock | null): T; } @@ -11035,7 +11219,7 @@ declare var self: WorkerGlobalScope & typeof globalThis; * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/WorkerGlobalScope/importScripts) */ -declare function importScripts(...urls: (string | URL)[]): void; +declare function importScripts(...urls: (TrustedScriptURL | string)[]): void; /** * The **`dispatchEvent()`** method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order. * @@ -11062,6 +11246,8 @@ declare var isSecureContext: boolean; declare var origin: string; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/performance) */ declare var performance: Performance; +/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/trustedTypes) */ +declare var trustedTypes: TrustedTypePolicyFactory; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/atob) */ declare function atob(data: string): string; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/btoa) */ @@ -11135,7 +11321,7 @@ type ReadableStreamReader = ReadableStreamDefaultReader | ReadableStreamBY type ReportList = Report[]; type RequestInfo = Request | string; type TexImageSource = ImageBitmap | ImageData | OffscreenCanvas; -type TimerHandler = string | Function; +type TimerHandler = string | Function | TrustedScript; type Transferable = OffscreenCanvas | ImageBitmap | MessagePort | ReadableStream | WritableStream | TransformStream | ArrayBuffer; type URLPatternInput = string | URLPatternInit; type Uint32List = Uint32Array | GLuint[]; diff --git a/baselines/ts5.6/webworker.generated.d.ts b/baselines/ts5.6/webworker.generated.d.ts index cdaec1532..bc86de286 100644 --- a/baselines/ts5.6/webworker.generated.d.ts +++ b/baselines/ts5.6/webworker.generated.d.ts @@ -861,6 +861,12 @@ interface Transformer { writableType?: undefined; } +interface TrustedTypePolicyOptions { + createHTML?: CreateHTMLCallback; + createScript?: CreateScriptCallback; + createScriptURL?: CreateScriptURLCallback; +} + interface URLPatternComponentResult { groups?: Record; input?: string; @@ -8044,7 +8050,7 @@ interface ServiceWorkerContainer extends EventTarget { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/ServiceWorkerContainer/register) */ - register(scriptURL: string | URL, options?: RegistrationOptions): Promise; + register(scriptURL: TrustedScriptURL | string, options?: RegistrationOptions): Promise; /** * The **`startMessages()`** method of the ServiceWorkerContainer interface explicitly starts the flow of messages being dispatched from a service worker to pages under its control (e.g., sent via Client.postMessage()). * @@ -8687,6 +8693,170 @@ declare var TransformStreamDefaultController: { new(): TransformStreamDefaultController; }; +/** + * The **`TrustedHTML`** interface of the Trusted Types API represents a string that a developer can insert into an injection sink that will render it as HTML. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedHTML) + */ +interface TrustedHTML { + /** + * The **`toJSON()`** method of the TrustedHTML interface returns a JSON representation of the stored data. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedHTML/toJSON) + */ + toJSON(): string; + toString(): string; +} + +declare var TrustedHTML: { + prototype: TrustedHTML; + new(): TrustedHTML; +}; + +/** + * The **`TrustedScript`** interface of the Trusted Types API represents a string with an uncompiled script body that a developer can insert into an injection sink that might execute the script. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedScript) + */ +interface TrustedScript { + /** + * The **`toJSON()`** method of the TrustedScript interface returns a JSON representation of the stored data. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedScript/toJSON) + */ + toJSON(): string; + toString(): string; +} + +declare var TrustedScript: { + prototype: TrustedScript; + new(): TrustedScript; +}; + +/** + * The **`TrustedScriptURL`** interface of the Trusted Types API represents a string that a developer can insert into an injection sink that will parse it as a URL of an external script. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedScriptURL) + */ +interface TrustedScriptURL { + /** + * The **`toJSON()`** method of the TrustedScriptURL interface returns a JSON representation of the stored data. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedScriptURL/toJSON) + */ + toJSON(): string; + toString(): string; +} + +declare var TrustedScriptURL: { + prototype: TrustedScriptURL; + new(): TrustedScriptURL; +}; + +/** + * The **`TrustedTypePolicy`** interface of the Trusted Types API defines a group of functions which create `TrustedType` objects. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicy) + */ +interface TrustedTypePolicy { + /** + * The **`name`** read-only property of the TrustedTypePolicy interface returns the name of the policy. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicy/name) + */ + readonly name: string; + /** + * The **`createHTML()`** method of the TrustedTypePolicy interface creates a TrustedHTML object using a policy created by TrustedTypePolicyFactory.createPolicy(). + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicy/createHTML) + */ + createHTML(input: string, ...arguments: any[]): TrustedHTML; + /** + * The **`createScript()`** method of the TrustedTypePolicy interface creates a TrustedScript object using a policy created by TrustedTypePolicyFactory.createPolicy(). + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicy/createScript) + */ + createScript(input: string, ...arguments: any[]): TrustedScript; + /** + * The **`createScriptURL()`** method of the TrustedTypePolicy interface creates a TrustedScriptURL object using a policy created by TrustedTypePolicyFactory.createPolicy(). + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicy/createScriptURL) + */ + createScriptURL(input: string, ...arguments: any[]): TrustedScriptURL; +} + +declare var TrustedTypePolicy: { + prototype: TrustedTypePolicy; + new(): TrustedTypePolicy; +}; + +/** + * The **`TrustedTypePolicyFactory`** interface of the Trusted Types API creates policies and allows the verification of Trusted Type objects against created policies. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory) + */ +interface TrustedTypePolicyFactory { + /** + * The **`defaultPolicy`** read-only property of the TrustedTypePolicyFactory interface returns the default TrustedTypePolicy or null if this is empty. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/defaultPolicy) + */ + readonly defaultPolicy: TrustedTypePolicy | null; + /** + * The **`emptyHTML`** read-only property of the TrustedTypePolicyFactory interface returns a TrustedHTML object containing an empty string. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/emptyHTML) + */ + readonly emptyHTML: TrustedHTML; + /** + * The **`emptyScript`** read-only property of the TrustedTypePolicyFactory interface returns a TrustedScript object containing an empty string. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/emptyScript) + */ + readonly emptyScript: TrustedScript; + /** + * The **`createPolicy()`** method of the TrustedTypePolicyFactory interface creates a TrustedTypePolicy object that implements the rules passed as `policyOptions`. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/createPolicy) + */ + createPolicy(policyName: string, policyOptions?: TrustedTypePolicyOptions): TrustedTypePolicy; + /** + * The **`getAttributeType()`** method of the TrustedTypePolicyFactory interface allows web developers to check if a Trusted Type is required for an element, and if so which Trusted Type is used. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/getAttributeType) + */ + getAttributeType(tagName: string, attribute: string, elementNs?: string | null, attrNs?: string | null): string | null; + /** + * The **`getPropertyType()`** method of the TrustedTypePolicyFactory interface allows web developers to check if a Trusted Type is required for an element's property. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/getPropertyType) + */ + getPropertyType(tagName: string, property: string, elementNs?: string | null): string | null; + /** + * The **`isHTML()`** method of the TrustedTypePolicyFactory interface returns true if it is passed a valid TrustedHTML object. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/isHTML) + */ + isHTML(value: any): boolean; + /** + * The **`isScript()`** method of the TrustedTypePolicyFactory interface returns true if it is passed a valid TrustedScript object. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/isScript) + */ + isScript(value: any): boolean; + /** + * The **`isScriptURL()`** method of the TrustedTypePolicyFactory interface returns true if it is passed a valid TrustedScriptURL object. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/isScriptURL) + */ + isScriptURL(value: any): boolean; +} + +declare var TrustedTypePolicyFactory: { + prototype: TrustedTypePolicyFactory; + new(): TrustedTypePolicyFactory; +}; + /** * The **`URL`** interface is used to parse, construct, normalize, and encode URL. * @@ -12035,6 +12205,8 @@ interface WindowOrWorkerGlobalScope { readonly origin: string; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/performance) */ readonly performance: Performance; + /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/trustedTypes) */ + readonly trustedTypes: TrustedTypePolicyFactory; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/atob) */ atob(data: string): string; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/btoa) */ @@ -12090,7 +12262,7 @@ interface Worker extends EventTarget, AbstractWorker, MessageEventTarget declare var Worker: { prototype: Worker; - new(scriptURL: string | URL, options?: WorkerOptions): Worker; + new(scriptURL: TrustedScriptURL | string, options?: WorkerOptions): Worker; }; interface WorkerGlobalScopeEventMap { @@ -12143,7 +12315,7 @@ interface WorkerGlobalScope extends EventTarget, FontFaceSource, WindowOrWorkerG * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/WorkerGlobalScope/importScripts) */ - importScripts(...urls: (string | URL)[]): void; + importScripts(...urls: (TrustedScriptURL | string)[]): void; addEventListener(type: K, listener: (this: WorkerGlobalScope, ev: WorkerGlobalScopeEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void; removeEventListener(type: K, listener: (this: WorkerGlobalScope, ev: WorkerGlobalScopeEventMap[K]) => any, options?: boolean | EventListenerOptions): void; @@ -12848,6 +13020,18 @@ interface AudioDataOutputCallback { (output: AudioData): void; } +interface CreateHTMLCallback { + (input: string, ...arguments: any[]): string | null; +} + +interface CreateScriptCallback { + (input: string, ...arguments: any[]): string | null; +} + +interface CreateScriptURLCallback { + (input: string, ...arguments: any[]): string | null; +} + interface EncodedAudioChunkOutputCallback { (output: EncodedAudioChunk, metadata?: EncodedAudioChunkMetadata): void; } @@ -12994,7 +13178,7 @@ declare var self: WorkerGlobalScope & typeof globalThis; * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/WorkerGlobalScope/importScripts) */ -declare function importScripts(...urls: (string | URL)[]): void; +declare function importScripts(...urls: (TrustedScriptURL | string)[]): void; /** * The **`dispatchEvent()`** method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order. * @@ -13021,6 +13205,8 @@ declare var isSecureContext: boolean; declare var origin: string; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/performance) */ declare var performance: Performance; +/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/trustedTypes) */ +declare var trustedTypes: TrustedTypePolicyFactory; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/atob) */ declare function atob(data: string): string; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/btoa) */ @@ -13105,7 +13291,7 @@ type ReadableStreamReader = ReadableStreamDefaultReader | ReadableStreamBY type ReportList = Report[]; type RequestInfo = Request | string; type TexImageSource = ImageBitmap | ImageData | OffscreenCanvas | VideoFrame; -type TimerHandler = string | Function; +type TimerHandler = string | Function | TrustedScript; type Transferable = OffscreenCanvas | ImageBitmap | MessagePort | MediaSourceHandle | ReadableStream | WritableStream | TransformStream | AudioData | VideoFrame | RTCDataChannel | ArrayBuffer; type URLPatternInput = string | URLPatternInit; type Uint32List = Uint32Array | GLuint[]; diff --git a/baselines/webworker.generated.d.ts b/baselines/webworker.generated.d.ts index 800f6b628..51535ebb5 100644 --- a/baselines/webworker.generated.d.ts +++ b/baselines/webworker.generated.d.ts @@ -861,6 +861,12 @@ interface Transformer { writableType?: undefined; } +interface TrustedTypePolicyOptions { + createHTML?: CreateHTMLCallback; + createScript?: CreateScriptCallback; + createScriptURL?: CreateScriptURLCallback; +} + interface URLPatternComponentResult { groups?: Record; input?: string; @@ -8044,7 +8050,7 @@ interface ServiceWorkerContainer extends EventTarget { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/ServiceWorkerContainer/register) */ - register(scriptURL: string | URL, options?: RegistrationOptions): Promise; + register(scriptURL: TrustedScriptURL | string, options?: RegistrationOptions): Promise; /** * The **`startMessages()`** method of the ServiceWorkerContainer interface explicitly starts the flow of messages being dispatched from a service worker to pages under its control (e.g., sent via Client.postMessage()). * @@ -8687,6 +8693,170 @@ declare var TransformStreamDefaultController: { new(): TransformStreamDefaultController; }; +/** + * The **`TrustedHTML`** interface of the Trusted Types API represents a string that a developer can insert into an injection sink that will render it as HTML. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedHTML) + */ +interface TrustedHTML { + /** + * The **`toJSON()`** method of the TrustedHTML interface returns a JSON representation of the stored data. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedHTML/toJSON) + */ + toJSON(): string; + toString(): string; +} + +declare var TrustedHTML: { + prototype: TrustedHTML; + new(): TrustedHTML; +}; + +/** + * The **`TrustedScript`** interface of the Trusted Types API represents a string with an uncompiled script body that a developer can insert into an injection sink that might execute the script. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedScript) + */ +interface TrustedScript { + /** + * The **`toJSON()`** method of the TrustedScript interface returns a JSON representation of the stored data. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedScript/toJSON) + */ + toJSON(): string; + toString(): string; +} + +declare var TrustedScript: { + prototype: TrustedScript; + new(): TrustedScript; +}; + +/** + * The **`TrustedScriptURL`** interface of the Trusted Types API represents a string that a developer can insert into an injection sink that will parse it as a URL of an external script. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedScriptURL) + */ +interface TrustedScriptURL { + /** + * The **`toJSON()`** method of the TrustedScriptURL interface returns a JSON representation of the stored data. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedScriptURL/toJSON) + */ + toJSON(): string; + toString(): string; +} + +declare var TrustedScriptURL: { + prototype: TrustedScriptURL; + new(): TrustedScriptURL; +}; + +/** + * The **`TrustedTypePolicy`** interface of the Trusted Types API defines a group of functions which create `TrustedType` objects. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicy) + */ +interface TrustedTypePolicy { + /** + * The **`name`** read-only property of the TrustedTypePolicy interface returns the name of the policy. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicy/name) + */ + readonly name: string; + /** + * The **`createHTML()`** method of the TrustedTypePolicy interface creates a TrustedHTML object using a policy created by TrustedTypePolicyFactory.createPolicy(). + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicy/createHTML) + */ + createHTML(input: string, ...arguments: any[]): TrustedHTML; + /** + * The **`createScript()`** method of the TrustedTypePolicy interface creates a TrustedScript object using a policy created by TrustedTypePolicyFactory.createPolicy(). + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicy/createScript) + */ + createScript(input: string, ...arguments: any[]): TrustedScript; + /** + * The **`createScriptURL()`** method of the TrustedTypePolicy interface creates a TrustedScriptURL object using a policy created by TrustedTypePolicyFactory.createPolicy(). + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicy/createScriptURL) + */ + createScriptURL(input: string, ...arguments: any[]): TrustedScriptURL; +} + +declare var TrustedTypePolicy: { + prototype: TrustedTypePolicy; + new(): TrustedTypePolicy; +}; + +/** + * The **`TrustedTypePolicyFactory`** interface of the Trusted Types API creates policies and allows the verification of Trusted Type objects against created policies. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory) + */ +interface TrustedTypePolicyFactory { + /** + * The **`defaultPolicy`** read-only property of the TrustedTypePolicyFactory interface returns the default TrustedTypePolicy or null if this is empty. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/defaultPolicy) + */ + readonly defaultPolicy: TrustedTypePolicy | null; + /** + * The **`emptyHTML`** read-only property of the TrustedTypePolicyFactory interface returns a TrustedHTML object containing an empty string. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/emptyHTML) + */ + readonly emptyHTML: TrustedHTML; + /** + * The **`emptyScript`** read-only property of the TrustedTypePolicyFactory interface returns a TrustedScript object containing an empty string. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/emptyScript) + */ + readonly emptyScript: TrustedScript; + /** + * The **`createPolicy()`** method of the TrustedTypePolicyFactory interface creates a TrustedTypePolicy object that implements the rules passed as `policyOptions`. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/createPolicy) + */ + createPolicy(policyName: string, policyOptions?: TrustedTypePolicyOptions): TrustedTypePolicy; + /** + * The **`getAttributeType()`** method of the TrustedTypePolicyFactory interface allows web developers to check if a Trusted Type is required for an element, and if so which Trusted Type is used. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/getAttributeType) + */ + getAttributeType(tagName: string, attribute: string, elementNs?: string | null, attrNs?: string | null): string | null; + /** + * The **`getPropertyType()`** method of the TrustedTypePolicyFactory interface allows web developers to check if a Trusted Type is required for an element's property. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/getPropertyType) + */ + getPropertyType(tagName: string, property: string, elementNs?: string | null): string | null; + /** + * The **`isHTML()`** method of the TrustedTypePolicyFactory interface returns true if it is passed a valid TrustedHTML object. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/isHTML) + */ + isHTML(value: any): boolean; + /** + * The **`isScript()`** method of the TrustedTypePolicyFactory interface returns true if it is passed a valid TrustedScript object. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/isScript) + */ + isScript(value: any): boolean; + /** + * The **`isScriptURL()`** method of the TrustedTypePolicyFactory interface returns true if it is passed a valid TrustedScriptURL object. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TrustedTypePolicyFactory/isScriptURL) + */ + isScriptURL(value: any): boolean; +} + +declare var TrustedTypePolicyFactory: { + prototype: TrustedTypePolicyFactory; + new(): TrustedTypePolicyFactory; +}; + /** * The **`URL`** interface is used to parse, construct, normalize, and encode URL. * @@ -12035,6 +12205,8 @@ interface WindowOrWorkerGlobalScope { readonly origin: string; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/performance) */ readonly performance: Performance; + /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/trustedTypes) */ + readonly trustedTypes: TrustedTypePolicyFactory; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/atob) */ atob(data: string): string; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/btoa) */ @@ -12090,7 +12262,7 @@ interface Worker extends EventTarget, AbstractWorker, MessageEventTarget declare var Worker: { prototype: Worker; - new(scriptURL: string | URL, options?: WorkerOptions): Worker; + new(scriptURL: TrustedScriptURL | string, options?: WorkerOptions): Worker; }; interface WorkerGlobalScopeEventMap { @@ -12143,7 +12315,7 @@ interface WorkerGlobalScope extends EventTarget, FontFaceSource, WindowOrWorkerG * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/WorkerGlobalScope/importScripts) */ - importScripts(...urls: (string | URL)[]): void; + importScripts(...urls: (TrustedScriptURL | string)[]): void; addEventListener(type: K, listener: (this: WorkerGlobalScope, ev: WorkerGlobalScopeEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void; removeEventListener(type: K, listener: (this: WorkerGlobalScope, ev: WorkerGlobalScopeEventMap[K]) => any, options?: boolean | EventListenerOptions): void; @@ -12848,6 +13020,18 @@ interface AudioDataOutputCallback { (output: AudioData): void; } +interface CreateHTMLCallback { + (input: string, ...arguments: any[]): string | null; +} + +interface CreateScriptCallback { + (input: string, ...arguments: any[]): string | null; +} + +interface CreateScriptURLCallback { + (input: string, ...arguments: any[]): string | null; +} + interface EncodedAudioChunkOutputCallback { (output: EncodedAudioChunk, metadata?: EncodedAudioChunkMetadata): void; } @@ -12994,7 +13178,7 @@ declare var self: WorkerGlobalScope & typeof globalThis; * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/WorkerGlobalScope/importScripts) */ -declare function importScripts(...urls: (string | URL)[]): void; +declare function importScripts(...urls: (TrustedScriptURL | string)[]): void; /** * The **`dispatchEvent()`** method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order. * @@ -13021,6 +13205,8 @@ declare var isSecureContext: boolean; declare var origin: string; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/performance) */ declare var performance: Performance; +/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/trustedTypes) */ +declare var trustedTypes: TrustedTypePolicyFactory; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/atob) */ declare function atob(data: string): string; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/btoa) */ @@ -13105,7 +13291,7 @@ type ReadableStreamReader = ReadableStreamDefaultReader | ReadableStreamBY type ReportList = Report[]; type RequestInfo = Request | string; type TexImageSource = ImageBitmap | ImageData | OffscreenCanvas | VideoFrame; -type TimerHandler = string | Function; +type TimerHandler = string | Function | TrustedScript; type Transferable = OffscreenCanvas | ImageBitmap | MessagePort | MediaSourceHandle | ReadableStream | WritableStream | TransformStream | AudioData | VideoFrame | RTCDataChannel | ArrayBuffer; type URLPatternInput = string | URLPatternInit; type Uint32List = Uint32Array | GLuint[]; diff --git a/inputfiles/overridingTypes.jsonc b/inputfiles/overridingTypes.jsonc index 8a5a30d30..bb86892f0 100644 --- a/inputfiles/overridingTypes.jsonc +++ b/inputfiles/overridingTypes.jsonc @@ -317,14 +317,6 @@ } } } - }, - "properties": { - "property": { - // TODO: only for bcd@6.0.24 progressive acceptance, should be removed - "trustedTypes": { - "exposed": "" - } - } } } } @@ -3810,21 +3802,6 @@ "GPUValidationError": { "exposed": "" }, - "TrustedHTML": { - "exposed": "" - }, - "TrustedScript": { - "exposed": "" - }, - "TrustedScriptURL": { - "exposed": "" - }, - "TrustedTypePolicy": { - "exposed": "" - }, - "TrustedTypePolicyFactory": { - "exposed": "" - }, "WGSLLanguageFeatures": { "exposed": "" } From 55df8ec320b6a2284c633dfe2c28583b3cd09ac7 Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Sat, 19 Jul 2025 20:02:23 +0200 Subject: [PATCH 2/3] Create trusted-types.ts --- unittests/files/trusted-types.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 unittests/files/trusted-types.ts diff --git a/unittests/files/trusted-types.ts b/unittests/files/trusted-types.ts new file mode 100644 index 000000000..d31ac9632 --- /dev/null +++ b/unittests/files/trusted-types.ts @@ -0,0 +1,15 @@ +declare const assertNotAssignable: () => ( + _x: T1, +) => T1 extends T + ? { error: "Right side should not be assignable to left side" } + : () => void; + +const policy = trustedTypes.createPolicy("policy"); + +document.body.innerHTML = "foo"; +document.body.innerHTML = policy.createHTML("foo"); + +declare const position: GeolocationPosition; +assertNotAssignable()(position)(); + +const html: string = document.body.innerHTML; From 83c077a54689b057a4403a7e65966865447baab1 Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Sat, 19 Jul 2025 20:33:05 +0200 Subject: [PATCH 3/3] Update trusted-types.ts --- unittests/files/trusted-types.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/unittests/files/trusted-types.ts b/unittests/files/trusted-types.ts index d31ac9632..e929596f1 100644 --- a/unittests/files/trusted-types.ts +++ b/unittests/files/trusted-types.ts @@ -1,6 +1,7 @@ -declare const assertNotAssignable: () => ( +declare const assertNotAssignable: ( _x: T1, -) => T1 extends T + _y: T2, +) => T2 extends T1 ? { error: "Right side should not be assignable to left side" } : () => void; @@ -10,6 +11,6 @@ document.body.innerHTML = "foo"; document.body.innerHTML = policy.createHTML("foo"); declare const position: GeolocationPosition; -assertNotAssignable()(position)(); +assertNotAssignable(document.head.innerHTML, position)(); const html: string = document.body.innerHTML;