diff options
Diffstat (limited to 'ext/webidl/00_webidl.js')
-rw-r--r-- | ext/webidl/00_webidl.js | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/ext/webidl/00_webidl.js b/ext/webidl/00_webidl.js index 4f51edfed..a71993c87 100644 --- a/ext/webidl/00_webidl.js +++ b/ext/webidl/00_webidl.js @@ -61,6 +61,14 @@ ReflectOwnKeys, RegExpPrototypeTest, Set, + SetPrototypeEntries, + SetPrototypeForEach, + SetPrototypeKeys, + SetPrototypeValues, + SetPrototypeHas, + SetPrototypeClear, + SetPrototypeDelete, + SetPrototypeAdd, // TODO(lucacasonato): add SharedArrayBuffer to primordials // SharedArrayBuffer, String, @@ -1048,6 +1056,108 @@ }); } + const setlikeInner = Symbol("[[set]]"); + + // Ref: https://webidl.spec.whatwg.org/#es-setlike + function setlike(obj, objPrototype, readonly) { + ObjectDefineProperties(obj, { + size: { + configurable: true, + enumerable: true, + get() { + assertBranded(this, objPrototype); + return obj[setlikeInner].size; + }, + }, + [SymbolIterator]: { + configurable: true, + enumerable: false, + writable: true, + value() { + assertBranded(this, objPrototype); + return obj[setlikeInner][SymbolIterator](); + }, + }, + entries: { + configurable: true, + enumerable: true, + writable: true, + value() { + assertBranded(this, objPrototype); + return SetPrototypeEntries(obj[setlikeInner]); + }, + }, + keys: { + configurable: true, + enumerable: true, + writable: true, + value() { + assertBranded(this, objPrototype); + return SetPrototypeKeys(obj[setlikeInner]); + }, + }, + values: { + configurable: true, + enumerable: true, + writable: true, + value() { + assertBranded(this, objPrototype); + return SetPrototypeValues(obj[setlikeInner]); + }, + }, + forEach: { + configurable: true, + enumerable: true, + writable: true, + value(callbackfn, thisArg) { + assertBranded(this, objPrototype); + return SetPrototypeForEach(obj[setlikeInner], callbackfn, thisArg); + }, + }, + has: { + configurable: true, + enumerable: true, + writable: true, + value(value) { + assertBranded(this, objPrototype); + return SetPrototypeHas(obj[setlikeInner], value); + }, + }, + }); + + if (!readonly) { + ObjectDefineProperties(obj, { + add: { + configurable: true, + enumerable: true, + writable: true, + value(value) { + assertBranded(this, objPrototype); + return SetPrototypeAdd(obj[setlikeInner], value); + }, + }, + delete: { + configurable: true, + enumerable: true, + writable: true, + value(value) { + assertBranded(this, objPrototype); + return SetPrototypeDelete(obj[setlikeInner], value); + }, + }, + clear: { + configurable: true, + enumerable: true, + writable: true, + value() { + assertBranded(this, objPrototype); + return SetPrototypeClear(obj[setlikeInner]); + }, + }, + }); + } + } + window.__bootstrap ??= {}; window.__bootstrap.webidl = { type, @@ -1068,5 +1178,7 @@ illegalConstructor, mixinPairIterable, configurePrototype, + setlike, + setlikeInner, }; })(this); |