diff --git a/baselines/dom.generated.d.ts b/baselines/dom.generated.d.ts index e56291e41..b41875ace 100644 --- a/baselines/dom.generated.d.ts +++ b/baselines/dom.generated.d.ts @@ -1759,6 +1759,12 @@ interface TransitionEventInit extends EventInit { pseudoElement?: string; } +interface TrustedTypePolicyOptions { + createHTML?: CreateHTMLCallback | null; + createScript?: CreateScriptCallback | null; + createScriptURL?: CreateScriptURLCallback | null; +} + interface UIEventInit extends EventInit { detail?: number; view?: Window | null; @@ -3556,13 +3562,13 @@ interface ChildNode extends Node { * * Throws a "HierarchyRequestError" DOMException if the constraints of the node tree are violated. */ - after(...nodes: (Node | string)[]): void; + after(...nodes: (Node | string | TrustedScript)[]): void; /** * Inserts nodes just before node, while replacing strings in nodes with equivalent Text nodes. * * Throws a "HierarchyRequestError" DOMException if the constraints of the node tree are violated. */ - before(...nodes: (Node | string)[]): void; + before(...nodes: (Node | string | TrustedScript)[]): void; /** Removes node. */ remove(): void; /** @@ -3570,7 +3576,7 @@ interface ChildNode extends Node { * * Throws a "HierarchyRequestError" DOMException if the constraints of the node tree are violated. */ - replaceWith(...nodes: (Node | string)[]): void; + replaceWith(...nodes: (Node | string | TrustedScript)[]): void; } /** @deprecated */ @@ -3954,7 +3960,7 @@ interface DOMParser { * * Values other than the above for type will cause a TypeError exception to be thrown. */ - parseFromString(string: string, type: DOMParserSupportedType): Document; + parseFromString(string: string | TrustedHTML, type: DOMParserSupportedType): Document; } declare var DOMParser: { @@ -4574,7 +4580,7 @@ interface Document extends Node, DocumentAndElementEventHandlers, DocumentOrShad * @param value Value to assign. * @deprecated */ - execCommand(commandId: string, showUI?: boolean, value?: string): boolean; + execCommand(commandId: string, showUI?: boolean, value?: string | TrustedHTML): boolean; /** Stops document's fullscreen element from being displayed fullscreen and resolves promise when done. */ exitFullscreen(): Promise; exitPictureInPicture(): Promise; @@ -4665,11 +4671,13 @@ interface Document extends Node, DocumentAndElementEventHandlers, DocumentOrShad * Writes one or more HTML expressions to a document in the specified window. * @param content Specifies the text and HTML tags to write. */ + write(text: TrustedHTML): void; write(...text: string[]): void; /** * Writes one or more HTML expressions, followed by a carriage return, to a document in the specified window. * @param content The text and HTML tags to write. */ + writeln(text: TrustedHTML): void; writeln(...text: string[]): void; addEventListener(type: K, listener: (this: Document, ev: DocumentEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void; @@ -4850,7 +4858,8 @@ interface Element extends Node, ARIAMixin, Animatable, ChildNode, InnerHTML, Non readonly namespaceURI: string | null; onfullscreenchange: ((this: Element, ev: Event) => any) | null; onfullscreenerror: ((this: Element, ev: Event) => any) | null; - outerHTML: string; + get outerHTML(): string; + set outerHTML(outerHTML: string | TrustedHTML); readonly ownerDocument: Document; readonly part: DOMTokenList; /** Returns the namespace prefix. */ @@ -4897,7 +4906,7 @@ interface Element extends Node, ARIAMixin, Animatable, ChildNode, InnerHTML, Non hasAttributes(): boolean; hasPointerCapture(pointerId: number): boolean; insertAdjacentElement(where: InsertPosition, element: Element): Element | null; - insertAdjacentHTML(position: InsertPosition, text: string): void; + insertAdjacentHTML(position: InsertPosition, text: string | TrustedHTML): void; insertAdjacentText(where: InsertPosition, data: string): void; /** Returns true if matching selectors against element's root yields element, and false otherwise. */ matches(selectors: string): boolean; @@ -6338,7 +6347,8 @@ interface HTMLElement extends Element, DocumentAndElementEventHandlers, ElementC draggable: boolean; hidden: boolean; inert: boolean; - innerText: string; + get innerText(): string; + set innerText(innerText: string | TrustedScript); lang: string; readonly offsetHeight: number; readonly offsetLeft: number; @@ -6374,7 +6384,8 @@ interface HTMLEmbedElement extends HTMLElement { */ name: string; /** Sets or retrieves a URL to be loaded by the object. */ - src: string; + get src(): string; + set src(src: string | TrustedScriptURL); type: string; /** Sets or retrieves the width of the object. */ width: string; @@ -6799,7 +6810,8 @@ interface HTMLIFrameElement extends HTMLElement { /** Sets or retrieves a URL to be loaded by the object. */ src: string; /** Sets or retrives the content of the page that is to contain. */ - srcdoc: string; + get srcdoc(): string; + set srcdoc(srcdoc: string | TrustedHTML); /** Sets or retrieves the width of the object. */ width: string; getSVGDocument(): Document | null; @@ -7398,7 +7410,8 @@ interface HTMLObjectElement extends HTMLElement { * Sets or retrieves the URL of the component. * @deprecated */ - codeBase: string; + get codeBase(): string; + set codeBase(codeBase: string | TrustedHTML); /** * Sets or retrieves the Internet media type for the code associated with the object. * @deprecated @@ -7408,7 +7421,8 @@ interface HTMLObjectElement extends HTMLElement { readonly contentDocument: Document | null; readonly contentWindow: WindowProxy | null; /** Sets or retrieves the URL that references the data of the object. */ - data: string; + get data(): string; + set data(data: string | TrustedHTML); /** @deprecated */ declare: boolean; /** Retrieves a reference to the form that the object is embedded in. */ @@ -7724,9 +7738,11 @@ interface HTMLScriptElement extends HTMLElement { noModule: boolean; referrerPolicy: string; /** Retrieves the URL to an external file that contains the source code or data. */ - src: string; + get src(): string; + set src(src: string | TrustedScriptURL); /** Retrieves or sets the text of the object as a string. */ - text: string; + get text(): string; + set text(text: string | TrustedScript); /** Sets or retrieves the MIME type for the associated scripting engine. */ type: string; addEventListener(type: K, listener: (this: HTMLScriptElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; @@ -8904,7 +8920,8 @@ declare var ImageData: { }; interface InnerHTML { - innerHTML: string; + get innerHTML(): string; + set innerHTML(innerHTML: string | TrustedHTML); } interface InputDeviceInfo extends MediaDeviceInfo { @@ -9931,7 +9948,8 @@ interface Node extends EventTarget { readonly parentNode: ParentNode | null; /** Returns the previous sibling. */ readonly previousSibling: ChildNode | null; - textContent: string | null; + get textContent(): string | null; + set textContent(textContent: string | TrustedScript | null); appendChild(node: T): T; /** Returns a copy of node. If deep is true, the copy also includes the node's descendants. */ cloneNode(deep?: boolean): Node; @@ -10284,13 +10302,13 @@ interface ParentNode extends Node { * * Throws a "HierarchyRequestError" DOMException if the constraints of the node tree are violated. */ - append(...nodes: (Node | string)[]): void; + append(...nodes: (Node | string | TrustedScript)[]): void; /** * Inserts nodes before the first child of node, while replacing strings in nodes with equivalent Text nodes. * * Throws a "HierarchyRequestError" DOMException if the constraints of the node tree are violated. */ - prepend(...nodes: (Node | string)[]): void; + prepend(...nodes: (Node | string | TrustedScript)[]): void; /** Returns the first element that is a descendant of node that matches selectors. */ querySelector(selectors: K): HTMLElementTagNameMap[K] | null; querySelector(selectors: K): SVGElementTagNameMap[K] | null; @@ -10304,7 +10322,7 @@ interface ParentNode extends Node { * * Throws a "HierarchyRequestError" DOMException if the constraints of the node tree are violated. */ - replaceChildren(...nodes: (Node | string)[]): void; + replaceChildren(...nodes: (Node | string | TrustedScript)[]): void; } /** This Canvas 2D API interface is used to declare a path that can then be used on a CanvasRenderingContext2D object. The path methods of the CanvasRenderingContext2D interface are also present on this interface, which gives you the convenience of being able to retain and replay your path whenever desired. */ @@ -11307,7 +11325,7 @@ interface Range extends AbstractRange { compareBoundaryPoints(how: number, sourceRange: Range): number; /** Returns −1 if the point is before the range, 0 if the point is in the range, and 1 if the point is after the range. */ comparePoint(node: Node, offset: number): number; - createContextualFragment(fragment: string): DocumentFragment; + createContextualFragment(fragment: string | TrustedHTML): DocumentFragment; deleteContents(): void; detach(): void; extractContents(): DocumentFragment; @@ -11694,7 +11712,8 @@ declare var SVGAnimatedRect: { /** The SVGAnimatedString interface represents string attributes which can be animated from each SVG declaration. You need to create SVG attribute before doing anything else, everything should be declared inside this. */ interface SVGAnimatedString { readonly animVal: string; - baseVal: string; + get baseVal(): string; + set baseVal(baseVal: string | TrustedScriptURL); } declare var SVGAnimatedString: { @@ -13378,7 +13397,7 @@ interface ServiceWorkerContainer extends EventTarget { readonly ready: Promise; getRegistration(clientURL?: string | URL): Promise; getRegistrations(): Promise>; - register(scriptURL: string | URL, options?: RegistrationOptions): Promise; + register(scriptURL: string | URL | TrustedScriptURL, options?: RegistrationOptions): Promise; startMessages(): void; addEventListener(type: K, listener: (this: ServiceWorkerContainer, ev: ServiceWorkerContainerEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void; @@ -13456,7 +13475,7 @@ interface SharedWorker extends EventTarget, AbstractWorker { declare var SharedWorker: { prototype: SharedWorker; - new(scriptURL: string | URL, options?: string | WorkerOptions): SharedWorker; + new(scriptURL: string | URL | TrustedScriptURL, options?: string | WorkerOptions): SharedWorker; }; interface Slottable { @@ -14190,6 +14209,66 @@ declare var TreeWalker: { new(): TreeWalker; }; +interface TrustedHTML { + toJSON(): string; + toString(): string; +} + +declare var TrustedHTML: { + prototype: TrustedHTML; + fromLiteral(templateStringsArray: any): TrustedHTML; + toString(): string; +}; + +interface TrustedScript { + toJSON(): string; + toString(): string; +} + +declare var TrustedScript: { + prototype: TrustedScript; + fromLiteral(templateStringsArray: any): TrustedScript; + toString(): string; +}; + +interface TrustedScriptURL { + toJSON(): string; + toString(): string; +} + +declare var TrustedScriptURL: { + prototype: TrustedScriptURL; + fromLiteral(templateStringsArray: any): TrustedScriptURL; + toString(): string; +}; + +interface TrustedTypePolicy { + readonly name: string; + createHTML(input: string, ...arguments: any[]): TrustedHTML; + createScript(input: string, ...arguments: any[]): TrustedScript; + createScriptURL(input: string, ...arguments: any[]): TrustedScriptURL; +} + +declare var TrustedTypePolicy: { + prototype: TrustedTypePolicy; +}; + +interface TrustedTypePolicyFactory { + readonly defaultPolicy: TrustedTypePolicy | null; + readonly emptyHTML: TrustedHTML; + readonly emptyScript: TrustedScript; + createPolicy(policyName: string, policyOptions?: TrustedTypePolicyOptions): TrustedTypePolicy; + getAttributeType(tagName: string, attribute: string, elementNs?: string, attrNs?: string): string | null; + getPropertyType(tagName: string, property: string, elementNs?: string): string | null; + isHTML(value: any): boolean; + isScript(value: any): boolean; + isScriptURL(value: any): boolean; +} + +declare var TrustedTypePolicyFactory: { + prototype: TrustedTypePolicyFactory; +}; + /** Simple user interface events. */ interface UIEvent extends Event { readonly detail: number; @@ -16668,6 +16747,7 @@ interface WindowOrWorkerGlobalScope { readonly isSecureContext: boolean; readonly origin: string; readonly performance: Performance; + readonly trustedTypes: TrustedTypePolicyFactory; atob(data: string): string; btoa(data: string): string; clearInterval(id: number | undefined): void; @@ -16708,7 +16788,7 @@ interface Worker extends EventTarget, AbstractWorker { declare var Worker: { prototype: Worker; - new(scriptURL: string | URL, options?: WorkerOptions): Worker; + new(scriptURL: string | URL | TrustedScriptURL, options?: WorkerOptions): Worker; }; /** Available only in secure contexts. */ @@ -17185,6 +17265,18 @@ interface BlobCallback { (blob: Blob | null): void; } +interface CreateHTMLCallback { + (input: string, ...arguments: any[]): string; +} + +interface CreateScriptCallback { + (input: string, ...arguments: any[]): string; +} + +interface CreateScriptURLCallback { + (input: string, ...arguments: any[]): string; +} + interface CustomElementConstructor { new (...params: any[]): HTMLElement; } @@ -17976,6 +18068,7 @@ declare var indexedDB: IDBFactory; declare var isSecureContext: boolean; declare var origin: string; declare var performance: Performance; +declare var trustedTypes: TrustedTypePolicyFactory; declare function atob(data: string): string; declare function btoa(data: string): string; declare function clearInterval(id: number | undefined): void; @@ -18047,8 +18140,9 @@ type ReadableStreamReader = ReadableStreamDefaultReader; type RenderingContext = CanvasRenderingContext2D | ImageBitmapRenderingContext | WebGLRenderingContext | WebGL2RenderingContext; type RequestInfo = Request | string; type TexImageSource = ImageBitmap | ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement; -type TimerHandler = string | Function; +type TimerHandler = string | Function | TrustedScript; type Transferable = ArrayBuffer | MessagePort | ImageBitmap; +type TrustedType = TrustedHTML | TrustedScript | TrustedScriptURL; type Uint32List = Uint32Array | GLuint[]; type UvmEntries = UvmEntry[]; type UvmEntry = number[]; diff --git a/baselines/serviceworker.generated.d.ts b/baselines/serviceworker.generated.d.ts index 6c489a793..e7d66dc74 100644 --- a/baselines/serviceworker.generated.d.ts +++ b/baselines/serviceworker.generated.d.ts @@ -622,6 +622,12 @@ interface Transformer { writableType?: undefined; } +interface TrustedTypePolicyOptions { + createHTML?: CreateHTMLCallback | null; + createScript?: CreateScriptCallback | null; + createScriptURL?: CreateScriptURLCallback | null; +} + interface UnderlyingSink { abort?: UnderlyingSinkAbortCallback; close?: UnderlyingSinkCloseCallback; @@ -2736,7 +2742,7 @@ interface ServiceWorkerContainer extends EventTarget { readonly ready: Promise; getRegistration(clientURL?: string | URL): Promise; getRegistrations(): Promise>; - register(scriptURL: string | URL, options?: RegistrationOptions): Promise; + register(scriptURL: string | URL | TrustedScriptURL, options?: RegistrationOptions): Promise; startMessages(): void; addEventListener(type: K, listener: (this: ServiceWorkerContainer, ev: ServiceWorkerContainerEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void; @@ -2972,6 +2978,66 @@ declare var TransformStreamDefaultController: { new(): TransformStreamDefaultController; }; +interface TrustedHTML { + toJSON(): string; + toString(): string; +} + +declare var TrustedHTML: { + prototype: TrustedHTML; + fromLiteral(templateStringsArray: any): TrustedHTML; + toString(): string; +}; + +interface TrustedScript { + toJSON(): string; + toString(): string; +} + +declare var TrustedScript: { + prototype: TrustedScript; + fromLiteral(templateStringsArray: any): TrustedScript; + toString(): string; +}; + +interface TrustedScriptURL { + toJSON(): string; + toString(): string; +} + +declare var TrustedScriptURL: { + prototype: TrustedScriptURL; + fromLiteral(templateStringsArray: any): TrustedScriptURL; + toString(): string; +}; + +interface TrustedTypePolicy { + readonly name: string; + createHTML(input: string, ...arguments: any[]): TrustedHTML; + createScript(input: string, ...arguments: any[]): TrustedScript; + createScriptURL(input: string, ...arguments: any[]): TrustedScriptURL; +} + +declare var TrustedTypePolicy: { + prototype: TrustedTypePolicy; +}; + +interface TrustedTypePolicyFactory { + readonly defaultPolicy: TrustedTypePolicy | null; + readonly emptyHTML: TrustedHTML; + readonly emptyScript: TrustedScript; + createPolicy(policyName: string, policyOptions?: TrustedTypePolicyOptions): TrustedTypePolicy; + getAttributeType(tagName: string, attribute: string, elementNs?: string, attrNs?: string): string | null; + getPropertyType(tagName: string, property: string, elementNs?: string): string | null; + isHTML(value: any): boolean; + isScript(value: any): boolean; + isScriptURL(value: any): boolean; +} + +declare var TrustedTypePolicyFactory: { + prototype: TrustedTypePolicyFactory; +}; + /** The URL interface represents an object providing static methods used for creating object URLs. */ interface URL { hash: string; @@ -5114,6 +5180,7 @@ interface WindowOrWorkerGlobalScope { readonly isSecureContext: boolean; readonly origin: string; readonly performance: Performance; + readonly trustedTypes: TrustedTypePolicyFactory; atob(data: string): string; btoa(data: string): string; clearInterval(id: number | undefined): void; @@ -5152,7 +5219,7 @@ interface WorkerGlobalScope extends EventTarget, FontFaceSource, WindowOrWorkerG /** Returns workerGlobal. */ readonly self: WorkerGlobalScope & typeof globalThis; /** Fetches each URL in urls, executes them one-by-one in the order they are passed, and then returns (or throws if something went amiss). */ - importScripts(...urls: (string | URL)[]): void; + importScripts(...urls: (string | URL | TrustedScriptURL)[]): 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; @@ -5387,6 +5454,18 @@ declare namespace WebAssembly { function validate(bytes: BufferSource): boolean; } +interface CreateHTMLCallback { + (input: string, ...arguments: any[]): string; +} + +interface CreateScriptCallback { + (input: string, ...arguments: any[]): string; +} + +interface CreateScriptURLCallback { + (input: string, ...arguments: any[]): string; +} + interface LockGrantedCallback { (lock: Lock | null): any; } @@ -5474,7 +5553,7 @@ declare var onunhandledrejection: ((this: ServiceWorkerGlobalScope, ev: PromiseR /** Returns workerGlobal. */ declare var self: WorkerGlobalScope & typeof globalThis; /** Fetches each URL in urls, executes them one-by-one in the order they are passed, and then returns (or throws if something went amiss). */ -declare function importScripts(...urls: (string | URL)[]): void; +declare function importScripts(...urls: (string | URL | TrustedScriptURL)[]): void; /** Dispatches a synthetic event event to target and returns true if either event's cancelable attribute value is false or its preventDefault() method was not invoked, and false otherwise. */ declare function dispatchEvent(event: Event): boolean; declare var fonts: FontFaceSet; @@ -5486,6 +5565,7 @@ declare var indexedDB: IDBFactory; declare var isSecureContext: boolean; declare var origin: string; declare var performance: Performance; +declare var trustedTypes: TrustedTypePolicyFactory; declare function atob(data: string): string; declare function btoa(data: string): string; declare function clearInterval(id: number | undefined): void; @@ -5541,8 +5621,9 @@ type ReadableStreamReadResult = ReadableStreamReadValueResult | ReadableSt type ReadableStreamReader = ReadableStreamDefaultReader; type RequestInfo = Request | string; type TexImageSource = ImageBitmap | ImageData | OffscreenCanvas; -type TimerHandler = string | Function; +type TimerHandler = string | Function | TrustedScript; type Transferable = ArrayBuffer | MessagePort | ImageBitmap; +type TrustedType = TrustedHTML | TrustedScript | TrustedScriptURL; type Uint32List = Uint32Array | GLuint[]; type VibratePattern = number | number[]; type XMLHttpRequestBodyInit = Blob | BufferSource | FormData | URLSearchParams | string; diff --git a/baselines/sharedworker.generated.d.ts b/baselines/sharedworker.generated.d.ts index f76da990d..a31a5fc55 100644 --- a/baselines/sharedworker.generated.d.ts +++ b/baselines/sharedworker.generated.d.ts @@ -588,6 +588,12 @@ interface Transformer { writableType?: undefined; } +interface TrustedTypePolicyOptions { + createHTML?: CreateHTMLCallback | null; + createScript?: CreateScriptCallback | null; + createScriptURL?: CreateScriptURLCallback | null; +} + interface UnderlyingSink { abort?: UnderlyingSinkAbortCallback; close?: UnderlyingSinkCloseCallback; @@ -2615,7 +2621,7 @@ interface ServiceWorkerContainer extends EventTarget { readonly ready: Promise; getRegistration(clientURL?: string | URL): Promise; getRegistrations(): Promise>; - register(scriptURL: string | URL, options?: RegistrationOptions): Promise; + register(scriptURL: string | URL | TrustedScriptURL, options?: RegistrationOptions): Promise; startMessages(): void; addEventListener(type: K, listener: (this: ServiceWorkerContainer, ev: ServiceWorkerContainerEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void; @@ -2836,6 +2842,66 @@ declare var TransformStreamDefaultController: { new(): TransformStreamDefaultController; }; +interface TrustedHTML { + toJSON(): string; + toString(): string; +} + +declare var TrustedHTML: { + prototype: TrustedHTML; + fromLiteral(templateStringsArray: any): TrustedHTML; + toString(): string; +}; + +interface TrustedScript { + toJSON(): string; + toString(): string; +} + +declare var TrustedScript: { + prototype: TrustedScript; + fromLiteral(templateStringsArray: any): TrustedScript; + toString(): string; +}; + +interface TrustedScriptURL { + toJSON(): string; + toString(): string; +} + +declare var TrustedScriptURL: { + prototype: TrustedScriptURL; + fromLiteral(templateStringsArray: any): TrustedScriptURL; + toString(): string; +}; + +interface TrustedTypePolicy { + readonly name: string; + createHTML(input: string, ...arguments: any[]): TrustedHTML; + createScript(input: string, ...arguments: any[]): TrustedScript; + createScriptURL(input: string, ...arguments: any[]): TrustedScriptURL; +} + +declare var TrustedTypePolicy: { + prototype: TrustedTypePolicy; +}; + +interface TrustedTypePolicyFactory { + readonly defaultPolicy: TrustedTypePolicy | null; + readonly emptyHTML: TrustedHTML; + readonly emptyScript: TrustedScript; + createPolicy(policyName: string, policyOptions?: TrustedTypePolicyOptions): TrustedTypePolicy; + getAttributeType(tagName: string, attribute: string, elementNs?: string, attrNs?: string): string | null; + getPropertyType(tagName: string, property: string, elementNs?: string): string | null; + isHTML(value: any): boolean; + isScript(value: any): boolean; + isScriptURL(value: any): boolean; +} + +declare var TrustedTypePolicyFactory: { + prototype: TrustedTypePolicyFactory; +}; + /** The URL interface represents an object providing static methods used for creating object URLs. */ interface URL { hash: string; @@ -4967,6 +5033,7 @@ interface WindowOrWorkerGlobalScope { readonly isSecureContext: boolean; readonly origin: string; readonly performance: Performance; + readonly trustedTypes: TrustedTypePolicyFactory; atob(data: string): string; btoa(data: string): string; clearInterval(id: number | undefined): void; @@ -5003,7 +5070,7 @@ interface Worker extends EventTarget, AbstractWorker { declare var Worker: { prototype: Worker; - new(scriptURL: string | URL, options?: WorkerOptions): Worker; + new(scriptURL: string | URL | TrustedScriptURL, options?: WorkerOptions): Worker; }; interface WorkerGlobalScopeEventMap { @@ -5030,7 +5097,7 @@ interface WorkerGlobalScope extends EventTarget, FontFaceSource, WindowOrWorkerG /** Returns workerGlobal. */ readonly self: WorkerGlobalScope & typeof globalThis; /** Fetches each URL in urls, executes them one-by-one in the order they are passed, and then returns (or throws if something went amiss). */ - importScripts(...urls: (string | URL)[]): void; + importScripts(...urls: (string | URL | TrustedScriptURL)[]): 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; @@ -5408,6 +5475,18 @@ declare namespace WebAssembly { function validate(bytes: BufferSource): boolean; } +interface CreateHTMLCallback { + (input: string, ...arguments: any[]): string; +} + +interface CreateScriptCallback { + (input: string, ...arguments: any[]): string; +} + +interface CreateScriptURLCallback { + (input: string, ...arguments: any[]): string; +} + interface LockGrantedCallback { (lock: Lock | null): any; } @@ -5488,7 +5567,7 @@ declare var onunhandledrejection: ((this: SharedWorkerGlobalScope, ev: PromiseRe /** Returns workerGlobal. */ declare var self: WorkerGlobalScope & typeof globalThis; /** Fetches each URL in urls, executes them one-by-one in the order they are passed, and then returns (or throws if something went amiss). */ -declare function importScripts(...urls: (string | URL)[]): void; +declare function importScripts(...urls: (string | URL | TrustedScriptURL)[]): void; /** Dispatches a synthetic event event to target and returns true if either event's cancelable attribute value is false or its preventDefault() method was not invoked, and false otherwise. */ declare function dispatchEvent(event: Event): boolean; declare var fonts: FontFaceSet; @@ -5500,6 +5579,7 @@ declare var indexedDB: IDBFactory; declare var isSecureContext: boolean; declare var origin: string; declare var performance: Performance; +declare var trustedTypes: TrustedTypePolicyFactory; declare function atob(data: string): string; declare function btoa(data: string): string; declare function clearInterval(id: number | undefined): void; @@ -5554,8 +5634,9 @@ type ReadableStreamReadResult = ReadableStreamReadValueResult | ReadableSt type ReadableStreamReader = ReadableStreamDefaultReader; type RequestInfo = Request | string; type TexImageSource = ImageBitmap | ImageData | OffscreenCanvas; -type TimerHandler = string | Function; +type TimerHandler = string | Function | TrustedScript; type Transferable = ArrayBuffer | MessagePort | ImageBitmap; +type TrustedType = TrustedHTML | TrustedScript | TrustedScriptURL; type Uint32List = Uint32Array | GLuint[]; type VibratePattern = number | number[]; type XMLHttpRequestBodyInit = Blob | BufferSource | FormData | URLSearchParams | string; diff --git a/baselines/webworker.generated.d.ts b/baselines/webworker.generated.d.ts index f9a5b1e88..d486a0c4d 100644 --- a/baselines/webworker.generated.d.ts +++ b/baselines/webworker.generated.d.ts @@ -638,6 +638,12 @@ interface Transformer { writableType?: undefined; } +interface TrustedTypePolicyOptions { + createHTML?: CreateHTMLCallback | null; + createScript?: CreateScriptCallback | null; + createScriptURL?: CreateScriptURLCallback | null; +} + interface UnderlyingSink { abort?: UnderlyingSinkAbortCallback; close?: UnderlyingSinkCloseCallback; @@ -2834,7 +2840,7 @@ interface ServiceWorkerContainer extends EventTarget { readonly ready: Promise; getRegistration(clientURL?: string | URL): Promise; getRegistrations(): Promise>; - register(scriptURL: string | URL, options?: RegistrationOptions): Promise; + register(scriptURL: string | URL | TrustedScriptURL, options?: RegistrationOptions): Promise; startMessages(): void; addEventListener(type: K, listener: (this: ServiceWorkerContainer, ev: ServiceWorkerContainerEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void; @@ -3091,6 +3097,66 @@ declare var TransformStreamDefaultController: { new(): TransformStreamDefaultController; }; +interface TrustedHTML { + toJSON(): string; + toString(): string; +} + +declare var TrustedHTML: { + prototype: TrustedHTML; + fromLiteral(templateStringsArray: any): TrustedHTML; + toString(): string; +}; + +interface TrustedScript { + toJSON(): string; + toString(): string; +} + +declare var TrustedScript: { + prototype: TrustedScript; + fromLiteral(templateStringsArray: any): TrustedScript; + toString(): string; +}; + +interface TrustedScriptURL { + toJSON(): string; + toString(): string; +} + +declare var TrustedScriptURL: { + prototype: TrustedScriptURL; + fromLiteral(templateStringsArray: any): TrustedScriptURL; + toString(): string; +}; + +interface TrustedTypePolicy { + readonly name: string; + createHTML(input: string, ...arguments: any[]): TrustedHTML; + createScript(input: string, ...arguments: any[]): TrustedScript; + createScriptURL(input: string, ...arguments: any[]): TrustedScriptURL; +} + +declare var TrustedTypePolicy: { + prototype: TrustedTypePolicy; +}; + +interface TrustedTypePolicyFactory { + readonly defaultPolicy: TrustedTypePolicy | null; + readonly emptyHTML: TrustedHTML; + readonly emptyScript: TrustedScript; + createPolicy(policyName: string, policyOptions?: TrustedTypePolicyOptions): TrustedTypePolicy; + getAttributeType(tagName: string, attribute: string, elementNs?: string, attrNs?: string): string | null; + getPropertyType(tagName: string, property: string, elementNs?: string): string | null; + isHTML(value: any): boolean; + isScript(value: any): boolean; + isScriptURL(value: any): boolean; +} + +declare var TrustedTypePolicyFactory: { + prototype: TrustedTypePolicyFactory; +}; + /** The URL interface represents an object providing static methods used for creating object URLs. */ interface URL { hash: string; @@ -5248,6 +5314,7 @@ interface WindowOrWorkerGlobalScope { readonly isSecureContext: boolean; readonly origin: string; readonly performance: Performance; + readonly trustedTypes: TrustedTypePolicyFactory; atob(data: string): string; btoa(data: string): string; clearInterval(id: number | undefined): void; @@ -5284,7 +5351,7 @@ interface Worker extends EventTarget, AbstractWorker { declare var Worker: { prototype: Worker; - new(scriptURL: string | URL, options?: WorkerOptions): Worker; + new(scriptURL: string | URL | TrustedScriptURL, options?: WorkerOptions): Worker; }; interface WorkerGlobalScopeEventMap { @@ -5311,7 +5378,7 @@ interface WorkerGlobalScope extends EventTarget, FontFaceSource, WindowOrWorkerG /** Returns workerGlobal. */ readonly self: WorkerGlobalScope & typeof globalThis; /** Fetches each URL in urls, executes them one-by-one in the order they are passed, and then returns (or throws if something went amiss). */ - importScripts(...urls: (string | URL)[]): void; + importScripts(...urls: (string | URL | TrustedScriptURL)[]): 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; @@ -5689,6 +5756,18 @@ declare namespace WebAssembly { function validate(bytes: BufferSource): boolean; } +interface CreateHTMLCallback { + (input: string, ...arguments: any[]): string; +} + +interface CreateScriptCallback { + (input: string, ...arguments: any[]): string; +} + +interface CreateScriptURLCallback { + (input: string, ...arguments: any[]): string; +} + interface FrameRequestCallback { (time: DOMHighResTimeStamp): void; } @@ -5777,7 +5856,7 @@ declare var onunhandledrejection: ((this: DedicatedWorkerGlobalScope, ev: Promis /** Returns workerGlobal. */ declare var self: WorkerGlobalScope & typeof globalThis; /** Fetches each URL in urls, executes them one-by-one in the order they are passed, and then returns (or throws if something went amiss). */ -declare function importScripts(...urls: (string | URL)[]): void; +declare function importScripts(...urls: (string | URL | TrustedScriptURL)[]): void; /** Dispatches a synthetic event event to target and returns true if either event's cancelable attribute value is false or its preventDefault() method was not invoked, and false otherwise. */ declare function dispatchEvent(event: Event): boolean; declare var fonts: FontFaceSet; @@ -5789,6 +5868,7 @@ declare var indexedDB: IDBFactory; declare var isSecureContext: boolean; declare var origin: string; declare var performance: Performance; +declare var trustedTypes: TrustedTypePolicyFactory; declare function atob(data: string): string; declare function btoa(data: string): string; declare function clearInterval(id: number | undefined): void; @@ -5846,8 +5926,9 @@ type ReadableStreamReadResult = ReadableStreamReadValueResult | ReadableSt type ReadableStreamReader = ReadableStreamDefaultReader; type RequestInfo = Request | string; type TexImageSource = ImageBitmap | ImageData | OffscreenCanvas; -type TimerHandler = string | Function; +type TimerHandler = string | Function | TrustedScript; type Transferable = ArrayBuffer | MessagePort | ImageBitmap; +type TrustedType = TrustedHTML | TrustedScript | TrustedScriptURL; type Uint32List = Uint32Array | GLuint[]; type VibratePattern = number | number[]; type XMLHttpRequestBodyInit = Blob | BufferSource | FormData | URLSearchParams | string; diff --git a/inputfiles/knownTypes.json b/inputfiles/knownTypes.json index c85fadef5..469b13b16 100644 --- a/inputfiles/knownTypes.json +++ b/inputfiles/knownTypes.json @@ -50,6 +50,7 @@ "RTCStatsType", "RTCTransportStats", "Transferable", + "TrustedType", "VideoFacingModeEnum" ], "Worker": [ @@ -80,7 +81,8 @@ "RsaKeyGenParams", "RsaOaepParams", "RsaPssParams", - "Transferable" + "Transferable", + "TrustedType" ], "Worklet": [ "EventListenerOrEventListenerObject", diff --git a/inputfiles/overridingTypes.jsonc b/inputfiles/overridingTypes.jsonc index cda89c29b..dd7f8141f 100644 --- a/inputfiles/overridingTypes.jsonc +++ b/inputfiles/overridingTypes.jsonc @@ -2,10 +2,96 @@ "mixins": { "mixin": { "ChildNode": { - "extends": "Node" + "extends": "Node", + "methods": { + "method": { + "after": { + "name": "after", + "signature": { + "0": { + "param": [ + { + "name": "nodes", + "overrideType": "Node | string | TrustedScript" + } + ] + } + } + }, + "before": { + "name": "before", + "signature": { + "0": { + "param": [ + { + "name": "nodes", + "overrideType": "Node | string | TrustedScript" + } + ] + } + } + }, + "replaceWith": { + "name": "replaceWith", + "signature": { + "0": { + "param": [ + { + "name": "nodes", + "overrideType": "Node | string | TrustedScript" + } + ] + } + } + } + } + } }, "ParentNode": { - "extends": "Node" + "extends": "Node", + "methods": { + "method": { + "append": { + "name": "append", + "signature": { + "0": { + "param": [ + { + "name": "nodes", + "overrideType": "Node | string | TrustedScript" + } + ] + } + } + }, + "prepend": { + "name": "prepend", + "signature": { + "0": { + "param": [ + { + "name": "nodes", + "overrideType": "Node | string | TrustedScript" + } + ] + } + } + }, + "replaceChildren": { + "name": "replaceChildren", + "signature": { + "0": { + "param": [ + { + "name": "nodes", + "overrideType": "Node | string | TrustedScript" + } + ] + } + } + } + } + } }, "Animatable": { "methods": { @@ -219,6 +305,17 @@ } } }, + "InnerHTML": { + "name": "InnerHTML", + "properties": { + "property": { + "innerHTML": { + "name": "innerHTML", + "setterType": "string | TrustedHTML" + } + } + } + }, "WindowOrWorkerGlobalScope": { "methods": { "method": { @@ -447,6 +544,9 @@ // Revisit when this get browser supports. "overrideType": "boolean", "nullable": false + }, + "innerText": { + "setterType": "string | TrustedScript" } } } @@ -660,6 +760,31 @@ "overrideType": "NodeListOf" } } + }, + "execCommand": { + "name": "execCommand", + "signature": { + "0": { + "param": [ + { + "name": "value", + "overrideType": "string | TrustedHTML" + } + ] + } + } + }, + "write": { + "name": "write", + "additionalSignatures": [ + "write(text: TrustedHTML): void" + ] + }, + "writeln": { + "name": "writeln", + "additionalSignatures": [ + "writeln(text: TrustedHTML): void" + ] } } }, @@ -839,6 +964,9 @@ }, "previousSibling": { "overrideType": "ChildNode" + }, + "textContent": { + "setterType": "string | TrustedScript | null" } } } @@ -1288,6 +1416,27 @@ "overrideType": "HTMLCollectionOf" } } + }, + "insertAdjacentHTML": { + "name": "insertAdjacentHTML", + "signature": { + "0": { + "param": [ + { + "name": "text", + "overrideType": "string | TrustedHTML" + } + ] + } + } + } + } + }, + "properties": { + "property": { + "outerHTML": { + "name": "outerHTML", + "setterType": "string | TrustedHTML" } } } @@ -1748,6 +1897,18 @@ "overrideType": "Promise" } } + }, + "register": { + "signature": { + "0": { + "param": [ + { + "name": "scriptURL", + "overrideType": "string | URL | TrustedScriptURL" + } + ] + } + } } } }, @@ -2175,6 +2336,18 @@ "type": "MessageEvent" } ] + }, + "constructor": { + "signature": { + "0": { + "param": [ + { + "name": "scriptURL", + "overrideType": "string | URL | TrustedScriptURL" + } + ] + } + } } }, "Crypto": { @@ -2799,6 +2972,23 @@ "type": "ErrorEvent" } ] + }, + "methods": { + "method": { + "importScripts": { + "name": "importScripts", + "signature": { + "0": { + "param": [ + { + "name": "urls", + "overrideType": "string | URL | TrustedScriptURL" + } + ] + } + } + } + } } }, "Instance": { @@ -2916,6 +3106,145 @@ }, "SourceBufferList": { "exposed": "Window" + }, + "DOMParser": { + "name": "DOMParser", + "methods": { + "method": { + "parseFromString": { + "signature": { + "0": { + "param": [ + { + "name": "string", + "overrideType": "string | TrustedHTML" + } + ] + } + } + } + } + } + }, + "HTMLEmbedElement": { + "name": "HTMLEmbedElement", + "properties": { + "property": { + "src": { + "setterType": "string | TrustedScriptURL" + } + } + } + + }, + "HTMLIFrameElement": { + "name": "HTMLIFrameElement", + "properties": { + "property": { + "srcdoc": { + "setterType": "string | TrustedHTML" + } + } + } + }, + "HTMLObjectElement": { + "name": "HTMLObjectElement", + "properties": { + "property": { + "codeBase": { + "setterType": "string | TrustedHTML" + }, + "data": { + "setterType": "string | TrustedHTML" + } + } + } + }, + "HTMLScriptElement": { + "name": "HTMLScriptElement", + "properties": { + "property": { + "src": { + "setterType": "string | TrustedScriptURL" + }, + "text": { + "setterType": "string | TrustedScript" + } + } + } + }, + "Range": { + "name": "Range", + "methods": { + "method": { + "createContextualFragment": { + "signature": { + "0": { + "param": [ + { + "name": "fragment", + "overrideType": "string | TrustedHTML" + } + ] + } + } + } + } + } + }, + "SharedWorker": { + "constructor": { + "signature": { + "0": { + "param": [ + { + "name": "scriptURL", + "overrideType": "string | URL | TrustedScriptURL" + } + ] + } + } + } + }, + "SVGAnimatedString": { + "properties": { + "property": { + "baseVal": { + "name": "baseVal", + "setterType": "string | TrustedScriptURL" + } + } + } + }, + "TrustedHTML": { + "name": "TrustedHTML", + "constructor": { + "signature": [] + } + }, + "TrustedScript": { + "name": "TrustedScript", + "constructor": { + "signature": [] + } + }, + "TrustedScriptURL": { + "name": "TrustedScriptURL", + "constructor": { + "signature": [] + } + }, + "TrustedTypePolicy": { + "name": "TrustedTypePolicy", + "constructor": { + "signature": [] + } + }, + "TrustedTypePolicyFactory": { + "name": "TrustedTypePolicyFactory", + "constructor": { + "signature": [] + } } } }, @@ -3248,6 +3577,10 @@ "name": "T" } ] + }, + { + "name": "TimerHandler", + "overrideType": "string | Function | TrustedScript" } ] }, diff --git a/src/build/bcd/keep-alive.ts b/src/build/bcd/keep-alive.ts index 2d05d977e..aa4dda62d 100644 --- a/src/build/bcd/keep-alive.ts +++ b/src/build/bcd/keep-alive.ts @@ -51,6 +51,22 @@ export const forceKeepAlive: Record = { "onerror", ], KeyframeEffect: ["iterationComposite"], + TrustedHTML: ["fromLiteral", "toJSON"], + TrustedScript: ["fromLiteral", "toJSON"], + TrustedScriptURL: ["fromLiteral", "toJSON"], + TrustedTypePolicy: ["createHTML", "createScript", "createScriptURL", "name"], + TrustedTypePolicyFactory: [ + "createPolicy", + "defaultPolicy", + "emptyHTML", + "emptyScript", + "getAttributeType", + "getPropertyType", + "getTypeMapping", + "isHTML", + "isScript", + "isScriptURL", + ], WebGLRenderingContextBase: ["lineWidth"], WebGL2RenderingContextOverloads: [ // These are implemented in WebGLRenderingContext and WebGL2RenderingContext separately @@ -70,6 +86,7 @@ export const forceKeepAlive: Record = { "uniform4fv", "uniform4iv", ], + WindowOrWorkerGlobalScope: ["trustedTypes"], WorkerGlobalScope: ["onrejectionhandled", "onunhandledrejection"], XMLHttpRequestEventTarget: [ // BCD unexpectedly is removing valid event data diff --git a/src/build/emitter.ts b/src/build/emitter.ts index 7f03f545d..c1cd54b43 100644 --- a/src/build/emitter.ts +++ b/src/build/emitter.ts @@ -814,19 +814,26 @@ export function emitWebIdl( pType += " | undefined"; } const optionalModifier = !p.optional || prefix ? "" : "?"; - if (!prefix && !p.readonly && p.putForwards) { + if (!prefix && !p.readonly && (p.putForwards || p.setterType)) { printer.printLine(`get ${p.name}${optionalModifier}(): ${pType};`); - const forwardingProperty = - allInterfacesMap[pType].properties?.property[p.putForwards]; - if (!forwardingProperty) { - throw new Error("Couldn't find [PutForwards]"); + let setterType: string; + if (p.putForwards) { + const forwardingProperty = + allInterfacesMap[pType].properties?.property[p.putForwards]; + if (!forwardingProperty) { + throw new Error("Couldn't find [PutForwards]"); + } + setterType = `${convertDomTypeToTsType( + forwardingProperty + )} | ${pType}`; + } else { + setterType = p.setterType ?? "undefined"; } - const setterType = `${convertDomTypeToTsType( - forwardingProperty - )} | ${pType}`; printer.printLine( - `set ${p.name}${optionalModifier}(${p.putForwards}: ${setterType});` + `set ${p.name}${optionalModifier}(${ + p.putForwards ?? p.name + }: ${setterType});` ); } else { const readOnlyModifier = p.readonly && prefix === "" ? "readonly " : ""; diff --git a/src/build/types.d.ts b/src/build/types.d.ts index ab4b13df8..16eb7f8f8 100644 --- a/src/build/types.d.ts +++ b/src/build/types.d.ts @@ -59,6 +59,7 @@ export interface Property extends Typed { deprecated?: boolean; exposed?: string; secureContext?: boolean; + setterType?: string; } export interface Event {