LibGC: Clear functions during finalization

A finalized GC::Function should no longer be callable. Clear the
underlying AK::Function during finalization so stale references fail as
empty callbacks instead of calling through finalized capture storage.
This commit is contained in:
Andreas Kling 2026-05-09 20:42:04 +02:00 committed by Andreas Kling
parent 5cf90c0d0d
commit 949889f124

View file

@ -18,6 +18,8 @@ class Function final : public Cell {
GC_DECLARE_ALLOCATOR(Function);
public:
static constexpr bool OVERRIDES_FINALIZE = true;
static Ref<Function> create(Heap& heap, ESCAPING AK::Function<T>&& function)
{
return heap.allocate<Function>(move(function));
@ -25,6 +27,12 @@ public:
virtual ~Function() override = default;
virtual void finalize() override
{
Base::finalize();
m_function = nullptr;
}
[[nodiscard]] AK::Function<T> const& function() const { return m_function; }
private: