mirror of
https://github.com/RGBCube/serenity
synced 2025-05-16 18:35:07 +00:00

This is pretty heavy and unoptimized, but it will do the trick for now. Basically, Heap now has a HashTable<HandleImpl*> and you can call JS::make_handle(T*) to construct a Handle<T> that guarantees that the pointee will always survive GC until the Handle<T> is destroyed.
18 lines
300 B
C++
18 lines
300 B
C++
#include <LibJS/Heap/Handle.h>
|
|
#include <LibJS/Heap/Heap.h>
|
|
#include <LibJS/Runtime/Cell.h>
|
|
|
|
namespace JS {
|
|
|
|
HandleImpl::HandleImpl(Cell* cell)
|
|
: m_cell(cell)
|
|
{
|
|
m_cell->heap().did_create_handle({}, *this);
|
|
}
|
|
|
|
HandleImpl::~HandleImpl()
|
|
{
|
|
m_cell->heap().did_destroy_handle({}, *this);
|
|
}
|
|
|
|
}
|