ladybird/Userland/Libraries/LibWeb/DOM/DocumentObserver.cpp
Andreas Kling bfd354492e LibWeb: Put most LibWeb GC objects in type-specific heap blocks
With this change, we now have ~1200 CellAllocators across both LibJS and
LibWeb in a normal WebContent instance.

This gives us a minimum heap size of 4.7 MiB in the scenario where we
only have one cell allocated per type. Of course, in practice there will
be many more of each type, so the effective overhead is quite a bit
smaller than that in practice.

I left a few types unconverted to this mechanism because I got tired of
doing this. :^)
2023-11-19 22:00:48 +01:00

46 lines
1.1 KiB
C++

/*
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibJS/Runtime/Realm.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/DocumentObserver.h>
namespace Web::DOM {
JS_DEFINE_ALLOCATOR(DocumentObserver);
DocumentObserver::DocumentObserver(JS::Realm& realm, DOM::Document& document)
: Bindings::PlatformObject(realm)
, m_document(document)
{
m_document->register_document_observer({}, *this);
}
void DocumentObserver::visit_edges(Cell::Visitor& visitor)
{
Base::visit_edges(visitor);
visitor.visit(m_document);
visitor.visit(m_document_became_inactive);
visitor.visit(m_document_completely_loaded);
}
void DocumentObserver::finalize()
{
Base::finalize();
m_document->unregister_document_observer({}, *this);
}
void DocumentObserver::set_document_became_inactive(Function<void()> callback)
{
m_document_became_inactive = JS::create_heap_function(vm().heap(), move(callback));
}
void DocumentObserver::set_document_completely_loaded(Function<void()> callback)
{
m_document_completely_loaded = JS::create_heap_function(vm().heap(), move(callback));
}
}