From 63e9406a8bcaf61966e6ffcb49b7f0b30c0d4cf9 Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Fri, 12 Apr 2019 15:40:21 +0900 Subject: [PATCH 1/2] update worker types --- baselines/dom.generated.d.ts | 35 ++++++++++++------- baselines/webworker.generated.d.ts | 29 ++++++++++----- inputfiles/addedTypes.json | 16 ++++----- .../HTML - ImageBitmap and animations.widl | 9 +++++ inputfiles/idl/HTML - Obsolete features.widl | 3 +- inputfiles/idl/WebGL 1.widl | 23 ++++++------ inputfiles/removedTypes.json | 6 ++++ src/index.ts | 22 +++++++++++- src/types.d.ts | 1 + src/widlprocess.ts | 17 +++++++-- 10 files changed, 115 insertions(+), 46 deletions(-) diff --git a/baselines/dom.generated.d.ts b/baselines/dom.generated.d.ts index 87c865ed3..d3b9a05b4 100644 --- a/baselines/dom.generated.d.ts +++ b/baselines/dom.generated.d.ts @@ -1654,14 +1654,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 { @@ -1854,6 +1855,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; @@ -5239,6 +5245,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; @@ -16424,7 +16435,7 @@ declare var WebGLRenderingContext: { }; interface WebGLRenderingContextBase { - readonly canvas: HTMLCanvasElement; + readonly canvas: HTMLCanvasElement | OffscreenCanvas; readonly drawingBufferHeight: GLsizei; readonly drawingBufferWidth: GLsizei; activeTexture(texture: GLenum): void; @@ -17100,7 +17111,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, GlobalFetch, WindowOrWorkerGlobalScope, WindowEventHandlers { +interface Window extends EventTarget, WindowTimers, WindowSessionStorage, WindowLocalStorage, WindowConsole, GlobalEventHandlers, IDBEnvironment, WindowBase64, GlobalFetch, AnimationFrameProvider, WindowOrWorkerGlobalScope, WindowEventHandlers { Blob: typeof Blob; TextDecoder: typeof TextDecoder; TextEncoder: typeof TextEncoder; @@ -17195,7 +17206,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; @@ -17215,7 +17225,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; @@ -18191,7 +18200,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; @@ -18211,7 +18219,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; @@ -18504,6 +18511,8 @@ declare var indexedDB: IDBFactory; declare function atob(encodedString: string): string; declare function btoa(rawString: string): string; declare function fetch(input: RequestInfo, init?: RequestInit): Promise; +declare function cancelAnimationFrame(handle: number): void; +declare function requestAnimationFrame(callback: FrameRequestCallback): number; declare var caches: CacheStorage; declare var crypto: Crypto; declare var indexedDB: IDBFactory; @@ -18576,7 +18585,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 b3c2c4912..74a6eb8f7 100644 --- a/baselines/webworker.generated.d.ts +++ b/baselines/webworker.generated.d.ts @@ -473,14 +473,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 { @@ -566,6 +567,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; @@ -1200,7 +1206,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; @@ -3640,6 +3646,7 @@ declare var WebGLRenderingContext: { }; interface WebGLRenderingContextBase { + readonly canvas: OffscreenCanvas; readonly drawingBufferHeight: GLsizei; readonly drawingBufferWidth: GLsizei; activeTexture(texture: GLenum): void; @@ -4585,6 +4592,10 @@ interface EventHandlerNonNull { (event: Event): any; } +interface FrameRequestCallback { + (time: number): void; +} + interface PerformanceObserverCallback { (entries: PerformanceObserverEntryList, observer: PerformanceObserver): void; } @@ -4673,6 +4684,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; @@ -4704,7 +4717,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 62ce7ab52..58aea0ca9 100644 --- a/inputfiles/addedTypes.json +++ b/inputfiles/addedTypes.json @@ -1075,15 +1075,13 @@ }, "Performance": { "name": "Performance", - "properties": { - "events": { - "event": [ - { - "name": "resourcetimingbufferfull", - "type": "Event" - } - ] - } + "events": { + "event": [ + { + "name": "resourcetimingbufferfull", + "type": "Event" + } + ] } }, "KeyboardEvent": { 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 a97f32293..8c01c081e 100644 --- a/inputfiles/removedTypes.json +++ b/inputfiles/removedTypes.json @@ -216,6 +216,12 @@ "ontouchmove": null, "ontouchstart": null } + }, + "methods": { + "method": { + "cancelAnimationFrame": null, + "requestAnimationFrame": null + } } }, "WheelEvent": { diff --git a/src/index.ts b/src/index.ts index 5d46a868c..a73743165 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) { + property[prop.name] = merge(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 11f2c044d..b3c8d2f8c 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -161,6 +161,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 2f7b7f3f7..6639b8fe2 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); From 96902dae1e5d5f6c4ebd8e80bb7d3db864341f82 Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Wed, 5 Jun 2019 12:05:27 +0900 Subject: [PATCH 2/2] simple value assigning --- inputfiles/addedTypes.json | 11 ----------- src/index.ts | 4 ++-- 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/inputfiles/addedTypes.json b/inputfiles/addedTypes.json index 8e87fccd9..64e018b03 100644 --- a/inputfiles/addedTypes.json +++ b/inputfiles/addedTypes.json @@ -1083,17 +1083,6 @@ } } }, - "Performance": { - "name": "Performance", - "events": { - "event": [ - { - "name": "resourcetimingbufferfull", - "type": "Event" - } - ] - } - }, "KeyboardEvent": { "name": "KeyboardEvent", "properties": { diff --git a/src/index.ts b/src/index.ts index fe9fe7e91..9a32d2f19 100644 --- a/src/index.ts +++ b/src/index.ts @@ -18,8 +18,8 @@ function mergeNamesakes(filtered: Browser.WebIdl) { } const { property } = i.properties!; for (const [prop] of Object.values(i.properties.namesakes)) { - if (prop) { - property[prop.name] = merge(property[prop.name] || {}, prop); + if (prop && !(prop.name in property)) { + property[prop.name] = prop; } } }