0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-02-07 23:06:50 -05:00

refactor(webidl): move prefix & context out of converters options bag (#18931)

This commit is contained in:
Leo Kettmeir 2023-05-01 12:47:13 +02:00 committed by GitHub
parent d856bfd336
commit b31cf9fde6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
31 changed files with 1042 additions and 964 deletions

View file

@ -85,10 +85,7 @@ class BroadcastChannel extends EventTarget {
const prefix = "Failed to construct 'BroadcastChannel'"; const prefix = "Failed to construct 'BroadcastChannel'";
webidl.requiredArguments(arguments.length, 1, prefix); webidl.requiredArguments(arguments.length, 1, prefix);
this[_name] = webidl.converters["DOMString"](name, { this[_name] = webidl.converters["DOMString"](name, prefix, "Argument 1");
prefix,
context: "Argument 1",
});
this[webidl.brand] = webidl.brand; this[webidl.brand] = webidl.brand;

41
ext/cache/01_cache.js vendored
View file

@ -27,10 +27,7 @@ class CacheStorage {
webidl.assertBranded(this, CacheStoragePrototype); webidl.assertBranded(this, CacheStoragePrototype);
const prefix = "Failed to execute 'open' on 'CacheStorage'"; const prefix = "Failed to execute 'open' on 'CacheStorage'";
webidl.requiredArguments(arguments.length, 1, prefix); webidl.requiredArguments(arguments.length, 1, prefix);
cacheName = webidl.converters["DOMString"](cacheName, { cacheName = webidl.converters["DOMString"](cacheName, prefix, "Argument 1");
prefix,
context: "Argument 1",
});
const cacheId = await core.opAsync("op_cache_storage_open", cacheName); const cacheId = await core.opAsync("op_cache_storage_open", cacheName);
const cache = webidl.createBranded(Cache); const cache = webidl.createBranded(Cache);
cache[_id] = cacheId; cache[_id] = cacheId;
@ -41,10 +38,7 @@ class CacheStorage {
webidl.assertBranded(this, CacheStoragePrototype); webidl.assertBranded(this, CacheStoragePrototype);
const prefix = "Failed to execute 'has' on 'CacheStorage'"; const prefix = "Failed to execute 'has' on 'CacheStorage'";
webidl.requiredArguments(arguments.length, 1, prefix); webidl.requiredArguments(arguments.length, 1, prefix);
cacheName = webidl.converters["DOMString"](cacheName, { cacheName = webidl.converters["DOMString"](cacheName, prefix, "Argument 1");
prefix,
context: "Argument 1",
});
return await core.opAsync("op_cache_storage_has", cacheName); return await core.opAsync("op_cache_storage_has", cacheName);
} }
@ -52,10 +46,7 @@ class CacheStorage {
webidl.assertBranded(this, CacheStoragePrototype); webidl.assertBranded(this, CacheStoragePrototype);
const prefix = "Failed to execute 'delete' on 'CacheStorage'"; const prefix = "Failed to execute 'delete' on 'CacheStorage'";
webidl.requiredArguments(arguments.length, 1, prefix); webidl.requiredArguments(arguments.length, 1, prefix);
cacheName = webidl.converters["DOMString"](cacheName, { cacheName = webidl.converters["DOMString"](cacheName, prefix, "Argument 1");
prefix,
context: "Argument 1",
});
return await core.opAsync("op_cache_storage_delete", cacheName); return await core.opAsync("op_cache_storage_delete", cacheName);
} }
} }
@ -76,14 +67,12 @@ class Cache {
webidl.assertBranded(this, CachePrototype); webidl.assertBranded(this, CachePrototype);
const prefix = "Failed to execute 'put' on 'Cache'"; const prefix = "Failed to execute 'put' on 'Cache'";
webidl.requiredArguments(arguments.length, 2, prefix); webidl.requiredArguments(arguments.length, 2, prefix);
request = webidl.converters["RequestInfo_DOMString"](request, { request = webidl.converters["RequestInfo_DOMString"](
request,
prefix, prefix,
context: "Argument 1", "Argument 1",
}); );
response = webidl.converters["Response"](response, { response = webidl.converters["Response"](response, prefix, "Argument 2");
prefix,
context: "Argument 2",
});
// Step 1. // Step 1.
let innerRequest = null; let innerRequest = null;
// Step 2. // Step 2.
@ -166,10 +155,11 @@ class Cache {
webidl.assertBranded(this, CachePrototype); webidl.assertBranded(this, CachePrototype);
const prefix = "Failed to execute 'match' on 'Cache'"; const prefix = "Failed to execute 'match' on 'Cache'";
webidl.requiredArguments(arguments.length, 1, prefix); webidl.requiredArguments(arguments.length, 1, prefix);
request = webidl.converters["RequestInfo_DOMString"](request, { request = webidl.converters["RequestInfo_DOMString"](
request,
prefix, prefix,
context: "Argument 1", "Argument 1",
}); );
const p = await this[_matchAll](request, options); const p = await this[_matchAll](request, options);
if (p.length > 0) { if (p.length > 0) {
return p[0]; return p[0];
@ -183,10 +173,11 @@ class Cache {
webidl.assertBranded(this, CachePrototype); webidl.assertBranded(this, CachePrototype);
const prefix = "Failed to execute 'delete' on 'Cache'"; const prefix = "Failed to execute 'delete' on 'Cache'";
webidl.requiredArguments(arguments.length, 1, prefix); webidl.requiredArguments(arguments.length, 1, prefix);
request = webidl.converters["RequestInfo_DOMString"](request, { request = webidl.converters["RequestInfo_DOMString"](
request,
prefix, prefix,
context: "Argument 1", "Argument 1",
}); );
// Step 1. // Step 1.
let r = null; let r = null;
// Step 2. // Step 2.

View file

@ -199,10 +199,11 @@ function normalizeAlgorithm(algorithm, op) {
// 1. // 1.
const registeredAlgorithms = supportedAlgorithms[op]; const registeredAlgorithms = supportedAlgorithms[op];
// 2. 3. // 2. 3.
const initialAlg = webidl.converters.Algorithm(algorithm, { const initialAlg = webidl.converters.Algorithm(
prefix: "Failed to normalize algorithm", algorithm,
context: "passed algorithm", "Failed to normalize algorithm",
}); "passed algorithm",
);
// 4. // 4.
let algName = initialAlg.name; let algName = initialAlg.name;
@ -232,10 +233,11 @@ function normalizeAlgorithm(algorithm, op) {
} }
// 6. // 6.
const normalizedAlgorithm = webidl.converters[desiredType](algorithm, { const normalizedAlgorithm = webidl.converters[desiredType](
prefix: "Failed to normalize algorithm", algorithm,
context: "passed algorithm", "Failed to normalize algorithm",
}); "passed algorithm",
);
// 7. // 7.
normalizedAlgorithm.name = algName; normalizedAlgorithm.name = algName;
@ -469,14 +471,12 @@ class SubtleCrypto {
webidl.assertBranded(this, SubtleCryptoPrototype); webidl.assertBranded(this, SubtleCryptoPrototype);
const prefix = "Failed to execute 'digest' on 'SubtleCrypto'"; const prefix = "Failed to execute 'digest' on 'SubtleCrypto'";
webidl.requiredArguments(arguments.length, 2, prefix); webidl.requiredArguments(arguments.length, 2, prefix);
algorithm = webidl.converters.AlgorithmIdentifier(algorithm, { algorithm = webidl.converters.AlgorithmIdentifier(
algorithm,
prefix, prefix,
context: "Argument 1", "Argument 1",
}); );
data = webidl.converters.BufferSource(data, { data = webidl.converters.BufferSource(data, prefix, "Argument 2");
prefix,
context: "Argument 2",
});
data = copyBuffer(data); data = copyBuffer(data);
@ -501,18 +501,13 @@ class SubtleCrypto {
webidl.assertBranded(this, SubtleCryptoPrototype); webidl.assertBranded(this, SubtleCryptoPrototype);
const prefix = "Failed to execute 'encrypt' on 'SubtleCrypto'"; const prefix = "Failed to execute 'encrypt' on 'SubtleCrypto'";
webidl.requiredArguments(arguments.length, 3, prefix); webidl.requiredArguments(arguments.length, 3, prefix);
algorithm = webidl.converters.AlgorithmIdentifier(algorithm, { algorithm = webidl.converters.AlgorithmIdentifier(
algorithm,
prefix, prefix,
context: "Argument 1", "Argument 1",
}); );
key = webidl.converters.CryptoKey(key, { key = webidl.converters.CryptoKey(key, prefix, "Argument 2");
prefix, data = webidl.converters.BufferSource(data, prefix, "Argument 3");
context: "Argument 2",
});
data = webidl.converters.BufferSource(data, {
prefix,
context: "Argument 3",
});
// 2. // 2.
data = copyBuffer(data); data = copyBuffer(data);
@ -549,18 +544,13 @@ class SubtleCrypto {
webidl.assertBranded(this, SubtleCryptoPrototype); webidl.assertBranded(this, SubtleCryptoPrototype);
const prefix = "Failed to execute 'decrypt' on 'SubtleCrypto'"; const prefix = "Failed to execute 'decrypt' on 'SubtleCrypto'";
webidl.requiredArguments(arguments.length, 3, prefix); webidl.requiredArguments(arguments.length, 3, prefix);
algorithm = webidl.converters.AlgorithmIdentifier(algorithm, { algorithm = webidl.converters.AlgorithmIdentifier(
algorithm,
prefix, prefix,
context: "Argument 1", "Argument 1",
}); );
key = webidl.converters.CryptoKey(key, { key = webidl.converters.CryptoKey(key, prefix, "Argument 2");
prefix, data = webidl.converters.BufferSource(data, prefix, "Argument 3");
context: "Argument 2",
});
data = webidl.converters.BufferSource(data, {
prefix,
context: "Argument 3",
});
// 2. // 2.
data = copyBuffer(data); data = copyBuffer(data);
@ -757,18 +747,13 @@ class SubtleCrypto {
webidl.assertBranded(this, SubtleCryptoPrototype); webidl.assertBranded(this, SubtleCryptoPrototype);
const prefix = "Failed to execute 'sign' on 'SubtleCrypto'"; const prefix = "Failed to execute 'sign' on 'SubtleCrypto'";
webidl.requiredArguments(arguments.length, 3, prefix); webidl.requiredArguments(arguments.length, 3, prefix);
algorithm = webidl.converters.AlgorithmIdentifier(algorithm, { algorithm = webidl.converters.AlgorithmIdentifier(
algorithm,
prefix, prefix,
context: "Argument 1", "Argument 1",
}); );
key = webidl.converters.CryptoKey(key, { key = webidl.converters.CryptoKey(key, prefix, "Argument 2");
prefix, data = webidl.converters.BufferSource(data, prefix, "Argument 3");
context: "Argument 2",
});
data = webidl.converters.BufferSource(data, {
prefix,
context: "Argument 3",
});
// 1. // 1.
data = copyBuffer(data); data = copyBuffer(data);
@ -921,26 +906,23 @@ class SubtleCrypto {
webidl.assertBranded(this, SubtleCryptoPrototype); webidl.assertBranded(this, SubtleCryptoPrototype);
const prefix = "Failed to execute 'importKey' on 'SubtleCrypto'"; const prefix = "Failed to execute 'importKey' on 'SubtleCrypto'";
webidl.requiredArguments(arguments.length, 4, prefix); webidl.requiredArguments(arguments.length, 4, prefix);
format = webidl.converters.KeyFormat(format, { format = webidl.converters.KeyFormat(format, prefix, "Argument 1");
keyData = webidl.converters["BufferSource or JsonWebKey"](
keyData,
prefix, prefix,
context: "Argument 1", "Argument 2",
}); );
keyData = webidl.converters["BufferSource or JsonWebKey"](keyData, { algorithm = webidl.converters.AlgorithmIdentifier(
algorithm,
prefix, prefix,
context: "Argument 2", "Argument 3",
}); );
algorithm = webidl.converters.AlgorithmIdentifier(algorithm, { extractable = webidl.converters.boolean(extractable, prefix, "Argument 4");
keyUsages = webidl.converters["sequence<KeyUsage>"](
keyUsages,
prefix, prefix,
context: "Argument 3", "Argument 5",
}); );
extractable = webidl.converters.boolean(extractable, {
prefix,
context: "Argument 4",
});
keyUsages = webidl.converters["sequence<KeyUsage>"](keyUsages, {
prefix,
context: "Argument 5",
});
// 2. // 2.
if (format !== "jwk") { if (format !== "jwk") {
@ -1055,14 +1037,8 @@ class SubtleCrypto {
webidl.assertBranded(this, SubtleCryptoPrototype); webidl.assertBranded(this, SubtleCryptoPrototype);
const prefix = "Failed to execute 'exportKey' on 'SubtleCrypto'"; const prefix = "Failed to execute 'exportKey' on 'SubtleCrypto'";
webidl.requiredArguments(arguments.length, 2, prefix); webidl.requiredArguments(arguments.length, 2, prefix);
format = webidl.converters.KeyFormat(format, { format = webidl.converters.KeyFormat(format, prefix, "Argument 1");
prefix, key = webidl.converters.CryptoKey(key, prefix, "Argument 2");
context: "Argument 1",
});
key = webidl.converters.CryptoKey(key, {
prefix,
context: "Argument 2",
});
const handle = key[_handle]; const handle = key[_handle];
// 2. // 2.
@ -1127,19 +1103,14 @@ class SubtleCrypto {
webidl.assertBranded(this, SubtleCryptoPrototype); webidl.assertBranded(this, SubtleCryptoPrototype);
const prefix = "Failed to execute 'deriveBits' on 'SubtleCrypto'"; const prefix = "Failed to execute 'deriveBits' on 'SubtleCrypto'";
webidl.requiredArguments(arguments.length, 3, prefix); webidl.requiredArguments(arguments.length, 3, prefix);
algorithm = webidl.converters.AlgorithmIdentifier(algorithm, { algorithm = webidl.converters.AlgorithmIdentifier(
algorithm,
prefix, prefix,
context: "Argument 1", "Argument 1",
}); );
baseKey = webidl.converters.CryptoKey(baseKey, { baseKey = webidl.converters.CryptoKey(baseKey, prefix, "Argument 2");
prefix,
context: "Argument 2",
});
if (length !== null) { if (length !== null) {
length = webidl.converters["unsigned long"](length, { length = webidl.converters["unsigned long"](length, prefix, "Argument 3");
prefix,
context: "Argument 3",
});
} }
// 2. // 2.
@ -1177,26 +1148,27 @@ class SubtleCrypto {
webidl.assertBranded(this, SubtleCryptoPrototype); webidl.assertBranded(this, SubtleCryptoPrototype);
const prefix = "Failed to execute 'deriveKey' on 'SubtleCrypto'"; const prefix = "Failed to execute 'deriveKey' on 'SubtleCrypto'";
webidl.requiredArguments(arguments.length, 5, prefix); webidl.requiredArguments(arguments.length, 5, prefix);
algorithm = webidl.converters.AlgorithmIdentifier(algorithm, { algorithm = webidl.converters.AlgorithmIdentifier(
algorithm,
prefix, prefix,
context: "Argument 1", "Argument 1",
}); );
baseKey = webidl.converters.CryptoKey(baseKey, { baseKey = webidl.converters.CryptoKey(baseKey, prefix, "Argument 2");
derivedKeyType = webidl.converters.AlgorithmIdentifier(
derivedKeyType,
prefix, prefix,
context: "Argument 2", "Argument 3",
}); );
derivedKeyType = webidl.converters.AlgorithmIdentifier(derivedKeyType, { extractable = webidl.converters["boolean"](
extractable,
prefix, prefix,
context: "Argument 3", "Argument 4",
}); );
extractable = webidl.converters["boolean"](extractable, { keyUsages = webidl.converters["sequence<KeyUsage>"](
keyUsages,
prefix, prefix,
context: "Argument 4", "Argument 5",
}); );
keyUsages = webidl.converters["sequence<KeyUsage>"](keyUsages, {
prefix,
context: "Argument 5",
});
// 2-3. // 2-3.
const normalizedAlgorithm = normalizeAlgorithm(algorithm, "deriveBits"); const normalizedAlgorithm = normalizeAlgorithm(algorithm, "deriveBits");
@ -1272,22 +1244,14 @@ class SubtleCrypto {
webidl.assertBranded(this, SubtleCryptoPrototype); webidl.assertBranded(this, SubtleCryptoPrototype);
const prefix = "Failed to execute 'verify' on 'SubtleCrypto'"; const prefix = "Failed to execute 'verify' on 'SubtleCrypto'";
webidl.requiredArguments(arguments.length, 4, prefix); webidl.requiredArguments(arguments.length, 4, prefix);
algorithm = webidl.converters.AlgorithmIdentifier(algorithm, { algorithm = webidl.converters.AlgorithmIdentifier(
algorithm,
prefix, prefix,
context: "Argument 1", "Argument 1",
}); );
key = webidl.converters.CryptoKey(key, { key = webidl.converters.CryptoKey(key, prefix, "Argument 2");
prefix, signature = webidl.converters.BufferSource(signature, prefix, "Argument 3");
context: "Argument 2", data = webidl.converters.BufferSource(data, prefix, "Argument 4");
});
signature = webidl.converters.BufferSource(signature, {
prefix,
context: "Argument 3",
});
data = webidl.converters.BufferSource(data, {
prefix,
context: "Argument 4",
});
// 2. // 2.
signature = copyBuffer(signature); signature = copyBuffer(signature);
@ -1412,22 +1376,18 @@ class SubtleCrypto {
webidl.assertBranded(this, SubtleCryptoPrototype); webidl.assertBranded(this, SubtleCryptoPrototype);
const prefix = "Failed to execute 'wrapKey' on 'SubtleCrypto'"; const prefix = "Failed to execute 'wrapKey' on 'SubtleCrypto'";
webidl.requiredArguments(arguments.length, 4, prefix); webidl.requiredArguments(arguments.length, 4, prefix);
format = webidl.converters.KeyFormat(format, { format = webidl.converters.KeyFormat(format, prefix, "Argument 1");
key = webidl.converters.CryptoKey(key, prefix, "Argument 2");
wrappingKey = webidl.converters.CryptoKey(
wrappingKey,
prefix, prefix,
context: "Argument 1", "Argument 3",
}); );
key = webidl.converters.CryptoKey(key, { wrapAlgorithm = webidl.converters.AlgorithmIdentifier(
wrapAlgorithm,
prefix, prefix,
context: "Argument 2", "Argument 4",
}); );
wrappingKey = webidl.converters.CryptoKey(wrappingKey, {
prefix,
context: "Argument 3",
});
wrapAlgorithm = webidl.converters.AlgorithmIdentifier(wrapAlgorithm, {
prefix,
context: "Argument 4",
});
let normalizedAlgorithm; let normalizedAlgorithm;
@ -1548,37 +1508,33 @@ class SubtleCrypto {
webidl.assertBranded(this, SubtleCryptoPrototype); webidl.assertBranded(this, SubtleCryptoPrototype);
const prefix = "Failed to execute 'unwrapKey' on 'SubtleCrypto'"; const prefix = "Failed to execute 'unwrapKey' on 'SubtleCrypto'";
webidl.requiredArguments(arguments.length, 7, prefix); webidl.requiredArguments(arguments.length, 7, prefix);
format = webidl.converters.KeyFormat(format, { format = webidl.converters.KeyFormat(format, prefix, "Argument 1");
wrappedKey = webidl.converters.BufferSource(
wrappedKey,
prefix, prefix,
context: "Argument 1", "Argument 2",
}); );
wrappedKey = webidl.converters.BufferSource(wrappedKey, { unwrappingKey = webidl.converters.CryptoKey(
unwrappingKey,
prefix, prefix,
context: "Argument 2", "Argument 3",
}); );
unwrappingKey = webidl.converters.CryptoKey(unwrappingKey, { unwrapAlgorithm = webidl.converters.AlgorithmIdentifier(
unwrapAlgorithm,
prefix, prefix,
context: "Argument 3", "Argument 4",
}); );
unwrapAlgorithm = webidl.converters.AlgorithmIdentifier(unwrapAlgorithm, {
prefix,
context: "Argument 4",
});
unwrappedKeyAlgorithm = webidl.converters.AlgorithmIdentifier( unwrappedKeyAlgorithm = webidl.converters.AlgorithmIdentifier(
unwrappedKeyAlgorithm, unwrappedKeyAlgorithm,
{ prefix,
prefix, "Argument 5",
context: "Argument 5",
},
); );
extractable = webidl.converters.boolean(extractable, { extractable = webidl.converters.boolean(extractable, prefix, "Argument 6");
keyUsages = webidl.converters["sequence<KeyUsage>"](
keyUsages,
prefix, prefix,
context: "Argument 6", "Argument 7",
}); );
keyUsages = webidl.converters["sequence<KeyUsage>"](keyUsages, {
prefix,
context: "Argument 7",
});
// 2. // 2.
wrappedKey = copyBuffer(wrappedKey); wrappedKey = copyBuffer(wrappedKey);
@ -1709,18 +1665,21 @@ class SubtleCrypto {
webidl.assertBranded(this, SubtleCryptoPrototype); webidl.assertBranded(this, SubtleCryptoPrototype);
const prefix = "Failed to execute 'generateKey' on 'SubtleCrypto'"; const prefix = "Failed to execute 'generateKey' on 'SubtleCrypto'";
webidl.requiredArguments(arguments.length, 3, prefix); webidl.requiredArguments(arguments.length, 3, prefix);
algorithm = webidl.converters.AlgorithmIdentifier(algorithm, { algorithm = webidl.converters.AlgorithmIdentifier(
algorithm,
prefix, prefix,
context: "Argument 1", "Argument 1",
}); );
extractable = webidl.converters["boolean"](extractable, { extractable = webidl.converters["boolean"](
extractable,
prefix, prefix,
context: "Argument 2", "Argument 2",
}); );
keyUsages = webidl.converters["sequence<KeyUsage>"](keyUsages, { keyUsages = webidl.converters["sequence<KeyUsage>"](
keyUsages,
prefix, prefix,
context: "Argument 3", "Argument 3",
}); );
const usages = keyUsages; const usages = keyUsages;
@ -4722,10 +4681,11 @@ class Crypto {
ops.op_crypto_get_random_values(typedArray); ops.op_crypto_get_random_values(typedArray);
return typedArray; return typedArray;
} }
typedArray = webidl.converters.ArrayBufferView(typedArray, { typedArray = webidl.converters.ArrayBufferView(
typedArray,
prefix, prefix,
context: "Argument 1", "Argument 1",
}); );
switch (tag) { switch (tag) {
case "Int8Array": case "Int8Array":
case "Uint8ClampedArray": case "Uint8ClampedArray":

View file

@ -14,23 +14,28 @@ const {
SafeArrayIterator, SafeArrayIterator,
} = primordials; } = primordials;
webidl.converters.AlgorithmIdentifier = (V, opts) => { webidl.converters.AlgorithmIdentifier = (V, prefix, context, opts) => {
// Union for (object or DOMString) // Union for (object or DOMString)
if (webidl.type(V) == "Object") { if (webidl.type(V) == "Object") {
return webidl.converters.object(V, opts); return webidl.converters.object(V, prefix, context, opts);
} }
return webidl.converters.DOMString(V, opts); return webidl.converters.DOMString(V, prefix, context, opts);
}; };
webidl.converters["BufferSource or JsonWebKey"] = (V, opts) => { webidl.converters["BufferSource or JsonWebKey"] = (
V,
prefix,
context,
opts,
) => {
// Union for (BufferSource or JsonWebKey) // Union for (BufferSource or JsonWebKey)
if ( if (
ArrayBufferIsView(V) || ArrayBufferIsView(V) ||
ObjectPrototypeIsPrototypeOf(ArrayBufferPrototype, V) ObjectPrototypeIsPrototypeOf(ArrayBufferPrototype, V)
) { ) {
return webidl.converters.BufferSource(V, opts); return webidl.converters.BufferSource(V, prefix, context, opts);
} }
return webidl.converters.JsonWebKey(V, opts); return webidl.converters.JsonWebKey(V, prefix, context, opts);
}; };
webidl.converters.KeyType = webidl.createEnumConverter("KeyType", [ webidl.converters.KeyType = webidl.createEnumConverter("KeyType", [
@ -81,8 +86,11 @@ const dictRsaKeyGenParams = [
...new SafeArrayIterator(dictAlgorithm), ...new SafeArrayIterator(dictAlgorithm),
{ {
key: "modulusLength", key: "modulusLength",
converter: (V, opts) => converter: (V, prefix, context, opts) =>
webidl.converters["unsigned long"](V, { ...opts, enforceRange: true }), webidl.converters["unsigned long"](V, prefix, context, {
...opts,
enforceRange: true,
}),
required: true, required: true,
}, },
{ {
@ -155,8 +163,11 @@ const dictAesKeyGenParams = [
...new SafeArrayIterator(dictAlgorithm), ...new SafeArrayIterator(dictAlgorithm),
{ {
key: "length", key: "length",
converter: (V, opts) => converter: (V, prefix, context, opts) =>
webidl.converters["unsigned short"](V, { ...opts, enforceRange: true }), webidl.converters["unsigned short"](V, prefix, context, {
...opts,
enforceRange: true,
}),
required: true, required: true,
}, },
]; ];
@ -173,8 +184,11 @@ const dictHmacKeyGenParams = [
}, },
{ {
key: "length", key: "length",
converter: (V, opts) => converter: (V, prefix, context, opts) =>
webidl.converters["unsigned long"](V, { ...opts, enforceRange: true }), webidl.converters["unsigned long"](V, prefix, context, {
...opts,
enforceRange: true,
}),
}, },
]; ];
@ -185,8 +199,11 @@ const dictRsaPssParams = [
...new SafeArrayIterator(dictAlgorithm), ...new SafeArrayIterator(dictAlgorithm),
{ {
key: "saltLength", key: "saltLength",
converter: (V, opts) => converter: (V, prefix, context, opts) =>
webidl.converters["unsigned long"](V, { ...opts, enforceRange: true }), webidl.converters["unsigned long"](V, prefix, context, {
...opts,
enforceRange: true,
}),
required: true, required: true,
}, },
]; ];
@ -226,8 +243,11 @@ const dictHmacImportParams = [
}, },
{ {
key: "length", key: "length",
converter: (V, opts) => converter: (V, prefix, context, opts) =>
webidl.converters["unsigned long"](V, { ...opts, enforceRange: true }), webidl.converters["unsigned long"](V, prefix, context, {
...opts,
enforceRange: true,
}),
}, },
]; ];
@ -374,8 +394,11 @@ const dictPbkdf2Params = [
}, },
{ {
key: "iterations", key: "iterations",
converter: (V, opts) => converter: (V, prefix, context, opts) =>
webidl.converters["unsigned long"](V, { ...opts, enforceRange: true }), webidl.converters["unsigned long"](V, prefix, context, {
...opts,
enforceRange: true,
}),
required: true, required: true,
}, },
{ {
@ -392,8 +415,11 @@ const dictAesDerivedKeyParams = [
...new SafeArrayIterator(dictAlgorithm), ...new SafeArrayIterator(dictAlgorithm),
{ {
key: "length", key: "length",
converter: (V, opts) => converter: (V, prefix, context, opts) =>
webidl.converters["unsigned long"](V, { ...opts, enforceRange: true }), webidl.converters["unsigned long"](V, prefix, context, {
...opts,
enforceRange: true,
}),
required: true, required: true,
}, },
]; ];
@ -416,8 +442,11 @@ const dictAesGcmParams = [
}, },
{ {
key: "tagLength", key: "tagLength",
converter: (V, opts) => converter: (V, prefix, context, opts) =>
webidl.converters["unsigned long"](V, { ...opts, enforceRange: true }), webidl.converters["unsigned long"](V, prefix, context, {
...opts,
enforceRange: true,
}),
}, },
{ {
key: "additionalData", key: "additionalData",
@ -434,8 +463,11 @@ const dictAesCtrParams = [
}, },
{ {
key: "length", key: "length",
converter: (V, opts) => converter: (V, prefix, context, opts) =>
webidl.converters["unsigned short"](V, { ...opts, enforceRange: true }), webidl.converters["unsigned short"](V, prefix, context, {
...opts,
enforceRange: true,
}),
required: true, required: true,
}, },
]; ];

View file

@ -251,10 +251,7 @@ class Headers {
constructor(init = undefined) { constructor(init = undefined) {
const prefix = "Failed to construct 'Headers'"; const prefix = "Failed to construct 'Headers'";
if (init !== undefined) { if (init !== undefined) {
init = webidl.converters["HeadersInit"](init, { init = webidl.converters["HeadersInit"](init, prefix, "Argument 1");
prefix,
context: "Argument 1",
});
} }
this[webidl.brand] = webidl.brand; this[webidl.brand] = webidl.brand;
@ -272,14 +269,8 @@ class Headers {
webidl.assertBranded(this, HeadersPrototype); webidl.assertBranded(this, HeadersPrototype);
const prefix = "Failed to execute 'append' on 'Headers'"; const prefix = "Failed to execute 'append' on 'Headers'";
webidl.requiredArguments(arguments.length, 2, prefix); webidl.requiredArguments(arguments.length, 2, prefix);
name = webidl.converters["ByteString"](name, { name = webidl.converters["ByteString"](name, prefix, "Argument 1");
prefix, value = webidl.converters["ByteString"](value, prefix, "Argument 2");
context: "Argument 1",
});
value = webidl.converters["ByteString"](value, {
prefix,
context: "Argument 2",
});
appendHeader(this, name, value); appendHeader(this, name, value);
} }
@ -289,10 +280,7 @@ class Headers {
delete(name) { delete(name) {
const prefix = "Failed to execute 'delete' on 'Headers'"; const prefix = "Failed to execute 'delete' on 'Headers'";
webidl.requiredArguments(arguments.length, 1, prefix); webidl.requiredArguments(arguments.length, 1, prefix);
name = webidl.converters["ByteString"](name, { name = webidl.converters["ByteString"](name, prefix, "Argument 1");
prefix,
context: "Argument 1",
});
if (!RegExpPrototypeTest(HTTP_TOKEN_CODE_POINT_RE, name)) { if (!RegExpPrototypeTest(HTTP_TOKEN_CODE_POINT_RE, name)) {
throw new TypeError("Header name is not valid."); throw new TypeError("Header name is not valid.");
@ -317,10 +305,7 @@ class Headers {
get(name) { get(name) {
const prefix = "Failed to execute 'get' on 'Headers'"; const prefix = "Failed to execute 'get' on 'Headers'";
webidl.requiredArguments(arguments.length, 1, prefix); webidl.requiredArguments(arguments.length, 1, prefix);
name = webidl.converters["ByteString"](name, { name = webidl.converters["ByteString"](name, prefix, "Argument 1");
prefix,
context: "Argument 1",
});
if (!RegExpPrototypeTest(HTTP_TOKEN_CODE_POINT_RE, name)) { if (!RegExpPrototypeTest(HTTP_TOKEN_CODE_POINT_RE, name)) {
throw new TypeError("Header name is not valid."); throw new TypeError("Header name is not valid.");
@ -336,10 +321,7 @@ class Headers {
has(name) { has(name) {
const prefix = "Failed to execute 'has' on 'Headers'"; const prefix = "Failed to execute 'has' on 'Headers'";
webidl.requiredArguments(arguments.length, 1, prefix); webidl.requiredArguments(arguments.length, 1, prefix);
name = webidl.converters["ByteString"](name, { name = webidl.converters["ByteString"](name, prefix, "Argument 1");
prefix,
context: "Argument 1",
});
if (!RegExpPrototypeTest(HTTP_TOKEN_CODE_POINT_RE, name)) { if (!RegExpPrototypeTest(HTTP_TOKEN_CODE_POINT_RE, name)) {
throw new TypeError("Header name is not valid."); throw new TypeError("Header name is not valid.");
@ -363,14 +345,8 @@ class Headers {
webidl.assertBranded(this, HeadersPrototype); webidl.assertBranded(this, HeadersPrototype);
const prefix = "Failed to execute 'set' on 'Headers'"; const prefix = "Failed to execute 'set' on 'Headers'";
webidl.requiredArguments(arguments.length, 2, prefix); webidl.requiredArguments(arguments.length, 2, prefix);
name = webidl.converters["ByteString"](name, { name = webidl.converters["ByteString"](name, prefix, "Argument 1");
prefix, value = webidl.converters["ByteString"](value, prefix, "Argument 2");
context: "Argument 1",
});
value = webidl.converters["ByteString"](value, {
prefix,
context: "Argument 2",
});
value = normalizeHeaderValue(value); value = normalizeHeaderValue(value);
@ -420,19 +396,29 @@ webidl.mixinPairIterable("Headers", Headers, _iterableHeaders, 0, 1);
webidl.configurePrototype(Headers); webidl.configurePrototype(Headers);
const HeadersPrototype = Headers.prototype; const HeadersPrototype = Headers.prototype;
webidl.converters["HeadersInit"] = (V, opts) => { webidl.converters["HeadersInit"] = (V, prefix, context, opts) => {
// Union for (sequence<sequence<ByteString>> or record<ByteString, ByteString>) // Union for (sequence<sequence<ByteString>> or record<ByteString, ByteString>)
if (webidl.type(V) === "Object" && V !== null) { if (webidl.type(V) === "Object" && V !== null) {
if (V[SymbolIterator] !== undefined) { if (V[SymbolIterator] !== undefined) {
return webidl.converters["sequence<sequence<ByteString>>"](V, opts); return webidl.converters["sequence<sequence<ByteString>>"](
V,
prefix,
context,
opts,
);
} }
return webidl.converters["record<ByteString, ByteString>"](V, opts); return webidl.converters["record<ByteString, ByteString>"](
V,
prefix,
context,
opts,
);
} }
throw webidl.makeException( throw webidl.makeException(
TypeError, TypeError,
"The provided value is not of type '(sequence<sequence<ByteString>> or record<ByteString, ByteString>)'", "The provided value is not of type '(sequence<sequence<ByteString>> or record<ByteString, ByteString>)'",
opts.prefix, prefix,
opts.context, context,
); );
}; };
webidl.converters["Headers"] = webidl.createInterfaceConverter( webidl.converters["Headers"] = webidl.createInterfaceConverter(

View file

@ -103,26 +103,26 @@ class FormData {
const prefix = "Failed to execute 'append' on 'FormData'"; const prefix = "Failed to execute 'append' on 'FormData'";
webidl.requiredArguments(arguments.length, 2, prefix); webidl.requiredArguments(arguments.length, 2, prefix);
name = webidl.converters["USVString"](name, { name = webidl.converters["USVString"](name, prefix, "Argument 1");
prefix,
context: "Argument 1",
});
if (ObjectPrototypeIsPrototypeOf(BlobPrototype, valueOrBlobValue)) { if (ObjectPrototypeIsPrototypeOf(BlobPrototype, valueOrBlobValue)) {
valueOrBlobValue = webidl.converters["Blob"](valueOrBlobValue, { valueOrBlobValue = webidl.converters["Blob"](
valueOrBlobValue,
prefix, prefix,
context: "Argument 2", "Argument 2",
}); );
if (filename !== undefined) { if (filename !== undefined) {
filename = webidl.converters["USVString"](filename, { filename = webidl.converters["USVString"](
filename,
prefix, prefix,
context: "Argument 3", "Argument 3",
}); );
} }
} else { } else {
valueOrBlobValue = webidl.converters["USVString"](valueOrBlobValue, { valueOrBlobValue = webidl.converters["USVString"](
valueOrBlobValue,
prefix, prefix,
context: "Argument 2", "Argument 2",
}); );
} }
const entry = createEntry(name, valueOrBlobValue, filename); const entry = createEntry(name, valueOrBlobValue, filename);
@ -139,10 +139,7 @@ class FormData {
const prefix = "Failed to execute 'name' on 'FormData'"; const prefix = "Failed to execute 'name' on 'FormData'";
webidl.requiredArguments(arguments.length, 1, prefix); webidl.requiredArguments(arguments.length, 1, prefix);
name = webidl.converters["USVString"](name, { name = webidl.converters["USVString"](name, prefix, "Argument 1");
prefix,
context: "Argument 1",
});
const list = this[entryList]; const list = this[entryList];
for (let i = 0; i < list.length; i++) { for (let i = 0; i < list.length; i++) {
@ -162,10 +159,7 @@ class FormData {
const prefix = "Failed to execute 'get' on 'FormData'"; const prefix = "Failed to execute 'get' on 'FormData'";
webidl.requiredArguments(arguments.length, 1, prefix); webidl.requiredArguments(arguments.length, 1, prefix);
name = webidl.converters["USVString"](name, { name = webidl.converters["USVString"](name, prefix, "Argument 1");
prefix,
context: "Argument 1",
});
const entries = this[entryList]; const entries = this[entryList];
for (let i = 0; i < entries.length; ++i) { for (let i = 0; i < entries.length; ++i) {
@ -184,10 +178,7 @@ class FormData {
const prefix = "Failed to execute 'getAll' on 'FormData'"; const prefix = "Failed to execute 'getAll' on 'FormData'";
webidl.requiredArguments(arguments.length, 1, prefix); webidl.requiredArguments(arguments.length, 1, prefix);
name = webidl.converters["USVString"](name, { name = webidl.converters["USVString"](name, prefix, "Argument 1");
prefix,
context: "Argument 1",
});
const returnList = []; const returnList = [];
const entries = this[entryList]; const entries = this[entryList];
@ -207,10 +198,7 @@ class FormData {
const prefix = "Failed to execute 'has' on 'FormData'"; const prefix = "Failed to execute 'has' on 'FormData'";
webidl.requiredArguments(arguments.length, 1, prefix); webidl.requiredArguments(arguments.length, 1, prefix);
name = webidl.converters["USVString"](name, { name = webidl.converters["USVString"](name, prefix, "Argument 1");
prefix,
context: "Argument 1",
});
const entries = this[entryList]; const entries = this[entryList];
for (let i = 0; i < entries.length; ++i) { for (let i = 0; i < entries.length; ++i) {
@ -231,26 +219,26 @@ class FormData {
const prefix = "Failed to execute 'set' on 'FormData'"; const prefix = "Failed to execute 'set' on 'FormData'";
webidl.requiredArguments(arguments.length, 2, prefix); webidl.requiredArguments(arguments.length, 2, prefix);
name = webidl.converters["USVString"](name, { name = webidl.converters["USVString"](name, prefix, "Argument 1");
prefix,
context: "Argument 1",
});
if (ObjectPrototypeIsPrototypeOf(BlobPrototype, valueOrBlobValue)) { if (ObjectPrototypeIsPrototypeOf(BlobPrototype, valueOrBlobValue)) {
valueOrBlobValue = webidl.converters["Blob"](valueOrBlobValue, { valueOrBlobValue = webidl.converters["Blob"](
valueOrBlobValue,
prefix, prefix,
context: "Argument 2", "Argument 2",
}); );
if (filename !== undefined) { if (filename !== undefined) {
filename = webidl.converters["USVString"](filename, { filename = webidl.converters["USVString"](
filename,
prefix, prefix,
context: "Argument 3", "Argument 3",
}); );
} }
} else { } else {
valueOrBlobValue = webidl.converters["USVString"](valueOrBlobValue, { valueOrBlobValue = webidl.converters["USVString"](
valueOrBlobValue,
prefix, prefix,
context: "Argument 2", "Argument 2",
}); );
} }
const entry = createEntry(name, valueOrBlobValue, filename); const entry = createEntry(name, valueOrBlobValue, filename);

View file

@ -448,16 +448,16 @@ function extractBody(object) {
return { body, contentType }; return { body, contentType };
} }
webidl.converters["BodyInit_DOMString"] = (V, opts) => { webidl.converters["BodyInit_DOMString"] = (V, prefix, context, opts) => {
// Union for (ReadableStream or Blob or ArrayBufferView or ArrayBuffer or FormData or URLSearchParams or USVString) // Union for (ReadableStream or Blob or ArrayBufferView or ArrayBuffer or FormData or URLSearchParams or USVString)
if (ObjectPrototypeIsPrototypeOf(ReadableStreamPrototype, V)) { if (ObjectPrototypeIsPrototypeOf(ReadableStreamPrototype, V)) {
return webidl.converters["ReadableStream"](V, opts); return webidl.converters["ReadableStream"](V, prefix, context, opts);
} else if (ObjectPrototypeIsPrototypeOf(BlobPrototype, V)) { } else if (ObjectPrototypeIsPrototypeOf(BlobPrototype, V)) {
return webidl.converters["Blob"](V, opts); return webidl.converters["Blob"](V, prefix, context, opts);
} else if (ObjectPrototypeIsPrototypeOf(FormDataPrototype, V)) { } else if (ObjectPrototypeIsPrototypeOf(FormDataPrototype, V)) {
return webidl.converters["FormData"](V, opts); return webidl.converters["FormData"](V, prefix, context, opts);
} else if (ObjectPrototypeIsPrototypeOf(URLSearchParamsPrototype, V)) { } else if (ObjectPrototypeIsPrototypeOf(URLSearchParamsPrototype, V)) {
return webidl.converters["URLSearchParams"](V, opts); return webidl.converters["URLSearchParams"](V, prefix, context, opts);
} }
if (typeof V === "object") { if (typeof V === "object") {
if ( if (
@ -465,16 +465,16 @@ webidl.converters["BodyInit_DOMString"] = (V, opts) => {
// deno-lint-ignore prefer-primordials // deno-lint-ignore prefer-primordials
ObjectPrototypeIsPrototypeOf(SharedArrayBuffer.prototype, V) ObjectPrototypeIsPrototypeOf(SharedArrayBuffer.prototype, V)
) { ) {
return webidl.converters["ArrayBuffer"](V, opts); return webidl.converters["ArrayBuffer"](V, prefix, context, opts);
} }
if (ArrayBufferIsView(V)) { if (ArrayBufferIsView(V)) {
return webidl.converters["ArrayBufferView"](V, opts); return webidl.converters["ArrayBufferView"](V, prefix, context, opts);
} }
} }
// BodyInit conversion is passed to extractBody(), which calls core.encode(). // BodyInit conversion is passed to extractBody(), which calls core.encode().
// core.encode() will UTF-8 encode strings with replacement, being equivalent to the USV normalization. // core.encode() will UTF-8 encode strings with replacement, being equivalent to the USV normalization.
// Therefore we can convert to DOMString instead of USVString and avoid a costly redundant conversion. // Therefore we can convert to DOMString instead of USVString and avoid a costly redundant conversion.
return webidl.converters["DOMString"](V, opts); return webidl.converters["DOMString"](V, prefix, context, opts);
}; };
webidl.converters["BodyInit_DOMString?"] = webidl.createNullableConverter( webidl.converters["BodyInit_DOMString?"] = webidl.createNullableConverter(
webidl.converters["BodyInit_DOMString"], webidl.converters["BodyInit_DOMString"],

View file

@ -274,14 +274,12 @@ class Request {
constructor(input, init = {}) { constructor(input, init = {}) {
const prefix = "Failed to construct 'Request'"; const prefix = "Failed to construct 'Request'";
webidl.requiredArguments(arguments.length, 1, prefix); webidl.requiredArguments(arguments.length, 1, prefix);
input = webidl.converters["RequestInfo_DOMString"](input, { input = webidl.converters["RequestInfo_DOMString"](
input,
prefix, prefix,
context: "Argument 1", "Argument 1",
}); );
init = webidl.converters["RequestInit"](init, { init = webidl.converters["RequestInit"](init, prefix, "Argument 2");
prefix,
context: "Argument 2",
});
this[webidl.brand] = webidl.brand; this[webidl.brand] = webidl.brand;
@ -501,15 +499,15 @@ webidl.converters["Request"] = webidl.createInterfaceConverter(
"Request", "Request",
RequestPrototype, RequestPrototype,
); );
webidl.converters["RequestInfo_DOMString"] = (V, opts) => { webidl.converters["RequestInfo_DOMString"] = (V, prefix, context, opts) => {
// Union for (Request or USVString) // Union for (Request or USVString)
if (typeof V == "object") { if (typeof V == "object") {
if (ObjectPrototypeIsPrototypeOf(RequestPrototype, V)) { if (ObjectPrototypeIsPrototypeOf(RequestPrototype, V)) {
return webidl.converters["Request"](V, opts); return webidl.converters["Request"](V, prefix, context, opts);
} }
} }
// Passed to new URL(...) which implicitly converts DOMString -> USVString // Passed to new URL(...) which implicitly converts DOMString -> USVString
return webidl.converters["DOMString"](V, opts); return webidl.converters["DOMString"](V, prefix, context, opts);
}; };
webidl.converters["RequestRedirect"] = webidl.createEnumConverter( webidl.converters["RequestRedirect"] = webidl.createEnumConverter(
"RequestRedirect", "RequestRedirect",

View file

@ -257,14 +257,8 @@ class Response {
*/ */
static redirect(url, status = 302) { static redirect(url, status = 302) {
const prefix = "Failed to call 'Response.redirect'"; const prefix = "Failed to call 'Response.redirect'";
url = webidl.converters["USVString"](url, { url = webidl.converters["USVString"](url, prefix, "Argument 1");
prefix, status = webidl.converters["unsigned short"](status, prefix, "Argument 2");
context: "Argument 1",
});
status = webidl.converters["unsigned short"](status, {
prefix,
context: "Argument 2",
});
const baseURL = getLocationHref(); const baseURL = getLocationHref();
const parsedURL = new URL(url, baseURL); const parsedURL = new URL(url, baseURL);
@ -291,10 +285,7 @@ class Response {
static json(data = undefined, init = {}) { static json(data = undefined, init = {}) {
const prefix = "Failed to call 'Response.json'"; const prefix = "Failed to call 'Response.json'";
data = webidl.converters.any(data); data = webidl.converters.any(data);
init = webidl.converters["ResponseInit_fast"](init, { init = webidl.converters["ResponseInit_fast"](init, prefix, "Argument 2");
prefix,
context: "Argument 2",
});
const str = serializeJSValueToJSONString(data); const str = serializeJSValueToJSONString(data);
const res = extractBody(str); const res = extractBody(str);
@ -315,14 +306,8 @@ class Response {
*/ */
constructor(body = null, init = undefined) { constructor(body = null, init = undefined) {
const prefix = "Failed to construct 'Response'"; const prefix = "Failed to construct 'Response'";
body = webidl.converters["BodyInit_DOMString?"](body, { body = webidl.converters["BodyInit_DOMString?"](body, prefix, "Argument 1");
prefix, init = webidl.converters["ResponseInit_fast"](init, prefix, "Argument 2");
context: "Argument 1",
});
init = webidl.converters["ResponseInit_fast"](init, {
prefix,
context: "Argument 2",
});
this[_response] = newInnerResponse(); this[_response] = newInnerResponse();
this[_headers] = headersFromHeaderList( this[_headers] = headersFromHeaderList(
@ -463,7 +448,12 @@ webidl.converters["ResponseInit"] = webidl.createDictionaryConverter(
converter: webidl.converters["HeadersInit"], converter: webidl.converters["HeadersInit"],
}], }],
); );
webidl.converters["ResponseInit_fast"] = function (init, opts) { webidl.converters["ResponseInit_fast"] = function (
init,
prefix,
context,
opts,
) {
if (init === undefined || init === null) { if (init === undefined || init === null) {
return { status: 200, statusText: "", headers: undefined }; return { status: 200, statusText: "", headers: undefined };
} }
@ -482,7 +472,7 @@ webidl.converters["ResponseInit_fast"] = function (init, opts) {
return { status, statusText, headers }; return { status, statusText, headers };
} }
// Slow default path // Slow default path
return webidl.converters["ResponseInit"](init, opts); return webidl.converters["ResponseInit"](init, prefix, context, opts);
}; };
/** /**

View file

@ -523,10 +523,11 @@ function handleWasmStreaming(source, rid) {
// This implements part of // This implements part of
// https://webassembly.github.io/spec/web-api/#compile-a-potential-webassembly-response // https://webassembly.github.io/spec/web-api/#compile-a-potential-webassembly-response
try { try {
const res = webidl.converters["Response"](source, { const res = webidl.converters["Response"](
prefix: "Failed to call 'WebAssembly.compileStreaming'", source,
context: "Argument 1", "Failed to call 'WebAssembly.compileStreaming'",
}); "Argument 1",
);
// 2.3. // 2.3.
// The spec is ambiguous here, see // The spec is ambiguous here, see

View file

@ -104,7 +104,8 @@ class URLSearchParams {
init = webidl.converters init = webidl.converters
["sequence<sequence<USVString>> or record<USVString, USVString> or USVString"]( ["sequence<sequence<USVString>> or record<USVString, USVString> or USVString"](
init, init,
{ prefix, context: "Argument 1" }, prefix,
"Argument 1",
); );
this[webidl.brand] = webidl.brand; this[webidl.brand] = webidl.brand;
if (!init) { if (!init) {
@ -158,14 +159,8 @@ class URLSearchParams {
webidl.assertBranded(this, URLSearchParamsPrototype); webidl.assertBranded(this, URLSearchParamsPrototype);
const prefix = "Failed to execute 'append' on 'URLSearchParams'"; const prefix = "Failed to execute 'append' on 'URLSearchParams'";
webidl.requiredArguments(arguments.length, 2, prefix); webidl.requiredArguments(arguments.length, 2, prefix);
name = webidl.converters.USVString(name, { name = webidl.converters.USVString(name, prefix, "Argument 1");
prefix, value = webidl.converters.USVString(value, prefix, "Argument 2");
context: "Argument 1",
});
value = webidl.converters.USVString(value, {
prefix,
context: "Argument 2",
});
ArrayPrototypePush(this[_list], [name, value]); ArrayPrototypePush(this[_list], [name, value]);
this.#updateUrlSearch(); this.#updateUrlSearch();
} }
@ -177,10 +172,7 @@ class URLSearchParams {
webidl.assertBranded(this, URLSearchParamsPrototype); webidl.assertBranded(this, URLSearchParamsPrototype);
const prefix = "Failed to execute 'append' on 'URLSearchParams'"; const prefix = "Failed to execute 'append' on 'URLSearchParams'";
webidl.requiredArguments(arguments.length, 1, prefix); webidl.requiredArguments(arguments.length, 1, prefix);
name = webidl.converters.USVString(name, { name = webidl.converters.USVString(name, prefix, "Argument 1");
prefix,
context: "Argument 1",
});
const list = this[_list]; const list = this[_list];
let i = 0; let i = 0;
while (i < list.length) { while (i < list.length) {
@ -201,10 +193,7 @@ class URLSearchParams {
webidl.assertBranded(this, URLSearchParamsPrototype); webidl.assertBranded(this, URLSearchParamsPrototype);
const prefix = "Failed to execute 'getAll' on 'URLSearchParams'"; const prefix = "Failed to execute 'getAll' on 'URLSearchParams'";
webidl.requiredArguments(arguments.length, 1, prefix); webidl.requiredArguments(arguments.length, 1, prefix);
name = webidl.converters.USVString(name, { name = webidl.converters.USVString(name, prefix, "Argument 1");
prefix,
context: "Argument 1",
});
const values = []; const values = [];
const entries = this[_list]; const entries = this[_list];
for (let i = 0; i < entries.length; ++i) { for (let i = 0; i < entries.length; ++i) {
@ -224,10 +213,7 @@ class URLSearchParams {
webidl.assertBranded(this, URLSearchParamsPrototype); webidl.assertBranded(this, URLSearchParamsPrototype);
const prefix = "Failed to execute 'get' on 'URLSearchParams'"; const prefix = "Failed to execute 'get' on 'URLSearchParams'";
webidl.requiredArguments(arguments.length, 1, prefix); webidl.requiredArguments(arguments.length, 1, prefix);
name = webidl.converters.USVString(name, { name = webidl.converters.USVString(name, prefix, "Argument 1");
prefix,
context: "Argument 1",
});
const entries = this[_list]; const entries = this[_list];
for (let i = 0; i < entries.length; ++i) { for (let i = 0; i < entries.length; ++i) {
const entry = entries[i]; const entry = entries[i];
@ -246,10 +232,7 @@ class URLSearchParams {
webidl.assertBranded(this, URLSearchParamsPrototype); webidl.assertBranded(this, URLSearchParamsPrototype);
const prefix = "Failed to execute 'has' on 'URLSearchParams'"; const prefix = "Failed to execute 'has' on 'URLSearchParams'";
webidl.requiredArguments(arguments.length, 1, prefix); webidl.requiredArguments(arguments.length, 1, prefix);
name = webidl.converters.USVString(name, { name = webidl.converters.USVString(name, prefix, "Argument 1");
prefix,
context: "Argument 1",
});
return ArrayPrototypeSome(this[_list], (entry) => entry[0] === name); return ArrayPrototypeSome(this[_list], (entry) => entry[0] === name);
} }
@ -261,14 +244,8 @@ class URLSearchParams {
webidl.assertBranded(this, URLSearchParamsPrototype); webidl.assertBranded(this, URLSearchParamsPrototype);
const prefix = "Failed to execute 'set' on 'URLSearchParams'"; const prefix = "Failed to execute 'set' on 'URLSearchParams'";
webidl.requiredArguments(arguments.length, 2, prefix); webidl.requiredArguments(arguments.length, 2, prefix);
name = webidl.converters.USVString(name, { name = webidl.converters.USVString(name, prefix, "Argument 1");
prefix, value = webidl.converters.USVString(value, prefix, "Argument 2");
context: "Argument 1",
});
value = webidl.converters.USVString(value, {
prefix,
context: "Argument 2",
});
const list = this[_list]; const list = this[_list];
@ -372,12 +349,9 @@ class URL {
constructor(url, base = undefined) { constructor(url, base = undefined) {
const prefix = "Failed to construct 'URL'"; const prefix = "Failed to construct 'URL'";
webidl.requiredArguments(arguments.length, 1, prefix); webidl.requiredArguments(arguments.length, 1, prefix);
url = webidl.converters.DOMString(url, { prefix, context: "Argument 1" }); url = webidl.converters.DOMString(url, prefix, "Argument 1");
if (base !== undefined) { if (base !== undefined) {
base = webidl.converters.DOMString(base, { base = webidl.converters.DOMString(base, prefix, "Argument 2");
prefix,
context: "Argument 2",
});
} }
this[webidl.brand] = webidl.brand; this[webidl.brand] = webidl.brand;
const status = opUrlParse(url, base); const status = opUrlParse(url, base);
@ -392,12 +366,9 @@ class URL {
static canParse(url, base = undefined) { static canParse(url, base = undefined) {
const prefix = "Failed to call 'URL.canParse'"; const prefix = "Failed to call 'URL.canParse'";
webidl.requiredArguments(arguments.length, 1, prefix); webidl.requiredArguments(arguments.length, 1, prefix);
url = webidl.converters.DOMString(url, { prefix, context: "Argument 1" }); url = webidl.converters.DOMString(url, prefix, "Argument 1");
if (base !== undefined) { if (base !== undefined) {
base = webidl.converters.DOMString(base, { base = webidl.converters.DOMString(base, prefix, "Argument 2");
prefix,
context: "Argument 2",
});
} }
const status = opUrlParse(url, base); const status = opUrlParse(url, base);
return status === 0 || status === 1; return status === 0 || status === 1;
@ -467,10 +438,7 @@ class URL {
webidl.assertBranded(this, URLPrototype); webidl.assertBranded(this, URLPrototype);
const prefix = "Failed to set 'hash' on 'URL'"; const prefix = "Failed to set 'hash' on 'URL'";
webidl.requiredArguments(arguments.length, 1, prefix); webidl.requiredArguments(arguments.length, 1, prefix);
value = webidl.converters.DOMString(value, { value = webidl.converters.DOMString(value, prefix, "Argument 1");
prefix,
context: "Argument 1",
});
try { try {
this.#serialization = opUrlReparse( this.#serialization = opUrlReparse(
this.#serialization, this.#serialization,
@ -495,10 +463,7 @@ class URL {
webidl.assertBranded(this, URLPrototype); webidl.assertBranded(this, URLPrototype);
const prefix = "Failed to set 'host' on 'URL'"; const prefix = "Failed to set 'host' on 'URL'";
webidl.requiredArguments(arguments.length, 1, prefix); webidl.requiredArguments(arguments.length, 1, prefix);
value = webidl.converters.DOMString(value, { value = webidl.converters.DOMString(value, prefix, "Argument 1");
prefix,
context: "Argument 1",
});
try { try {
this.#serialization = opUrlReparse( this.#serialization = opUrlReparse(
this.#serialization, this.#serialization,
@ -523,10 +488,7 @@ class URL {
webidl.assertBranded(this, URLPrototype); webidl.assertBranded(this, URLPrototype);
const prefix = "Failed to set 'hostname' on 'URL'"; const prefix = "Failed to set 'hostname' on 'URL'";
webidl.requiredArguments(arguments.length, 1, prefix); webidl.requiredArguments(arguments.length, 1, prefix);
value = webidl.converters.DOMString(value, { value = webidl.converters.DOMString(value, prefix, "Argument 1");
prefix,
context: "Argument 1",
});
try { try {
this.#serialization = opUrlReparse( this.#serialization = opUrlReparse(
this.#serialization, this.#serialization,
@ -550,10 +512,7 @@ class URL {
webidl.assertBranded(this, URLPrototype); webidl.assertBranded(this, URLPrototype);
const prefix = "Failed to set 'href' on 'URL'"; const prefix = "Failed to set 'href' on 'URL'";
webidl.requiredArguments(arguments.length, 1, prefix); webidl.requiredArguments(arguments.length, 1, prefix);
value = webidl.converters.DOMString(value, { value = webidl.converters.DOMString(value, prefix, "Argument 1");
prefix,
context: "Argument 1",
});
const status = opUrlParse(value); const status = opUrlParse(value);
this.#serialization = getSerialization(status, value); this.#serialization = getSerialization(status, value);
this.#updateComponents(); this.#updateComponents();
@ -606,10 +565,7 @@ class URL {
webidl.assertBranded(this, URLPrototype); webidl.assertBranded(this, URLPrototype);
const prefix = "Failed to set 'password' on 'URL'"; const prefix = "Failed to set 'password' on 'URL'";
webidl.requiredArguments(arguments.length, 1, prefix); webidl.requiredArguments(arguments.length, 1, prefix);
value = webidl.converters.DOMString(value, { value = webidl.converters.DOMString(value, prefix, "Argument 1");
prefix,
context: "Argument 1",
});
try { try {
this.#serialization = opUrlReparse( this.#serialization = opUrlReparse(
this.#serialization, this.#serialization,
@ -639,10 +595,7 @@ class URL {
webidl.assertBranded(this, URLPrototype); webidl.assertBranded(this, URLPrototype);
const prefix = "Failed to set 'pathname' on 'URL'"; const prefix = "Failed to set 'pathname' on 'URL'";
webidl.requiredArguments(arguments.length, 1, prefix); webidl.requiredArguments(arguments.length, 1, prefix);
value = webidl.converters.DOMString(value, { value = webidl.converters.DOMString(value, prefix, "Argument 1");
prefix,
context: "Argument 1",
});
try { try {
this.#serialization = opUrlReparse( this.#serialization = opUrlReparse(
this.#serialization, this.#serialization,
@ -674,10 +627,7 @@ class URL {
webidl.assertBranded(this, URLPrototype); webidl.assertBranded(this, URLPrototype);
const prefix = "Failed to set 'port' on 'URL'"; const prefix = "Failed to set 'port' on 'URL'";
webidl.requiredArguments(arguments.length, 1, prefix); webidl.requiredArguments(arguments.length, 1, prefix);
value = webidl.converters.DOMString(value, { value = webidl.converters.DOMString(value, prefix, "Argument 1");
prefix,
context: "Argument 1",
});
try { try {
this.#serialization = opUrlReparse( this.#serialization = opUrlReparse(
this.#serialization, this.#serialization,
@ -702,10 +652,7 @@ class URL {
webidl.assertBranded(this, URLPrototype); webidl.assertBranded(this, URLPrototype);
const prefix = "Failed to set 'protocol' on 'URL'"; const prefix = "Failed to set 'protocol' on 'URL'";
webidl.requiredArguments(arguments.length, 1, prefix); webidl.requiredArguments(arguments.length, 1, prefix);
value = webidl.converters.DOMString(value, { value = webidl.converters.DOMString(value, prefix, "Argument 1");
prefix,
context: "Argument 1",
});
try { try {
this.#serialization = opUrlReparse( this.#serialization = opUrlReparse(
this.#serialization, this.#serialization,
@ -733,10 +680,7 @@ class URL {
webidl.assertBranded(this, URLPrototype); webidl.assertBranded(this, URLPrototype);
const prefix = "Failed to set 'search' on 'URL'"; const prefix = "Failed to set 'search' on 'URL'";
webidl.requiredArguments(arguments.length, 1, prefix); webidl.requiredArguments(arguments.length, 1, prefix);
value = webidl.converters.DOMString(value, { value = webidl.converters.DOMString(value, prefix, "Argument 1");
prefix,
context: "Argument 1",
});
try { try {
this.#serialization = opUrlReparse( this.#serialization = opUrlReparse(
this.#serialization, this.#serialization,
@ -773,10 +717,7 @@ class URL {
webidl.assertBranded(this, URLPrototype); webidl.assertBranded(this, URLPrototype);
const prefix = "Failed to set 'username' on 'URL'"; const prefix = "Failed to set 'username' on 'URL'";
webidl.requiredArguments(arguments.length, 1, prefix); webidl.requiredArguments(arguments.length, 1, prefix);
value = webidl.converters.DOMString(value, { value = webidl.converters.DOMString(value, prefix, "Argument 1");
prefix,
context: "Argument 1",
});
try { try {
this.#serialization = opUrlReparse( this.#serialization = opUrlReparse(
this.#serialization, this.#serialization,
@ -827,15 +768,25 @@ function parseUrlEncoded(bytes) {
webidl webidl
.converters[ .converters[
"sequence<sequence<USVString>> or record<USVString, USVString> or USVString" "sequence<sequence<USVString>> or record<USVString, USVString> or USVString"
] = (V, opts) => { ] = (V, prefix, context, opts) => {
// Union for (sequence<sequence<USVString>> or record<USVString, USVString> or USVString) // Union for (sequence<sequence<USVString>> or record<USVString, USVString> or USVString)
if (webidl.type(V) === "Object" && V !== null) { if (webidl.type(V) === "Object" && V !== null) {
if (V[SymbolIterator] !== undefined) { if (V[SymbolIterator] !== undefined) {
return webidl.converters["sequence<sequence<USVString>>"](V, opts); return webidl.converters["sequence<sequence<USVString>>"](
V,
prefix,
context,
opts,
);
} }
return webidl.converters["record<USVString, USVString>"](V, opts); return webidl.converters["record<USVString, USVString>"](
V,
prefix,
context,
opts,
);
} }
return webidl.converters.USVString(V, opts); return webidl.converters.USVString(V, prefix, context, opts);
}; };
export { export {

View file

@ -56,15 +56,9 @@ class URLPattern {
this[webidl.brand] = webidl.brand; this[webidl.brand] = webidl.brand;
const prefix = "Failed to construct 'URLPattern'"; const prefix = "Failed to construct 'URLPattern'";
webidl.requiredArguments(arguments.length, 1, prefix); webidl.requiredArguments(arguments.length, 1, prefix);
input = webidl.converters.URLPatternInput(input, { input = webidl.converters.URLPatternInput(input, prefix, "Argument 1");
prefix,
context: "Argument 1",
});
if (baseURL !== undefined) { if (baseURL !== undefined) {
baseURL = webidl.converters.USVString(baseURL, { baseURL = webidl.converters.USVString(baseURL, prefix, "Argument 2");
prefix,
context: "Argument 2",
});
} }
const components = ops.op_urlpattern_parse(input, baseURL); const components = ops.op_urlpattern_parse(input, baseURL);
@ -134,15 +128,9 @@ class URLPattern {
webidl.assertBranded(this, URLPatternPrototype); webidl.assertBranded(this, URLPatternPrototype);
const prefix = "Failed to execute 'test' on 'URLPattern'"; const prefix = "Failed to execute 'test' on 'URLPattern'";
webidl.requiredArguments(arguments.length, 1, prefix); webidl.requiredArguments(arguments.length, 1, prefix);
input = webidl.converters.URLPatternInput(input, { input = webidl.converters.URLPatternInput(input, prefix, "Argument 1");
prefix,
context: "Argument 1",
});
if (baseURL !== undefined) { if (baseURL !== undefined) {
baseURL = webidl.converters.USVString(baseURL, { baseURL = webidl.converters.USVString(baseURL, prefix, "Argument 2");
prefix,
context: "Argument 2",
});
} }
const res = ops.op_urlpattern_process_match_input( const res = ops.op_urlpattern_process_match_input(
@ -175,15 +163,9 @@ class URLPattern {
webidl.assertBranded(this, URLPatternPrototype); webidl.assertBranded(this, URLPatternPrototype);
const prefix = "Failed to execute 'exec' on 'URLPattern'"; const prefix = "Failed to execute 'exec' on 'URLPattern'";
webidl.requiredArguments(arguments.length, 1, prefix); webidl.requiredArguments(arguments.length, 1, prefix);
input = webidl.converters.URLPatternInput(input, { input = webidl.converters.URLPatternInput(input, prefix, "Argument 1");
prefix,
context: "Argument 1",
});
if (baseURL !== undefined) { if (baseURL !== undefined) {
baseURL = webidl.converters.USVString(baseURL, { baseURL = webidl.converters.USVString(baseURL, prefix, "Argument 2");
prefix,
context: "Argument 2",
});
} }
const res = ops.op_urlpattern_process_match_input( const res = ops.op_urlpattern_process_match_input(
@ -258,12 +240,12 @@ webidl.converters.URLPatternInit = webidl
{ key: "baseURL", converter: webidl.converters.USVString }, { key: "baseURL", converter: webidl.converters.USVString },
]); ]);
webidl.converters["URLPatternInput"] = (V, opts) => { webidl.converters["URLPatternInput"] = (V, prefix, context, opts) => {
// Union for (URLPatternInit or USVString) // Union for (URLPatternInit or USVString)
if (typeof V == "object") { if (typeof V == "object") {
return webidl.converters.URLPatternInit(V, opts); return webidl.converters.URLPatternInit(V, prefix, context, opts);
} }
return webidl.converters.USVString(V, opts); return webidl.converters.USVString(V, prefix, context, opts);
}; };
export { URLPattern }; export { URLPattern };

View file

@ -94,14 +94,16 @@ class DOMException {
// https://webidl.spec.whatwg.org/#dom-domexception-domexception // https://webidl.spec.whatwg.org/#dom-domexception-domexception
constructor(message = "", name = "Error") { constructor(message = "", name = "Error") {
message = webidl.converters.DOMString(message, { message = webidl.converters.DOMString(
prefix: "Failed to construct 'DOMException'", message,
context: "Argument 1", "Failed to construct 'DOMException'",
}); "Argument 1",
name = webidl.converters.DOMString(name, { );
prefix: "Failed to construct 'DOMException'", name = webidl.converters.DOMString(
context: "Argument 2", name,
}); "Failed to construct 'DOMException'",
"Argument 2",
);
const code = nameToCodeMapping[name] ?? 0; const code = nameToCodeMapping[name] ?? 0;
this[_message] = message; this[_message] = message;

View file

@ -122,7 +122,7 @@ const isTrusted = ObjectGetOwnPropertyDescriptor({
}, },
}, "isTrusted").get; }, "isTrusted").get;
const eventInitConverter = webidl.createDictionaryConverter("EventInit", [{ webidl.converters.EventInit = webidl.createDictionaryConverter("EventInit", [{
key: "bubbles", key: "bubbles",
defaultValue: false, defaultValue: false,
converter: webidl.converters.boolean, converter: webidl.converters.boolean,
@ -167,14 +167,16 @@ class Event {
1, 1,
"Failed to construct 'Event'", "Failed to construct 'Event'",
); );
type = webidl.converters.DOMString(type, { type = webidl.converters.DOMString(
prefix: "Failed to construct 'Event'", type,
context: "Argument 1", "Failed to construct 'Event'",
}); "Argument 1",
const eventInit = eventInitConverter(eventInitDict, { );
prefix: "Failed to construct 'Event'", const eventInit = webidl.converters.EventInit(
context: "Argument 2", eventInitDict,
}); "Failed to construct 'Event'",
"Argument 2",
);
this[_attributes] = { this[_attributes] = {
type, type,
...eventInit, ...eventInit,
@ -947,13 +949,13 @@ function lazyAddEventListenerOptionsConverter() {
); );
} }
webidl.converters.AddEventListenerOptions = (V, opts) => { webidl.converters.AddEventListenerOptions = (V, prefix, context, opts) => {
if (webidl.type(V) !== "Object" || V === null) { if (webidl.type(V) !== "Object" || V === null) {
V = { capture: Boolean(V) }; V = { capture: Boolean(V) };
} }
lazyAddEventListenerOptionsConverter(); lazyAddEventListenerOptionsConverter();
return addEventListenerOptionsConverter(V, opts); return addEventListenerOptionsConverter(V, prefix, context, opts);
}; };
class EventTarget { class EventTarget {
@ -973,10 +975,11 @@ class EventTarget {
webidl.requiredArguments(arguments.length, 2, prefix); webidl.requiredArguments(arguments.length, 2, prefix);
options = webidl.converters.AddEventListenerOptions(options, { options = webidl.converters.AddEventListenerOptions(
options,
prefix, prefix,
context: "Argument 3", "Argument 3",
}); );
if (callback === null) { if (callback === null) {
return; return;

View file

@ -46,9 +46,14 @@ class AbortSignal extends EventTarget {
static timeout(millis) { static timeout(millis) {
const prefix = "Failed to call 'AbortSignal.timeout'"; const prefix = "Failed to call 'AbortSignal.timeout'";
webidl.requiredArguments(arguments.length, 1, prefix); webidl.requiredArguments(arguments.length, 1, prefix);
millis = webidl.converters["unsigned long long"](millis, { millis = webidl.converters["unsigned long long"](
enforceRange: true, millis,
}); prefix,
"Argument 1",
{
enforceRange: true,
},
);
const signal = new AbortSignal(illegalConstructorKey); const signal = new AbortSignal(illegalConstructorKey);
signal[timerId] = setTimeout( signal[timerId] = setTimeout(

View file

@ -23,10 +23,7 @@ const {
function atob(data) { function atob(data) {
const prefix = "Failed to execute 'atob'"; const prefix = "Failed to execute 'atob'";
webidl.requiredArguments(arguments.length, 1, prefix); webidl.requiredArguments(arguments.length, 1, prefix);
data = webidl.converters.DOMString(data, { data = webidl.converters.DOMString(data, prefix, "Argument 1");
prefix,
context: "Argument 1",
});
try { try {
return ops.op_base64_atob(data); return ops.op_base64_atob(data);
} catch (e) { } catch (e) {
@ -47,10 +44,7 @@ function atob(data) {
function btoa(data) { function btoa(data) {
const prefix = "Failed to execute 'btoa'"; const prefix = "Failed to execute 'btoa'";
webidl.requiredArguments(arguments.length, 1, prefix); webidl.requiredArguments(arguments.length, 1, prefix);
data = webidl.converters.DOMString(data, { data = webidl.converters.DOMString(data, prefix, "Argument 1");
prefix,
context: "Argument 1",
});
try { try {
return ops.op_base64_btoa(data); return ops.op_base64_btoa(data);
} catch (e) { } catch (e) {

View file

@ -4666,10 +4666,7 @@ class ByteLengthQueuingStrategy {
constructor(init) { constructor(init) {
const prefix = "Failed to construct 'ByteLengthQueuingStrategy'"; const prefix = "Failed to construct 'ByteLengthQueuingStrategy'";
webidl.requiredArguments(arguments.length, 1, prefix); webidl.requiredArguments(arguments.length, 1, prefix);
init = webidl.converters.QueuingStrategyInit(init, { init = webidl.converters.QueuingStrategyInit(init, prefix, "Argument 1");
prefix,
context: "Argument 1",
});
this[webidl.brand] = webidl.brand; this[webidl.brand] = webidl.brand;
this[_globalObject] = globalThis; this[_globalObject] = globalThis;
this[_highWaterMark] = init.highWaterMark; this[_highWaterMark] = init.highWaterMark;
@ -4723,10 +4720,7 @@ class CountQueuingStrategy {
constructor(init) { constructor(init) {
const prefix = "Failed to construct 'CountQueuingStrategy'"; const prefix = "Failed to construct 'CountQueuingStrategy'";
webidl.requiredArguments(arguments.length, 1, prefix); webidl.requiredArguments(arguments.length, 1, prefix);
init = webidl.converters.QueuingStrategyInit(init, { init = webidl.converters.QueuingStrategyInit(init, prefix, "Argument 1");
prefix,
context: "Argument 1",
});
this[webidl.brand] = webidl.brand; this[webidl.brand] = webidl.brand;
this[_globalObject] = globalThis; this[_globalObject] = globalThis;
this[_highWaterMark] = init.highWaterMark; this[_highWaterMark] = init.highWaterMark;
@ -4803,18 +4797,20 @@ class ReadableStream {
constructor(underlyingSource = undefined, strategy = undefined) { constructor(underlyingSource = undefined, strategy = undefined) {
const prefix = "Failed to construct 'ReadableStream'"; const prefix = "Failed to construct 'ReadableStream'";
if (underlyingSource !== undefined) { if (underlyingSource !== undefined) {
underlyingSource = webidl.converters.object(underlyingSource, { underlyingSource = webidl.converters.object(
underlyingSource,
prefix, prefix,
context: "Argument 1", "Argument 1",
}); );
} else { } else {
underlyingSource = null; underlyingSource = null;
} }
if (strategy !== undefined) { if (strategy !== undefined) {
strategy = webidl.converters.QueuingStrategy(strategy, { strategy = webidl.converters.QueuingStrategy(
strategy,
prefix, prefix,
context: "Argument 2", "Argument 2",
}); );
} else { } else {
strategy = {}; strategy = {};
} }
@ -4823,7 +4819,8 @@ class ReadableStream {
if (underlyingSource !== undefined) { if (underlyingSource !== undefined) {
underlyingSourceDict = webidl.converters.UnderlyingSource( underlyingSourceDict = webidl.converters.UnderlyingSource(
underlyingSource, underlyingSource,
{ prefix, context: "underlyingSource" }, prefix,
"underlyingSource",
); );
} }
initializeReadableStream(this); initializeReadableStream(this);
@ -4890,10 +4887,11 @@ class ReadableStream {
webidl.assertBranded(this, ReadableStreamPrototype); webidl.assertBranded(this, ReadableStreamPrototype);
const prefix = "Failed to execute 'getReader' on 'ReadableStream'"; const prefix = "Failed to execute 'getReader' on 'ReadableStream'";
if (options !== undefined) { if (options !== undefined) {
options = webidl.converters.ReadableStreamGetReaderOptions(options, { options = webidl.converters.ReadableStreamGetReaderOptions(
options,
prefix, prefix,
context: "Argument 1", "Argument 1",
}); );
} else { } else {
options = {}; options = {};
} }
@ -4915,14 +4913,16 @@ class ReadableStream {
webidl.assertBranded(this, ReadableStreamPrototype); webidl.assertBranded(this, ReadableStreamPrototype);
const prefix = "Failed to execute 'pipeThrough' on 'ReadableStream'"; const prefix = "Failed to execute 'pipeThrough' on 'ReadableStream'";
webidl.requiredArguments(arguments.length, 1, prefix); webidl.requiredArguments(arguments.length, 1, prefix);
transform = webidl.converters.ReadableWritablePair(transform, { transform = webidl.converters.ReadableWritablePair(
transform,
prefix, prefix,
context: "Argument 1", "Argument 1",
}); );
options = webidl.converters.StreamPipeOptions(options, { options = webidl.converters.StreamPipeOptions(
options,
prefix, prefix,
context: "Argument 2", "Argument 2",
}); );
const { readable, writable } = transform; const { readable, writable } = transform;
const { preventClose, preventAbort, preventCancel, signal } = options; const { preventClose, preventAbort, preventCancel, signal } = options;
if (isReadableStreamLocked(this)) { if (isReadableStreamLocked(this)) {
@ -4953,14 +4953,16 @@ class ReadableStream {
webidl.assertBranded(this, ReadableStreamPrototype); webidl.assertBranded(this, ReadableStreamPrototype);
const prefix = "Failed to execute 'pipeTo' on 'ReadableStream'"; const prefix = "Failed to execute 'pipeTo' on 'ReadableStream'";
webidl.requiredArguments(arguments.length, 1, prefix); webidl.requiredArguments(arguments.length, 1, prefix);
destination = webidl.converters.WritableStream(destination, { destination = webidl.converters.WritableStream(
destination,
prefix, prefix,
context: "Argument 1", "Argument 1",
}); );
options = webidl.converters.StreamPipeOptions(options, { options = webidl.converters.StreamPipeOptions(
options,
prefix, prefix,
context: "Argument 2", "Argument 2",
}); );
} catch (err) { } catch (err) {
return PromiseReject(err); return PromiseReject(err);
} }
@ -4999,10 +5001,11 @@ class ReadableStream {
values(options = {}) { values(options = {}) {
webidl.assertBranded(this, ReadableStreamPrototype); webidl.assertBranded(this, ReadableStreamPrototype);
const prefix = "Failed to execute 'values' on 'ReadableStream'"; const prefix = "Failed to execute 'values' on 'ReadableStream'";
options = webidl.converters.ReadableStreamIteratorOptions(options, { options = webidl.converters.ReadableStreamIteratorOptions(
options,
prefix, prefix,
context: "Argument 1", "Argument 1",
}); );
/** @type {AsyncIterableIterator<R>} */ /** @type {AsyncIterableIterator<R>} */
const iterator = ObjectCreate(readableStreamAsyncIteratorPrototype); const iterator = ObjectCreate(readableStreamAsyncIteratorPrototype);
const reader = acquireReadableStreamDefaultReader(this); const reader = acquireReadableStreamDefaultReader(this);
@ -5044,10 +5047,7 @@ class ReadableStreamDefaultReader {
constructor(stream) { constructor(stream) {
const prefix = "Failed to construct 'ReadableStreamDefaultReader'"; const prefix = "Failed to construct 'ReadableStreamDefaultReader'";
webidl.requiredArguments(arguments.length, 1, prefix); webidl.requiredArguments(arguments.length, 1, prefix);
stream = webidl.converters.ReadableStream(stream, { stream = webidl.converters.ReadableStream(stream, prefix, "Argument 1");
prefix,
context: "Argument 1",
});
this[webidl.brand] = webidl.brand; this[webidl.brand] = webidl.brand;
setUpReadableStreamDefaultReader(this, stream); setUpReadableStreamDefaultReader(this, stream);
} }
@ -5144,10 +5144,7 @@ class ReadableStreamBYOBReader {
constructor(stream) { constructor(stream) {
const prefix = "Failed to construct 'ReadableStreamBYOBReader'"; const prefix = "Failed to construct 'ReadableStreamBYOBReader'";
webidl.requiredArguments(arguments.length, 1, prefix); webidl.requiredArguments(arguments.length, 1, prefix);
stream = webidl.converters.ReadableStream(stream, { stream = webidl.converters.ReadableStream(stream, prefix, "Argument 1");
prefix,
context: "Argument 1",
});
this[webidl.brand] = webidl.brand; this[webidl.brand] = webidl.brand;
setUpReadableStreamBYOBReader(this, stream); setUpReadableStreamBYOBReader(this, stream);
} }
@ -5160,10 +5157,7 @@ class ReadableStreamBYOBReader {
try { try {
webidl.assertBranded(this, ReadableStreamBYOBReaderPrototype); webidl.assertBranded(this, ReadableStreamBYOBReaderPrototype);
const prefix = "Failed to execute 'read' on 'ReadableStreamBYOBReader'"; const prefix = "Failed to execute 'read' on 'ReadableStreamBYOBReader'";
view = webidl.converters.ArrayBufferView(view, { view = webidl.converters.ArrayBufferView(view, prefix, "Argument 1");
prefix,
context: "Argument 1",
});
} catch (err) { } catch (err) {
return PromiseReject(err); return PromiseReject(err);
} }
@ -5286,11 +5280,14 @@ class ReadableStreamBYOBRequest {
webidl.assertBranded(this, ReadableStreamBYOBRequestPrototype); webidl.assertBranded(this, ReadableStreamBYOBRequestPrototype);
const prefix = "Failed to execute 'respond' on 'ReadableStreamBYOBRequest'"; const prefix = "Failed to execute 'respond' on 'ReadableStreamBYOBRequest'";
webidl.requiredArguments(arguments.length, 1, prefix); webidl.requiredArguments(arguments.length, 1, prefix);
bytesWritten = webidl.converters["unsigned long long"](bytesWritten, { bytesWritten = webidl.converters["unsigned long long"](
enforceRange: true, bytesWritten,
prefix, prefix,
context: "Argument 1", "Argument 1",
}); {
enforceRange: true,
},
);
if (this[_controller] === undefined) { if (this[_controller] === undefined) {
throw new TypeError("This BYOB request has been invalidated"); throw new TypeError("This BYOB request has been invalidated");
@ -5319,10 +5316,7 @@ class ReadableStreamBYOBRequest {
const prefix = const prefix =
"Failed to execute 'respondWithNewView' on 'ReadableStreamBYOBRequest'"; "Failed to execute 'respondWithNewView' on 'ReadableStreamBYOBRequest'";
webidl.requiredArguments(arguments.length, 1, prefix); webidl.requiredArguments(arguments.length, 1, prefix);
view = webidl.converters.ArrayBufferView(view, { view = webidl.converters.ArrayBufferView(view, prefix, "Argument 1");
prefix,
context: "Argument 1",
});
if (this[_controller] === undefined) { if (this[_controller] === undefined) {
throw new TypeError("This BYOB request has been invalidated"); throw new TypeError("This BYOB request has been invalidated");
@ -5414,10 +5408,7 @@ class ReadableByteStreamController {
"Failed to execute 'enqueue' on 'ReadableByteStreamController'"; "Failed to execute 'enqueue' on 'ReadableByteStreamController'";
webidl.requiredArguments(arguments.length, 1, prefix); webidl.requiredArguments(arguments.length, 1, prefix);
const arg1 = "Argument 1"; const arg1 = "Argument 1";
chunk = webidl.converters.ArrayBufferView(chunk, { chunk = webidl.converters.ArrayBufferView(chunk, prefix, arg1);
prefix,
context: arg1,
});
let buffer, byteLength; let buffer, byteLength;
if (TypedArrayPrototypeGetSymbolToStringTag(chunk) === undefined) { if (TypedArrayPrototypeGetSymbolToStringTag(chunk) === undefined) {
buffer = DataViewPrototypeGetBuffer(/** @type {DataView} */ (chunk)); buffer = DataViewPrototypeGetBuffer(/** @type {DataView} */ (chunk));
@ -5700,27 +5691,27 @@ class TransformStream {
) { ) {
const prefix = "Failed to construct 'TransformStream'"; const prefix = "Failed to construct 'TransformStream'";
if (transformer !== undefined) { if (transformer !== undefined) {
transformer = webidl.converters.object(transformer, { transformer = webidl.converters.object(transformer, prefix, "Argument 1");
prefix,
context: "Argument 1",
});
} }
writableStrategy = webidl.converters.QueuingStrategy(writableStrategy, { writableStrategy = webidl.converters.QueuingStrategy(
writableStrategy,
prefix, prefix,
context: "Argument 2", "Argument 2",
}); );
readableStrategy = webidl.converters.QueuingStrategy(readableStrategy, { readableStrategy = webidl.converters.QueuingStrategy(
readableStrategy,
prefix, prefix,
context: "Argument 2", "Argument 3",
}); );
this[webidl.brand] = webidl.brand; this[webidl.brand] = webidl.brand;
if (transformer === undefined) { if (transformer === undefined) {
transformer = null; transformer = null;
} }
const transformerDict = webidl.converters.Transformer(transformer, { const transformerDict = webidl.converters.Transformer(
transformer,
prefix, prefix,
context: "transformer", "transformer",
}); );
if (transformerDict.readableType !== undefined) { if (transformerDict.readableType !== undefined) {
throw new RangeError( throw new RangeError(
`${prefix}: readableType transformers not supported.`, `${prefix}: readableType transformers not supported.`,
@ -5887,22 +5878,25 @@ class WritableStream {
constructor(underlyingSink = undefined, strategy = {}) { constructor(underlyingSink = undefined, strategy = {}) {
const prefix = "Failed to construct 'WritableStream'"; const prefix = "Failed to construct 'WritableStream'";
if (underlyingSink !== undefined) { if (underlyingSink !== undefined) {
underlyingSink = webidl.converters.object(underlyingSink, { underlyingSink = webidl.converters.object(
underlyingSink,
prefix, prefix,
context: "Argument 1", "Argument 1",
}); );
} }
strategy = webidl.converters.QueuingStrategy(strategy, { strategy = webidl.converters.QueuingStrategy(
strategy,
prefix, prefix,
context: "Argument 2", "Argument 2",
}); );
this[webidl.brand] = webidl.brand; this[webidl.brand] = webidl.brand;
if (underlyingSink === undefined) { if (underlyingSink === undefined) {
underlyingSink = null; underlyingSink = null;
} }
const underlyingSinkDict = webidl.converters.UnderlyingSink( const underlyingSinkDict = webidl.converters.UnderlyingSink(
underlyingSink, underlyingSink,
{ prefix, context: "underlyingSink" }, prefix,
"underlyingSink",
); );
if (underlyingSinkDict.type != null) { if (underlyingSinkDict.type != null) {
throw new RangeError( throw new RangeError(
@ -6003,10 +5997,7 @@ class WritableStreamDefaultWriter {
constructor(stream) { constructor(stream) {
const prefix = "Failed to construct 'WritableStreamDefaultWriter'"; const prefix = "Failed to construct 'WritableStreamDefaultWriter'";
webidl.requiredArguments(arguments.length, 1, prefix); webidl.requiredArguments(arguments.length, 1, prefix);
stream = webidl.converters.WritableStream(stream, { stream = webidl.converters.WritableStream(stream, prefix, "Argument 1");
prefix,
context: "Argument 1",
});
this[webidl.brand] = webidl.brand; this[webidl.brand] = webidl.brand;
setUpWritableStreamDefaultWriter(this, stream); setUpWritableStreamDefaultWriter(this, stream);
} }
@ -6251,8 +6242,8 @@ webidl.converters.UnderlyingSource = webidl
}, },
{ {
key: "autoAllocateChunkSize", key: "autoAllocateChunkSize",
converter: (V, opts) => converter: (V, prefix, context, opts) =>
webidl.converters["unsigned long long"](V, { webidl.converters["unsigned long long"](V, prefix, context, {
...opts, ...opts,
enforceRange: true, enforceRange: true,
}), }),

View file

@ -53,14 +53,12 @@ class TextDecoder {
*/ */
constructor(label = "utf-8", options = {}) { constructor(label = "utf-8", options = {}) {
const prefix = "Failed to construct 'TextDecoder'"; const prefix = "Failed to construct 'TextDecoder'";
label = webidl.converters.DOMString(label, { label = webidl.converters.DOMString(label, prefix, "Argument 1");
options = webidl.converters.TextDecoderOptions(
options,
prefix, prefix,
context: "Argument 1", "Argument 2",
}); );
options = webidl.converters.TextDecoderOptions(options, {
prefix,
context: "Argument 2",
});
const encoding = ops.op_encoding_normalize_label(label); const encoding = ops.op_encoding_normalize_label(label);
this.#encoding = encoding; this.#encoding = encoding;
this.#fatal = options.fatal; this.#fatal = options.fatal;
@ -95,18 +93,17 @@ class TextDecoder {
webidl.assertBranded(this, TextDecoderPrototype); webidl.assertBranded(this, TextDecoderPrototype);
const prefix = "Failed to execute 'decode' on 'TextDecoder'"; const prefix = "Failed to execute 'decode' on 'TextDecoder'";
if (input !== undefined) { if (input !== undefined) {
input = webidl.converters.BufferSource(input, { input = webidl.converters.BufferSource(input, prefix, "Argument 1", {
prefix,
context: "Argument 1",
allowShared: true, allowShared: true,
}); });
} }
let stream = false; let stream = false;
if (options !== undefined) { if (options !== undefined) {
options = webidl.converters.TextDecodeOptions(options, { options = webidl.converters.TextDecodeOptions(
options,
prefix, prefix,
context: "Argument 2", "Argument 2",
}); );
stream = options.stream; stream = options.stream;
} }
@ -215,13 +212,13 @@ class TextEncoder {
*/ */
encode(input = "") { encode(input = "") {
webidl.assertBranded(this, TextEncoderPrototype); webidl.assertBranded(this, TextEncoderPrototype);
const prefix = "Failed to execute 'encode' on 'TextEncoder'";
// The WebIDL type of `input` is `USVString`, but `core.encode` already // The WebIDL type of `input` is `USVString`, but `core.encode` already
// converts lone surrogates to the replacement character. // converts lone surrogates to the replacement character.
input = webidl.converters.DOMString(input, { input = webidl.converters.DOMString(
prefix, input,
context: "Argument 1", "Failed to execute 'encode' on 'TextEncoder'",
}); "Argument 1",
);
return core.encode(input); return core.encode(input);
} }
@ -235,15 +232,15 @@ class TextEncoder {
const prefix = "Failed to execute 'encodeInto' on 'TextEncoder'"; const prefix = "Failed to execute 'encodeInto' on 'TextEncoder'";
// The WebIDL type of `source` is `USVString`, but the ops bindings // The WebIDL type of `source` is `USVString`, but the ops bindings
// already convert lone surrogates to the replacement character. // already convert lone surrogates to the replacement character.
source = webidl.converters.DOMString(source, { source = webidl.converters.DOMString(source, prefix, "Argument 1");
destination = webidl.converters.Uint8Array(
destination,
prefix, prefix,
context: "Argument 1", "Argument 2",
}); {
destination = webidl.converters.Uint8Array(destination, { allowShared: true,
prefix, },
context: "Argument 2", );
allowShared: true,
});
ops.op_encoding_encode_into(source, destination, encodeIntoBuf); ops.op_encoding_encode_into(source, destination, encodeIntoBuf);
return { return {
read: encodeIntoBuf[0], read: encodeIntoBuf[0],
@ -269,21 +266,19 @@ class TextDecoderStream {
*/ */
constructor(label = "utf-8", options = {}) { constructor(label = "utf-8", options = {}) {
const prefix = "Failed to construct 'TextDecoderStream'"; const prefix = "Failed to construct 'TextDecoderStream'";
label = webidl.converters.DOMString(label, { label = webidl.converters.DOMString(label, prefix, "Argument 1");
options = webidl.converters.TextDecoderOptions(
options,
prefix, prefix,
context: "Argument 1", "Argument 2",
}); );
options = webidl.converters.TextDecoderOptions(options, {
prefix,
context: "Argument 2",
});
this.#decoder = new TextDecoder(label, options); this.#decoder = new TextDecoder(label, options);
this.#transform = new TransformStream({ this.#transform = new TransformStream({
// The transform and flush functions need access to TextDecoderStream's // The transform and flush functions need access to TextDecoderStream's
// `this`, so they are defined as functions rather than methods. // `this`, so they are defined as functions rather than methods.
transform: (chunk, controller) => { transform: (chunk, controller) => {
try { try {
chunk = webidl.converters.BufferSource(chunk, { chunk = webidl.converters.BufferSource(chunk, prefix, "chunk", {
allowShared: true, allowShared: true,
}); });
const decoded = this.#decoder.decode(chunk, { stream: true }); const decoded = this.#decoder.decode(chunk, { stream: true });

View file

@ -218,14 +218,16 @@ class Blob {
*/ */
constructor(blobParts = [], options = {}) { constructor(blobParts = [], options = {}) {
const prefix = "Failed to construct 'Blob'"; const prefix = "Failed to construct 'Blob'";
blobParts = webidl.converters["sequence<BlobPart>"](blobParts, { blobParts = webidl.converters["sequence<BlobPart>"](
context: "Argument 1", blobParts,
prefix, prefix,
}); "Argument 1",
options = webidl.converters["BlobPropertyBag"](options, { );
context: "Argument 2", options = webidl.converters["BlobPropertyBag"](
options,
prefix, prefix,
}); "Argument 2",
);
this[webidl.brand] = webidl.brand; this[webidl.brand] = webidl.brand;
@ -261,24 +263,21 @@ class Blob {
webidl.assertBranded(this, BlobPrototype); webidl.assertBranded(this, BlobPrototype);
const prefix = "Failed to execute 'slice' on 'Blob'"; const prefix = "Failed to execute 'slice' on 'Blob'";
if (start !== undefined) { if (start !== undefined) {
start = webidl.converters["long long"](start, { start = webidl.converters["long long"](start, prefix, "Argument 1", {
clamp: true, clamp: true,
context: "Argument 1",
prefix,
}); });
} }
if (end !== undefined) { if (end !== undefined) {
end = webidl.converters["long long"](end, { end = webidl.converters["long long"](end, prefix, "Argument 2", {
clamp: true, clamp: true,
context: "Argument 2",
prefix,
}); });
} }
if (contentType !== undefined) { if (contentType !== undefined) {
contentType = webidl.converters["DOMString"](contentType, { contentType = webidl.converters["DOMString"](
context: "Argument 3", contentType,
prefix, prefix,
}); "Argument 3",
);
} }
// deno-lint-ignore no-this-alias // deno-lint-ignore no-this-alias
@ -430,27 +429,27 @@ webidl.converters["Blob"] = webidl.createInterfaceConverter(
"Blob", "Blob",
Blob.prototype, Blob.prototype,
); );
webidl.converters["BlobPart"] = (V, opts) => { webidl.converters["BlobPart"] = (V, prefix, context, opts) => {
// Union for ((ArrayBuffer or ArrayBufferView) or Blob or USVString) // Union for ((ArrayBuffer or ArrayBufferView) or Blob or USVString)
if (typeof V == "object") { if (typeof V == "object") {
if (ObjectPrototypeIsPrototypeOf(BlobPrototype, V)) { if (ObjectPrototypeIsPrototypeOf(BlobPrototype, V)) {
return webidl.converters["Blob"](V, opts); return webidl.converters["Blob"](V, prefix, context, opts);
} }
if ( if (
ObjectPrototypeIsPrototypeOf(ArrayBufferPrototype, V) || ObjectPrototypeIsPrototypeOf(ArrayBufferPrototype, V) ||
// deno-lint-ignore prefer-primordials // deno-lint-ignore prefer-primordials
ObjectPrototypeIsPrototypeOf(SharedArrayBuffer.prototype, V) ObjectPrototypeIsPrototypeOf(SharedArrayBuffer.prototype, V)
) { ) {
return webidl.converters["ArrayBuffer"](V, opts); return webidl.converters["ArrayBuffer"](V, prefix, context, opts);
} }
if (ArrayBufferIsView(V)) { if (ArrayBufferIsView(V)) {
return webidl.converters["ArrayBufferView"](V, opts); return webidl.converters["ArrayBufferView"](V, prefix, context, opts);
} }
} }
// BlobPart is passed to processBlobParts after conversion, which calls core.encode() // BlobPart is passed to processBlobParts after conversion, which calls core.encode()
// on the string. // on the string.
// core.encode() is equivalent to USVString normalization. // core.encode() is equivalent to USVString normalization.
return webidl.converters["DOMString"](V, opts); return webidl.converters["DOMString"](V, prefix, context, opts);
}; };
webidl.converters["sequence<BlobPart>"] = webidl.createSequenceConverter( webidl.converters["sequence<BlobPart>"] = webidl.createSequenceConverter(
webidl.converters["BlobPart"], webidl.converters["BlobPart"],
@ -494,18 +493,17 @@ class File extends Blob {
const prefix = "Failed to construct 'File'"; const prefix = "Failed to construct 'File'";
webidl.requiredArguments(arguments.length, 2, prefix); webidl.requiredArguments(arguments.length, 2, prefix);
fileBits = webidl.converters["sequence<BlobPart>"](fileBits, { fileBits = webidl.converters["sequence<BlobPart>"](
context: "Argument 1", fileBits,
prefix, prefix,
}); "Argument 1",
fileName = webidl.converters["USVString"](fileName, { );
context: "Argument 2", fileName = webidl.converters["USVString"](fileName, prefix, "Argument 2");
options = webidl.converters["FilePropertyBag"](
options,
prefix, prefix,
}); "Argument 3",
options = webidl.converters["FilePropertyBag"](options, { );
context: "Argument 3",
prefix,
});
super(fileBits, options); super(fileBits, options);

View file

@ -383,10 +383,7 @@ class FileReader extends EventTarget {
const prefix = "Failed to execute 'readAsText' on 'FileReader'"; const prefix = "Failed to execute 'readAsText' on 'FileReader'";
webidl.requiredArguments(arguments.length, 1, prefix); webidl.requiredArguments(arguments.length, 1, prefix);
if (encoding !== undefined) { if (encoding !== undefined) {
encoding = webidl.converters["DOMString"](encoding, { encoding = webidl.converters["DOMString"](encoding, prefix, "Argument 2");
prefix,
context: "Argument 2",
});
} }
// alias for readAsArrayBuffer // alias for readAsArrayBuffer
this.#readOperation(blob, { kind: "Text", encoding }); this.#readOperation(blob, { kind: "Text", encoding });

View file

@ -24,10 +24,7 @@ import { URL } from "ext:deno_url/00_url.js";
function createObjectURL(blob) { function createObjectURL(blob) {
const prefix = "Failed to execute 'createObjectURL' on 'URL'"; const prefix = "Failed to execute 'createObjectURL' on 'URL'";
webidl.requiredArguments(arguments.length, 1, prefix); webidl.requiredArguments(arguments.length, 1, prefix);
blob = webidl.converters["Blob"](blob, { blob = webidl.converters["Blob"](blob, prefix, "Argument 1");
context: "Argument 1",
prefix,
});
return ops.op_blob_create_object_url(blob.type, getParts(blob)); return ops.op_blob_create_object_url(blob.type, getParts(blob));
} }
@ -39,10 +36,7 @@ function createObjectURL(blob) {
function revokeObjectURL(url) { function revokeObjectURL(url) {
const prefix = "Failed to execute 'revokeObjectURL' on 'URL'"; const prefix = "Failed to execute 'revokeObjectURL' on 'URL'";
webidl.requiredArguments(arguments.length, 1, prefix); webidl.requiredArguments(arguments.length, 1, prefix);
url = webidl.converters["DOMString"](url, { url = webidl.converters["DOMString"](url, prefix, "Argument 1");
context: "Argument 1",
prefix,
});
ops.op_blob_revoke_object_url(url); ops.op_blob_revoke_object_url(url);
} }

View file

@ -110,16 +110,15 @@ class MessagePort extends EventTarget {
) { ) {
const transfer = webidl.converters["sequence<object>"]( const transfer = webidl.converters["sequence<object>"](
transferOrOptions, transferOrOptions,
{ prefix, context: "Argument 2" }, prefix,
"Argument 2",
); );
options = { transfer }; options = { transfer };
} else { } else {
options = webidl.converters.StructuredSerializeOptions( options = webidl.converters.StructuredSerializeOptions(
transferOrOptions, transferOrOptions,
{ prefix,
prefix, "Argument 2",
context: "Argument 2",
},
); );
} }
const { transfer } = options; const { transfer } = options;
@ -330,10 +329,11 @@ webidl.converters.StructuredSerializeOptions = webidl
function structuredClone(value, options) { function structuredClone(value, options) {
const prefix = "Failed to execute 'structuredClone'"; const prefix = "Failed to execute 'structuredClone'";
webidl.requiredArguments(arguments.length, 1, prefix); webidl.requiredArguments(arguments.length, 1, prefix);
options = webidl.converters.StructuredSerializeOptions(options, { options = webidl.converters.StructuredSerializeOptions(
options,
prefix, prefix,
context: "Argument 2", "Argument 2",
}); );
const messageData = serializeJsMessageData(value, options.transfer); const messageData = serializeJsMessageData(value, options.transfer);
return deserializeJsMessageData(messageData)[0]; return deserializeJsMessageData(messageData)[0];
} }

View file

@ -29,19 +29,13 @@ class CompressionStream {
constructor(format) { constructor(format) {
const prefix = "Failed to construct 'CompressionStream'"; const prefix = "Failed to construct 'CompressionStream'";
webidl.requiredArguments(arguments.length, 1, prefix); webidl.requiredArguments(arguments.length, 1, prefix);
format = webidl.converters.CompressionFormat(format, { format = webidl.converters.CompressionFormat(format, prefix, "Argument 1");
prefix,
context: "Argument 1",
});
const rid = ops.op_compression_new(format, false); const rid = ops.op_compression_new(format, false);
this.#transform = new TransformStream({ this.#transform = new TransformStream({
transform(chunk, controller) { transform(chunk, controller) {
chunk = webidl.converters.BufferSource(chunk, { chunk = webidl.converters.BufferSource(chunk, prefix, "chunk");
prefix,
context: "chunk",
});
const output = ops.op_compression_write( const output = ops.op_compression_write(
rid, rid,
chunk, chunk,
@ -77,19 +71,13 @@ class DecompressionStream {
constructor(format) { constructor(format) {
const prefix = "Failed to construct 'DecompressionStream'"; const prefix = "Failed to construct 'DecompressionStream'";
webidl.requiredArguments(arguments.length, 1, prefix); webidl.requiredArguments(arguments.length, 1, prefix);
format = webidl.converters.CompressionFormat(format, { format = webidl.converters.CompressionFormat(format, prefix, "Argument 1");
prefix,
context: "Argument 1",
});
const rid = ops.op_compression_new(format, true); const rid = ops.op_compression_new(format, true);
this.#transform = new TransformStream({ this.#transform = new TransformStream({
transform(chunk, controller) { transform(chunk, controller) {
chunk = webidl.converters.BufferSource(chunk, { chunk = webidl.converters.BufferSource(chunk, prefix, "chunk");
prefix,
context: "chunk",
});
const output = ops.op_compression_write( const output = ops.op_compression_write(
rid, rid,
chunk, chunk,

View file

@ -41,11 +41,16 @@ webidl.converters["PerformanceMarkOptions"] = webidl
], ],
); );
webidl.converters["DOMString or DOMHighResTimeStamp"] = (V, opts) => { webidl.converters["DOMString or DOMHighResTimeStamp"] = (
V,
prefix,
context,
opts,
) => {
if (webidl.type(V) === "Number" && V !== null) { if (webidl.type(V) === "Number" && V !== null) {
return webidl.converters.DOMHighResTimeStamp(V, opts); return webidl.converters.DOMHighResTimeStamp(V, prefix, context, opts);
} }
return webidl.converters.DOMString(V, opts); return webidl.converters.DOMString(V, prefix, context, opts);
}; };
webidl.converters["PerformanceMeasureOptions"] = webidl webidl.converters["PerformanceMeasureOptions"] = webidl
@ -71,11 +76,21 @@ webidl.converters["PerformanceMeasureOptions"] = webidl
], ],
); );
webidl.converters["DOMString or PerformanceMeasureOptions"] = (V, opts) => { webidl.converters["DOMString or PerformanceMeasureOptions"] = (
V,
prefix,
context,
opts,
) => {
if (webidl.type(V) === "Object" && V !== null) { if (webidl.type(V) === "Object" && V !== null) {
return webidl.converters["PerformanceMeasureOptions"](V, opts); return webidl.converters["PerformanceMeasureOptions"](
V,
prefix,
context,
opts,
);
} }
return webidl.converters.DOMString(V, opts); return webidl.converters.DOMString(V, prefix, context, opts);
}; };
function setTimeOrigin(origin) { function setTimeOrigin(origin) {
@ -221,15 +236,13 @@ class PerformanceMark extends PerformanceEntry {
const prefix = "Failed to construct 'PerformanceMark'"; const prefix = "Failed to construct 'PerformanceMark'";
webidl.requiredArguments(arguments.length, 1, prefix); webidl.requiredArguments(arguments.length, 1, prefix);
name = webidl.converters.DOMString(name, { name = webidl.converters.DOMString(name, prefix, "Argument 1");
prefix,
context: "Argument 1",
});
options = webidl.converters.PerformanceMarkOptions(options, { options = webidl.converters.PerformanceMarkOptions(
options,
prefix, prefix,
context: "Argument 2", "Argument 2",
}); );
const { detail = null, startTime = now() } = options; const { detail = null, startTime = now() } = options;
@ -345,10 +358,11 @@ class Performance extends EventTarget {
clearMarks(markName = undefined) { clearMarks(markName = undefined) {
webidl.assertBranded(this, PerformancePrototype); webidl.assertBranded(this, PerformancePrototype);
if (markName !== undefined) { if (markName !== undefined) {
markName = webidl.converters.DOMString(markName, { markName = webidl.converters.DOMString(
prefix: "Failed to execute 'clearMarks' on 'Performance'", markName,
context: "Argument 1", "Failed to execute 'clearMarks' on 'Performance'",
}); "Argument 1",
);
performanceEntries = ArrayPrototypeFilter( performanceEntries = ArrayPrototypeFilter(
performanceEntries, performanceEntries,
@ -365,10 +379,11 @@ class Performance extends EventTarget {
clearMeasures(measureName = undefined) { clearMeasures(measureName = undefined) {
webidl.assertBranded(this, PerformancePrototype); webidl.assertBranded(this, PerformancePrototype);
if (measureName !== undefined) { if (measureName !== undefined) {
measureName = webidl.converters.DOMString(measureName, { measureName = webidl.converters.DOMString(
prefix: "Failed to execute 'clearMeasures' on 'Performance'", measureName,
context: "Argument 1", "Failed to execute 'clearMeasures' on 'Performance'",
}); "Argument 1",
);
performanceEntries = ArrayPrototypeFilter( performanceEntries = ArrayPrototypeFilter(
performanceEntries, performanceEntries,
@ -396,16 +411,10 @@ class Performance extends EventTarget {
const prefix = "Failed to execute 'getEntriesByName' on 'Performance'"; const prefix = "Failed to execute 'getEntriesByName' on 'Performance'";
webidl.requiredArguments(arguments.length, 1, prefix); webidl.requiredArguments(arguments.length, 1, prefix);
name = webidl.converters.DOMString(name, { name = webidl.converters.DOMString(name, prefix, "Argument 1");
prefix,
context: "Argument 1",
});
if (type !== undefined) { if (type !== undefined) {
type = webidl.converters.DOMString(type, { type = webidl.converters.DOMString(type, prefix, "Argument 2");
prefix,
context: "Argument 2",
});
} }
return filterByNameType(name, type); return filterByNameType(name, type);
@ -416,10 +425,7 @@ class Performance extends EventTarget {
const prefix = "Failed to execute 'getEntriesByName' on 'Performance'"; const prefix = "Failed to execute 'getEntriesByName' on 'Performance'";
webidl.requiredArguments(arguments.length, 1, prefix); webidl.requiredArguments(arguments.length, 1, prefix);
type = webidl.converters.DOMString(type, { type = webidl.converters.DOMString(type, prefix, "Argument 1");
prefix,
context: "Argument 1",
});
return filterByNameType(undefined, type); return filterByNameType(undefined, type);
} }
@ -432,15 +438,13 @@ class Performance extends EventTarget {
const prefix = "Failed to execute 'mark' on 'Performance'"; const prefix = "Failed to execute 'mark' on 'Performance'";
webidl.requiredArguments(arguments.length, 1, prefix); webidl.requiredArguments(arguments.length, 1, prefix);
markName = webidl.converters.DOMString(markName, { markName = webidl.converters.DOMString(markName, prefix, "Argument 1");
prefix,
context: "Argument 1",
});
markOptions = webidl.converters.PerformanceMarkOptions(markOptions, { markOptions = webidl.converters.PerformanceMarkOptions(
markOptions,
prefix, prefix,
context: "Argument 2", "Argument 2",
}); );
// 3.1.1.1 If the global object is a Window object and markName uses the // 3.1.1.1 If the global object is a Window object and markName uses the
// same name as a read only attribute in the PerformanceTiming interface, // same name as a read only attribute in the PerformanceTiming interface,
@ -460,22 +464,21 @@ class Performance extends EventTarget {
const prefix = "Failed to execute 'measure' on 'Performance'"; const prefix = "Failed to execute 'measure' on 'Performance'";
webidl.requiredArguments(arguments.length, 1, prefix); webidl.requiredArguments(arguments.length, 1, prefix);
measureName = webidl.converters.DOMString(measureName, { measureName = webidl.converters.DOMString(
measureName,
prefix, prefix,
context: "Argument 1", "Argument 1",
}); );
startOrMeasureOptions = webidl.converters startOrMeasureOptions = webidl.converters
["DOMString or PerformanceMeasureOptions"](startOrMeasureOptions, { ["DOMString or PerformanceMeasureOptions"](
startOrMeasureOptions,
prefix, prefix,
context: "Argument 2", "Argument 2",
}); );
if (endMark !== undefined) { if (endMark !== undefined) {
endMark = webidl.converters.DOMString(endMark, { endMark = webidl.converters.DOMString(endMark, prefix, "Argument 3");
prefix,
context: "Argument 3",
});
} }
if ( if (

View file

@ -191,7 +191,7 @@ function createIntegerConversion(bitLength, typeOpts) {
const twoToTheBitLength = MathPow(2, bitLength); const twoToTheBitLength = MathPow(2, bitLength);
const twoToOneLessThanTheBitLength = MathPow(2, bitLength - 1); const twoToOneLessThanTheBitLength = MathPow(2, bitLength - 1);
return (V, opts = {}) => { return (V, prefix = undefined, context = undefined, opts = {}) => {
let x = toNumber(V); let x = toNumber(V);
x = censorNegativeZero(x); x = censorNegativeZero(x);
@ -200,8 +200,8 @@ function createIntegerConversion(bitLength, typeOpts) {
throw makeException( throw makeException(
TypeError, TypeError,
"is not a finite number", "is not a finite number",
opts.prefix, prefix,
opts.context, context,
); );
} }
@ -211,8 +211,8 @@ function createIntegerConversion(bitLength, typeOpts) {
throw makeException( throw makeException(
TypeError, TypeError,
`is outside the accepted range of ${lowerBound} to ${upperBound}, inclusive`, `is outside the accepted range of ${lowerBound} to ${upperBound}, inclusive`,
opts.prefix, prefix,
opts.context, context,
); );
} }
@ -250,7 +250,7 @@ function createLongLongConversion(bitLength, { unsigned }) {
const lowerBound = unsigned ? 0 : NumberMIN_SAFE_INTEGER; const lowerBound = unsigned ? 0 : NumberMIN_SAFE_INTEGER;
const asBigIntN = unsigned ? BigIntAsUintN : BigIntAsIntN; const asBigIntN = unsigned ? BigIntAsUintN : BigIntAsIntN;
return (V, opts = {}) => { return (V, prefix = undefined, context = undefined, opts = {}) => {
let x = toNumber(V); let x = toNumber(V);
x = censorNegativeZero(x); x = censorNegativeZero(x);
@ -259,8 +259,8 @@ function createLongLongConversion(bitLength, { unsigned }) {
throw makeException( throw makeException(
TypeError, TypeError,
"is not a finite number", "is not a finite number",
opts.prefix, prefix,
opts.context, context,
); );
} }
@ -270,8 +270,8 @@ function createLongLongConversion(bitLength, { unsigned }) {
throw makeException( throw makeException(
TypeError, TypeError,
`is outside the accepted range of ${lowerBound} to ${upperBound}, inclusive`, `is outside the accepted range of ${lowerBound} to ${upperBound}, inclusive`,
opts.prefix, prefix,
opts.context, context,
); );
} }
@ -320,15 +320,15 @@ converters["unsigned long long"] = createLongLongConversion(64, {
unsigned: true, unsigned: true,
}); });
converters.float = (V, opts) => { converters.float = (V, prefix, context, _opts) => {
const x = toNumber(V); const x = toNumber(V);
if (!NumberIsFinite(x)) { if (!NumberIsFinite(x)) {
throw makeException( throw makeException(
TypeError, TypeError,
"is not a finite floating-point value", "is not a finite floating-point value",
opts.prefix, prefix,
opts.context, context,
); );
} }
@ -342,15 +342,15 @@ converters.float = (V, opts) => {
throw makeException( throw makeException(
TypeError, TypeError,
"is outside the range of a single-precision floating-point value", "is outside the range of a single-precision floating-point value",
opts.prefix, prefix,
opts.context, context,
); );
} }
return y; return y;
}; };
converters["unrestricted float"] = (V, _opts) => { converters["unrestricted float"] = (V, _prefix, _context, _opts) => {
const x = toNumber(V); const x = toNumber(V);
if (isNaN(x)) { if (isNaN(x)) {
@ -364,28 +364,28 @@ converters["unrestricted float"] = (V, _opts) => {
return MathFround(x); return MathFround(x);
}; };
converters.double = (V, opts) => { converters.double = (V, prefix, context, _opts) => {
const x = toNumber(V); const x = toNumber(V);
if (!NumberIsFinite(x)) { if (!NumberIsFinite(x)) {
throw makeException( throw makeException(
TypeError, TypeError,
"is not a finite floating-point value", "is not a finite floating-point value",
opts.prefix, prefix,
opts.context, context,
); );
} }
return x; return x;
}; };
converters["unrestricted double"] = (V, _opts) => { converters["unrestricted double"] = (V, _prefix, _context, _opts) => {
const x = toNumber(V); const x = toNumber(V);
return x; return x;
}; };
converters.DOMString = function (V, opts = {}) { converters.DOMString = function (V, prefix, context, opts = {}) {
if (typeof V === "string") { if (typeof V === "string") {
return V; return V;
} else if (V === null && opts.treatNullAsEmptyString) { } else if (V === null && opts.treatNullAsEmptyString) {
@ -394,8 +394,8 @@ converters.DOMString = function (V, opts = {}) {
throw makeException( throw makeException(
TypeError, TypeError,
"is a symbol, which cannot be converted to a string", "is a symbol, which cannot be converted to a string",
opts.prefix, prefix,
opts.context, context,
); );
} }
@ -404,21 +404,21 @@ converters.DOMString = function (V, opts = {}) {
// deno-lint-ignore no-control-regex // deno-lint-ignore no-control-regex
const IS_BYTE_STRING = new SafeRegExp(/^[\x00-\xFF]*$/); const IS_BYTE_STRING = new SafeRegExp(/^[\x00-\xFF]*$/);
converters.ByteString = (V, opts) => { converters.ByteString = (V, prefix, context, opts) => {
const x = converters.DOMString(V, opts); const x = converters.DOMString(V, prefix, context, opts);
if (!RegExpPrototypeTest(IS_BYTE_STRING, x)) { if (!RegExpPrototypeTest(IS_BYTE_STRING, x)) {
throw makeException( throw makeException(
TypeError, TypeError,
"is not a valid ByteString", "is not a valid ByteString",
opts.prefix, prefix,
opts.context, context,
); );
} }
return x; return x;
}; };
converters.USVString = (V, opts) => { converters.USVString = (V, prefix, context, opts) => {
const S = converters.DOMString(V, opts); const S = converters.DOMString(V, prefix, context, opts);
const n = S.length; const n = S.length;
let U = ""; let U = "";
for (let i = 0; i < n; ++i) { for (let i = 0; i < n; ++i) {
@ -444,13 +444,13 @@ converters.USVString = (V, opts) => {
return U; return U;
}; };
converters.object = (V, opts) => { converters.object = (V, prefix, context, _opts) => {
if (type(V) !== "Object") { if (type(V) !== "Object") {
throw makeException( throw makeException(
TypeError, TypeError,
"is not an object", "is not an object",
opts.prefix, prefix,
opts.context, context,
); );
} }
@ -461,13 +461,13 @@ converters.object = (V, opts) => {
// Neither Function nor VoidFunction is defined with [TreatNonObjectAsNull], so // Neither Function nor VoidFunction is defined with [TreatNonObjectAsNull], so
// handling for that is omitted. // handling for that is omitted.
function convertCallbackFunction(V, opts) { function convertCallbackFunction(V, prefix, context, _opts) {
if (typeof V !== "function") { if (typeof V !== "function") {
throw makeException( throw makeException(
TypeError, TypeError,
"is not a function", "is not a function",
opts.prefix, prefix,
opts.context, context,
); );
} }
return V; return V;
@ -487,34 +487,44 @@ function isSharedArrayBuffer(V) {
return ObjectPrototypeIsPrototypeOf(SharedArrayBuffer.prototype, V); return ObjectPrototypeIsPrototypeOf(SharedArrayBuffer.prototype, V);
} }
converters.ArrayBuffer = (V, opts = {}) => { converters.ArrayBuffer = (
V,
prefix = undefined,
context = undefined,
opts = {},
) => {
if (!isNonSharedArrayBuffer(V)) { if (!isNonSharedArrayBuffer(V)) {
if (opts.allowShared && !isSharedArrayBuffer(V)) { if (opts.allowShared && !isSharedArrayBuffer(V)) {
throw makeException( throw makeException(
TypeError, TypeError,
"is not an ArrayBuffer or SharedArrayBuffer", "is not an ArrayBuffer or SharedArrayBuffer",
opts.prefix, prefix,
opts.context, context,
); );
} }
throw makeException( throw makeException(
TypeError, TypeError,
"is not an ArrayBuffer", "is not an ArrayBuffer",
opts.prefix, prefix,
opts.context, context,
); );
} }
return V; return V;
}; };
converters.DataView = (V, opts = {}) => { converters.DataView = (
V,
prefix = undefined,
context = undefined,
opts = {},
) => {
if (!isDataView(V)) { if (!isDataView(V)) {
throw makeException( throw makeException(
TypeError, TypeError,
"is not a DataView", "is not a DataView",
opts.prefix, prefix,
opts.context, context,
); );
} }
@ -522,8 +532,8 @@ converters.DataView = (V, opts = {}) => {
throw makeException( throw makeException(
TypeError, TypeError,
"is backed by a SharedArrayBuffer, which is not allowed", "is backed by a SharedArrayBuffer, which is not allowed",
opts.prefix, prefix,
opts.context, context,
); );
} }
@ -547,13 +557,18 @@ ArrayPrototypeForEach(
const article = RegExpPrototypeTest(new SafeRegExp(/^[AEIOU]/), name) const article = RegExpPrototypeTest(new SafeRegExp(/^[AEIOU]/), name)
? "an" ? "an"
: "a"; : "a";
converters[name] = (V, opts = {}) => { converters[name] = (
V,
prefix = undefined,
context = undefined,
opts = {},
) => {
if (TypedArrayPrototypeGetSymbolToStringTag(V) !== name) { if (TypedArrayPrototypeGetSymbolToStringTag(V) !== name) {
throw makeException( throw makeException(
TypeError, TypeError,
`is not ${article} ${name} object`, `is not ${article} ${name} object`,
opts.prefix, prefix,
opts.context, context,
); );
} }
if ( if (
@ -563,8 +578,8 @@ ArrayPrototypeForEach(
throw makeException( throw makeException(
TypeError, TypeError,
"is a view on a SharedArrayBuffer, which is not allowed", "is a view on a SharedArrayBuffer, which is not allowed",
opts.prefix, prefix,
opts.context, context,
); );
} }
@ -575,13 +590,18 @@ ArrayPrototypeForEach(
// Common definitions // Common definitions
converters.ArrayBufferView = (V, opts = {}) => { converters.ArrayBufferView = (
V,
prefix = undefined,
context = undefined,
opts = {},
) => {
if (!ArrayBufferIsView(V)) { if (!ArrayBufferIsView(V)) {
throw makeException( throw makeException(
TypeError, TypeError,
"is not a view on an ArrayBuffer or SharedArrayBuffer", "is not a view on an ArrayBuffer or SharedArrayBuffer",
opts.prefix, prefix,
opts.context, context,
); );
} }
let buffer; let buffer;
@ -594,15 +614,20 @@ converters.ArrayBufferView = (V, opts = {}) => {
throw makeException( throw makeException(
TypeError, TypeError,
"is a view on a SharedArrayBuffer, which is not allowed", "is a view on a SharedArrayBuffer, which is not allowed",
opts.prefix, prefix,
opts.context, context,
); );
} }
return V; return V;
}; };
converters.BufferSource = (V, opts = {}) => { converters.BufferSource = (
V,
prefix = undefined,
context = undefined,
opts = {},
) => {
if (ArrayBufferIsView(V)) { if (ArrayBufferIsView(V)) {
let buffer; let buffer;
if (TypedArrayPrototypeGetSymbolToStringTag(V) !== undefined) { if (TypedArrayPrototypeGetSymbolToStringTag(V) !== undefined) {
@ -614,8 +639,8 @@ converters.BufferSource = (V, opts = {}) => {
throw makeException( throw makeException(
TypeError, TypeError,
"is a view on a SharedArrayBuffer, which is not allowed", "is a view on a SharedArrayBuffer, which is not allowed",
opts.prefix, prefix,
opts.context, context,
); );
} }
@ -626,8 +651,8 @@ converters.BufferSource = (V, opts = {}) => {
throw makeException( throw makeException(
TypeError, TypeError,
"is not an ArrayBuffer or a view on one", "is not an ArrayBuffer or a view on one",
opts.prefix, prefix,
opts.context, context,
); );
} }
if ( if (
@ -638,8 +663,8 @@ converters.BufferSource = (V, opts = {}) => {
throw makeException( throw makeException(
TypeError, TypeError,
"is not an ArrayBuffer, SharedArrayBuffer, or a view on one", "is not an ArrayBuffer, SharedArrayBuffer, or a view on one",
opts.prefix, prefix,
opts.context, context,
); );
} }
@ -744,7 +769,7 @@ function createDictionaryConverter(name, ...dictionaries) {
} }
} }
return function (V, opts = {}) { return function (V, prefix = undefined, context = undefined, opts = {}) {
const typeV = type(V); const typeV = type(V);
switch (typeV) { switch (typeV) {
case "Undefined": case "Undefined":
@ -755,8 +780,8 @@ function createDictionaryConverter(name, ...dictionaries) {
throw makeException( throw makeException(
TypeError, TypeError,
"can not be converted to a dictionary", "can not be converted to a dictionary",
opts.prefix, prefix,
opts.context, context,
); );
} }
const esDict = V; const esDict = V;
@ -780,18 +805,23 @@ function createDictionaryConverter(name, ...dictionaries) {
} }
if (esMemberValue !== undefined) { if (esMemberValue !== undefined) {
const context = `'${key}' of '${name}'${ const memberContext = `'${key}' of '${name}'${
opts.context ? ` (${opts.context})` : "" context ? ` (${context})` : ""
}`; }`;
const converter = member.converter; const converter = member.converter;
const idlMemberValue = converter(esMemberValue, { ...opts, context }); const idlMemberValue = converter(
esMemberValue,
prefix,
memberContext,
opts,
);
idlDict[key] = idlMemberValue; idlDict[key] = idlMemberValue;
} else if (member.required) { } else if (member.required) {
throw makeException( throw makeException(
TypeError, TypeError,
`can not be converted to '${name}' because '${key}' is required in '${name}'.`, `can not be converted to '${name}' because '${key}' is required in '${name}'.`,
opts.prefix, prefix,
opts.context, context,
); );
} }
} }
@ -804,13 +834,13 @@ function createDictionaryConverter(name, ...dictionaries) {
function createEnumConverter(name, values) { function createEnumConverter(name, values) {
const E = new SafeSet(values); const E = new SafeSet(values);
return function (V, opts = {}) { return function (V, prefix = undefined, _context = undefined, _opts = {}) {
const S = String(V); const S = String(V);
if (!E.has(S)) { if (!E.has(S)) {
throw new TypeError( throw new TypeError(
`${ `${
opts.prefix ? opts.prefix + ": " : "" prefix ? prefix + ": " : ""
}The provided value '${S}' is not a valid enum value of type ${name}.`, }The provided value '${S}' is not a valid enum value of type ${name}.`,
); );
} }
@ -820,7 +850,7 @@ function createEnumConverter(name, values) {
} }
function createNullableConverter(converter) { function createNullableConverter(converter) {
return (V, opts = {}) => { return (V, prefix = undefined, context = undefined, opts = {}) => {
// FIXME: If Type(V) is not Object, and the conversion to an IDL value is // FIXME: If Type(V) is not Object, and the conversion to an IDL value is
// being performed due to V being assigned to an attribute whose type is a // being performed due to V being assigned to an attribute whose type is a
// nullable callback function that is annotated with // nullable callback function that is annotated with
@ -828,19 +858,19 @@ function createNullableConverter(converter) {
// value null. // value null.
if (V === null || V === undefined) return null; if (V === null || V === undefined) return null;
return converter(V, opts); return converter(V, prefix, context, opts);
}; };
} }
// https://heycam.github.io/webidl/#es-sequence // https://heycam.github.io/webidl/#es-sequence
function createSequenceConverter(converter) { function createSequenceConverter(converter) {
return function (V, opts = {}) { return function (V, prefix = undefined, context = undefined, opts = {}) {
if (type(V) !== "Object") { if (type(V) !== "Object") {
throw makeException( throw makeException(
TypeError, TypeError,
"can not be converted to sequence.", "can not be converted to sequence.",
opts.prefix, prefix,
opts.context, context,
); );
} }
const iter = V?.[SymbolIterator]?.(); const iter = V?.[SymbolIterator]?.();
@ -848,8 +878,8 @@ function createSequenceConverter(converter) {
throw makeException( throw makeException(
TypeError, TypeError,
"can not be converted to sequence.", "can not be converted to sequence.",
opts.prefix, prefix,
opts.context, context,
); );
} }
const array = []; const array = [];
@ -859,15 +889,17 @@ function createSequenceConverter(converter) {
throw makeException( throw makeException(
TypeError, TypeError,
"can not be converted to sequence.", "can not be converted to sequence.",
opts.prefix, prefix,
opts.context, context,
); );
} }
if (res.done === true) break; if (res.done === true) break;
const val = converter(res.value, { const val = converter(
...opts, res.value,
context: `${opts.context}, index ${array.length}`, prefix,
}); `${context}, index ${array.length}`,
opts,
);
ArrayPrototypePush(array, val); ArrayPrototypePush(array, val);
} }
return array; return array;
@ -875,13 +907,13 @@ function createSequenceConverter(converter) {
} }
function createRecordConverter(keyConverter, valueConverter) { function createRecordConverter(keyConverter, valueConverter) {
return (V, opts) => { return (V, prefix, context, opts) => {
if (type(V) !== "Object") { if (type(V) !== "Object") {
throw makeException( throw makeException(
TypeError, TypeError,
"can not be converted to dictionary.", "can not be converted to dictionary.",
opts.prefix, prefix,
opts.context, context,
); );
} }
const result = {}; const result = {};
@ -891,9 +923,9 @@ function createRecordConverter(keyConverter, valueConverter) {
if (!ObjectPrototypeHasOwnProperty(V, key)) { if (!ObjectPrototypeHasOwnProperty(V, key)) {
continue; continue;
} }
const typedKey = keyConverter(key, opts); const typedKey = keyConverter(key, prefix, context, opts);
const value = V[key]; const value = V[key];
const typedValue = valueConverter(value, opts); const typedValue = valueConverter(value, prefix, context, opts);
result[typedKey] = typedValue; result[typedKey] = typedValue;
} }
return result; return result;
@ -904,9 +936,9 @@ function createRecordConverter(keyConverter, valueConverter) {
const key = keys[i]; const key = keys[i];
const desc = ObjectGetOwnPropertyDescriptor(V, key); const desc = ObjectGetOwnPropertyDescriptor(V, key);
if (desc !== undefined && desc.enumerable === true) { if (desc !== undefined && desc.enumerable === true) {
const typedKey = keyConverter(key, opts); const typedKey = keyConverter(key, prefix, context, opts);
const value = V[key]; const value = V[key];
const typedValue = valueConverter(value, opts); const typedValue = valueConverter(value, prefix, context, opts);
result[typedKey] = typedValue; result[typedKey] = typedValue;
} }
} }
@ -915,8 +947,11 @@ function createRecordConverter(keyConverter, valueConverter) {
} }
function createPromiseConverter(converter) { function createPromiseConverter(converter) {
return (V, opts) => return (V, prefix, context, opts) =>
PromisePrototypeThen(PromiseResolve(V), (V) => converter(V, opts)); PromisePrototypeThen(
PromiseResolve(V),
(V) => converter(V, prefix, context, opts),
);
} }
function invokeCallbackFunction( function invokeCallbackFunction(
@ -929,10 +964,7 @@ function invokeCallbackFunction(
) { ) {
try { try {
const rv = ReflectApply(callable, thisArg, args); const rv = ReflectApply(callable, thisArg, args);
return returnValueConverter(rv, { return returnValueConverter(rv, prefix, "return value");
prefix,
context: "return value",
});
} catch (err) { } catch (err) {
if (returnsPromise === true) { if (returnsPromise === true) {
return PromiseReject(err); return PromiseReject(err);
@ -944,13 +976,13 @@ function invokeCallbackFunction(
const brand = Symbol("[[webidl.brand]]"); const brand = Symbol("[[webidl.brand]]");
function createInterfaceConverter(name, prototype) { function createInterfaceConverter(name, prototype) {
return (V, opts) => { return (V, prefix, context, _opts) => {
if (!ObjectPrototypeIsPrototypeOf(prototype, V) || V[brand] !== brand) { if (!ObjectPrototypeIsPrototypeOf(prototype, V) || V[brand] !== brand) {
throw makeException( throw makeException(
TypeError, TypeError,
`is not of type ${name}.`, `is not of type ${name}.`,
opts.prefix, prefix,
opts.context, context,
); );
} }
return V; return V;

View file

@ -5,29 +5,13 @@
/// <reference lib="esnext" /> /// <reference lib="esnext" />
declare module "ext:deno_webidl/00_webidl.js" { declare module "ext:deno_webidl/00_webidl.js" {
interface ValueConverterOpts {
/**
* The prefix for error messages created by this converter.
* Examples:
* - `Failed to construct 'Event'`
* - `Failed to execute 'removeEventListener' on 'EventTarget'`
*/
prefix: string;
/**
* The context of this value error messages created by this converter.
* Examples:
* - `Argument 1`
* - `Argument 3`
*/
context: string;
}
function makeException( function makeException(
ErrorType: any, ErrorType: any,
message: string, message: string,
prefix: string, prefix?: string,
context: string, context?: string,
): any; ): any;
interface IntConverterOpts extends ValueConverterOpts { interface IntConverterOpts {
/** /**
* Wether to throw if the number is outside of the acceptable values for * Wether to throw if the number is outside of the acceptable values for
* this type. * this type.
@ -38,13 +22,13 @@ declare module "ext:deno_webidl/00_webidl.js" {
*/ */
clamp?: boolean; clamp?: boolean;
} }
interface StringConverterOpts extends ValueConverterOpts { interface StringConverterOpts {
/** /**
* Wether to treat `null` value as an empty string. * Wether to treat `null` value as an empty string.
*/ */
treatNullAsEmptyString?: boolean; treatNullAsEmptyString?: boolean;
} }
interface BufferConverterOpts extends ValueConverterOpts { interface BufferConverterOpts {
/** /**
* Wether to allow `SharedArrayBuffer` (not just `ArrayBuffer`). * Wether to allow `SharedArrayBuffer` (not just `ArrayBuffer`).
*/ */
@ -55,148 +39,322 @@ declare module "ext:deno_webidl/00_webidl.js" {
/** /**
* Convert a value into a `boolean` (bool). * Convert a value into a `boolean` (bool).
*/ */
boolean(v: any, opts?: IntConverterOpts): boolean; boolean(
v: any,
prefix?: string,
context?: string,
opts?: IntConverterOpts,
): boolean;
/** /**
* Convert a value into a `byte` (int8). * Convert a value into a `byte` (int8).
*/ */
byte(v: any, opts?: IntConverterOpts): number; byte(
v: any,
prefix?: string,
context?: string,
opts?: IntConverterOpts,
): number;
/** /**
* Convert a value into a `octet` (uint8). * Convert a value into a `octet` (uint8).
*/ */
octet(v: any, opts?: IntConverterOpts): number; octet(
v: any,
prefix?: string,
context?: string,
opts?: IntConverterOpts,
): number;
/** /**
* Convert a value into a `short` (int16). * Convert a value into a `short` (int16).
*/ */
short(v: any, opts?: IntConverterOpts): number; short(
v: any,
prefix?: string,
context?: string,
opts?: IntConverterOpts,
): number;
/** /**
* Convert a value into a `unsigned short` (uint16). * Convert a value into a `unsigned short` (uint16).
*/ */
["unsigned short"](v: any, opts?: IntConverterOpts): number; ["unsigned short"](
v: any,
prefix?: string,
context?: string,
opts?: IntConverterOpts,
): number;
/** /**
* Convert a value into a `long` (int32). * Convert a value into a `long` (int32).
*/ */
long(v: any, opts?: IntConverterOpts): number; long(
v: any,
prefix?: string,
context?: string,
opts?: IntConverterOpts,
): number;
/** /**
* Convert a value into a `unsigned long` (uint32). * Convert a value into a `unsigned long` (uint32).
*/ */
["unsigned long"](v: any, opts?: IntConverterOpts): number; ["unsigned long"](
v: any,
prefix?: string,
context?: string,
opts?: IntConverterOpts,
): number;
/** /**
* Convert a value into a `long long` (int64). * Convert a value into a `long long` (int64).
* **Note this is truncated to a JS number (53 bit precision).** * **Note this is truncated to a JS number (53 bit precision).**
*/ */
["long long"](v: any, opts?: IntConverterOpts): number; ["long long"](
v: any,
prefix?: string,
context?: string,
opts?: IntConverterOpts,
): number;
/** /**
* Convert a value into a `unsigned long long` (uint64). * Convert a value into a `unsigned long long` (uint64).
* **Note this is truncated to a JS number (53 bit precision).** * **Note this is truncated to a JS number (53 bit precision).**
*/ */
["unsigned long long"](v: any, opts?: IntConverterOpts): number; ["unsigned long long"](
v: any,
prefix?: string,
context?: string,
opts?: IntConverterOpts,
): number;
/** /**
* Convert a value into a `float` (f32). * Convert a value into a `float` (f32).
*/ */
float(v: any, opts?: ValueConverterOpts): number; float(
v: any,
prefix?: string,
context?: string,
opts?: any,
): number;
/** /**
* Convert a value into a `unrestricted float` (f32, infinity, or NaN). * Convert a value into a `unrestricted float` (f32, infinity, or NaN).
*/ */
["unrestricted float"](v: any, opts?: ValueConverterOpts): number; ["unrestricted float"](
v: any,
prefix?: string,
context?: string,
opts?: any,
): number;
/** /**
* Convert a value into a `double` (f64). * Convert a value into a `double` (f64).
*/ */
double(v: any, opts?: ValueConverterOpts): number; double(
v: any,
prefix?: string,
context?: string,
opts?: any,
): number;
/** /**
* Convert a value into a `unrestricted double` (f64, infinity, or NaN). * Convert a value into a `unrestricted double` (f64, infinity, or NaN).
*/ */
["unrestricted double"](v: any, opts?: ValueConverterOpts): number; ["unrestricted double"](
v: any,
prefix?: string,
context?: string,
opts?: any,
): number;
/** /**
* Convert a value into a `DOMString` (string). * Convert a value into a `DOMString` (string).
*/ */
DOMString(v: any, opts?: StringConverterOpts): string; DOMString(
v: any,
prefix?: string,
context?: string,
opts?: StringConverterOpts,
): string;
/** /**
* Convert a value into a `ByteString` (string with only u8 codepoints). * Convert a value into a `ByteString` (string with only u8 codepoints).
*/ */
ByteString(v: any, opts?: StringConverterOpts): string; ByteString(
v: any,
prefix?: string,
context?: string,
opts?: StringConverterOpts,
): string;
/** /**
* Convert a value into a `USVString` (string with only valid non * Convert a value into a `USVString` (string with only valid non
* surrogate Unicode code points). * surrogate Unicode code points).
*/ */
USVString(v: any, opts?: StringConverterOpts): string; USVString(
v: any,
prefix?: string,
context?: string,
opts?: StringConverterOpts,
): string;
/** /**
* Convert a value into an `object` (object). * Convert a value into an `object` (object).
*/ */
object(v: any, opts?: ValueConverterOpts): object; object(
v: any,
prefix?: string,
context?: string,
opts?: any,
): object;
/** /**
* Convert a value into an `ArrayBuffer` (ArrayBuffer). * Convert a value into an `ArrayBuffer` (ArrayBuffer).
*/ */
ArrayBuffer(v: any, opts?: BufferConverterOpts): ArrayBuffer; ArrayBuffer(
v: any,
prefix?: string,
context?: string,
opts?: BufferConverterOpts,
): ArrayBuffer;
/** /**
* Convert a value into a `DataView` (ArrayBuffer). * Convert a value into a `DataView` (ArrayBuffer).
*/ */
DataView(v: any, opts?: BufferConverterOpts): DataView; DataView(
v: any,
prefix?: string,
context?: string,
opts?: BufferConverterOpts,
): DataView;
/** /**
* Convert a value into a `Int8Array` (Int8Array). * Convert a value into a `Int8Array` (Int8Array).
*/ */
Int8Array(v: any, opts?: BufferConverterOpts): Int8Array; Int8Array(
v: any,
prefix?: string,
context?: string,
opts?: BufferConverterOpts,
): Int8Array;
/** /**
* Convert a value into a `Int16Array` (Int16Array). * Convert a value into a `Int16Array` (Int16Array).
*/ */
Int16Array(v: any, opts?: BufferConverterOpts): Int16Array; Int16Array(
v: any,
prefix?: string,
context?: string,
opts?: BufferConverterOpts,
): Int16Array;
/** /**
* Convert a value into a `Int32Array` (Int32Array). * Convert a value into a `Int32Array` (Int32Array).
*/ */
Int32Array(v: any, opts?: BufferConverterOpts): Int32Array; Int32Array(
v: any,
prefix?: string,
context?: string,
opts?: BufferConverterOpts,
): Int32Array;
/** /**
* Convert a value into a `Uint8Array` (Uint8Array). * Convert a value into a `Uint8Array` (Uint8Array).
*/ */
Uint8Array(v: any, opts?: BufferConverterOpts): Uint8Array; Uint8Array(
v: any,
prefix?: string,
context?: string,
opts?: BufferConverterOpts,
): Uint8Array;
/** /**
* Convert a value into a `Uint16Array` (Uint16Array). * Convert a value into a `Uint16Array` (Uint16Array).
*/ */
Uint16Array(v: any, opts?: BufferConverterOpts): Uint16Array; Uint16Array(
v: any,
prefix?: string,
context?: string,
opts?: BufferConverterOpts,
): Uint16Array;
/** /**
* Convert a value into a `Uint32Array` (Uint32Array). * Convert a value into a `Uint32Array` (Uint32Array).
*/ */
Uint32Array(v: any, opts?: BufferConverterOpts): Uint32Array; Uint32Array(
v: any,
prefix?: string,
context?: string,
opts?: BufferConverterOpts,
): Uint32Array;
/** /**
* Convert a value into a `Uint8ClampedArray` (Uint8ClampedArray). * Convert a value into a `Uint8ClampedArray` (Uint8ClampedArray).
*/ */
Uint8ClampedArray( Uint8ClampedArray(
v: any, v: any,
prefix?: string,
context?: string,
opts?: BufferConverterOpts, opts?: BufferConverterOpts,
): Uint8ClampedArray; ): Uint8ClampedArray;
/** /**
* Convert a value into a `Float32Array` (Float32Array). * Convert a value into a `Float32Array` (Float32Array).
*/ */
Float32Array(v: any, opts?: BufferConverterOpts): Float32Array; Float32Array(
v: any,
prefix?: string,
context?: string,
opts?: BufferConverterOpts,
): Float32Array;
/** /**
* Convert a value into a `Float64Array` (Float64Array). * Convert a value into a `Float64Array` (Float64Array).
*/ */
Float64Array(v: any, opts?: BufferConverterOpts): Float64Array; Float64Array(
v: any,
prefix?: string,
context?: string,
opts?: BufferConverterOpts,
): Float64Array;
/** /**
* Convert a value into an `ArrayBufferView` (ArrayBufferView). * Convert a value into an `ArrayBufferView` (ArrayBufferView).
*/ */
ArrayBufferView(v: any, opts?: BufferConverterOpts): ArrayBufferView; ArrayBufferView(
v: any,
prefix?: string,
context?: string,
opts?: BufferConverterOpts,
): ArrayBufferView;
/** /**
* Convert a value into a `BufferSource` (ArrayBuffer or ArrayBufferView). * Convert a value into a `BufferSource` (ArrayBuffer or ArrayBufferView).
*/ */
BufferSource( BufferSource(
v: any, v: any,
prefix?: string,
context?: string,
opts?: BufferConverterOpts, opts?: BufferConverterOpts,
): ArrayBuffer | ArrayBufferView; ): ArrayBuffer | ArrayBufferView;
/** /**
* Convert a value into a `DOMTimeStamp` (u64). Alias for unsigned long long * Convert a value into a `DOMTimeStamp` (u64). Alias for unsigned long long
*/ */
DOMTimeStamp(v: any, opts?: IntConverterOpts): number; DOMTimeStamp(
v: any,
prefix?: string,
context?: string,
opts?: IntConverterOpts,
): number;
/** /**
* Convert a value into a `Function` ((...args: any[]) => any). * Convert a value into a `Function` ((...args: any[]) => any).
*/ */
Function(v: any, opts?: ValueConverterOpts): (...args: any) => any; Function(
v: any,
prefix?: string,
context?: string,
opts?: any,
): (...args: any) => any;
/** /**
* Convert a value into a `VoidFunction` (() => void). * Convert a value into a `VoidFunction` (() => void).
*/ */
VoidFunction(v: any, opts?: ValueConverterOpts): () => void; VoidFunction(
["UVString?"](v: any, opts?: ValueConverterOpts): string | null; v: any,
["sequence<double>"](v: any, opts?: ValueConverterOpts): number[]; prefix?: string,
context?: string,
opts?: any,
): () => void;
["UVString?"](
v: any,
prefix?: string,
context?: string,
opts?: StringConverterOpts,
): string | null;
["sequence<double>"](
v: any,
prefix?: string,
context?: string,
opts?: any,
): number[];
[type: string]: (v: any, opts: ValueConverterOpts) => any; [type: string]: (
v: any,
prefix?: string,
context?: string,
opts?: any,
) => any;
}; };
/** /**
@ -210,7 +368,12 @@ declare module "ext:deno_webidl/00_webidl.js" {
type Dictionary = DictionaryMember[]; type Dictionary = DictionaryMember[];
interface DictionaryMember { interface DictionaryMember {
key: string; key: string;
converter: (v: any, opts: ValueConverterOpts) => any; converter: (
v: any,
prefix?: string,
context?: string,
opts?: any,
) => any;
defaultValue?: any; defaultValue?: any;
required?: boolean; required?: boolean;
} }
@ -221,7 +384,12 @@ declare module "ext:deno_webidl/00_webidl.js" {
function createDictionaryConverter<T>( function createDictionaryConverter<T>(
name: string, name: string,
...dictionaries: Dictionary[] ...dictionaries: Dictionary[]
): (v: any, opts: ValueConverterOpts) => T; ): (
v: any,
prefix?: string,
context?: string,
opts?: any,
) => T;
/** /**
* Create a converter for enums. * Create a converter for enums.
@ -229,28 +397,63 @@ declare module "ext:deno_webidl/00_webidl.js" {
function createEnumConverter( function createEnumConverter(
name: string, name: string,
values: string[], values: string[],
): (v: any, opts: ValueConverterOpts) => string; ): (
v: any,
prefix?: string,
context?: string,
opts?: any,
) => string;
/** /**
* Create a converter that makes the contained type nullable. * Create a converter that makes the contained type nullable.
*/ */
function createNullableConverter<T>( function createNullableConverter<T>(
converter: (v: any, opts: ValueConverterOpts) => T, converter: (
): (v: any, opts: ValueConverterOpts) => T | null; v: any,
prefix?: string,
context?: string,
opts?: any,
) => T,
): (
v: any,
prefix?: string,
context?: string,
opts?: any,
) => T | null;
/** /**
* Create a converter that converts a sequence of the inner type. * Create a converter that converts a sequence of the inner type.
*/ */
function createSequenceConverter<T>( function createSequenceConverter<T>(
converter: (v: any, opts: ValueConverterOpts) => T, converter: (
): (v: any, opts: ValueConverterOpts) => T[]; v: any,
prefix?: string,
context?: string,
opts?: any,
) => T,
): (
v: any,
prefix?: string,
context?: string,
opts?: any,
) => T[];
/** /**
* Create a converter that converts a Promise of the inner type. * Create a converter that converts a Promise of the inner type.
*/ */
function createPromiseConverter<T>( function createPromiseConverter<T>(
converter: (v: any, opts: ValueConverterOpts) => T, converter: (
): (v: any, opts: ValueConverterOpts) => Promise<T>; v: any,
prefix?: string,
context?: string,
opts?: any,
) => T,
): (
v: any,
prefix?: string,
context?: string,
opts?: any,
) => Promise<T>;
/** /**
* Invoke a callback function. * Invoke a callback function.
@ -259,7 +462,12 @@ declare module "ext:deno_webidl/00_webidl.js" {
callable: (...args: any) => any, callable: (...args: any) => any,
args: any[], args: any[],
thisArg: any, thisArg: any,
returnValueConverter: (v: any, opts: ValueConverterOpts) => T, returnValueConverter: (
v: any,
prefix?: string,
context?: string,
opts?: any,
) => T,
prefix: string, prefix: string,
returnsPromise?: boolean, returnsPromise?: boolean,
): T; ): T;
@ -290,17 +498,34 @@ declare module "ext:deno_webidl/00_webidl.js" {
function createInterfaceConverter( function createInterfaceConverter(
name: string, name: string,
prototype: any, prototype: any,
): (v: any, opts: ValueConverterOpts) => any; ): (
v: any,
prefix?: string,
context?: string,
opts?: any,
) => any;
function createRecordConverter< function createRecordConverter<
K extends string | number | symbol, K extends string | number | symbol,
V, V,
>( >(
keyConverter: (v: any, opts: ValueConverterOpts) => K, keyConverter: (
valueConverter: (v: any, opts: ValueConverterOpts) => V, v: any,
prefix?: string,
context?: string,
opts?: any,
) => K,
valueConverter: (
v: any,
prefix?: string,
context?: string,
opts?: any,
) => V,
): ( ): (
v: Record<K, V>, v: Record<K, V>,
opts: ValueConverterOpts, prefix?: string,
context?: string,
opts?: any,
) => any; ) => any;
/** /**

View file

@ -52,20 +52,25 @@ const {
TypedArrayPrototypeGetSymbolToStringTag, TypedArrayPrototypeGetSymbolToStringTag,
} = primordials; } = primordials;
webidl.converters["sequence<DOMString> or DOMString"] = (V, opts) => { webidl.converters["sequence<DOMString> or DOMString"] = (
V,
prefix,
context,
opts,
) => {
// Union for (sequence<DOMString> or DOMString) // Union for (sequence<DOMString> or DOMString)
if (webidl.type(V) === "Object" && V !== null) { if (webidl.type(V) === "Object" && V !== null) {
if (V[SymbolIterator] !== undefined) { if (V[SymbolIterator] !== undefined) {
return webidl.converters["sequence<DOMString>"](V, opts); return webidl.converters["sequence<DOMString>"](V, prefix, context, opts);
} }
} }
return webidl.converters.DOMString(V, opts); return webidl.converters.DOMString(V, prefix, context, opts);
}; };
webidl.converters["WebSocketSend"] = (V, opts) => { webidl.converters["WebSocketSend"] = (V, prefix, context, opts) => {
// Union for (Blob or ArrayBufferView or ArrayBuffer or USVString) // Union for (Blob or ArrayBufferView or ArrayBuffer or USVString)
if (ObjectPrototypeIsPrototypeOf(BlobPrototype, V)) { if (ObjectPrototypeIsPrototypeOf(BlobPrototype, V)) {
return webidl.converters["Blob"](V, opts); return webidl.converters["Blob"](V, prefix, context, opts);
} }
if (typeof V === "object") { if (typeof V === "object") {
if ( if (
@ -73,13 +78,13 @@ webidl.converters["WebSocketSend"] = (V, opts) => {
// deno-lint-ignore prefer-primordials // deno-lint-ignore prefer-primordials
ObjectPrototypeIsPrototypeOf(SharedArrayBuffer.prototype, V) ObjectPrototypeIsPrototypeOf(SharedArrayBuffer.prototype, V)
) { ) {
return webidl.converters["ArrayBuffer"](V, opts); return webidl.converters["ArrayBuffer"](V, prefix, context, opts);
} }
if (ArrayBufferIsView(V)) { if (ArrayBufferIsView(V)) {
return webidl.converters["ArrayBufferView"](V, opts); return webidl.converters["ArrayBufferView"](V, prefix, context, opts);
} }
} }
return webidl.converters["USVString"](V, opts); return webidl.converters["USVString"](V, prefix, context, opts);
}; };
/** role */ /** role */
@ -158,9 +163,10 @@ class WebSocket extends EventTarget {
} }
set binaryType(value) { set binaryType(value) {
webidl.assertBranded(this, WebSocketPrototype); webidl.assertBranded(this, WebSocketPrototype);
value = webidl.converters.DOMString(value, { value = webidl.converters.DOMString(
prefix: "Failed to set 'binaryType' on 'WebSocket'", value,
}); "Failed to set 'binaryType' on 'WebSocket'",
);
if (value === "blob" || value === "arraybuffer") { if (value === "blob" || value === "arraybuffer") {
this[_binaryType] = value; this[_binaryType] = value;
} }
@ -177,16 +183,11 @@ class WebSocket extends EventTarget {
this[webidl.brand] = webidl.brand; this[webidl.brand] = webidl.brand;
const prefix = "Failed to construct 'WebSocket'"; const prefix = "Failed to construct 'WebSocket'";
webidl.requiredArguments(arguments.length, 1, prefix); webidl.requiredArguments(arguments.length, 1, prefix);
url = webidl.converters.USVString(url, { url = webidl.converters.USVString(url, prefix, "Argument 1");
prefix,
context: "Argument 1",
});
protocols = webidl.converters["sequence<DOMString> or DOMString"]( protocols = webidl.converters["sequence<DOMString> or DOMString"](
protocols, protocols,
{ prefix,
prefix, "Argument 2",
context: "Argument 2",
},
); );
let wsURL; let wsURL;
@ -304,10 +305,7 @@ class WebSocket extends EventTarget {
const prefix = "Failed to execute 'send' on 'WebSocket'"; const prefix = "Failed to execute 'send' on 'WebSocket'";
webidl.requiredArguments(arguments.length, 1, prefix); webidl.requiredArguments(arguments.length, 1, prefix);
data = webidl.converters.WebSocketSend(data, { data = webidl.converters.WebSocketSend(data, prefix, "Argument 1");
prefix,
context: "Argument 1",
});
if (this[_readyState] !== OPEN) { if (this[_readyState] !== OPEN) {
throw new DOMException("readyState not OPEN", "InvalidStateError"); throw new DOMException("readyState not OPEN", "InvalidStateError");
@ -372,18 +370,13 @@ class WebSocket extends EventTarget {
const prefix = "Failed to execute 'close' on 'WebSocket'"; const prefix = "Failed to execute 'close' on 'WebSocket'";
if (code !== undefined) { if (code !== undefined) {
code = webidl.converters["unsigned short"](code, { code = webidl.converters["unsigned short"](code, prefix, "Argument 1", {
prefix,
clamp: true, clamp: true,
context: "Argument 1",
}); });
} }
if (reason !== undefined) { if (reason !== undefined) {
reason = webidl.converters.USVString(reason, { reason = webidl.converters.USVString(reason, prefix, "Argument 2");
prefix,
context: "Argument 2",
});
} }
if (!this[_server]) { if (!this[_server]) {

View file

@ -88,14 +88,12 @@ class WebSocketStream {
this[webidl.brand] = webidl.brand; this[webidl.brand] = webidl.brand;
const prefix = "Failed to construct 'WebSocketStream'"; const prefix = "Failed to construct 'WebSocketStream'";
webidl.requiredArguments(arguments.length, 1, prefix); webidl.requiredArguments(arguments.length, 1, prefix);
url = webidl.converters.USVString(url, { url = webidl.converters.USVString(url, prefix, "Argument 1");
options = webidl.converters.WebSocketStreamOptions(
options,
prefix, prefix,
context: "Argument 1", "Argument 2",
}); );
options = webidl.converters.WebSocketStreamOptions(options, {
prefix,
context: "Argument 2",
});
const wsURL = new URL(url); const wsURL = new URL(url);
@ -366,10 +364,11 @@ class WebSocketStream {
close(closeInfo) { close(closeInfo) {
webidl.assertBranded(this, WebSocketStreamPrototype); webidl.assertBranded(this, WebSocketStreamPrototype);
closeInfo = webidl.converters.WebSocketCloseInfo(closeInfo, { closeInfo = webidl.converters.WebSocketCloseInfo(
prefix: "Failed to execute 'close' on 'WebSocketStream'", closeInfo,
context: "Argument 1", "Failed to execute 'close' on 'WebSocketStream'",
}); "Argument 1",
);
if ( if (
closeInfo.code && closeInfo.code &&

View file

@ -36,10 +36,7 @@ class Storage {
webidl.assertBranded(this, StoragePrototype); webidl.assertBranded(this, StoragePrototype);
const prefix = "Failed to execute 'key' on 'Storage'"; const prefix = "Failed to execute 'key' on 'Storage'";
webidl.requiredArguments(arguments.length, 1, prefix); webidl.requiredArguments(arguments.length, 1, prefix);
index = webidl.converters["unsigned long"](index, { index = webidl.converters["unsigned long"](index, prefix, "Argument 1");
prefix,
context: "Argument 1",
});
return ops.op_webstorage_key(index, this[_persistent]); return ops.op_webstorage_key(index, this[_persistent]);
} }
@ -48,14 +45,8 @@ class Storage {
webidl.assertBranded(this, StoragePrototype); webidl.assertBranded(this, StoragePrototype);
const prefix = "Failed to execute 'setItem' on 'Storage'"; const prefix = "Failed to execute 'setItem' on 'Storage'";
webidl.requiredArguments(arguments.length, 2, prefix); webidl.requiredArguments(arguments.length, 2, prefix);
key = webidl.converters.DOMString(key, { key = webidl.converters.DOMString(key, prefix, "Argument 1");
prefix, value = webidl.converters.DOMString(value, prefix, "Argument 2");
context: "Argument 1",
});
value = webidl.converters.DOMString(value, {
prefix,
context: "Argument 2",
});
ops.op_webstorage_set(key, value, this[_persistent]); ops.op_webstorage_set(key, value, this[_persistent]);
} }
@ -64,10 +55,7 @@ class Storage {
webidl.assertBranded(this, StoragePrototype); webidl.assertBranded(this, StoragePrototype);
const prefix = "Failed to execute 'getItem' on 'Storage'"; const prefix = "Failed to execute 'getItem' on 'Storage'";
webidl.requiredArguments(arguments.length, 1, prefix); webidl.requiredArguments(arguments.length, 1, prefix);
key = webidl.converters.DOMString(key, { key = webidl.converters.DOMString(key, prefix, "Argument 1");
prefix,
context: "Argument 1",
});
return ops.op_webstorage_get(key, this[_persistent]); return ops.op_webstorage_get(key, this[_persistent]);
} }
@ -76,10 +64,7 @@ class Storage {
webidl.assertBranded(this, StoragePrototype); webidl.assertBranded(this, StoragePrototype);
const prefix = "Failed to execute 'removeItem' on 'Storage'"; const prefix = "Failed to execute 'removeItem' on 'Storage'";
webidl.requiredArguments(arguments.length, 1, prefix); webidl.requiredArguments(arguments.length, 1, prefix);
key = webidl.converters.DOMString(key, { key = webidl.converters.DOMString(key, prefix, "Argument 1");
prefix,
context: "Argument 1",
});
ops.op_webstorage_remove(key, this[_persistent]); ops.op_webstorage_remove(key, this[_persistent]);
} }

View file

@ -202,7 +202,7 @@ class Worker extends EventTarget {
postMessage(message, transferOrOptions = {}) { postMessage(message, transferOrOptions = {}) {
const prefix = "Failed to execute 'postMessage' on 'MessagePort'"; const prefix = "Failed to execute 'postMessage' on 'MessagePort'";
webidl.requiredArguments(arguments.length, 1, { prefix }); webidl.requiredArguments(arguments.length, 1, prefix);
message = webidl.converters.any(message); message = webidl.converters.any(message);
let options; let options;
if ( if (
@ -212,16 +212,15 @@ class Worker extends EventTarget {
) { ) {
const transfer = webidl.converters["sequence<object>"]( const transfer = webidl.converters["sequence<object>"](
transferOrOptions, transferOrOptions,
{ prefix, context: "Argument 2" }, prefix,
"Argument 2",
); );
options = { transfer }; options = { transfer };
} else { } else {
options = webidl.converters.StructuredSerializeOptions( options = webidl.converters.StructuredSerializeOptions(
transferOrOptions, transferOrOptions,
{ prefix,
prefix, "Argument 2",
context: "Argument 2",
},
); );
} }
const { transfer } = options; const { transfer } = options;

View file

@ -101,7 +101,7 @@ function workerClose() {
function postMessage(message, transferOrOptions = {}) { function postMessage(message, transferOrOptions = {}) {
const prefix = const prefix =
"Failed to execute 'postMessage' on 'DedicatedWorkerGlobalScope'"; "Failed to execute 'postMessage' on 'DedicatedWorkerGlobalScope'";
webidl.requiredArguments(arguments.length, 1, { prefix }); webidl.requiredArguments(arguments.length, 1, prefix);
message = webidl.converters.any(message); message = webidl.converters.any(message);
let options; let options;
if ( if (
@ -111,16 +111,15 @@ function postMessage(message, transferOrOptions = {}) {
) { ) {
const transfer = webidl.converters["sequence<object>"]( const transfer = webidl.converters["sequence<object>"](
transferOrOptions, transferOrOptions,
{ prefix, context: "Argument 2" }, prefix,
"Argument 2",
); );
options = { transfer }; options = { transfer };
} else { } else {
options = webidl.converters.StructuredSerializeOptions( options = webidl.converters.StructuredSerializeOptions(
transferOrOptions, transferOrOptions,
{ prefix,
prefix, "Argument 2",
context: "Argument 2",
},
); );
} }
const { transfer } = options; const { transfer } = options;