mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-01 07:52:50 +00:00
LibWeb: Disentangle associated MessagePorts when a document is destroyed
This commit is contained in:
parent
d44dd756b3
commit
ba1b26cdc2
Notes:
github-actions[bot]
2024-10-17 20:35:40 +00:00
Author: https://github.com/trflynn89
Commit: ba1b26cdc2
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1835
Reviewed-by: https://github.com/ADKaster ✅
3 changed files with 30 additions and 3 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue