2021-06-12 02:28:30 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <LibJS/Runtime/WeakMap.h>
|
|
|
|
|
|
|
|
namespace JS {
|
|
|
|
|
2024-11-14 15:01:23 +00:00
|
|
|
GC_DEFINE_ALLOCATOR(WeakMap);
|
2023-11-19 08:45:05 +00:00
|
|
|
|
2024-11-14 15:01:23 +00:00
|
|
|
GC::Ref<WeakMap> WeakMap::create(Realm& realm)
|
2021-06-12 02:28:30 +00:00
|
|
|
{
|
2024-11-13 16:50:17 +00:00
|
|
|
return realm.create<WeakMap>(realm.intrinsics().weak_map_prototype());
|
2021-06-12 02:28:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
WeakMap::WeakMap(Object& prototype)
|
2022-12-14 11:17:58 +00:00
|
|
|
: Object(ConstructWithPrototypeTag::Tag, prototype)
|
2021-06-12 02:28:30 +00:00
|
|
|
, WeakContainer(heap())
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2024-11-14 15:01:23 +00:00
|
|
|
void WeakMap::remove_dead_cells(Badge<GC::Heap>)
|
2021-06-12 02:28:30 +00:00
|
|
|
{
|
2022-01-05 15:57:16 +00:00
|
|
|
m_values.remove_all_matching([](Cell* key, Value) {
|
|
|
|
return key->state() != Cell::State::Live;
|
|
|
|
});
|
2021-06-12 02:28:30 +00:00
|
|
|
}
|
|
|
|
|
2021-09-11 16:19:40 +00:00
|
|
|
void WeakMap::visit_edges(Visitor& visitor)
|
|
|
|
{
|
|
|
|
Base::visit_edges(visitor);
|
|
|
|
for (auto& entry : m_values)
|
|
|
|
visitor.visit(entry.value);
|
|
|
|
}
|
|
|
|
|
2021-06-12 02:28:30 +00:00
|
|
|
}
|