WeakSet.cpp 637 B

12345678910111213141516171819202122232425262728293031
  1. /*
  2. * Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibJS/Runtime/WeakSet.h>
  7. namespace JS {
  8. JS_DEFINE_ALLOCATOR(WeakSet);
  9. NonnullGCPtr<WeakSet> WeakSet::create(Realm& realm)
  10. {
  11. return realm.heap().allocate<WeakSet>(realm, realm.intrinsics().weak_set_prototype());
  12. }
  13. WeakSet::WeakSet(Object& prototype)
  14. : Object(ConstructWithPrototypeTag::Tag, prototype)
  15. , WeakContainer(heap())
  16. {
  17. }
  18. void WeakSet::remove_dead_cells(Badge<Heap>)
  19. {
  20. m_values.remove_all_matching([](Cell* cell) {
  21. return cell->state() != Cell::State::Live;
  22. });
  23. }
  24. }