Skip to content

Commit 63a13ca

Browse files
authored
feat(WebAssembly): Make WebAssembly.Global generic (#963)
* feat(WebAssembly): Make `WebAssembly.Global` generic * fixup! feat(WebAssembly): Make `WebAssembly.Global` generic * fixup! feat(WebAssembly): Make `WebAssembly.Global` generic
1 parent aa27e37 commit 63a13ca

9 files changed

+186
-41
lines changed

baselines/audioworklet.generated.d.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,16 +1193,16 @@ declare namespace WebAssembly {
11931193
};
11941194

11951195
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global) */
1196-
interface Global {
1196+
interface Global<T extends ValueType = ValueType> {
11971197
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global/value) */
1198-
value: any;
1198+
value: ValueTypeMap[T];
11991199
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global/valueOf) */
1200-
valueOf(): any;
1200+
valueOf(): ValueTypeMap[T];
12011201
}
12021202

12031203
var Global: {
12041204
prototype: Global;
1205-
new(descriptor: GlobalDescriptor, v?: any): Global;
1205+
new<T extends ValueType = ValueType>(descriptor: GlobalDescriptor<T>, v?: ValueTypeMap[T]): Global<T>;
12061206
};
12071207

12081208
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance) */
@@ -1279,9 +1279,9 @@ declare namespace WebAssembly {
12791279
new(descriptor: TableDescriptor, value?: any): Table;
12801280
};
12811281

1282-
interface GlobalDescriptor {
1282+
interface GlobalDescriptor<T extends ValueType = ValueType> {
12831283
mutable?: boolean;
1284-
value: ValueType;
1284+
value: T;
12851285
}
12861286

12871287
interface MemoryDescriptor {
@@ -1307,19 +1307,29 @@ declare namespace WebAssembly {
13071307
maximum?: number;
13081308
}
13091309

1310+
interface ValueTypeMap {
1311+
anyfunc: Function;
1312+
externref: any;
1313+
f32: number;
1314+
f64: number;
1315+
i32: number;
1316+
i64: bigint;
1317+
v128: never;
1318+
}
1319+
13101320
interface WebAssemblyInstantiatedSource {
13111321
instance: Instance;
13121322
module: Module;
13131323
}
13141324

13151325
type ImportExportKind = "function" | "global" | "memory" | "table";
13161326
type TableKind = "anyfunc" | "externref";
1317-
type ValueType = "anyfunc" | "externref" | "f32" | "f64" | "i32" | "i64" | "v128";
13181327
type ExportValue = Function | Global | Memory | Table;
13191328
type Exports = Record<string, ExportValue>;
13201329
type ImportValue = ExportValue | number;
13211330
type Imports = Record<string, ModuleImports>;
13221331
type ModuleImports = Record<string, ImportValue>;
1332+
type ValueType = keyof ValueTypeMap;
13231333
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compile) */
13241334
function compile(bytes: BufferSource): Promise<Module>;
13251335
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate) */

baselines/dom.generated.d.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26382,16 +26382,16 @@ declare namespace WebAssembly {
2638226382
};
2638326383

2638426384
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global) */
26385-
interface Global {
26385+
interface Global<T extends ValueType = ValueType> {
2638626386
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global/value) */
26387-
value: any;
26387+
value: ValueTypeMap[T];
2638826388
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global/valueOf) */
26389-
valueOf(): any;
26389+
valueOf(): ValueTypeMap[T];
2639026390
}
2639126391

2639226392
var Global: {
2639326393
prototype: Global;
26394-
new(descriptor: GlobalDescriptor, v?: any): Global;
26394+
new<T extends ValueType = ValueType>(descriptor: GlobalDescriptor<T>, v?: ValueTypeMap[T]): Global<T>;
2639526395
};
2639626396

2639726397
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance) */
@@ -26468,9 +26468,9 @@ declare namespace WebAssembly {
2646826468
new(descriptor: TableDescriptor, value?: any): Table;
2646926469
};
2647026470

26471-
interface GlobalDescriptor {
26471+
interface GlobalDescriptor<T extends ValueType = ValueType> {
2647226472
mutable?: boolean;
26473-
value: ValueType;
26473+
value: T;
2647426474
}
2647526475

2647626476
interface MemoryDescriptor {
@@ -26496,19 +26496,29 @@ declare namespace WebAssembly {
2649626496
maximum?: number;
2649726497
}
2649826498

26499+
interface ValueTypeMap {
26500+
anyfunc: Function;
26501+
externref: any;
26502+
f32: number;
26503+
f64: number;
26504+
i32: number;
26505+
i64: bigint;
26506+
v128: never;
26507+
}
26508+
2649926509
interface WebAssemblyInstantiatedSource {
2650026510
instance: Instance;
2650126511
module: Module;
2650226512
}
2650326513

2650426514
type ImportExportKind = "function" | "global" | "memory" | "table";
2650526515
type TableKind = "anyfunc" | "externref";
26506-
type ValueType = "anyfunc" | "externref" | "f32" | "f64" | "i32" | "i64" | "v128";
2650726516
type ExportValue = Function | Global | Memory | Table;
2650826517
type Exports = Record<string, ExportValue>;
2650926518
type ImportValue = ExportValue | number;
2651026519
type Imports = Record<string, ModuleImports>;
2651126520
type ModuleImports = Record<string, ImportValue>;
26521+
type ValueType = keyof ValueTypeMap;
2651226522
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compile) */
2651326523
function compile(bytes: BufferSource): Promise<Module>;
2651426524
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compileStreaming) */

