ladybird/Userland/Libraries/LibJS/Heap/ConservativeVector.cpp
Andreas Kling 4bbb0a5c35 LibJS: Add ConservativeVector<T>
This works very similarly to MarkedVector<T>, but instead of expecting
T to be Value or a GC-allocated pointer type, T can be anything.
Every pointer-sized value in the vector's storage will be checked during
conservative root scanning.

In other words, this allows you to put something like this in a
ConservativeVector<Foo> and it will be protected from GC:

    struct Foo {
        i64 number;
        Value some_value;
        GCPtr<Object> some_object;
    };
2024-02-22 16:44:54 +01:00

23 lines
453 B
C++

/*
* Copyright (c) 2024, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibJS/Heap/ConservativeVector.h>
#include <LibJS/Heap/Heap.h>
namespace JS {
ConservativeVectorBase::ConservativeVectorBase(Heap& heap)
: m_heap(&heap)
{
m_heap->did_create_conservative_vector({}, *this);
}
ConservativeVectorBase::~ConservativeVectorBase()
{
m_heap->did_destroy_conservative_vector({}, *this);
}
}