LibWeb: Do not use JS::Handle for mutation observers

Using JS::Handle in WebEngineCustomData means that mutation observers
will live as long as VM while actually they should be deallocated as
soon as they are no longer used in a script that created them.
This commit is contained in:
Aliaksandr Kalenik 2023-09-27 14:58:14 +02:00 committed by Andreas Kling
parent e7a3040c9f
commit 15629e8925
Notes: sideshowbarker 2024-07-17 10:16:43 +09:00
2 changed files with 8 additions and 2 deletions

View file

@ -49,7 +49,7 @@ struct WebEngineCustomData final : public JS::VM::CustomData {
// https://dom.spec.whatwg.org/#mutation-observer-list
// FIXME: This should be a set.
Vector<JS::Handle<DOM::MutationObserver>> mutation_observers;
Vector<JS::NonnullGCPtr<DOM::MutationObserver>> mutation_observers;
JS::Handle<JS::Realm> internal_realm;

View file

@ -29,7 +29,13 @@ MutationObserver::MutationObserver(JS::Realm& realm, JS::GCPtr<WebIDL::CallbackT
agent_custom_data->mutation_observers.append(*this);
}
MutationObserver::~MutationObserver() = default;
MutationObserver::~MutationObserver()
{
auto* agent_custom_data = verify_cast<Bindings::WebEngineCustomData>(vm().custom_data());
agent_custom_data->mutation_observers.remove_all_matching([this](auto& observer) {
return observer.ptr() == this;
});
}
void MutationObserver::initialize(JS::Realm& realm)
{