Skip to content

Commit 3bd4988

Browse files
committed
feat(WebAssembly): Make WebAssembly.Global generic
1 parent c7f8137 commit 3bd4988

9 files changed

+189
-46
lines changed

baselines/audioworklet.generated.d.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -439,14 +439,14 @@ declare namespace WebAssembly {
439439
(message?: string): CompileError;
440440
};
441441

442-
interface Global {
443-
value: any;
444-
valueOf(): any;
442+
interface Global<T extends ValueType = ValueType> {
443+
value: ValueTypeMap[T];
444+
valueOf(): ValueTypeMap[T];
445445
}
446446

447447
var Global: {
448448
prototype: Global;
449-
new(descriptor: GlobalDescriptor, v?: any): Global;
449+
new<T extends ValueType = ValueType>(descriptor: GlobalDescriptor<T>, v?: ValueTypeMap[T]): Global<T>;
450450
};
451451

452452
interface Instance {
@@ -509,9 +509,9 @@ declare namespace WebAssembly {
509509
new(descriptor: TableDescriptor, value?: any): Table;
510510
};
511511

512-
interface GlobalDescriptor {
512+
interface GlobalDescriptor<T extends ValueType = ValueType> {
513513
mutable?: boolean;
514-
value: ValueType;
514+
value: T;
515515
}
516516

517517
interface MemoryDescriptor {
@@ -537,19 +537,28 @@ declare namespace WebAssembly {
537537
maximum?: number;
538538
}
539539

540+
interface ValueTypeMap {
541+
anyfunc: Function;
542+
externref: any;
543+
f32: number;
544+
f64: number;
545+
i32: number;
546+
i64: bigint;
547+
}
548+
540549
interface WebAssemblyInstantiatedSource {
541550
instance: Instance;
542551
module: Module;
543552
}
544553

545554
type ImportExportKind = "function" | "global" | "memory" | "table";
546555
type TableKind = "anyfunc" | "externref";
547-
type ValueType = "anyfunc" | "externref" | "f32" | "f64" | "i32" | "i64";
548556
type ExportValue = Function | Global | Memory | Table;
549557
type Exports = Record<string, ExportValue>;
550558
type ImportValue = ExportValue | number;
551559
type Imports = Record<string, ModuleImports>;
552560
type ModuleImports = Record<string, ImportValue>;
561+
type ValueType = keyof ValueTypeMap;
553562
function compile(bytes: BufferSource): Promise<Module>;
554563
function instantiate(bytes: BufferSource, importObject?: Imports): Promise<WebAssemblyInstantiatedSource>;
555564
function instantiate(moduleObject: Module, importObject?: Imports): Promise<Instance>;

baselines/dom.generated.d.ts

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1936,7 +1936,7 @@ interface AnimationEventMap {
19361936
}
19371937

19381938
interface Animation extends EventTarget {
1939-
currentTime: number | null;
1939+
currentTime: CSSNumberish | null;
19401940
effect: AnimationEffect | null;
19411941
readonly finished: Promise<Animation>;
19421942
id: string;
@@ -1948,7 +1948,7 @@ interface Animation extends EventTarget {
19481948
playbackRate: number;
19491949
readonly ready: Promise<Animation>;
19501950
readonly replaceState: AnimationReplaceState;
1951-
startTime: number | null;
1951+
startTime: CSSNumberish | null;
19521952
timeline: AnimationTimeline | null;
19531953
cancel(): void;
19541954
commitStyles(): void;
@@ -5652,7 +5652,7 @@ interface GlobalEventHandlers {
56525652
* @param ev The event.
56535653
*/
56545654
onwaiting: ((this: GlobalEventHandlers, ev: Event) => any) | null;
5655-
/** @deprecated This is a legacy alias of `onanimationend`. */
5655+
/** @deprecated This is a legacy alias of `onanimationstart`. */
56565656
onwebkitanimationend: ((this: GlobalEventHandlers, ev: Event) => any) | null;
56575657
/** @deprecated This is a legacy alias of `onanimationiteration`. */
56585658
onwebkitanimationiteration: ((this: GlobalEventHandlers, ev: Event) => any) | null;
@@ -8622,6 +8622,14 @@ interface InnerHTML {
86228622
innerHTML: string;
86238623
}
86248624

8625+
interface InputDeviceInfo extends MediaDeviceInfo {
8626+
}
8627+
8628+
declare var InputDeviceInfo: {
8629+
prototype: InputDeviceInfo;
8630+
new(): InputDeviceInfo;
8631+
};
8632+
86258633
interface InputEvent extends UIEvent {
86268634
readonly data: string | null;
86278635
readonly dataTransfer: DataTransfer | null;
@@ -16559,14 +16567,14 @@ declare namespace WebAssembly {
1655916567
(message?: string): CompileError;
1656016568
};
1656116569

16562-
interface Global {
16563-
value: any;
16564-
valueOf(): any;
16570+
interface Global<T extends ValueType = ValueType> {
16571+
value: ValueTypeMap[T];
16572+
valueOf(): ValueTypeMap[T];
1656516573
}
1656616574

1656716575
var Global: {
1656816576
prototype: Global;
16569-
new(descriptor: GlobalDescriptor, v?: any): Global;
16577+
new<T extends ValueType = ValueType>(descriptor: GlobalDescriptor<T>, v?: ValueTypeMap[T]): Global<T>;
1657016578
};
1657116579

1657216580
interface Instance {
@@ -16629,9 +16637,9 @@ declare namespace WebAssembly {
1662916637
new(descriptor: TableDescriptor, value?: any): Table;
1663016638
};
1663116639

16632-
interface GlobalDescriptor {
16640+
interface GlobalDescriptor<T extends ValueType = ValueType> {
1663316641
mutable?: boolean;
16634-
value: ValueType;
16642+
value: T;
1663516643
}
1663616644

1663716645
interface MemoryDescriptor {
@@ -16657,19 +16665,28 @@ declare namespace WebAssembly {
1665716665
maximum?: number;
1665816666
}
1665916667

16668+
interface ValueTypeMap {
16669+
anyfunc: Function;
16670+
externref: any;
16671+
f32: number;
16672+
f64: number;
16673+
i32: number;
16674+
i64: bigint;
16675+
}
16676+
1666016677
interface WebAssemblyInstantiatedSource {
1666116678
instance: Instance;
1666216679
module: Module;
1666316680
}
1666416681

1666516682
type ImportExportKind = "function" | "global" | "memory" | "table";
1666616683
type TableKind = "anyfunc" | "externref";
16667-
type ValueType = "anyfunc" | "externref" | "f32" | "f64" | "i32" | "i64";
1666816684
type ExportValue = Function | Global | Memory | Table;
1666916685
type Exports = Record<string, ExportValue>;
1667016686
type ImportValue = ExportValue | number;
1667116687
type Imports = Record<string, ModuleImports>;
1667216688
type ModuleImports = Record<string, ImportValue>;
16689+
type ValueType = keyof ValueTypeMap;
1667316690
function compile(bytes: BufferSource): Promise<Module>;
1667416691
function compileStreaming(source: Response | PromiseLike<Response>): Promise<Module>;
1667516692
function instantiate(bytes: BufferSource, importObject?: Imports): Promise<WebAssemblyInstantiatedSource>;
@@ -17404,7 +17421,7 @@ declare var onvolumechange: ((this: Window, ev: Event) => any) | null;
1740417421
* @param ev The event.
1740517422
*/
1740617423
declare var onwaiting: ((this: Window, ev: Event) => any) | null;
17407-
/** @deprecated This is a legacy alias of `onanimationend`. */
17424+
/** @deprecated This is a legacy alias of `onanimationstart`. */
1740817425
declare var onwebkitanimationend: ((this: Window, ev: Event) => any) | null;
1740917426
/** @deprecated This is a legacy alias of `onanimationiteration`. */
1741017427
declare var onwebkitanimationiteration: ((this: Window, ev: Event) => any) | null;

baselines/serviceworker.generated.d.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5112,14 +5112,14 @@ declare namespace WebAssembly {
51125112
(message?: string): CompileError;
51135113
};
51145114

5115-
interface Global {
5116-
value: any;
5117-
valueOf(): any;
5115+
interface Global<T extends ValueType = ValueType> {
5116+
value: ValueTypeMap[T];
5117+
valueOf(): ValueTypeMap[T];
51185118
}
51195119

51205120
var Global: {
51215121
prototype: Global;
5122-
new(descriptor: GlobalDescriptor, v?: any): Global;
5122+
new<T extends ValueType = ValueType>(descriptor: GlobalDescriptor<T>, v?: ValueTypeMap[T]): Global<T>;
51235123
};
51245124

51255125
interface Instance {
@@ -5182,9 +5182,9 @@ declare namespace WebAssembly {
51825182
new(descriptor: TableDescriptor, value?: any): Table;
51835183
};
51845184

5185-
interface GlobalDescriptor {
5185+
interface GlobalDescriptor<T extends ValueType = ValueType> {
51865186
mutable?: boolean;
5187-
value: ValueType;
5187+
value: T;
51885188
}
51895189

51905190
interface MemoryDescriptor {
@@ -5210,19 +5210,28 @@ declare namespace WebAssembly {
52105210
maximum?: number;
52115211
}
52125212

5213+
interface ValueTypeMap {
5214+
anyfunc: Function;
5215+
externref: any;
5216+
f32: number;
5217+
f64: number;
5218+
i32: number;
5219+
i64: bigint;
5220+
}
5221+
52135222
interface WebAssemblyInstantiatedSource {
52145223
instance: Instance;
52155224
module: Module;
52165225
}
52175226

52185227
type ImportExportKind = "function" | "global" | "memory" | "table";
52195228
type TableKind = "anyfunc" | "externref";
5220-
type ValueType = "anyfunc" | "externref" | "f32" | "f64" | "i32" | "i64";
52215229
type ExportValue = Function | Global | Memory | Table;
52225230
type Exports = Record<string, ExportValue>;
52235231
type ImportValue = ExportValue | number;
52245232
type Imports = Record<string, ModuleImports>;
52255233
type ModuleImports = Record<string, ImportValue>;
5234+
type ValueType = keyof ValueTypeMap;
52265235
function compile(bytes: BufferSource): Promise<Module>;
52275236
function compileStreaming(source: Response | PromiseLike<Response>): Promise<Module>;
52285237
function instantiate(bytes: BufferSource, importObject?: Imports): Promise<WebAssemblyInstantiatedSource>;

baselines/sharedworker.generated.d.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5141,14 +5141,14 @@ declare namespace WebAssembly {
51415141
(message?: string): CompileError;
51425142
};
51435143

5144-
interface Global {
5145-
value: any;
5146-
valueOf(): any;
5144+
interface Global<T extends ValueType = ValueType> {
5145+
value: ValueTypeMap[T];
5146+
valueOf(): ValueTypeMap[T];
51475147
}
51485148

51495149
var Global: {
51505150
prototype: Global;
5151-
new(descriptor: GlobalDescriptor, v?: any): Global;
5151+
new<T extends ValueType = ValueType>(descriptor: GlobalDescriptor<T>, v?: ValueTypeMap[T]): Global<T>;
51525152
};
51535153

51545154
interface Instance {
@@ -5211,9 +5211,9 @@ declare namespace WebAssembly {
52115211
new(descriptor: TableDescriptor, value?: any): Table;
52125212
};
52135213

5214-
interface GlobalDescriptor {
5214+
interface GlobalDescriptor<T extends ValueType = ValueType> {
52155215
mutable?: boolean;
5216-
value: ValueType;
5216+
value: T;
52175217
}
52185218

52195219
interface MemoryDescriptor {
@@ -5239,19 +5239,28 @@ declare namespace WebAssembly {
52395239
maximum?: number;
52405240
}
52415241

5242+
interface ValueTypeMap {
5243+
anyfunc: Function;
5244+
externref: any;
5245+
f32: number;
5246+
f64: number;
5247+
i32: number;
5248+
i64: bigint;
5249+
}
5250+
52425251
interface WebAssemblyInstantiatedSource {
52435252
instance: Instance;
52445253
module: Module;
52455254
}
52465255

52475256
type ImportExportKind = "function" | "global" | "memory" | "table";
52485257
type TableKind = "anyfunc" | "externref";
5249-
type ValueType = "anyfunc" | "externref" | "f32" | "f64" | "i32" | "i64";
52505258
type ExportValue = Function | Global | Memory | Table;
52515259
type Exports = Record<string, ExportValue>;
52525260
type ImportValue = ExportValue | number;
52535261
type Imports = Record<string, ModuleImports>;
52545262
type ModuleImports = Record<string, ImportValue>;
5263+
type ValueType = keyof ValueTypeMap;
52555264
function compile(bytes: BufferSource): Promise<Module>;
52565265
function compileStreaming(source: Response | PromiseLike<Response>): Promise<Module>;
52575266
function instantiate(bytes: BufferSource, importObject?: Imports): Promise<WebAssemblyInstantiatedSource>;

baselines/webworker.generated.d.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5355,14 +5355,14 @@ declare namespace WebAssembly {
53555355
(message?: string): CompileError;
53565356
};
53575357

5358-
interface Global {
5359-
value: any;
5360-
valueOf(): any;
5358+
interface Global<T extends ValueType = ValueType> {
5359+
value: ValueTypeMap[T];
5360+
valueOf(): ValueTypeMap[T];
53615361
}
53625362

53635363
var Global: {
53645364
prototype: Global;
5365-
new(descriptor: GlobalDescriptor, v?: any): Global;
5365+
new<T extends ValueType = ValueType>(descriptor: GlobalDescriptor<T>, v?: ValueTypeMap[T]): Global<T>;
53665366
};
53675367

53685368
interface Instance {
@@ -5425,9 +5425,9 @@ declare namespace WebAssembly {
54255425
new(descriptor: TableDescriptor, value?: any): Table;
54265426
};
54275427

5428-
interface GlobalDescriptor {
5428+
interface GlobalDescriptor<T extends ValueType = ValueType> {
54295429
mutable?: boolean;
5430-
value: ValueType;
5430+
value: T;
54315431
}
54325432

54335433
interface MemoryDescriptor {
@@ -5453,19 +5453,28 @@ declare namespace WebAssembly {
54535453
maximum?: number;
54545454
}
54555455

5456+
interface ValueTypeMap {
5457+
anyfunc: Function;
5458+
externref: any;
5459+
f32: number;
5460+
f64: number;
5461+
i32: number;
5462+
i64: bigint;
5463+
}
5464+
54565465
interface WebAssemblyInstantiatedSource {
54575466
instance: Instance;
54585467
module: Module;
54595468
}
54605469

54615470
type ImportExportKind = "function" | "global" | "memory" | "table";
54625471
type TableKind = "anyfunc" | "externref";
5463-
type ValueType = "anyfunc" | "externref" | "f32" | "f64" | "i32" | "i64";
54645472
type ExportValue = Function | Global | Memory | Table;
54655473
type Exports = Record<string, ExportValue>;
54665474
type ImportValue = ExportValue | number;
54675475
type Imports = Record<string, ModuleImports>;
54685476
type ModuleImports = Record<string, ImportValue>;
5477+
type ValueType = keyof ValueTypeMap;
54695478
function compile(bytes: BufferSource): Promise<Module>;
54705479
function compileStreaming(source: Response | PromiseLike<Response>): Promise<Module>;
54715480
function instantiate(bytes: BufferSource, importObject?: Imports): Promise<WebAssemblyInstantiatedSource>;

0 commit comments

Comments
 (0)