mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-28 04:08:08 +00:00
LibWeb: Disentangle associated MessagePorts when a document is destroyed
This commit is contained in:
@@ -29,6 +29,12 @@ constexpr u8 IPC_FILE_TAG = 0xA5;
|
||||
|
||||
JS_DEFINE_ALLOCATOR(MessagePort);
|
||||
|
||||
static HashTable<JS::RawGCPtr<MessagePort>>& all_message_ports()
|
||||
{
|
||||
static HashTable<JS::RawGCPtr<MessagePort>> ports;
|
||||
return ports;
|
||||
}
|
||||
|
||||
JS::NonnullGCPtr<MessagePort> MessagePort::create(JS::Realm& realm)
|
||||
{
|
||||
return realm.heap().allocate<MessagePort>(realm, realm);
|
||||
@@ -37,13 +43,21 @@ JS::NonnullGCPtr<MessagePort> MessagePort::create(JS::Realm& realm)
|
||||
MessagePort::MessagePort(JS::Realm& realm)
|
||||
: DOM::EventTarget(realm)
|
||||
{
|
||||
all_message_ports().set(this);
|
||||
}
|
||||
|
||||
MessagePort::~MessagePort()
|
||||
{
|
||||
all_message_ports().remove(this);
|
||||
disentangle();
|
||||
}
|
||||
|
||||
void MessagePort::for_each_message_port(Function<void(MessagePort&)> callback)
|
||||
{
|
||||
for (auto port : all_message_ports())
|
||||
callback(*port);
|
||||
}
|
||||
|
||||
void MessagePort::initialize(JS::Realm& realm)
|
||||
{
|
||||
Base::initialize(realm);
|
||||
|
||||
Reference in New Issue
Block a user