Add all Map and Set methods to IterableWeakMap and IterableWeakSet

This commit is contained in:
Samuel Elliott 2018-07-18 21:47:32 +01:00
parent 6b97505f66
commit 821f46481e
No known key found for this signature in database
GPG Key ID: 8420C7CDE43DC4D6
1 changed files with 44 additions and 0 deletions

View File

@ -26,6 +26,30 @@ export class IterableWeakMap extends WeakMap {
values() {
return IterableWeakCollections.getWeakMapEntries(this).map(e => e[1]).values();
}
forEach(callback, thisArg) {
for (let [key, value] of this) {
callback.call(thisArg, value, key, this);
}
}
clear() {
for (let key of this.keys()) {
this.delete(key);
}
}
get size() {
return IterableWeakCollections.getWeakMapEntries(this).length;
}
get [Symbol.toStringTag]() {
return 'IterableWeakMap';
}
static get [Symbol.species]() {
return IterableWeakMap;
}
}
export class IterableWeakSet extends WeakSet {
@ -36,6 +60,26 @@ export class IterableWeakSet extends WeakSet {
values() {
return IterableWeakCollections.getWeakSetValues(this).values();
}
forEach(callback, thisArg) {
for (let value of this) {
callback.call(thisArg, value, value, this);
}
}
clear() {
for (let value of this) {
this.delete(value);
}
}
get size() {
return IterableWeakCollections.getWeakSetValues(this).length;
}
static get [Symbol.species]() {
return IterableWeakSet;
}
}
export class IterableWeakCollections {