summaryrefslogtreecommitdiff
path: root/op_crates/webidl
diff options
context:
space:
mode:
Diffstat (limited to 'op_crates/webidl')
-rw-r--r--op_crates/webidl/00_webidl.js45
-rw-r--r--op_crates/webidl/internal.d.ts12
2 files changed, 57 insertions, 0 deletions
diff --git a/op_crates/webidl/00_webidl.js b/op_crates/webidl/00_webidl.js
index 843fd329e..508abe44d 100644
--- a/op_crates/webidl/00_webidl.js
+++ b/op_crates/webidl/00_webidl.js
@@ -802,6 +802,50 @@
throw new TypeError("Illegal constructor");
}
+ function mixinPairIterable(name, prototype, dataSymbol, keyKey, valueKey) {
+ const methods = {
+ *entries() {
+ assertBranded(this, prototype);
+ for (const entry of this[dataSymbol]) {
+ yield [entry[keyKey], entry[valueKey]];
+ }
+ },
+ [Symbol.iterator]() {
+ assertBranded(this, prototype);
+ return this.entries();
+ },
+ *keys() {
+ assertBranded(this, prototype);
+ for (const entry of this[dataSymbol]) {
+ yield entry[keyKey];
+ }
+ },
+ *values() {
+ assertBranded(this, prototype);
+ for (const entry of this[dataSymbol]) {
+ yield entry[valueKey];
+ }
+ },
+ forEach(idlCallback, thisArg) {
+ assertBranded(this, prototype);
+ const prefix = `Failed to execute 'forEach' on '${name}'`;
+ requiredArguments(arguments.length, 1, { prefix });
+ idlCallback = converters["Function"](idlCallback, {
+ prefix,
+ context: "Argument 1",
+ });
+ idlCallback = idlCallback.bind(thisArg ?? globalThis);
+ const pairs = this[dataSymbol];
+ for (let i = 0; i < pairs.length; i++) {
+ const entry = pairs[i];
+ idlCallback(entry[valueKey], entry[keyKey], this);
+ }
+ },
+ };
+
+ return Object.assign(prototype.prototype, methods);
+ }
+
window.__bootstrap ??= {};
window.__bootstrap.webidl = {
makeException,
@@ -817,5 +861,6 @@
createBranded,
assertBranded,
illegalConstructor,
+ mixinPairIterable,
};
})(this);
diff --git a/op_crates/webidl/internal.d.ts b/op_crates/webidl/internal.d.ts
index 425ee674e..ca72566a5 100644
--- a/op_crates/webidl/internal.d.ts
+++ b/op_crates/webidl/internal.d.ts
@@ -286,6 +286,18 @@ declare namespace globalThis {
v: Record<K, V>,
opts: ValueConverterOpts,
) => any;
+
+ /**
+ * Mix in the iterable declarations defined in WebIDL.
+ * https://heycam.github.io/webidl/#es-iterable
+ */
+ declare function mixinPairIterable(
+ name: string,
+ prototype: any,
+ dataSymbol: symbol,
+ keyKey: string | number | symbol,
+ valueKey: string | number | symbol,
+ ): void;
}
}
}