diff options
author | Luca Casonato <lucacasonato@yahoo.com> | 2021-04-14 22:49:16 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-14 22:49:16 +0200 |
commit | 353e79c796efc6c6aa328abb4d7cef5e642944af (patch) | |
tree | 5ae6d1778c0a1dfa53ac62e409d6da8cdb31285f /op_crates/webidl/00_webidl.js | |
parent | 5214acd3d9dec56ee159544f0f6bf9834a62c097 (diff) |
chore: align FormData to spec (#10169)
This PR aligns `FormData` to spec. All WPT tests are passing.
Diffstat (limited to 'op_crates/webidl/00_webidl.js')
-rw-r--r-- | op_crates/webidl/00_webidl.js | 45 |
1 files changed, 45 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); |