2021-06-12 05:28:30 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <LibJS/Runtime/WeakMap.h>
|
|
|
|
|
|
|
|
namespace JS {
|
|
|
|
|
2022-08-16 00:20:49 +01:00
|
|
|
WeakMap* WeakMap::create(Realm& realm)
|
2021-06-12 05:28:30 +03:00
|
|
|
{
|
2022-08-27 00:54:55 +01:00
|
|
|
return realm.heap().allocate<WeakMap>(realm, *realm.intrinsics().weak_map_prototype());
|
2021-06-12 05:28:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
WeakMap::WeakMap(Object& prototype)
|
|
|
|
: Object(prototype)
|
|
|
|
, WeakContainer(heap())
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-10-05 18:44:31 +02:00
|
|
|
void WeakMap::remove_dead_cells(Badge<Heap>)
|
2021-06-12 05:28:30 +03:00
|
|
|
{
|
2022-01-05 16:57:16 +01:00
|
|
|
m_values.remove_all_matching([](Cell* key, Value) {
|
|
|
|
return key->state() != Cell::State::Live;
|
|
|
|
});
|
2021-06-12 05:28:30 +03:00
|
|
|
}
|
|
|
|
|
2021-09-11 19:19:40 +03:00
|
|
|
void WeakMap::visit_edges(Visitor& visitor)
|
|
|
|
{
|
|
|
|
Base::visit_edges(visitor);
|
|
|
|
for (auto& entry : m_values)
|
|
|
|
visitor.visit(entry.value);
|
|
|
|
}
|
|
|
|
|
2021-06-12 05:28:30 +03:00
|
|
|
}
|