Skip to content

Commit 66fbabb

Browse files
Bashamegasaschanaz
andauthored
Support additionalType (#2279)
Co-authored-by: saschanaz <[email protected]>
1 parent 9f981a4 commit 66fbabb

File tree

4 files changed

+42
-44
lines changed

4 files changed

+42
-44
lines changed

inputfiles/overridingTypes.jsonc

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,6 @@
3030
}
3131
}
3232
},
33-
"WebGLRenderingContextBase": {
34-
"methods": {
35-
"method": {
36-
"pixelStorei": {
37-
"name": "pixelStorei",
38-
"signature": {
39-
"0": {
40-
"param": [
41-
{
42-
"name": "param",
43-
"additionalTypes": ["GLboolean"]
44-
}
45-
]
46-
}
47-
}
48-
}
49-
}
50-
}
51-
},
5233
"Body": {
5334
"properties": {
5435
"property": {
@@ -1369,18 +1350,6 @@
13691350
"SubtleCrypto": {
13701351
"methods": {
13711352
"method": {
1372-
"decrypt": {
1373-
"signature": {
1374-
"0": {
1375-
"param": [
1376-
{
1377-
"name": "algorithm",
1378-
"additionalTypes": ["RsaOaepParams", "AesCtrParams", "AesCbcParams", "AesGcmParams"]
1379-
}
1380-
]
1381-
}
1382-
}
1383-
},
13841353
"deriveBits": {
13851354
"signature": {
13861355
"0": {

inputfiles/patches/webcrypto.kdl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ interface CryptoKey {
1313
}
1414
}
1515

16+
interface SubtleCrypto {
17+
method decrypt signatureIndex=0 {
18+
param algorithm {
19+
additionalTypes RsaOaepParams AesCtrParams AesCbcParams AesGcmParams
20+
}
21+
}
22+
}
23+
1624
removals {
1725
enum KeyFormat {
1826
raw-private // No implementation as of 2025-09

inputfiles/patches/webgl.kdl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,4 +170,10 @@ interface-mixin WebGLRenderingContextBase {
170170
param extensionName overrideType="\"WEBGL_multi_draw\""
171171
type WEBGL_multi_draw nullable=#true
172172
}
173+
174+
method pixelStorei signatureIndex=0 {
175+
param param {
176+
additionalTypes GLboolean
177+
}
178+
}
173179
}

src/build/patches.ts

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,32 @@ function handleProperty(child: Node): Partial<Property> {
262262
};
263263
}
264264

265+
function handleParam(node: Node) {
266+
const name = string(node.values[0]);
267+
let additionalTypes: string[] | undefined;
268+
269+
for (const child of node.children) {
270+
switch (child.name) {
271+
case "additionalTypes": {
272+
if (additionalTypes) {
273+
throw new Error("Unexpected multiple additionalTypes node");
274+
}
275+
additionalTypes = child.values.map(string);
276+
break;
277+
}
278+
default:
279+
throw new Error(`Unexpected child "${child.name}" in param "${name}"`);
280+
}
281+
}
282+
283+
return {
284+
name,
285+
...optionalMember("type", "string", node.properties?.type),
286+
...optionalMember("overrideType", "string", node.properties?.overrideType),
287+
additionalTypes,
288+
};
289+
}
290+
265291
/**
266292
* Handles a child node of type "method" and adds it to the method object.
267293
* @param child The child node to handle.
@@ -282,15 +308,7 @@ function handleMethod(child: Node): DeepPartial<OverridableMethod> {
282308
break;
283309

284310
case "param":
285-
params.push({
286-
name: string(c.values[0]),
287-
...optionalMember("type", "string", c.properties?.type),
288-
...optionalMember(
289-
"overrideType",
290-
"string",
291-
c.properties?.overrideType,
292-
),
293-
});
311+
params.push(handleParam(c));
294312
break;
295313

296314
default:
@@ -308,12 +326,9 @@ function handleMethod(child: Node): DeepPartial<OverridableMethod> {
308326
: null;
309327

310328
const signatureIndex = child.properties?.signatureIndex;
311-
if ((params.length || signatureIndex) && !type) {
312-
throw new Error("A method signature requires a type");
313-
}
314329

315330
let signature: OverridableMethod["signature"] = [];
316-
if (type) {
331+
if (type || params.length > 0) {
317332
// Determine the actual signature object
318333
const signatureObj: DeepPartial<Signature> = {
319334
param: params,

0 commit comments

Comments
 (0)