baselines/serviceworker.generated.d.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8035,16 +8035,16 @@ declare namespace WebAssembly {
80358035
};
80368036

80378037
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global) */
8038-
interface Global {
8038+
interface Global<T extends ValueType = ValueType> {
80398039
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global/value) */
8040-
value: any;
8040+
value: ValueTypeMap[T];
80418041
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global/valueOf) */
8042-
valueOf(): any;
8042+
valueOf(): ValueTypeMap[T];
80438043
}
80448044

80458045
var Global: {
80468046
prototype: Global;
8047-
new(descriptor: GlobalDescriptor, v?: any): Global;
8047+
new<T extends ValueType = ValueType>(descriptor: GlobalDescriptor<T>, v?: ValueTypeMap[T]): Global<T>;
80488048
};
80498049

80508050
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance) */
@@ -8121,9 +8121,9 @@ declare namespace WebAssembly {
81218121
new(descriptor: TableDescriptor, value?: any): Table;
81228122
};
81238123

8124-
interface GlobalDescriptor {
8124+
interface GlobalDescriptor<T extends ValueType = ValueType> {
81258125
mutable?: boolean;
8126-
value: ValueType;
8126+
value: T;
81278127
}
81288128

81298129
interface MemoryDescriptor {
@@ -8149,19 +8149,29 @@ declare namespace WebAssembly {
81498149
maximum?: number;
81508150
}
81518151

8152+
interface ValueTypeMap {
8153+
anyfunc: Function;
8154+
externref: any;
8155+
f32: number;
8156+
f64: number;
8157+
i32: number;
8158+
i64: bigint;
8159+
v128: never;
8160+
}
8161+
81528162
interface WebAssemblyInstantiatedSource {
81538163
instance: Instance;
81548164
module: Module;
81558165
}
81568166

81578167
type ImportExportKind = "function" | "global" | "memory" | "table";
81588168
type TableKind = "anyfunc" | "externref";
8159-
type ValueType = "anyfunc" | "externref" | "f32" | "f64" | "i32" | "i64" | "v128";
81608169
type ExportValue = Function | Global | Memory | Table;
81618170
type Exports = Record<string, ExportValue>;
81628171
type ImportValue = ExportValue | number;
81638172
type Imports = Record<string, ModuleImports>;
81648173
type ModuleImports = Record<string, ImportValue>;
8174+
type ValueType = keyof ValueTypeMap;
81658175
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compile) */
81668176
function compile(bytes: BufferSource): Promise<Module>;
81678177
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compileStreaming) */

baselines/sharedworker.generated.d.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8055,16 +8055,16 @@ declare namespace WebAssembly {
80558055
};
80568056

80578057
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global) */
8058-
interface Global {
8058+
interface Global<T extends ValueType = ValueType> {
80598059
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global/value) */
8060-
value: any;
8060+
value: ValueTypeMap[T];
80618061
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global/valueOf) */
8062-
valueOf(): any;
8062+
valueOf(): ValueTypeMap[T];
80638063
}
80648064

80658065
var Global: {
80668066
prototype: Global;
8067-
new(descriptor: GlobalDescriptor, v?: any): Global;
8067+
new<T extends ValueType = ValueType>(descriptor: GlobalDescriptor<T>, v?: ValueTypeMap[T]): Global<T>;
80688068
};
80698069

80708070
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance) */
@@ -8141,9 +8141,9 @@ declare namespace WebAssembly {
81418141
new(descriptor: TableDescriptor, value?: any): Table;
81428142
};
81438143

8144-
interface GlobalDescriptor {
8144+
interface GlobalDescriptor<T extends ValueType = ValueType> {
81458145
mutable?: boolean;
8146-
value: ValueType;
8146+
value: T;
81478147
}
81488148

81498149
interface MemoryDescriptor {
@@ -8169,19 +8169,29 @@ declare namespace WebAssembly {
81698169
maximum?: number;
81708170
}
81718171

8172+
interface ValueTypeMap {
8173+
anyfunc: Function;
8174+
externref: any;
8175+
f32: number;
8176+
f64: number;
8177+
i32: number;
8178+
i64: bigint;
8179+
v128: never;
8180+
}
8181+
81728182
interface WebAssemblyInstantiatedSource {
81738183
instance: Instance;
81748184
module: Module;
81758185
}
81768186

81778187
type ImportExportKind = "function" | "global" | "memory" | "table";
81788188
type TableKind = "anyfunc" | "externref";
8179-
type ValueType = "anyfunc" | "externref" | "f32" | "f64" | "i32" | "i64" | "v128";
81808189
type ExportValue = Function | Global | Memory | Table;
81818190
type Exports = Record<string, ExportValue>;
81828191
type ImportValue = ExportValue | number;
81838192
type Imports = Record<string, ModuleImports>;
81848193
type ModuleImports = Record<string, ImportValue>;
8194+
type ValueType = keyof ValueTypeMap;
81858195
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compile) */
81868196
function compile(bytes: BufferSource): Promise<Module>;
81878197
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compileStreaming) */

