Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 22 additions & 13 deletions baselines/dom.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
29 changes: 21 additions & 8 deletions baselines/webworker.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -512,14 +512,15 @@ interface UnderlyingSource<R = any> {
}

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 {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -3708,6 +3714,7 @@ declare var WebGLRenderingContext: {
};

interface WebGLRenderingContextBase {
readonly canvas: OffscreenCanvas;
readonly drawingBufferHeight: GLsizei;
readonly drawingBufferWidth: GLsizei;
activeTexture(texture: GLenum): void;
Expand Down Expand Up @@ -4652,6 +4659,10 @@ interface EventHandlerNonNull {
(event: Event): any;
}

interface FrameRequestCallback {
(time: number): void;
}

interface PerformanceObserverCallback {
(entries: PerformanceObserverEntryList, observer: PerformanceObserver): void;
}
Expand Down Expand Up @@ -4737,6 +4748,8 @@ declare function fetch(input: RequestInfo, init?: RequestInit): Promise<Response
declare function queueMicrotask(callback: Function): void;
declare function setInterval(handler: TimerHandler, timeout?: number, ...arguments: any[]): number;
declare function setTimeout(handler: TimerHandler, timeout?: number, ...arguments: any[]): number;
declare function cancelAnimationFrame(handle: number): void;
declare function requestAnimationFrame(callback: FrameRequestCallback): number;
declare function addEventListener<K extends keyof DedicatedWorkerGlobalScopeEventMap>(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<K extends keyof DedicatedWorkerGlobalScopeEventMap>(type: K, listener: (this: DedicatedWorkerGlobalScope, ev: DedicatedWorkerGlobalScopeEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
Expand Down Expand Up @@ -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;
Expand Down
13 changes: 0 additions & 13 deletions inputfiles/addedTypes.json
Original file line number Diff line number Diff line change
Expand Up @@ -1083,19 +1083,6 @@
}
}
},
"Performance": {
"name": "Performance",
"properties": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is just a bugfix right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was my intention but looks like this is completely redundant. I'll remove this.

"events": {
"event": [
{
"name": "resourcetimingbufferfull",
"type": "Event"
}
]
}
}
},
"KeyboardEvent": {
"name": "KeyboardEvent",
"properties": {
Expand Down
9 changes: 9 additions & 0 deletions inputfiles/idl/HTML - ImageBitmap and animations.widl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
3 changes: 1 addition & 2 deletions inputfiles/idl/HTML - Obsolete features.widl
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,7 @@ partial interface Window {
[Replaceable, SameObject] readonly attribute External external;
};

[Exposed=Window,
NoInterfaceObject]
[Exposed=Window]
interface External {
void AddSearchProvider();
void IsSearchProviderInstalled();
Expand Down
23 changes: 13 additions & 10 deletions inputfiles/idl/WebGL 1.widl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -106,7 +107,8 @@ typedef (ImageBitmap or
ImageData or
HTMLImageElement or
HTMLCanvasElement or
HTMLVideoElement) TexImageSource;
HTMLVideoElement or
OffscreenCanvas) TexImageSource;

typedef ([AllowShared] Float32Array or sequence<GLfloat>) Float32List;
typedef ([AllowShared] Int32Array or sequence<GLint>) Int32List;
Expand Down Expand Up @@ -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;

Expand Down
6 changes: 6 additions & 0 deletions inputfiles/removedTypes.json
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,12 @@
"ontouchstart": null
}
},
"methods": {
"method": {
"cancelAnimationFrame": null,
"requestAnimationFrame": null
}
},
"implements": [
"GlobalFetch"
]
Expand Down
22 changes: 21 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,36 @@ 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<string>) {
const worker = getExposedTypes(webidl, "Worker", forceKnownWorkerTypes);
mergeNamesakes(worker);
const result = emitWebIdl(worker, Flavor.Worker);
fs.writeFileSync(tsWorkerOutput, result);
return;
}

function emitDomWeb(webidl: Browser.WebIdl, tsWebOutput: string, forceKnownWindowTypes: Set<string>) {
const browser = getExposedTypes(webidl, "Window", forceKnownWindowTypes);

mergeNamesakes(browser);
const result = emitWebIdl(browser, Flavor.Web);
fs.writeFileSync(tsWebOutput, result);
return;
Expand Down
1 change: 1 addition & 0 deletions src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ export interface Interface {
}
properties?: {
property: Record<string, Property>;
namesakes?: Record<string, Property[]>;
}
constructor?: Constructor;
"secure-context"?: 1;
Expand Down
17 changes: 14 additions & 3 deletions src/widlprocess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks like this can happen more than once, but the code in mergeNamesakes assumes there's only one entry in each namesakes in line 20: for (const [prop] of .... Is that correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, because in line 20 the namesakes value is already filtered by exposure ([Exposed] in IDL).

} 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);
Expand Down