diff --git a/baselines/dom.generated.d.ts b/baselines/dom.generated.d.ts index 7b1cfbc32..8ec2fc0dd 100644 --- a/baselines/dom.generated.d.ts +++ b/baselines/dom.generated.d.ts @@ -1714,14 +1714,15 @@ interface WebAuthnExtensions { } interface WebGLContextAttributes { - alpha?: GLboolean; - antialias?: GLboolean; - depth?: GLboolean; + alpha?: boolean; + antialias?: boolean; + depth?: boolean; + desynchronized?: boolean; failIfMajorPerformanceCaveat?: boolean; powerPreference?: WebGLPowerPreference; - premultipliedAlpha?: GLboolean; - preserveDrawingBuffer?: GLboolean; - stencil?: GLboolean; + premultipliedAlpha?: boolean; + preserveDrawingBuffer?: boolean; + stencil?: boolean; } interface WebGLContextEventInit extends EventInit { @@ -1927,6 +1928,11 @@ declare var AnimationEvent: { new(type: string, animationEventInitDict?: AnimationEventInit): AnimationEvent; }; +interface AnimationFrameProvider { + cancelAnimationFrame(handle: number): void; + requestAnimationFrame(callback: FrameRequestCallback): number; +} + interface AnimationPlaybackEvent extends Event { readonly currentTime: number | null; readonly timelineTime: number | null; @@ -5346,6 +5352,11 @@ interface External { IsSearchProviderInstalled(): void; } +declare var External: { + prototype: External; + new(): External; +}; + /** Provides information about files and allows JavaScript in a web page to access their content. */ interface File extends Blob { readonly lastModified: number; @@ -16599,7 +16610,7 @@ declare var WebGLRenderingContext: { }; interface WebGLRenderingContextBase { - readonly canvas: HTMLCanvasElement; + readonly canvas: HTMLCanvasElement | OffscreenCanvas; readonly drawingBufferHeight: GLsizei; readonly drawingBufferWidth: GLsizei; activeTexture(texture: GLenum): void; @@ -17275,7 +17286,7 @@ interface WindowEventMap extends GlobalEventHandlersEventMap, WindowEventHandler } /** A window containing a DOM document; the document property points to the DOM document loaded in that window. */ -interface Window extends EventTarget, WindowTimers, WindowSessionStorage, WindowLocalStorage, WindowConsole, GlobalEventHandlers, IDBEnvironment, WindowBase64, WindowOrWorkerGlobalScope, WindowEventHandlers { +interface Window extends EventTarget, WindowTimers, WindowSessionStorage, WindowLocalStorage, WindowConsole, GlobalEventHandlers, IDBEnvironment, WindowBase64, AnimationFrameProvider, WindowOrWorkerGlobalScope, WindowEventHandlers { Blob: typeof Blob; TextDecoder: typeof TextDecoder; TextEncoder: typeof TextEncoder; @@ -17370,7 +17381,6 @@ interface Window extends EventTarget, WindowTimers, WindowSessionStorage, Window readonly window: Window; alert(message?: any): void; blur(): void; - cancelAnimationFrame(handle: number): void; /** @deprecated */ captureEvents(): void; close(): void; @@ -17390,7 +17400,6 @@ interface Window extends EventTarget, WindowTimers, WindowSessionStorage, Window prompt(message?: string, _default?: string): string | null; /** @deprecated */ releaseEvents(): void; - requestAnimationFrame(callback: FrameRequestCallback): number; resizeBy(x: number, y: number): void; resizeTo(x: number, y: number): void; scroll(options?: ScrollToOptions): void; @@ -18366,7 +18375,6 @@ declare var top: Window; declare var window: Window; declare function alert(message?: any): void; declare function blur(): void; -declare function cancelAnimationFrame(handle: number): void; /** @deprecated */ declare function captureEvents(): void; declare function close(): void; @@ -18386,7 +18394,6 @@ declare function print(): void; declare function prompt(message?: string, _default?: string): string | null; /** @deprecated */ declare function releaseEvents(): void; -declare function requestAnimationFrame(callback: FrameRequestCallback): number; declare function resizeBy(x: number, y: number): void; declare function resizeTo(x: number, y: number): void; declare function scroll(options?: ScrollToOptions): void; @@ -18677,6 +18684,8 @@ declare var onwheel: ((this: Window, ev: WheelEvent) => any) | null; declare var indexedDB: IDBFactory; declare function atob(encodedString: string): string; declare function btoa(rawString: string): string; +declare function cancelAnimationFrame(handle: number): void; +declare function requestAnimationFrame(callback: FrameRequestCallback): number; declare var caches: CacheStorage; declare var crypto: Crypto; declare var indexedDB: IDBFactory; @@ -18749,7 +18758,7 @@ type GLsizeiptr = number; type GLuint = number; type GLfloat = number; type GLclampf = number; -type TexImageSource = ImageBitmap | ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement; +type TexImageSource = ImageBitmap | ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | OffscreenCanvas; type Float32List = Float32Array | GLfloat[]; type Int32List = Int32Array | GLint[]; type BufferSource = ArrayBufferView | ArrayBuffer; diff --git a/baselines/webworker.generated.d.ts b/baselines/webworker.generated.d.ts index 8115f73c6..2aa5b5505 100644 --- a/baselines/webworker.generated.d.ts +++ b/baselines/webworker.generated.d.ts @@ -512,14 +512,15 @@ interface UnderlyingSource { } interface WebGLContextAttributes { - alpha?: GLboolean; - antialias?: GLboolean; - depth?: GLboolean; + alpha?: boolean; + antialias?: boolean; + depth?: boolean; + desynchronized?: boolean; failIfMajorPerformanceCaveat?: boolean; powerPreference?: WebGLPowerPreference; - premultipliedAlpha?: GLboolean; - preserveDrawingBuffer?: GLboolean; - stencil?: GLboolean; + premultipliedAlpha?: boolean; + preserveDrawingBuffer?: boolean; + stencil?: boolean; } interface WebGLContextEventInit extends EventInit { @@ -603,6 +604,11 @@ interface AesCmacParams extends Algorithm { length: number; } +interface AnimationFrameProvider { + cancelAnimationFrame(handle: number): void; + requestAnimationFrame(callback: FrameRequestCallback): number; +} + /** A file-like object of immutable, raw data. Blobs represent data that isn't necessarily in a JavaScript-native format. The File interface is based on Blob, inheriting blob functionality and expanding it to support files on the user's system. */ interface Blob { readonly size: number; @@ -1232,7 +1238,7 @@ interface DedicatedWorkerGlobalScopeEventMap extends WorkerGlobalScopeEventMap { } /** (the Worker global scope) is accessible through the self keyword. Some additional global functions, namespaces objects, and constructors, not typically associated with the worker global scope, but available on it, are listed in the JavaScript Reference. See also: Functions available to workers. */ -interface DedicatedWorkerGlobalScope extends WorkerGlobalScope { +interface DedicatedWorkerGlobalScope extends WorkerGlobalScope, AnimationFrameProvider { onmessage: ((this: DedicatedWorkerGlobalScope, ev: MessageEvent) => any) | null; close(): void; postMessage(message: any, transfer: Transferable[]): void; @@ -3708,6 +3714,7 @@ declare var WebGLRenderingContext: { }; interface WebGLRenderingContextBase { + readonly canvas: OffscreenCanvas; readonly drawingBufferHeight: GLsizei; readonly drawingBufferWidth: GLsizei; activeTexture(texture: GLenum): void; @@ -4652,6 +4659,10 @@ interface EventHandlerNonNull { (event: Event): any; } +interface FrameRequestCallback { + (time: number): void; +} + interface PerformanceObserverCallback { (entries: PerformanceObserverEntryList, observer: PerformanceObserver): void; } @@ -4737,6 +4748,8 @@ declare function fetch(input: RequestInfo, init?: RequestInit): Promise(type: K, listener: (this: DedicatedWorkerGlobalScope, ev: DedicatedWorkerGlobalScopeEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; declare function addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void; declare function removeEventListener(type: K, listener: (this: DedicatedWorkerGlobalScope, ev: DedicatedWorkerGlobalScopeEventMap[K]) => any, options?: boolean | EventListenerOptions): void; @@ -4768,7 +4781,7 @@ type GLsizeiptr = number; type GLuint = number; type GLfloat = number; type GLclampf = number; -type TexImageSource = ImageBitmap | ImageData; +type TexImageSource = ImageBitmap | ImageData | OffscreenCanvas; type Float32List = Float32Array | GLfloat[]; type Int32List = Int32Array | GLint[]; type BufferSource = ArrayBufferView | ArrayBuffer; diff --git a/inputfiles/addedTypes.json b/inputfiles/addedTypes.json index 40fa45518..64e018b03 100644 --- a/inputfiles/addedTypes.json +++ b/inputfiles/addedTypes.json @@ -1083,19 +1083,6 @@ } } }, - "Performance": { - "name": "Performance", - "properties": { - "events": { - "event": [ - { - "name": "resourcetimingbufferfull", - "type": "Event" - } - ] - } - } - }, "KeyboardEvent": { "name": "KeyboardEvent", "properties": { diff --git a/inputfiles/idl/HTML - ImageBitmap and animations.widl b/inputfiles/idl/HTML - ImageBitmap and animations.widl index 0d8f7ef70..6a47109e5 100644 --- a/inputfiles/idl/HTML - ImageBitmap and animations.widl +++ b/inputfiles/idl/HTML - ImageBitmap and animations.widl @@ -22,3 +22,12 @@ dictionary ImageBitmapOptions { [EnforceRange] unsigned long resizeHeight; ResizeQuality resizeQuality = "low"; }; + +callback FrameRequestCallback = void (DOMHighResTimeStamp time); + +interface mixin AnimationFrameProvider { + unsigned long requestAnimationFrame(FrameRequestCallback callback); + void cancelAnimationFrame(unsigned long handle); +}; +Window includes AnimationFrameProvider; +DedicatedWorkerGlobalScope includes AnimationFrameProvider; diff --git a/inputfiles/idl/HTML - Obsolete features.widl b/inputfiles/idl/HTML - Obsolete features.widl index b5cf66ae0..3f27eb9a9 100644 --- a/inputfiles/idl/HTML - Obsolete features.widl +++ b/inputfiles/idl/HTML - Obsolete features.widl @@ -286,8 +286,7 @@ partial interface Window { [Replaceable, SameObject] readonly attribute External external; }; -[Exposed=Window, - NoInterfaceObject] +[Exposed=Window] interface External { void AddSearchProvider(); void IsSearchProviderInstalled(); diff --git a/inputfiles/idl/WebGL 1.widl b/inputfiles/idl/WebGL 1.widl index a6df3de6b..9ee01ac91 100644 --- a/inputfiles/idl/WebGL 1.widl +++ b/inputfiles/idl/WebGL 1.widl @@ -3,7 +3,7 @@ // WebGL IDL definitions scraped from the Khronos specification: // https://www.khronos.org/registry/webgl/specs/latest/ -// Copyright (c) 2018 The Khronos Group Inc. +// Copyright (c) 2019 The Khronos Group Inc. // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and/or associated documentation files (the @@ -46,14 +46,15 @@ enum WebGLPowerPreference { "default", "low-power", "high-performance" }; dictionary WebGLContextAttributes { - GLboolean alpha = true; - GLboolean depth = true; - GLboolean stencil = false; - GLboolean antialias = true; - GLboolean premultipliedAlpha = true; - GLboolean preserveDrawingBuffer = false; + boolean alpha = true; + boolean depth = true; + boolean stencil = false; + boolean antialias = true; + boolean premultipliedAlpha = true; + boolean preserveDrawingBuffer = false; WebGLPowerPreference powerPreference = "default"; - GLboolean failIfMajorPerformanceCaveat = false; + boolean failIfMajorPerformanceCaveat = false; + boolean desynchronized = false; }; [Exposed=(Window,Worker)] @@ -106,7 +107,8 @@ typedef (ImageBitmap or ImageData or HTMLImageElement or HTMLCanvasElement or - HTMLVideoElement) TexImageSource; + HTMLVideoElement or + OffscreenCanvas) TexImageSource; typedef ([AllowShared] Float32Array or sequence) Float32List; typedef ([AllowShared] Int32Array or sequence) Int32List; @@ -532,7 +534,8 @@ interface mixin WebGLRenderingContextBase const GLenum UNPACK_COLORSPACE_CONVERSION_WEBGL = 0x9243; const GLenum BROWSER_DEFAULT_WEBGL = 0x9244; - [Exposed=Window] readonly attribute HTMLCanvasElement canvas; + [Exposed=Window] readonly attribute (HTMLCanvasElement or OffscreenCanvas) canvas; + [Exposed=Worker] readonly attribute OffscreenCanvas canvas; readonly attribute GLsizei drawingBufferWidth; readonly attribute GLsizei drawingBufferHeight; diff --git a/inputfiles/removedTypes.json b/inputfiles/removedTypes.json index 5b9855e72..b1d3b6f10 100644 --- a/inputfiles/removedTypes.json +++ b/inputfiles/removedTypes.json @@ -246,6 +246,12 @@ "ontouchstart": null } }, + "methods": { + "method": { + "cancelAnimationFrame": null, + "requestAnimationFrame": null + } + }, "implements": [ "GlobalFetch" ] diff --git a/src/index.ts b/src/index.ts index 57aa28b0b..9a32d2f19 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,8 +6,28 @@ import { Flavor, emitWebIdl } from "./emitter"; import { convert } from "./widlprocess"; import { getExposedTypes } from "./expose"; +function mergeNamesakes(filtered: Browser.WebIdl) { + const targets = [ + ...Object.values(filtered.interfaces!.interface), + ...Object.values(filtered.mixins!.mixin), + ...filtered.namespaces! + ]; + for (const i of targets) { + if (!i.properties || !i.properties.namesakes) { + continue; + } + const { property } = i.properties!; + for (const [prop] of Object.values(i.properties.namesakes)) { + if (prop && !(prop.name in property)) { + property[prop.name] = prop; + } + } + } +} + function emitDomWorker(webidl: Browser.WebIdl, tsWorkerOutput: string, forceKnownWorkerTypes: Set) { const worker = getExposedTypes(webidl, "Worker", forceKnownWorkerTypes); + mergeNamesakes(worker); const result = emitWebIdl(worker, Flavor.Worker); fs.writeFileSync(tsWorkerOutput, result); return; @@ -15,7 +35,7 @@ function emitDomWorker(webidl: Browser.WebIdl, tsWorkerOutput: string, forceKnow function emitDomWeb(webidl: Browser.WebIdl, tsWebOutput: string, forceKnownWindowTypes: Set) { const browser = getExposedTypes(webidl, "Window", forceKnownWindowTypes); - + mergeNamesakes(browser); const result = emitWebIdl(browser, Flavor.Web); fs.writeFileSync(tsWebOutput, result); return; diff --git a/src/types.d.ts b/src/types.d.ts index 018326ccb..5647f65c1 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -166,6 +166,7 @@ export interface Interface { } properties?: { property: Record; + namesakes?: Record; } constructor?: Constructor; "secure-context"?: 1; diff --git a/src/widlprocess.ts b/src/widlprocess.ts index dda75c7af..7e04c303a 100644 --- a/src/widlprocess.ts +++ b/src/widlprocess.ts @@ -112,7 +112,7 @@ function convertInterfaceCommon(i: webidl2.InterfaceType | webidl2.InterfaceMixi constants: { constant: {} }, methods: { method: {} }, "anonymous-methods": { method: [] }, - properties: { property: {} }, + properties: { property: {}, namesakes: {} }, constructor: getConstructor(i.extAttrs, i.name), "named-constructor": getNamedConstructor(i.extAttrs, i.name), exposed: getExtAttrConcatenated(i.extAttrs, "Exposed"), @@ -130,8 +130,19 @@ function convertInterfaceCommon(i: webidl2.InterfaceType | webidl2.InterfaceMixi addComments(result.constants!.constant[member.name], commentMap, i.name, member.name); } else if (member.type === "attribute") { - result.properties!.property[member.name] = convertAttribute(member, result.exposed); - addComments(result.properties!.property[member.name], commentMap, i.name, member.name); + const { properties } = result; + const prop = convertAttribute(member, result.exposed); + addComments(prop, commentMap, i.name, member.name); + + if (member.name in properties!.namesakes!) { + properties!.namesakes![member.name].push(prop); + } else if (member.name in properties!.property) { + const existing = properties!.property[member.name]; + delete properties!.property[member.name]; + properties!.namesakes![member.name] = [existing, prop]; + } else { + properties!.property[member.name] = prop; + } } else if (member.type === "operation" && member.idlType) { const operation = convertOperation(member, result.exposed);