Files
bun.sh/src/bun.js/bindings/BunWorkerGlobalScope.cpp
190n ea65a2ad48 Bump WebKit (#17095)
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
2025-02-12 22:08:53 -08:00

46 lines
1.5 KiB
C++

#include "config.h"
#include "BunWorkerGlobalScope.h"
#include "MessagePortChannelProviderImpl.h"
#include <wtf/TZoneMallocInlines.h>
namespace WebCore {
WTF_MAKE_TZONE_ALLOCATED_IMPL(WorkerGlobalScope);
MessagePortChannelProvider& WorkerGlobalScope::messagePortChannelProvider()
{
return *reinterpret_cast<MessagePortChannelProvider*>(&MessagePortChannelProviderImpl::singleton());
}
void WorkerGlobalScope::onDidChangeListenerImpl(EventTarget& self, const AtomString& eventType, OnDidChangeListenerKind kind)
{
if (eventType == eventNames().messageEvent) {
auto& global = static_cast<WorkerGlobalScope&>(self);
switch (kind) {
case Add:
if (global.m_messageEventCount == 0) {
global.scriptExecutionContext()->refEventLoop();
}
global.m_messageEventCount++;
break;
case Remove:
global.m_messageEventCount--;
if (global.m_messageEventCount == 0) {
global.scriptExecutionContext()->unrefEventLoop();
}
break;
// I dont think clear in this context is ever called. If it is (search OnDidChangeListenerKind::Clear for the impl),
// it may actually call once per event, in a way the Remove code above would suffice.
case Clear:
if (global.m_messageEventCount > 0) {
global.scriptExecutionContext()->unrefEventLoop();
}
global.m_messageEventCount = 0;
break;
}
}
};
}