WeakMap.cpp 761 B

123456789101112131415161718192021222324252627282930313233343536
  1. /*
  2. * Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibJS/Runtime/WeakMap.h>
  7. namespace JS {
  8. NonnullGCPtr<WeakMap> WeakMap::create(Realm& realm)
  9. {
  10. return realm.heap().allocate<WeakMap>(realm, realm.intrinsics().weak_map_prototype());
  11. }
  12. WeakMap::WeakMap(Object& prototype)
  13. : Object(ConstructWithPrototypeTag::Tag, prototype)
  14. , WeakContainer(heap())
  15. {
  16. }
  17. void WeakMap::remove_dead_cells(Badge<Heap>)
  18. {
  19. m_values.remove_all_matching([](Cell* key, Value) {
  20. return key->state() != Cell::State::Live;
  21. });
  22. }
  23. void WeakMap::visit_edges(Visitor& visitor)
  24. {
  25. Base::visit_edges(visitor);
  26. for (auto& entry : m_values)
  27. visitor.visit(entry.value);
  28. }
  29. }