WeakSet.h 891 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /*
  2. * Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/HashTable.h>
  8. #include <LibJS/Runtime/GlobalObject.h>
  9. #include <LibJS/Runtime/Object.h>
  10. #include <LibJS/Runtime/WeakContainer.h>
  11. namespace JS {
  12. class WeakSet final
  13. : public Object
  14. , public WeakContainer {
  15. JS_OBJECT(WeakSet, Object);
  16. JS_DECLARE_ALLOCATOR(WeakSet);
  17. public:
  18. static NonnullGCPtr<WeakSet> create(Realm&);
  19. virtual ~WeakSet() override = default;
  20. HashTable<GCPtr<Cell>> const& values() const { return m_values; }
  21. HashTable<GCPtr<Cell>>& values() { return m_values; }
  22. virtual void remove_dead_cells(Badge<Heap>) override;
  23. private:
  24. explicit WeakSet(Object& prototype);
  25. HashTable<GCPtr<Cell>> m_values; // This stores Cell pointers instead of Object pointers to aide with sweeping
  26. };
  27. }