baselines/webworker.generated.d.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8701,16 +8701,16 @@ declare namespace WebAssembly {
87018701
};
87028702

87038703
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global) */
8704-
interface Global {
8704+
interface Global<T extends ValueType = ValueType> {
87058705
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global/value) */
8706-
value: any;
8706+
value: ValueTypeMap[T];
87078707
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global/valueOf) */
8708-
valueOf(): any;
8708+
valueOf(): ValueTypeMap[T];
87098709
}
87108710

87118711
var Global: {
87128712
prototype: Global;
8713-
new(descriptor: GlobalDescriptor, v?: any): Global;
8713+
new<T extends ValueType = ValueType>(descriptor: GlobalDescriptor<T>, v?: ValueTypeMap[T]): Global<T>;
87148714
};
87158715

87168716
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance) */
@@ -8787,9 +8787,9 @@ declare namespace WebAssembly {
87878787
new(descriptor: TableDescriptor, value?: any): Table;
87888788
};
87898789

8790-
interface GlobalDescriptor {
8790+
interface GlobalDescriptor<T extends ValueType = ValueType> {
87918791
mutable?: boolean;
8792-
value: ValueType;
8792+
value: T;
87938793
}
87948794

87958795
interface MemoryDescriptor {
@@ -8815,19 +8815,29 @@ declare namespace WebAssembly {
88158815
maximum?: number;
88168816
}
88178817

8818+
interface ValueTypeMap {
8819+
anyfunc: Function;
8820+
externref: any;
8821+
f32: number;
8822+
f64: number;
8823+
i32: number;
8824+
i64: bigint;
8825+
v128: never;
8826+
}
8827+
88188828
interface WebAssemblyInstantiatedSource {
88198829
instance: Instance;
88208830
module: Module;
88218831
}
88228832

88238833
type ImportExportKind = "function" | "global" | "memory" | "table";
88248834
type TableKind = "anyfunc" | "externref";
8825-
type ValueType = "anyfunc" | "externref" | "f32" | "f64" | "i32" | "i64" | "v128";
88268835
type ExportValue = Function | Global | Memory | Table;
88278836
type Exports = Record<string, ExportValue>;
88288837
type ImportValue = ExportValue | number;
88298838
type Imports = Record<string, ModuleImports>;
88308839
type ModuleImports = Record<string, ImportValue>;
8840+
type ValueType = keyof ValueTypeMap;
88318841
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compile) */
88328842
function compile(bytes: BufferSource): Promise<Module>;
88338843
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compileStreaming) */

inputfiles/addedTypes.jsonc

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,6 +1269,50 @@
12691269
}
12701270
}
12711271
}
1272+
},
1273+
"ValueTypeMap": {
1274+
"name": "ValueTypeMap",
1275+
"legacyNamespace": "WebAssembly",
1276+
"exposed":"Window Worker Worklet",
1277+
"members": {
1278+
"member": {
1279+
"anyfunc": {
1280+
"name": "anyfunc",
1281+
"overrideType": "Function",
1282+
"required": 1
1283+
},
1284+
"externref": {
1285+
"name": "externref",
1286+
"overrideType": "any",
1287+
"required": 1
1288+
},
1289+
"f32": {
1290+
"name": "f32",
1291+
"overrideType": "number",
1292+
"required": 1
1293+
},
1294+
"f64": {
1295+
"name": "f64",
1296+
"overrideType": "number",
1297+
"required": 1
1298+
},
1299+
"i32": {
1300+
"name": "i32",
1301+
"overrideType": "number",
1302+
"required": 1
1303+
},
1304+
"i64": {
1305+
"name": "i64",
1306+
"overrideType": "bigint",
1307+
"required": 1
1308+
},
1309+
"v128": {
1310+
"name": "v128",
1311+
"overrideType": "never",
1312+
"required": 1
1313+
}
1314+
}
1315+
}
12721316
}
12731317
}
12741318
},
@@ -1305,6 +1349,11 @@
13051349
"name": "WindowProxy",
13061350
"type": "Window"
13071351
},
1352+
{
1353+
"name": "ValueType",
1354+
"legacyNamespace": "WebAssembly",
1355+
"overrideType": "keyof ValueTypeMap"
1356+
},
13081357
{
13091358
"name": "ExportValue",
13101359
"legacyNamespace": "WebAssembly",

0 commit comments

Comments
 (0)