diff --git a/Libraries/LibJS/Heap/Heap.cpp b/Libraries/LibJS/Heap/Heap.cpp index 4406060ba8f..47c92c425b7 100644 --- a/Libraries/LibJS/Heap/Heap.cpp +++ b/Libraries/LibJS/Heap/Heap.cpp @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -19,7 +20,6 @@ #include #include #include -#include #include #ifdef HAS_ADDRESS_SANITIZER @@ -28,8 +28,9 @@ namespace JS { -Heap::Heap(VM& vm) +Heap::Heap(VM& vm, Function&)> gather_embedder_roots) : HeapBase(vm) + , m_gather_embedder_roots(move(gather_embedder_roots)) { static_assert(HeapBlock::min_possible_cell_size <= 32, "Heap Cell tracking uses too much data!"); m_size_based_cell_allocators.append(make(64)); @@ -259,7 +260,7 @@ void Heap::collect_garbage(CollectionType collection_type, bool print_report) void Heap::gather_roots(HashMap& roots) { - vm().gather_roots(roots); + m_gather_embedder_roots(roots); gather_conservative_roots(roots); for (auto& handle : m_handles) diff --git a/Libraries/LibJS/Heap/Heap.h b/Libraries/LibJS/Heap/Heap.h index 5a38dd25f9d..694a70d81a5 100644 --- a/Libraries/LibJS/Heap/Heap.h +++ b/Libraries/LibJS/Heap/Heap.h @@ -7,6 +7,7 @@ #pragma once #include +#include #include #include #include @@ -32,7 +33,7 @@ class Heap : public HeapBase { AK_MAKE_NONMOVABLE(Heap); public: - explicit Heap(VM&); + explicit Heap(VM&, Function&)> gather_embedder_roots); ~Heap(); template @@ -145,6 +146,7 @@ private: bool m_collecting_garbage { false }; StackInfo m_stack_info; + Function&)> m_gather_embedder_roots; }; inline void Heap::did_create_handle(Badge, HandleImpl& impl) diff --git a/Libraries/LibJS/Runtime/VM.cpp b/Libraries/LibJS/Runtime/VM.cpp index 111bf8ad760..afc5538bc49 100644 --- a/Libraries/LibJS/Runtime/VM.cpp +++ b/Libraries/LibJS/Runtime/VM.cpp @@ -62,7 +62,9 @@ static constexpr auto make_single_ascii_character_strings(IndexSequence()); VM::VM(OwnPtr custom_data, ErrorMessages error_messages) - : m_heap(*this) + : m_heap(*this, [this](HashMap& roots) { + gather_roots(roots); + }) , m_error_messages(move(error_messages)) , m_custom_data(move(custom_data)) {