ladybird/Userland/Libraries/LibJS/Runtime/WeakSet.cpp
Idan Horowitz a00d154522 LibJS: Notify WeakSets when heap cells are sweeped
This is an implementation of the following optional optimization:
https://tc39.es/ecma262/#sec-weakref-execution
2021-06-09 21:52:25 +01:00

33 lines
648 B
C++

/*
* Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibJS/Runtime/WeakSet.h>
namespace JS {
WeakSet* WeakSet::create(GlobalObject& global_object)
{
return global_object.heap().allocate<WeakSet>(global_object, *global_object.weak_set_prototype());
}
WeakSet::WeakSet(Object& prototype)
: Object(prototype)
{
heap().did_create_weak_set({}, *this);
}
WeakSet::~WeakSet()
{
heap().did_destroy_weak_set({}, *this);
}
void WeakSet::remove_sweeped_cells(Badge<Heap>, Vector<Cell*>& cells)
{
for (auto* cell : cells)
m_values.remove(cell);
}
}