Sha256: 87498cc5a019e0ec5da66af8bb82bf25481dc6444c1ddc98d747c7a9ece203f2

Contents?: true

Size: 1.13 KB

Versions: 46

Compression:

Stored size: 1.13 KB

Contents

"use strict";

// An iterable WeakSet implementation inspired by the iterable WeakMap example code in the WeakRefs specification:
// https://github.com/tc39/proposal-weakrefs#iterable-weakmaps
module.exports = class IterableWeakSet {
  constructor() {
    this._refSet = new Set();
    this._refMap = new WeakMap();
    this._finalizationRegistry = new FinalizationRegistry(({ ref, set }) => set.delete(ref));
  }

  add(value) {
    if (!this._refMap.has(value)) {
      const ref = new WeakRef(value);
      this._refMap.set(value, ref);
      this._refSet.add(ref);
      this._finalizationRegistry.register(value, { ref, set: this._refSet }, ref);
    }

    return this;
  }

  delete(value) {
    const ref = this._refMap.get(value);
    if (!ref) {
      return false;
    }

    this._refMap.delete(value);
    this._refSet.delete(ref);
    this._finalizationRegistry.unregister(ref);
    return true;
  }

  has(value) {
    return this._refMap.has(value);
  }

  * [Symbol.iterator]() {
    for (const ref of this._refSet) {
      const value = ref.deref();
      if (value === undefined) {
        continue;
      }
      yield value;
    }
  }
};

Version data entries

46 entries across 46 versions & 2 rubygems

Version Path
appmap-0.66.1 ./node_modules/jsdom/lib/jsdom/living/helpers/iterable-weak-set.js
appmap-0.66.0 ./node_modules/jsdom/lib/jsdom/living/helpers/iterable-weak-set.js
appmap-0.65.1 ./node_modules/jsdom/lib/jsdom/living/helpers/iterable-weak-set.js
appmap-0.65.0 ./node_modules/jsdom/lib/jsdom/living/helpers/iterable-weak-set.js
appmap-0.64.0 ./node_modules/jsdom/lib/jsdom/living/helpers/iterable-weak-set.js
appmap-0.63.0 ./node_modules/jsdom/lib/jsdom/living/helpers/iterable-weak-set.js