From c8f1deeac92bf4c8b4f22ea1db74135e7aeea167 Mon Sep 17 00:00:00 2001 From: Tobias Smolka Date: Thu, 13 Jan 2022 18:16:37 +0100 Subject: [PATCH 1/7] Add Trusted Types APIs --- inputfiles/overridingTypes.jsonc | 42 ++++++++++++++++++++++++++++++++ src/build/bcd/keep-alive.ts | 17 +++++++++++++ 2 files changed, 59 insertions(+) diff --git a/inputfiles/overridingTypes.jsonc b/inputfiles/overridingTypes.jsonc index 01c8591df..1e709a27c 100644 --- a/inputfiles/overridingTypes.jsonc +++ b/inputfiles/overridingTypes.jsonc @@ -612,6 +612,18 @@ "overrideType": "NodeListOf" } } + }, + "write": { + "name": "write", + "additionalSignatures": [ + "write(text: TrustedHTML): void" + ] + }, + "writeln": { + "name": "writeln", + "additionalSignatures": [ + "writeln(text: TrustedHTML): void" + ] } } }, @@ -2821,6 +2833,36 @@ }, "SourceBufferList": { "exposed": "Window" + }, + "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": [] + } } } }, diff --git a/src/build/bcd/keep-alive.ts b/src/build/bcd/keep-alive.ts index 22a8f3849..1863e308e 100644 --- a/src/build/bcd/keep-alive.ts +++ b/src/build/bcd/keep-alive.ts @@ -44,6 +44,22 @@ export const forceKeepAlive: Record = { MediaCapabilities: ["encodingInfo"], RTCDtlsTransport: ["onstatechange", "state"], RTCPeerConnection: ["canTrickleIceCandidates"], + 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 @@ -64,5 +80,6 @@ export const forceKeepAlive: Record = { "uniform4iv", ], WindowEventHandlers: ["onpagehide", "onpageshow"], + WindowOrWorkerGlobalScope: ["trustedTypes"], WorkerGlobalScope: ["onrejectionhandled", "onunhandledrejection"], }; From 86656f9752f0aeb5e08c6afe5466876851855c6d Mon Sep 17 00:00:00 2001 From: Tobias Smolka Date: Thu, 13 Jan 2022 18:18:57 +0100 Subject: [PATCH 2/7] Accept new baselines --- baselines/dom.generated.d.ts | 82 ++++++++++++++++++++++++++ baselines/serviceworker.generated.d.ts | 80 +++++++++++++++++++++++++ baselines/sharedworker.generated.d.ts | 80 +++++++++++++++++++++++++ baselines/webworker.generated.d.ts | 80 +++++++++++++++++++++++++ 4 files changed, 322 insertions(+) diff --git a/baselines/dom.generated.d.ts b/baselines/dom.generated.d.ts index 494af4a4c..d0439f131 100644 --- a/baselines/dom.generated.d.ts +++ b/baselines/dom.generated.d.ts @@ -1703,6 +1703,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; @@ -4544,11 +4550,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; @@ -13884,6 +13892,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; @@ -16356,6 +16424,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): void; @@ -16871,6 +16940,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; } @@ -17631,6 +17712,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): void; diff --git a/baselines/serviceworker.generated.d.ts b/baselines/serviceworker.generated.d.ts index 3e74c159d..0094a8185 100644 --- a/baselines/serviceworker.generated.d.ts +++ b/baselines/serviceworker.generated.d.ts @@ -595,6 +595,12 @@ interface Transformer { writableType?: undefined; } +interface TrustedTypePolicyOptions { + createHTML?: CreateHTMLCallback | null; + createScript?: CreateScriptCallback | null; + createScriptURL?: CreateScriptURLCallback | null; +} + interface UnderlyingSink { abort?: UnderlyingSinkAbortCallback; close?: UnderlyingSinkCloseCallback; @@ -2909,6 +2915,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; @@ -5059,6 +5125,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): void; @@ -5330,6 +5397,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 OnErrorEventHandlerNonNull { (event: Event | string, source?: string, lineno?: number, colno?: number, error?: Error): any; } @@ -5424,6 +5503,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): void; diff --git a/baselines/sharedworker.generated.d.ts b/baselines/sharedworker.generated.d.ts index 066ecb3c5..01d366f98 100644 --- a/baselines/sharedworker.generated.d.ts +++ b/baselines/sharedworker.generated.d.ts @@ -561,6 +561,12 @@ interface Transformer { writableType?: undefined; } +interface TrustedTypePolicyOptions { + createHTML?: CreateHTMLCallback | null; + createScript?: CreateScriptCallback | null; + createScriptURL?: CreateScriptURLCallback | null; +} + interface UnderlyingSink { abort?: UnderlyingSinkAbortCallback; close?: UnderlyingSinkCloseCallback; @@ -2775,6 +2781,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; @@ -4914,6 +4980,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): void; @@ -5353,6 +5420,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 OnErrorEventHandlerNonNull { (event: Event | string, source?: string, lineno?: number, colno?: number, error?: Error): any; } @@ -5441,6 +5520,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): void; diff --git a/baselines/webworker.generated.d.ts b/baselines/webworker.generated.d.ts index 2ab6c38a4..6f4654af5 100644 --- a/baselines/webworker.generated.d.ts +++ b/baselines/webworker.generated.d.ts @@ -595,6 +595,12 @@ interface Transformer { writableType?: undefined; } +interface TrustedTypePolicyOptions { + createHTML?: CreateHTMLCallback | null; + createScript?: CreateScriptCallback | null; + createScriptURL?: CreateScriptURLCallback | null; +} + interface UnderlyingSink { abort?: UnderlyingSinkAbortCallback; close?: UnderlyingSinkCloseCallback; @@ -2982,6 +2988,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; @@ -5134,6 +5200,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): void; @@ -5573,6 +5640,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; } @@ -5669,6 +5748,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): void; From 6fd788f669ded8104a5f4bb432e9148fe8eaddcd Mon Sep 17 00:00:00 2001 From: Tobias Smolka Date: Fri, 14 Jan 2022 12:20:40 +0100 Subject: [PATCH 3/7] Override Trusted Types Sinks --- inputfiles/knownTypes.json | 4 +- inputfiles/overridingTypes.jsonc | 302 ++++++++++++++++++++++++++++++- 2 files changed, 303 insertions(+), 3 deletions(-) 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 1e709a27c..a3e8605b2 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": { @@ -613,6 +699,19 @@ } } }, + "execCommand": { + "name": "execCommand", + "signature": { + "0": { + "param": [ + { + "name": "value", + "overrideType": "string | TrustedHTML" + } + ] + } + } + }, "write": { "name": "write", "additionalSignatures": [ @@ -803,6 +902,9 @@ }, "previousSibling": { "overrideType": "ChildNode" + }, + "textContent": { + "overrideType": "string | TrustedScript" } } } @@ -1252,6 +1354,27 @@ "overrideType": "HTMLCollectionOf" } } + }, + "insertAdjacentHTML": { + "name": "insertAdjacentHTML", + "signature": { + "0": { + "param": [ + { + "name": "text", + "overrideType": "string | TrustedHTML" + } + ] + } + } + } + } + }, + "properties": { + "property": { + "outerHTML": { + "name": "outerHTML", + "overrideType": "string | TrustedHTML" } } } @@ -1712,6 +1835,18 @@ "overrideType": "Promise" } } + }, + "register": { + "signature": { + "0": { + "param": [ + { + "name": "scriptURL", + "overrideType": "string | URL | TrustedScriptURL" + } + ] + } + } } } }, @@ -2123,6 +2258,18 @@ "type": "MessageEvent" } ] + }, + "constructor": { + "signature": { + "0": { + "param": [ + { + "name": "scriptURL", + "overrideType": "string | URL | TrustedScriptURL" + } + ] + } + } } }, "Crypto": { @@ -2716,6 +2863,23 @@ "type": "ErrorEvent" } ] + }, + "methods": { + "method": { + "importScripts": { + "name": "importScripts", + "signature": { + "0": { + "param": [ + { + "name": "urls", + "overrideType": "string | URL | TrustedScriptURL" + } + ] + } + } + } + } } }, "Instance": { @@ -2834,6 +2998,136 @@ "SourceBufferList": { "exposed": "Window" }, + "DOMParser": { + "name": "DOMParser", + "methods": { + "method": { + "parseFromString": { + "signature": { + "0": { + "param": [ + { + "name": "string", + "overrideType": "string | TrustedHTML" + } + ] + } + } + } + } + } + }, + "HTMLElement": { + "name": "HTMLElement", + "properties": { + "property": { + "innerText": { + "overrideType": "string | TrustedScript" + } + } + } + }, + "HTMLEmbedElement": { + "name": "HTMLEmbedElement", + "properties": { + "property": { + "src": { + "overrideType": "string | TrustedScriptURL" + } + } + } + + }, + "HTMLIFrameElement": { + "name": "HTMLIFrameElement", + "properties": { + "property": { + "srcdoc": { + "overrideType": "string | TrustedHTML" + } + } + } + }, + "HTMLObjectElement": { + "name": "HTMLObjectElement", + "properties": { + "property": { + "codeBase": { + "overrideType": "string | TrustedHTML" + }, + "data": { + "overrideType": "string | TrustedHTML" + } + } + } + }, + "HTMLScriptElement": { + "name": "HTMLScriptElement", + "properties": { + "property": { + "src": { + "overrideType": "string | TrustedScriptURL" + }, + "text": { + "overrideType": "string | TrustedScript" + } + } + } + }, + "InnerHTML": { + "name": "InnerHTML", + "properties": { + "property": { + "innerHTML": { + "name": "innerHTML", + "overrideType": "string | TrustedHTML" + } + } + } + }, + "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", + "overrideType": "string | TrustedScriptURL" + } + } + } + }, "TrustedHTML": { "name": "TrustedHTML", "constructor": { @@ -3186,6 +3480,10 @@ "name": "T" } ] + }, + { + "name": "TimerHandler", + "overrideType": "string | Function | TrustedScript" } ] }, From 9832d8e9dde93ed903c105f853ae7b1248981eca Mon Sep 17 00:00:00 2001 From: Tobias Smolka Date: Fri, 14 Jan 2022 12:22:42 +0100 Subject: [PATCH 4/7] Accept new baselines --- baselines/audioworklet.generated.d.ts | 9 +++++ baselines/dom.generated.d.ts | 56 ++++++++++++++------------ baselines/serviceworker.generated.d.ts | 18 +++++++-- baselines/sharedworker.generated.d.ts | 20 ++++++--- baselines/webworker.generated.d.ts | 20 ++++++--- 5 files changed, 84 insertions(+), 39 deletions(-) diff --git a/baselines/audioworklet.generated.d.ts b/baselines/audioworklet.generated.d.ts index 168c92ea7..d2bf71297 100644 --- a/baselines/audioworklet.generated.d.ts +++ b/baselines/audioworklet.generated.d.ts @@ -241,6 +241,15 @@ declare var EventTarget: { new(): EventTarget; }; +interface InnerHTML { + innerHTML: string | TrustedHTML; +} + +declare var InnerHTML: { + prototype: InnerHTML; + new(): InnerHTML; +}; + /** A message received by a target object. */ interface MessageEvent extends Event { /** Returns the data of the message. */ diff --git a/baselines/dom.generated.d.ts b/baselines/dom.generated.d.ts index d0439f131..c3381a5fc 100644 --- a/baselines/dom.generated.d.ts +++ b/baselines/dom.generated.d.ts @@ -3447,13 +3447,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; /** @@ -3461,7 +3461,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 */ @@ -3843,7 +3843,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: { @@ -4459,7 +4459,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; @@ -4737,7 +4737,7 @@ 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; + outerHTML: string | TrustedHTML; readonly ownerDocument: Document; readonly part: DOMTokenList; /** Returns the namespace prefix. */ @@ -4784,7 +4784,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; @@ -6176,7 +6176,7 @@ interface HTMLElement extends Element, DocumentAndElementEventHandlers, ElementC dir: string; draggable: boolean; hidden: boolean; - innerText: string; + innerText: string | TrustedScript; lang: string; readonly offsetHeight: number; readonly offsetLeft: number; @@ -6212,7 +6212,7 @@ interface HTMLEmbedElement extends HTMLElement { */ name: string; /** Sets or retrieves a URL to be loaded by the object. */ - src: string; + src: string | TrustedScriptURL; type: string; /** Sets or retrieves the width of the object. */ width: string; @@ -6637,7 +6637,7 @@ 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; + srcdoc: string | TrustedHTML; /** Sets or retrieves the width of the object. */ width: string; getSVGDocument(): Document | null; @@ -7234,7 +7234,7 @@ interface HTMLObjectElement extends HTMLElement { * Sets or retrieves the URL of the component. * @deprecated */ - codeBase: string; + codeBase: string | TrustedHTML; /** * Sets or retrieves the Internet media type for the code associated with the object. * @deprecated @@ -7244,7 +7244,7 @@ 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; + data: string | TrustedHTML; /** @deprecated */ declare: boolean; /** Retrieves a reference to the form that the object is embedded in. */ @@ -7550,9 +7550,9 @@ interface HTMLScriptElement extends HTMLElement { noModule: boolean; referrerPolicy: string; /** Retrieves the URL to an external file that contains the source code or data. */ - src: string; + src: string | TrustedScriptURL; /** Retrieves or sets the text of the object as a string. */ - text: string; + 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; @@ -8724,9 +8724,14 @@ declare var ImageData: { }; interface InnerHTML { - innerHTML: string; + innerHTML: string | TrustedHTML; } +declare var InnerHTML: { + prototype: InnerHTML; + new(): InnerHTML; +}; + interface InputDeviceInfo extends MediaDeviceInfo { } @@ -9723,7 +9728,7 @@ interface Node extends EventTarget { readonly parentNode: ParentNode | null; /** Returns the previous sibling. */ readonly previousSibling: ChildNode | null; - textContent: string | null; + 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; @@ -10076,13 +10081,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; @@ -10096,7 +10101,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. */ @@ -11012,7 +11017,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; @@ -11398,7 +11403,7 @@ 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; + baseVal: string | TrustedScriptURL; } declare var SVGAnimatedString: { @@ -13082,7 +13087,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; @@ -13158,7 +13163,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 { @@ -16464,7 +16469,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. */ @@ -17784,8 +17789,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 0094a8185..78ddfa9e6 100644 --- a/baselines/serviceworker.generated.d.ts +++ b/baselines/serviceworker.generated.d.ts @@ -2043,6 +2043,15 @@ declare var ImageData: { new(data: Uint8ClampedArray, sw: number, sh?: number, settings?: ImageDataSettings): ImageData; }; +interface InnerHTML { + innerHTML: string | TrustedHTML; +} + +declare var InnerHTML: { + prototype: InnerHTML; + new(): InnerHTML; +}; + interface KHR_parallel_shader_compile { readonly COMPLETION_STATUS_KHR: GLenum; } @@ -2681,7 +2690,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; @@ -5163,7 +5172,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; @@ -5491,7 +5500,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; @@ -5558,8 +5567,9 @@ type ReadableStreamDefaultReadResult = ReadableStreamDefaultReadValueResult = 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 01d366f98..6c31cc2d0 100644 --- a/baselines/sharedworker.generated.d.ts +++ b/baselines/sharedworker.generated.d.ts @@ -1963,6 +1963,15 @@ declare var ImageData: { new(data: Uint8ClampedArray, sw: number, sh?: number, settings?: ImageDataSettings): ImageData; }; +interface InnerHTML { + innerHTML: string | TrustedHTML; +} + +declare var InnerHTML: { + prototype: InnerHTML; + new(): InnerHTML; +}; + interface KHR_parallel_shader_compile { readonly COMPLETION_STATUS_KHR: GLenum; } @@ -2561,7 +2570,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; @@ -5016,7 +5025,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 { @@ -5043,7 +5052,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; @@ -5508,7 +5517,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; @@ -5574,8 +5583,9 @@ type ReadableStreamDefaultReadResult = ReadableStreamDefaultReadValueResult = 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 6f4654af5..43e045739 100644 --- a/baselines/webworker.generated.d.ts +++ b/baselines/webworker.generated.d.ts @@ -2095,6 +2095,15 @@ declare var ImageData: { new(data: Uint8ClampedArray, sw: number, sh?: number, settings?: ImageDataSettings): ImageData; }; +interface InnerHTML { + innerHTML: string | TrustedHTML; +} + +declare var InnerHTML: { + prototype: InnerHTML; + new(): InnerHTML; +}; + interface KHR_parallel_shader_compile { readonly COMPLETION_STATUS_KHR: GLenum; } @@ -2733,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; @@ -5236,7 +5245,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 { @@ -5263,7 +5272,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; @@ -5736,7 +5745,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; @@ -5805,8 +5814,9 @@ type ReadableStreamDefaultReadResult = ReadableStreamDefaultReadValueResult = 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; From 89141a78c2e284f37ba6ad26732fe3300a2c03ab Mon Sep 17 00:00:00 2001 From: Tobias Smolka Date: Fri, 14 Jan 2022 12:27:32 +0100 Subject: [PATCH 5/7] Fix InnerHTML --- baselines/audioworklet.generated.d.ts | 9 --------- baselines/dom.generated.d.ts | 5 ----- baselines/serviceworker.generated.d.ts | 9 --------- baselines/sharedworker.generated.d.ts | 9 --------- baselines/webworker.generated.d.ts | 9 --------- inputfiles/overridingTypes.jsonc | 22 +++++++++++----------- 6 files changed, 11 insertions(+), 52 deletions(-) diff --git a/baselines/audioworklet.generated.d.ts b/baselines/audioworklet.generated.d.ts index d2bf71297..168c92ea7 100644 --- a/baselines/audioworklet.generated.d.ts +++ b/baselines/audioworklet.generated.d.ts @@ -241,15 +241,6 @@ declare var EventTarget: { new(): EventTarget; }; -interface InnerHTML { - innerHTML: string | TrustedHTML; -} - -declare var InnerHTML: { - prototype: InnerHTML; - new(): InnerHTML; -}; - /** A message received by a target object. */ interface MessageEvent extends Event { /** Returns the data of the message. */ diff --git a/baselines/dom.generated.d.ts b/baselines/dom.generated.d.ts index c3381a5fc..261ab1096 100644 --- a/baselines/dom.generated.d.ts +++ b/baselines/dom.generated.d.ts @@ -8727,11 +8727,6 @@ interface InnerHTML { innerHTML: string | TrustedHTML; } -declare var InnerHTML: { - prototype: InnerHTML; - new(): InnerHTML; -}; - interface InputDeviceInfo extends MediaDeviceInfo { } diff --git a/baselines/serviceworker.generated.d.ts b/baselines/serviceworker.generated.d.ts index 78ddfa9e6..19e75df06 100644 --- a/baselines/serviceworker.generated.d.ts +++ b/baselines/serviceworker.generated.d.ts @@ -2043,15 +2043,6 @@ declare var ImageData: { new(data: Uint8ClampedArray, sw: number, sh?: number, settings?: ImageDataSettings): ImageData; }; -interface InnerHTML { - innerHTML: string | TrustedHTML; -} - -declare var InnerHTML: { - prototype: InnerHTML; - new(): InnerHTML; -}; - interface KHR_parallel_shader_compile { readonly COMPLETION_STATUS_KHR: GLenum; } diff --git a/baselines/sharedworker.generated.d.ts b/baselines/sharedworker.generated.d.ts index 6c31cc2d0..7648f9ea4 100644 --- a/baselines/sharedworker.generated.d.ts +++ b/baselines/sharedworker.generated.d.ts @@ -1963,15 +1963,6 @@ declare var ImageData: { new(data: Uint8ClampedArray, sw: number, sh?: number, settings?: ImageDataSettings): ImageData; }; -interface InnerHTML { - innerHTML: string | TrustedHTML; -} - -declare var InnerHTML: { - prototype: InnerHTML; - new(): InnerHTML; -}; - interface KHR_parallel_shader_compile { readonly COMPLETION_STATUS_KHR: GLenum; } diff --git a/baselines/webworker.generated.d.ts b/baselines/webworker.generated.d.ts index 43e045739..2775c1d52 100644 --- a/baselines/webworker.generated.d.ts +++ b/baselines/webworker.generated.d.ts @@ -2095,15 +2095,6 @@ declare var ImageData: { new(data: Uint8ClampedArray, sw: number, sh?: number, settings?: ImageDataSettings): ImageData; }; -interface InnerHTML { - innerHTML: string | TrustedHTML; -} - -declare var InnerHTML: { - prototype: InnerHTML; - new(): InnerHTML; -}; - interface KHR_parallel_shader_compile { readonly COMPLETION_STATUS_KHR: GLenum; } diff --git a/inputfiles/overridingTypes.jsonc b/inputfiles/overridingTypes.jsonc index a3e8605b2..2dc1bf035 100644 --- a/inputfiles/overridingTypes.jsonc +++ b/inputfiles/overridingTypes.jsonc @@ -305,6 +305,17 @@ } } } + }, + "InnerHTML": { + "name": "InnerHTML", + "properties": { + "property": { + "innerHTML": { + "name": "innerHTML", + "overrideType": "string | TrustedHTML" + } + } + } } } }, @@ -3074,17 +3085,6 @@ } } }, - "InnerHTML": { - "name": "InnerHTML", - "properties": { - "property": { - "innerHTML": { - "name": "innerHTML", - "overrideType": "string | TrustedHTML" - } - } - } - }, "Range": { "name": "Range", "methods": { From b4156fb3dc5efee3b8303c119190fe59dfaeaab3 Mon Sep 17 00:00:00 2001 From: Tobias Smolka Date: Mon, 17 Jan 2022 16:39:25 +0100 Subject: [PATCH 6/7] Override setter types for Sink properties --- baselines/dom.generated.d.ts | 33 +++++++++++++++++--------- baselines/serviceworker.generated.d.ts | 12 ++++++++++ baselines/sharedworker.generated.d.ts | 12 ++++++++++ inputfiles/overridingTypes.jsonc | 22 ++++++++--------- src/build/emitter.ts | 23 +++++++++++------- src/build/types.d.ts | 1 + 6 files changed, 72 insertions(+), 31 deletions(-) diff --git a/baselines/dom.generated.d.ts b/baselines/dom.generated.d.ts index e4d6683b8..83032e335 100644 --- a/baselines/dom.generated.d.ts +++ b/baselines/dom.generated.d.ts @@ -4769,7 +4769,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 | TrustedHTML; + get outerHTML(): string; + set outerHTML(outerHTML: string | TrustedHTML); readonly ownerDocument: Document; readonly part: DOMTokenList; /** Returns the namespace prefix. */ @@ -6211,7 +6212,8 @@ interface HTMLElement extends Element, DocumentAndElementEventHandlers, ElementC dir: string; draggable: boolean; hidden: boolean; - innerText: string | TrustedScript; + get innerText(): string; + set innerText(innerText: string | TrustedScript); lang: string; readonly offsetHeight: number; readonly offsetLeft: number; @@ -6247,7 +6249,8 @@ interface HTMLEmbedElement extends HTMLElement { */ name: string; /** Sets or retrieves a URL to be loaded by the object. */ - src: string | TrustedScriptURL; + get src(): string; + set src(src: string | TrustedScriptURL); type: string; /** Sets or retrieves the width of the object. */ width: string; @@ -6672,7 +6675,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 | TrustedHTML; + get srcdoc(): string; + set srcdoc(srcdoc: string | TrustedHTML); /** Sets or retrieves the width of the object. */ width: string; getSVGDocument(): Document | null; @@ -7269,7 +7273,8 @@ interface HTMLObjectElement extends HTMLElement { * Sets or retrieves the URL of the component. * @deprecated */ - codeBase: string | TrustedHTML; + get codeBase(): string; + set codeBase(codeBase: string | TrustedHTML); /** * Sets or retrieves the Internet media type for the code associated with the object. * @deprecated @@ -7279,7 +7284,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 | TrustedHTML; + get data(): string; + set data(data: string | TrustedHTML); /** @deprecated */ declare: boolean; /** Retrieves a reference to the form that the object is embedded in. */ @@ -7585,9 +7591,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 | TrustedScriptURL; + get src(): string; + set src(src: string | TrustedScriptURL); /** Retrieves or sets the text of the object as a string. */ - text: string | TrustedScript; + 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; @@ -8759,7 +8767,8 @@ declare var ImageData: { }; interface InnerHTML { - innerHTML: string | TrustedHTML; + get innerHTML(): string; + set innerHTML(innerHTML: string | TrustedHTML); } interface InputDeviceInfo extends MediaDeviceInfo { @@ -9781,7 +9790,8 @@ interface Node extends EventTarget { readonly parentNode: ParentNode | null; /** Returns the previous sibling. */ readonly previousSibling: ChildNode | null; - textContent: string | TrustedScript | null; + get textContent(): string | null; + set textContent(textContent: string | TrustedScript); 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; @@ -11459,7 +11469,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 | TrustedScriptURL; + get baseVal(): string; + set baseVal(baseVal: string | TrustedScriptURL); } declare var SVGAnimatedString: { diff --git a/baselines/serviceworker.generated.d.ts b/baselines/serviceworker.generated.d.ts index d7b033399..279dcb883 100644 --- a/baselines/serviceworker.generated.d.ts +++ b/baselines/serviceworker.generated.d.ts @@ -5438,6 +5438,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; } diff --git a/baselines/sharedworker.generated.d.ts b/baselines/sharedworker.generated.d.ts index 48a09d7a3..64ce01861 100644 --- a/baselines/sharedworker.generated.d.ts +++ b/baselines/sharedworker.generated.d.ts @@ -5461,6 +5461,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; } diff --git a/inputfiles/overridingTypes.jsonc b/inputfiles/overridingTypes.jsonc index 2dc1bf035..fb449aecb 100644 --- a/inputfiles/overridingTypes.jsonc +++ b/inputfiles/overridingTypes.jsonc @@ -312,7 +312,7 @@ "property": { "innerHTML": { "name": "innerHTML", - "overrideType": "string | TrustedHTML" + "setterType": "string | TrustedHTML" } } } @@ -915,7 +915,7 @@ "overrideType": "ChildNode" }, "textContent": { - "overrideType": "string | TrustedScript" + "setterType": "string | TrustedScript" } } } @@ -1385,7 +1385,7 @@ "property": { "outerHTML": { "name": "outerHTML", - "overrideType": "string | TrustedHTML" + "setterType": "string | TrustedHTML" } } } @@ -3033,7 +3033,7 @@ "properties": { "property": { "innerText": { - "overrideType": "string | TrustedScript" + "setterType": "string | TrustedScript" } } } @@ -3043,7 +3043,7 @@ "properties": { "property": { "src": { - "overrideType": "string | TrustedScriptURL" + "setterType": "string | TrustedScriptURL" } } } @@ -3054,7 +3054,7 @@ "properties": { "property": { "srcdoc": { - "overrideType": "string | TrustedHTML" + "setterType": "string | TrustedHTML" } } } @@ -3064,10 +3064,10 @@ "properties": { "property": { "codeBase": { - "overrideType": "string | TrustedHTML" + "setterType": "string | TrustedHTML" }, "data": { - "overrideType": "string | TrustedHTML" + "setterType": "string | TrustedHTML" } } } @@ -3077,10 +3077,10 @@ "properties": { "property": { "src": { - "overrideType": "string | TrustedScriptURL" + "setterType": "string | TrustedScriptURL" }, "text": { - "overrideType": "string | TrustedScript" + "setterType": "string | TrustedScript" } } } @@ -3123,7 +3123,7 @@ "property": { "baseVal": { "name": "baseVal", - "overrideType": "string | TrustedScriptURL" + "setterType": "string | TrustedScriptURL" } } } diff --git a/src/build/emitter.ts b/src/build/emitter.ts index 12e129831..ab6766677 100644 --- a/src/build/emitter.ts +++ b/src/build/emitter.ts @@ -807,19 +807,24 @@ 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 { From abe7b0a343064ea1f0dfef03785e62ff7c1216ff Mon Sep 17 00:00:00 2001 From: Tobias Smolka Date: Mon, 17 Jan 2022 16:46:03 +0100 Subject: [PATCH 7/7] Fix tests --- baselines/dom.generated.d.ts | 2 +- inputfiles/overridingTypes.jsonc | 2 +- src/build/emitter.ts | 6 ++++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/baselines/dom.generated.d.ts b/baselines/dom.generated.d.ts index 83032e335..4a88aac42 100644 --- a/baselines/dom.generated.d.ts +++ b/baselines/dom.generated.d.ts @@ -9791,7 +9791,7 @@ interface Node extends EventTarget { /** Returns the previous sibling. */ readonly previousSibling: ChildNode | null; get textContent(): string | null; - set textContent(textContent: string | TrustedScript); + 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; diff --git a/inputfiles/overridingTypes.jsonc b/inputfiles/overridingTypes.jsonc index fb449aecb..aab0e17ba 100644 --- a/inputfiles/overridingTypes.jsonc +++ b/inputfiles/overridingTypes.jsonc @@ -915,7 +915,7 @@ "overrideType": "ChildNode" }, "textContent": { - "setterType": "string | TrustedScript" + "setterType": "string | TrustedScript | null" } } } diff --git a/src/build/emitter.ts b/src/build/emitter.ts index ab6766677..cf498e678 100644 --- a/src/build/emitter.ts +++ b/src/build/emitter.ts @@ -820,11 +820,13 @@ export function emitWebIdl( setterType = `${convertDomTypeToTsType( forwardingProperty )} | ${pType}`; - } else { + } else { setterType = p.setterType ?? "undefined"; } printer.printLine( - `set ${p.name}${optionalModifier}(${p.putForwards ?? p.name}: ${setterType});` + `set ${p.name}${optionalModifier}(${ + p.putForwards ?? p.name + }: ${setterType});` ); } else { const readOnlyModifier = p.readonly && prefix === "" ? "readonly " : "";