2021-06-09 16:23:04 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <LibJS/Runtime/WeakSet.h>
|
|
|
|
|
|
|
|
namespace JS {
|
|
|
|
|
2024-11-14 15:01:23 +00:00
|
|
|
GC_DEFINE_ALLOCATOR(WeakSet);
|
2023-11-19 08:45:05 +00:00
|
|
|
|
2024-11-14 15:01:23 +00:00
|
|
|
GC::Ref<WeakSet> WeakSet::create(Realm& realm)
|
2021-06-09 16:23:04 +00:00
|
|
|
{
|
2024-11-13 16:50:17 +00:00
|
|
|
return realm.create<WeakSet>(realm.intrinsics().weak_set_prototype());
|
2021-06-09 16:23:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
WeakSet::WeakSet(Object& prototype)
|
2022-12-14 11:17:58 +00:00
|
|
|
: Object(ConstructWithPrototypeTag::Tag, prototype)
|
2021-06-12 02:23:33 +00:00
|
|
|
, WeakContainer(heap())
|
2021-06-09 16:23:04 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2024-11-14 15:01:23 +00:00
|
|
|
void WeakSet::remove_dead_cells(Badge<GC::Heap>)
|
2021-06-09 17:10:47 +00:00
|
|
|
{
|
2022-01-05 15:48:05 +00:00
|
|
|
m_values.remove_all_matching([](Cell* cell) {
|
|
|
|
return cell->state() != Cell::State::Live;
|
|
|
|
});
|
2021-06-09 16:23:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|