LibWeb/HTML: Use finalize to clean up MessagePort instances

This commit is contained in:
Shannon Booth 2025-01-01 01:20:37 +13:00 committed by Andreas Kling
commit e767029e24
Notes: github-actions[bot] 2025-01-02 10:39:57 +00:00
2 changed files with 9 additions and 5 deletions

View file

@ -47,11 +47,7 @@ MessagePort::MessagePort(JS::Realm& realm)
all_message_ports().set(this); all_message_ports().set(this);
} }
MessagePort::~MessagePort() MessagePort::~MessagePort() = default;
{
all_message_ports().remove(this);
disentangle();
}
void MessagePort::for_each_message_port(Function<void(MessagePort&)> callback) void MessagePort::for_each_message_port(Function<void(MessagePort&)> callback)
{ {
@ -65,6 +61,13 @@ void MessagePort::initialize(JS::Realm& realm)
WEB_SET_PROTOTYPE_FOR_INTERFACE(MessagePort); WEB_SET_PROTOTYPE_FOR_INTERFACE(MessagePort);
} }
void MessagePort::finalize()
{
Base::finalize();
all_message_ports().remove(this);
disentangle();
}
void MessagePort::visit_edges(Cell::Visitor& visitor) void MessagePort::visit_edges(Cell::Visitor& visitor)
{ {
Base::visit_edges(visitor); Base::visit_edges(visitor);

View file

@ -68,6 +68,7 @@ private:
explicit MessagePort(JS::Realm&); explicit MessagePort(JS::Realm&);
virtual void initialize(JS::Realm&) override; virtual void initialize(JS::Realm&) override;
virtual void finalize() override;
virtual void visit_edges(Cell::Visitor&) override; virtual void visit_edges(Cell::Visitor&) override;
bool is_entangled() const; bool is_entangled() const;