Skip to content

Commit ab3d46e

Browse files
saschanazsandersn
authored andcommitted
General type updates (#684)
* update worker types * simple value assigning
1 parent 17d343a commit ab3d46e

File tree

10 files changed

+108
-50
lines changed

10 files changed

+108
-50
lines changed

baselines/dom.generated.d.ts

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1714,14 +1714,15 @@ interface WebAuthnExtensions {
17141714
}
17151715

17161716
interface WebGLContextAttributes {
1717-
alpha?: GLboolean;
1718-
antialias?: GLboolean;
1719-
depth?: GLboolean;
1717+
alpha?: boolean;
1718+
antialias?: boolean;
1719+
depth?: boolean;
1720+
desynchronized?: boolean;
17201721
failIfMajorPerformanceCaveat?: boolean;
17211722
powerPreference?: WebGLPowerPreference;
1722-
premultipliedAlpha?: GLboolean;
1723-
preserveDrawingBuffer?: GLboolean;
1724-
stencil?: GLboolean;
1723+
premultipliedAlpha?: boolean;
1724+
preserveDrawingBuffer?: boolean;
1725+
stencil?: boolean;
17251726
}
17261727

17271728
interface WebGLContextEventInit extends EventInit {
@@ -1927,6 +1928,11 @@ declare var AnimationEvent: {
19271928
new(type: string, animationEventInitDict?: AnimationEventInit): AnimationEvent;
19281929
};
19291930

1931+
interface AnimationFrameProvider {
1932+
cancelAnimationFrame(handle: number): void;
1933+
requestAnimationFrame(callback: FrameRequestCallback): number;
1934+
}
1935+
19301936
interface AnimationPlaybackEvent extends Event {
19311937
readonly currentTime: number | null;
19321938
readonly timelineTime: number | null;
@@ -5346,6 +5352,11 @@ interface External {
53465352
IsSearchProviderInstalled(): void;
53475353
}
53485354

5355+
declare var External: {
5356+
prototype: External;
5357+
new(): External;
5358+
};
5359+
53495360
/** Provides information about files and allows JavaScript in a web page to access their content. */
53505361
interface File extends Blob {
53515362
readonly lastModified: number;
@@ -16599,7 +16610,7 @@ declare var WebGLRenderingContext: {
1659916610
};
1660016611

1660116612
interface WebGLRenderingContextBase {
16602-
readonly canvas: HTMLCanvasElement;
16613+
readonly canvas: HTMLCanvasElement | OffscreenCanvas;
1660316614
readonly drawingBufferHeight: GLsizei;
1660416615
readonly drawingBufferWidth: GLsizei;
1660516616
activeTexture(texture: GLenum): void;
@@ -17275,7 +17286,7 @@ interface WindowEventMap extends GlobalEventHandlersEventMap, WindowEventHandler
1727517286
}
1727617287

1727717288
/** A window containing a DOM document; the document property points to the DOM document loaded in that window. */
17278-
interface Window extends EventTarget, WindowTimers, WindowSessionStorage, WindowLocalStorage, WindowConsole, GlobalEventHandlers, IDBEnvironment, WindowBase64, WindowOrWorkerGlobalScope, WindowEventHandlers {
17289+
interface Window extends EventTarget, WindowTimers, WindowSessionStorage, WindowLocalStorage, WindowConsole, GlobalEventHandlers, IDBEnvironment, WindowBase64, AnimationFrameProvider, WindowOrWorkerGlobalScope, WindowEventHandlers {
1727917290
Blob: typeof Blob;
1728017291
TextDecoder: typeof TextDecoder;
1728117292
TextEncoder: typeof TextEncoder;
@@ -17370,7 +17381,6 @@ interface Window extends EventTarget, WindowTimers, WindowSessionStorage, Window
1737017381
readonly window: Window;
1737117382
alert(message?: any): void;
1737217383
blur(): void;
17373-
cancelAnimationFrame(handle: number): void;
1737417384
/** @deprecated */
1737517385
captureEvents(): void;
1737617386
close(): void;
@@ -17390,7 +17400,6 @@ interface Window extends EventTarget, WindowTimers, WindowSessionStorage, Window
1739017400
prompt(message?: string, _default?: string): string | null;
1739117401
/** @deprecated */
1739217402
releaseEvents(): void;
17393-
requestAnimationFrame(callback: FrameRequestCallback): number;
1739417403
resizeBy(x: number, y: number): void;
1739517404
resizeTo(x: number, y: number): void;
1739617405
scroll(options?: ScrollToOptions): void;
@@ -18366,7 +18375,6 @@ declare var top: Window;
1836618375
declare var window: Window;
1836718376
declare function alert(message?: any): void;
1836818377
declare function blur(): void;
18369-
declare function cancelAnimationFrame(handle: number): void;
1837018378
/** @deprecated */
1837118379
declare function captureEvents(): void;
1837218380
declare function close(): void;
@@ -18386,7 +18394,6 @@ declare function print(): void;
1838618394
declare function prompt(message?: string, _default?: string): string | null;
1838718395
/** @deprecated */
1838818396
declare function releaseEvents(): void;
18389-
declare function requestAnimationFrame(callback: FrameRequestCallback): number;
1839018397
declare function resizeBy(x: number, y: number): void;
1839118398
declare function resizeTo(x: number, y: number): void;
1839218399
declare function scroll(options?: ScrollToOptions): void;
@@ -18677,6 +18684,8 @@ declare var onwheel: ((this: Window, ev: WheelEvent) => any) | null;
1867718684
declare var indexedDB: IDBFactory;
1867818685
declare function atob(encodedString: string): string;
1867918686
declare function btoa(rawString: string): string;
18687+
declare function cancelAnimationFrame(handle: number): void;
18688+
declare function requestAnimationFrame(callback: FrameRequestCallback): number;
1868018689
declare var caches: CacheStorage;
1868118690
declare var crypto: Crypto;
1868218691
declare var indexedDB: IDBFactory;
@@ -18749,7 +18758,7 @@ type GLsizeiptr = number;
1874918758
type GLuint = number;
1875018759
type GLfloat = number;
1875118760
type GLclampf = number;
18752-
type TexImageSource = ImageBitmap | ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement;
18761+
type TexImageSource = ImageBitmap | ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | OffscreenCanvas;
1875318762
type Float32List = Float32Array | GLfloat[];
1875418763
type Int32List = Int32Array | GLint[];
1875518764
type BufferSource = ArrayBufferView | ArrayBuffer;

baselines/webworker.generated.d.ts

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -512,14 +512,15 @@ interface UnderlyingSource<R = any> {
512512
}
513513

514514
interface WebGLContextAttributes {
515-
alpha?: GLboolean;
516-
antialias?: GLboolean;
517-
depth?: GLboolean;
515+
alpha?: boolean;
516+
antialias?: boolean;
517+
depth?: boolean;
518+
desynchronized?: boolean;
518519
failIfMajorPerformanceCaveat?: boolean;
519520
powerPreference?: WebGLPowerPreference;
520-
premultipliedAlpha?: GLboolean;
521-
preserveDrawingBuffer?: GLboolean;
522-
stencil?: GLboolean;
521+
premultipliedAlpha?: boolean;
522+
preserveDrawingBuffer?: boolean;
523+
stencil?: boolean;
523524
}
524525

525526
interface WebGLContextEventInit extends EventInit {
@@ -603,6 +604,11 @@ interface AesCmacParams extends Algorithm {
603604
length: number;
604605
}
605606

607+
interface AnimationFrameProvider {
608+
cancelAnimationFrame(handle: number): void;
609+
requestAnimationFrame(callback: FrameRequestCallback): number;
610+
}
611+
606612
/** 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. */
607613
interface Blob {
608614
readonly size: number;
@@ -1232,7 +1238,7 @@ interface DedicatedWorkerGlobalScopeEventMap extends WorkerGlobalScopeEventMap {
12321238
}
12331239

12341240
/** (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. */
1235-
interface DedicatedWorkerGlobalScope extends WorkerGlobalScope {
1241+
interface DedicatedWorkerGlobalScope extends WorkerGlobalScope, AnimationFrameProvider {
12361242
onmessage: ((this: DedicatedWorkerGlobalScope, ev: MessageEvent) => any) | null;
12371243
close(): void;
12381244
postMessage(message: any, transfer: Transferable[]): void;
@@ -3708,6 +3714,7 @@ declare var WebGLRenderingContext: {
37083714
};
37093715

37103716
interface WebGLRenderingContextBase {
3717+
readonly canvas: OffscreenCanvas;
37113718
readonly drawingBufferHeight: GLsizei;
37123719
readonly drawingBufferWidth: GLsizei;
37133720
activeTexture(texture: GLenum): void;
@@ -4652,6 +4659,10 @@ interface EventHandlerNonNull {
46524659
(event: Event): any;
46534660
}
46544661

4662+
interface FrameRequestCallback {
4663+
(time: number): void;
4664+
}
4665+
46554666
interface PerformanceObserverCallback {
46564667
(entries: PerformanceObserverEntryList, observer: PerformanceObserver): void;
46574668
}
@@ -4737,6 +4748,8 @@ declare function fetch(input: RequestInfo, init?: RequestInit): Promise<Response
47374748
declare function queueMicrotask(callback: Function): void;
47384749
declare function setInterval(handler: TimerHandler, timeout?: number, ...arguments: any[]): number;
47394750
declare function setTimeout(handler: TimerHandler, timeout?: number, ...arguments: any[]): number;
4751+
declare function cancelAnimationFrame(handle: number): void;
4752+
declare function requestAnimationFrame(callback: FrameRequestCallback): number;
47404753
declare function addEventListener<K extends keyof DedicatedWorkerGlobalScopeEventMap>(type: K, listener: (this: DedicatedWorkerGlobalScope, ev: DedicatedWorkerGlobalScopeEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
47414754
declare function addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
47424755
declare function removeEventListener<K extends keyof DedicatedWorkerGlobalScopeEventMap>(type: K, listener: (this: DedicatedWorkerGlobalScope, ev: DedicatedWorkerGlobalScopeEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
@@ -4768,7 +4781,7 @@ type GLsizeiptr = number;
47684781
type GLuint = number;
47694782
type GLfloat = number;
47704783
type GLclampf = number;
4771-
type TexImageSource = ImageBitmap | ImageData;
4784+
type TexImageSource = ImageBitmap | ImageData | OffscreenCanvas;
47724785
type Float32List = Float32Array | GLfloat[];
47734786
type Int32List = Int32Array | GLint[];
47744787
type BufferSource = ArrayBufferView | ArrayBuffer;

inputfiles/addedTypes.json

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,19 +1083,6 @@
10831083
}
10841084
}
10851085
},
1086-
"Performance": {
1087-
"name": "Performance",
1088-
"properties": {
1089-
"events": {
1090-
"event": [
1091-
{
1092-
"name": "resourcetimingbufferfull",
1093-
"type": "Event"
1094-
}
1095-
]
1096-
}
1097-
}
1098-
},
10991086
"KeyboardEvent": {
11001087
"name": "KeyboardEvent",
11011088
"properties": {

inputfiles/idl/HTML - ImageBitmap and animations.widl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,12 @@ dictionary ImageBitmapOptions {
2222
[EnforceRange] unsigned long resizeHeight;
2323
ResizeQuality resizeQuality = "low";
2424
};
25+
26+
callback FrameRequestCallback = void (DOMHighResTimeStamp time);
27+
28+
interface mixin AnimationFrameProvider {
29+
unsigned long requestAnimationFrame(FrameRequestCallback callback);
30+
void cancelAnimationFrame(unsigned long handle);
31+
};
32+
Window includes AnimationFrameProvider;
33+
DedicatedWorkerGlobalScope includes AnimationFrameProvider;

inputfiles/idl/HTML - Obsolete features.widl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,7 @@ partial interface Window {
286286
[Replaceable, SameObject] readonly attribute External external;
287287
};
288288

289-
[Exposed=Window,
290-
NoInterfaceObject]
289+
[Exposed=Window]
291290
interface External {
292291
void AddSearchProvider();
293292
void IsSearchProviderInstalled();

inputfiles/idl/WebGL 1.widl

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// WebGL IDL definitions scraped from the Khronos specification:
44
// https://www.khronos.org/registry/webgl/specs/latest/
55

6-
// Copyright (c) 2018 The Khronos Group Inc.
6+
// Copyright (c) 2019 The Khronos Group Inc.
77
//
88
// Permission is hereby granted, free of charge, to any person obtaining a
99
// copy of this software and/or associated documentation files (the
@@ -46,14 +46,15 @@ enum WebGLPowerPreference { "default", "low-power", "high-performance" };
4646

4747

4848
dictionary WebGLContextAttributes {
49-
GLboolean alpha = true;
50-
GLboolean depth = true;
51-
GLboolean stencil = false;
52-
GLboolean antialias = true;
53-
GLboolean premultipliedAlpha = true;
54-
GLboolean preserveDrawingBuffer = false;
49+
boolean alpha = true;
50+
boolean depth = true;
51+
boolean stencil = false;
52+
boolean antialias = true;
53+
boolean premultipliedAlpha = true;
54+
boolean preserveDrawingBuffer = false;
5555
WebGLPowerPreference powerPreference = "default";
56-
GLboolean failIfMajorPerformanceCaveat = false;
56+
boolean failIfMajorPerformanceCaveat = false;
57+
boolean desynchronized = false;
5758
};
5859

5960
[Exposed=(Window,Worker)]
@@ -106,7 +107,8 @@ typedef (ImageBitmap or
106107
ImageData or
107108
HTMLImageElement or
108109
HTMLCanvasElement or
109-
HTMLVideoElement) TexImageSource;
110+
HTMLVideoElement or
111+
OffscreenCanvas) TexImageSource;
110112

111113
typedef ([AllowShared] Float32Array or sequence<GLfloat>) Float32List;
112114
typedef ([AllowShared] Int32Array or sequence<GLint>) Int32List;
@@ -532,7 +534,8 @@ interface mixin WebGLRenderingContextBase
532534
const GLenum UNPACK_COLORSPACE_CONVERSION_WEBGL = 0x9243;
533535
const GLenum BROWSER_DEFAULT_WEBGL = 0x9244;
534536

535-
[Exposed=Window] readonly attribute HTMLCanvasElement canvas;
537+
[Exposed=Window] readonly attribute (HTMLCanvasElement or OffscreenCanvas) canvas;
538+
[Exposed=Worker] readonly attribute OffscreenCanvas canvas;
536539
readonly attribute GLsizei drawingBufferWidth;
537540
readonly attribute GLsizei drawingBufferHeight;
538541

inputfiles/removedTypes.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,12 @@
246246
"ontouchstart": null
247247
}
248248
},
249+
"methods": {
250+
"method": {
251+
"cancelAnimationFrame": null,
252+
"requestAnimationFrame": null
253+
}
254+
},
249255
"implements": [
250256
"GlobalFetch"
251257
]

src/index.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,36 @@ import { Flavor, emitWebIdl } from "./emitter";
66
import { convert } from "./widlprocess";
77
import { getExposedTypes } from "./expose";
88

9+
function mergeNamesakes(filtered: Browser.WebIdl) {
10+
const targets = [
11+
...Object.values(filtered.interfaces!.interface),
12+
...Object.values(filtered.mixins!.mixin),
13+
...filtered.namespaces!
14+
];
15+
for (const i of targets) {
16+
if (!i.properties || !i.properties.namesakes) {
17+
continue;
18+
}
19+
const { property } = i.properties!;
20+
for (const [prop] of Object.values(i.properties.namesakes)) {
21+
if (prop && !(prop.name in property)) {
22+
property[prop.name] = prop;
23+
}
24+
}
25+
}
26+
}
27+
928
function emitDomWorker(webidl: Browser.WebIdl, tsWorkerOutput: string, forceKnownWorkerTypes: Set<string>) {
1029
const worker = getExposedTypes(webidl, "Worker", forceKnownWorkerTypes);
30+
mergeNamesakes(worker);
1131
const result = emitWebIdl(worker, Flavor.Worker);
1232
fs.writeFileSync(tsWorkerOutput, result);
1333
return;
1434
}
1535

1636
function emitDomWeb(webidl: Browser.WebIdl, tsWebOutput: string, forceKnownWindowTypes: Set<string>) {
1737
const browser = getExposedTypes(webidl, "Window", forceKnownWindowTypes);
18-
38+
mergeNamesakes(browser);
1939
const result = emitWebIdl(browser, Flavor.Web);
2040
fs.writeFileSync(tsWebOutput, result);
2141
return;

src/types.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ export interface Interface {
166166
}
167167
properties?: {
168168
property: Record<string, Property>;
169+
namesakes?: Record<string, Property[]>;
169170
}
170171
constructor?: Constructor;
171172
"secure-context"?: 1;

src/widlprocess.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ function convertInterfaceCommon(i: webidl2.InterfaceType | webidl2.InterfaceMixi
112112
constants: { constant: {} },
113113
methods: { method: {} },
114114
"anonymous-methods": { method: [] },
115-
properties: { property: {} },
115+
properties: { property: {}, namesakes: {} },
116116
constructor: getConstructor(i.extAttrs, i.name),
117117
"named-constructor": getNamedConstructor(i.extAttrs, i.name),
118118
exposed: getExtAttrConcatenated(i.extAttrs, "Exposed"),
@@ -130,8 +130,19 @@ function convertInterfaceCommon(i: webidl2.InterfaceType | webidl2.InterfaceMixi
130130
addComments(result.constants!.constant[member.name], commentMap, i.name, member.name);
131131
}
132132
else if (member.type === "attribute") {
133-
result.properties!.property[member.name] = convertAttribute(member, result.exposed);
134-
addComments(result.properties!.property[member.name], commentMap, i.name, member.name);
133+
const { properties } = result;
134+
const prop = convertAttribute(member, result.exposed);
135+
addComments(prop, commentMap, i.name, member.name);
136+
137+
if (member.name in properties!.namesakes!) {
138+
properties!.namesakes![member.name].push(prop);
139+
} else if (member.name in properties!.property) {
140+
const existing = properties!.property[member.name];
141+
delete properties!.property[member.name];
142+
properties!.namesakes![member.name] = [existing, prop];
143+
} else {
144+
properties!.property[member.name] = prop;
145+
}
135146
}
136147
else if (member.type === "operation" && member.idlType) {
137148
const operation = convertOperation(member, result.exposed);

0 commit comments

Comments
 (0)