1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-23 15:49:44 -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'";
webidl.requiredArguments(arguments.length, 1, prefix);
this[_name] = webidl.converters["DOMString"](name, {
prefix,
context: "Argument 1",
});
this[_name] = webidl.converters["DOMString"](name, prefix, "Argument 1");
this[webidl.brand] = webidl.brand;

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

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

View file

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

View file

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

View file

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

View file

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

View file

@ -448,16 +448,16 @@ function extractBody(object) {
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)
if (ObjectPrototypeIsPrototypeOf(ReadableStreamPrototype, V)) {
return webidl.converters["ReadableStream"](V, opts);
return webidl.converters["ReadableStream"](V, prefix, context, opts);
} else if (ObjectPrototypeIsPrototypeOf(BlobPrototype, V)) {
return webidl.converters["Blob"](V, opts);
return webidl.converters["Blob"](V, prefix, context, opts);
} else if (ObjectPrototypeIsPrototypeOf(FormDataPrototype, V)) {
return webidl.converters["FormData"](V, opts);
return webidl.converters["FormData"](V, prefix, context, opts);
} else if (ObjectPrototypeIsPrototypeOf(URLSearchParamsPrototype, V)) {
return webidl.converters["URLSearchParams"](V, opts);
return webidl.converters["URLSearchParams"](V, prefix, context, opts);
}
if (typeof V === "object") {
if (
@ -465,16 +465,16 @@ webidl.converters["BodyInit_DOMString"] = (V, opts) => {
// deno-lint-ignore prefer-primordials
ObjectPrototypeIsPrototypeOf(SharedArrayBuffer.prototype, V)
) {
return webidl.converters["ArrayBuffer"](V, opts);
return webidl.converters["ArrayBuffer"](V, prefix, context, opts);
}
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().
// 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.
return webidl.converters["DOMString"](V, opts);
return webidl.converters["DOMString"](V, prefix, context, opts);
};
webidl.converters["BodyInit_DOMString?"] = webidl.createNullableConverter(
webidl.converters["BodyInit_DOMString"],

View file

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

View file

@ -257,14 +257,8 @@ class Response {
*/
static redirect(url, status = 302) {
const prefix = "Failed to call 'Response.redirect'";
url = webidl.converters["USVString"](url, {
prefix,
context: "Argument 1",
});
status = webidl.converters["unsigned short"](status, {
prefix,
context: "Argument 2",
});
url = webidl.converters["USVString"](url, prefix, "Argument 1");
status = webidl.converters["unsigned short"](status, prefix, "Argument 2");
const baseURL = getLocationHref();
const parsedURL = new URL(url, baseURL);
@ -291,10 +285,7 @@ class Response {
static json(data = undefined, init = {}) {
const prefix = "Failed to call 'Response.json'";
data = webidl.converters.any(data);
init = webidl.converters["ResponseInit_fast"](init, {
prefix,
context: "Argument 2",
});
init = webidl.converters["ResponseInit_fast"](init, prefix, "Argument 2");
const str = serializeJSValueToJSONString(data);
const res = extractBody(str);
@ -315,14 +306,8 @@ class Response {
*/
constructor(body = null, init = undefined) {
const prefix = "Failed to construct 'Response'";
body = webidl.converters["BodyInit_DOMString?"](body, {
prefix,
context: "Argument 1",
});
init = webidl.converters["ResponseInit_fast"](init, {
prefix,
context: "Argument 2",
});
body = webidl.converters["BodyInit_DOMString?"](body, prefix, "Argument 1");
init = webidl.converters["ResponseInit_fast"](init, prefix, "Argument 2");
this[_response] = newInnerResponse();
this[_headers] = headersFromHeaderList(
@ -463,7 +448,12 @@ webidl.converters["ResponseInit"] = webidl.createDictionaryConverter(
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) {
return { status: 200, statusText: "", headers: undefined };
}
@ -482,7 +472,7 @@ webidl.converters["ResponseInit_fast"] = function (init, opts) {
return { status, statusText, headers };
}
// 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
// https://webassembly.github.io/spec/web-api/#compile-a-potential-webassembly-response
try {
const res = webidl.converters["Response"](source, {
prefix: "Failed to call 'WebAssembly.compileStreaming'",
context: "Argument 1",
});
const res = webidl.converters["Response"](
source,
"Failed to call 'WebAssembly.compileStreaming'",
"Argument 1",
);
// 2.3.
// The spec is ambiguous here, see

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -29,19 +29,13 @@ class CompressionStream {
constructor(format) {
const prefix = "Failed to construct 'CompressionStream'";
webidl.requiredArguments(arguments.length, 1, prefix);
format = webidl.converters.CompressionFormat(format, {
prefix,
context: "Argument 1",
});
format = webidl.converters.CompressionFormat(format, prefix, "Argument 1");
const rid = ops.op_compression_new(format, false);
this.#transform = new TransformStream({
transform(chunk, controller) {
chunk = webidl.converters.BufferSource(chunk, {
prefix,
context: "chunk",
});
chunk = webidl.converters.BufferSource(chunk, prefix, "chunk");
const output = ops.op_compression_write(
rid,
chunk,
@ -77,19 +71,13 @@ class DecompressionStream {
constructor(format) {
const prefix = "Failed to construct 'DecompressionStream'";
webidl.requiredArguments(arguments.length, 1, prefix);
format = webidl.converters.CompressionFormat(format, {
prefix,
context: "Argument 1",
});
format = webidl.converters.CompressionFormat(format, prefix, "Argument 1");
const rid = ops.op_compression_new(format, true);
this.#transform = new TransformStream({
transform(chunk, controller) {
chunk = webidl.converters.BufferSource(chunk, {
prefix,
context: "chunk",
});
chunk = webidl.converters.BufferSource(chunk, prefix, "chunk");
const output = ops.op_compression_write(
rid,
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) {
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
@ -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) {
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) {
@ -221,15 +236,13 @@ class PerformanceMark extends PerformanceEntry {
const prefix = "Failed to construct 'PerformanceMark'";
webidl.requiredArguments(arguments.length, 1, prefix);
name = webidl.converters.DOMString(name, {
prefix,
context: "Argument 1",
});
name = webidl.converters.DOMString(name, prefix, "Argument 1");
options = webidl.converters.PerformanceMarkOptions(options, {
options = webidl.converters.PerformanceMarkOptions(
options,
prefix,
context: "Argument 2",
});
"Argument 2",
);
const { detail = null, startTime = now() } = options;
@ -345,10 +358,11 @@ class Performance extends EventTarget {
clearMarks(markName = undefined) {
webidl.assertBranded(this, PerformancePrototype);
if (markName !== undefined) {
markName = webidl.converters.DOMString(markName, {
prefix: "Failed to execute 'clearMarks' on 'Performance'",
context: "Argument 1",
});
markName = webidl.converters.DOMString(
markName,
"Failed to execute 'clearMarks' on 'Performance'",
"Argument 1",
);
performanceEntries = ArrayPrototypeFilter(
performanceEntries,
@ -365,10 +379,11 @@ class Performance extends EventTarget {
clearMeasures(measureName = undefined) {
webidl.assertBranded(this, PerformancePrototype);
if (measureName !== undefined) {
measureName = webidl.converters.DOMString(measureName, {
prefix: "Failed to execute 'clearMeasures' on 'Performance'",
context: "Argument 1",
});
measureName = webidl.converters.DOMString(
measureName,
"Failed to execute 'clearMeasures' on 'Performance'",
"Argument 1",
);
performanceEntries = ArrayPrototypeFilter(
performanceEntries,
@ -396,16 +411,10 @@ class Performance extends EventTarget {
const prefix = "Failed to execute 'getEntriesByName' on 'Performance'";
webidl.requiredArguments(arguments.length, 1, prefix);
name = webidl.converters.DOMString(name, {
prefix,
context: "Argument 1",
});
name = webidl.converters.DOMString(name, prefix, "Argument 1");
if (type !== undefined) {
type = webidl.converters.DOMString(type, {
prefix,
context: "Argument 2",
});
type = webidl.converters.DOMString(type, prefix, "Argument 2");
}
return filterByNameType(name, type);
@ -416,10 +425,7 @@ class Performance extends EventTarget {
const prefix = "Failed to execute 'getEntriesByName' on 'Performance'";
webidl.requiredArguments(arguments.length, 1, prefix);
type = webidl.converters.DOMString(type, {
prefix,
context: "Argument 1",
});
type = webidl.converters.DOMString(type, prefix, "Argument 1");
return filterByNameType(undefined, type);
}
@ -432,15 +438,13 @@ class Performance extends EventTarget {
const prefix = "Failed to execute 'mark' on 'Performance'";
webidl.requiredArguments(arguments.length, 1, prefix);
markName = webidl.converters.DOMString(markName, {
prefix,
context: "Argument 1",
});
markName = webidl.converters.DOMString(markName, prefix, "Argument 1");
markOptions = webidl.converters.PerformanceMarkOptions(markOptions, {
markOptions = webidl.converters.PerformanceMarkOptions(
markOptions,
prefix,
context: "Argument 2",
});
"Argument 2",
);
// 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,
@ -460,22 +464,21 @@ class Performance extends EventTarget {
const prefix = "Failed to execute 'measure' on 'Performance'";
webidl.requiredArguments(arguments.length, 1, prefix);
measureName = webidl.converters.DOMString(measureName, {
measureName = webidl.converters.DOMString(
measureName,
prefix,
context: "Argument 1",
});
"Argument 1",
);
startOrMeasureOptions = webidl.converters
["DOMString or PerformanceMeasureOptions"](startOrMeasureOptions, {
["DOMString or PerformanceMeasureOptions"](
startOrMeasureOptions,
prefix,
context: "Argument 2",
});
"Argument 2",
);
if (endMark !== undefined) {
endMark = webidl.converters.DOMString(endMark, {
prefix,
context: "Argument 3",
});
endMark = webidl.converters.DOMString(endMark, prefix, "Argument 3");
}
if (

View file

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

View file

@ -5,29 +5,13 @@
/// <reference lib="esnext" />
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(
ErrorType: any,
message: string,
prefix: string,
context: string,
prefix?: string,
context?: string,
): any;
interface IntConverterOpts extends ValueConverterOpts {
interface IntConverterOpts {
/**
* Wether to throw if the number is outside of the acceptable values for
* this type.
@ -38,13 +22,13 @@ declare module "ext:deno_webidl/00_webidl.js" {
*/
clamp?: boolean;
}
interface StringConverterOpts extends ValueConverterOpts {
interface StringConverterOpts {
/**
* Wether to treat `null` value as an empty string.
*/
treatNullAsEmptyString?: boolean;
}
interface BufferConverterOpts extends ValueConverterOpts {
interface BufferConverterOpts {
/**
* 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).
*/
boolean(v: any, opts?: IntConverterOpts): boolean;
boolean(
v: any,
prefix?: string,
context?: string,
opts?: IntConverterOpts,
): boolean;
/**
* 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).
*/
octet(v: any, opts?: IntConverterOpts): number;
octet(
v: any,
prefix?: string,
context?: string,
opts?: IntConverterOpts,
): number;
/**
* 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).
*/
["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).
*/
long(v: any, opts?: IntConverterOpts): number;
long(
v: any,
prefix?: string,
context?: string,
opts?: IntConverterOpts,
): number;
/**
* 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).
* **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).
* **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).
*/
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).
*/
["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).
*/
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).
*/
["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).
*/
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).
*/
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
* 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).
*/
object(v: any, opts?: ValueConverterOpts): object;
object(
v: any,
prefix?: string,
context?: string,
opts?: any,
): object;
/**
* 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).
*/
DataView(v: any, opts?: BufferConverterOpts): DataView;
DataView(
v: any,
prefix?: string,
context?: string,
opts?: BufferConverterOpts,
): DataView;
/**
* 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).
*/
Int16Array(v: any, opts?: BufferConverterOpts): Int16Array;
Int16Array(
v: any,
prefix?: string,
context?: string,
opts?: BufferConverterOpts,
): Int16Array;
/**
* 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).
*/
Uint8Array(v: any, opts?: BufferConverterOpts): Uint8Array;
Uint8Array(
v: any,
prefix?: string,
context?: string,
opts?: BufferConverterOpts,
): Uint8Array;
/**
* 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).
*/
Uint32Array(v: any, opts?: BufferConverterOpts): Uint32Array;
Uint32Array(
v: any,
prefix?: string,
context?: string,
opts?: BufferConverterOpts,
): Uint32Array;
/**
* Convert a value into a `Uint8ClampedArray` (Uint8ClampedArray).
*/
Uint8ClampedArray(
v: any,
prefix?: string,
context?: string,
opts?: BufferConverterOpts,
): Uint8ClampedArray;
/**
* 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).
*/
Float64Array(v: any, opts?: BufferConverterOpts): Float64Array;
Float64Array(
v: any,
prefix?: string,
context?: string,
opts?: BufferConverterOpts,
): Float64Array;
/**
* 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).
*/
BufferSource(
v: any,
prefix?: string,
context?: string,
opts?: BufferConverterOpts,
): ArrayBuffer | ArrayBufferView;
/**
* 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).
*/
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).
*/
VoidFunction(v: any, opts?: ValueConverterOpts): () => void;
["UVString?"](v: any, opts?: ValueConverterOpts): string | null;
["sequence<double>"](v: any, opts?: ValueConverterOpts): number[];
VoidFunction(
v: any,
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[];
interface DictionaryMember {
key: string;
converter: (v: any, opts: ValueConverterOpts) => any;
converter: (
v: any,
prefix?: string,
context?: string,
opts?: any,
) => any;
defaultValue?: any;
required?: boolean;
}
@ -221,7 +384,12 @@ declare module "ext:deno_webidl/00_webidl.js" {
function createDictionaryConverter<T>(
name: string,
...dictionaries: Dictionary[]
): (v: any, opts: ValueConverterOpts) => T;
): (
v: any,
prefix?: string,
context?: string,
opts?: any,
) => T;
/**
* Create a converter for enums.
@ -229,28 +397,63 @@ declare module "ext:deno_webidl/00_webidl.js" {
function createEnumConverter(
name: 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.
*/
function createNullableConverter<T>(
converter: (v: any, opts: ValueConverterOpts) => T,
): (v: any, opts: ValueConverterOpts) => T | null;
converter: (
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.
*/
function createSequenceConverter<T>(
converter: (v: any, opts: ValueConverterOpts) => T,
): (v: any, opts: ValueConverterOpts) => T[];
converter: (
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.
*/
function createPromiseConverter<T>(
converter: (v: any, opts: ValueConverterOpts) => T,
): (v: any, opts: ValueConverterOpts) => Promise<T>;
converter: (
v: any,
prefix?: string,
context?: string,
opts?: any,
) => T,
): (
v: any,
prefix?: string,
context?: string,
opts?: any,
) => Promise<T>;
/**
* Invoke a callback function.
@ -259,7 +462,12 @@ declare module "ext:deno_webidl/00_webidl.js" {
callable: (...args: any) => any,
args: any[],
thisArg: any,
returnValueConverter: (v: any, opts: ValueConverterOpts) => T,
returnValueConverter: (
v: any,
prefix?: string,
context?: string,
opts?: any,
) => T,
prefix: string,
returnsPromise?: boolean,
): T;
@ -290,17 +498,34 @@ declare module "ext:deno_webidl/00_webidl.js" {
function createInterfaceConverter(
name: string,
prototype: any,
): (v: any, opts: ValueConverterOpts) => any;
): (
v: any,
prefix?: string,
context?: string,
opts?: any,
) => any;
function createRecordConverter<
K extends string | number | symbol,
V,
>(
keyConverter: (v: any, opts: ValueConverterOpts) => K,
valueConverter: (v: any, opts: ValueConverterOpts) => V,
keyConverter: (
v: any,
prefix?: string,
context?: string,
opts?: any,
) => K,
valueConverter: (
v: any,
prefix?: string,
context?: string,
opts?: any,
) => V,
): (
v: Record<K, V>,
opts: ValueConverterOpts,
prefix?: string,
context?: string,
opts?: any,
) => any;
/**

View file

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

View file

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

View file

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

View file

@ -202,7 +202,7 @@ class Worker extends EventTarget {
postMessage(message, transferOrOptions = {}) {
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);
let options;
if (
@ -212,16 +212,15 @@ class Worker extends EventTarget {
) {
const transfer = webidl.converters["sequence<object>"](
transferOrOptions,
{ prefix, context: "Argument 2" },
prefix,
"Argument 2",
);
options = { transfer };
} else {
options = webidl.converters.StructuredSerializeOptions(
transferOrOptions,
{
prefix,
context: "Argument 2",
},
prefix,
"Argument 2",
);
}
const { transfer } = options;

View file

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