aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/bindings/BunWorkerGlobalScope.h
blob: f8e0be52e9687016fa5798fed6d5c23b749f6a77 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#pragma once

#include "root.h"

#include "EventNames.h"
#include "EventTarget.h"
#include "ContextDestructionObserver.h"
#include "ExceptionOr.h"
#include <wtf/URL.h>
#include <wtf/HashSet.h>
#include <wtf/Lock.h>

namespace WebCore {

class MessagePortChannelProvider;
class MessagePortChannelProviderImpl;

class GlobalScope : public RefCounted<GlobalScope>, public EventTargetWithInlineData {
    WTF_MAKE_ISO_ALLOCATED(GlobalScope);

    uint32_t m_messageEventCount;

    static void onDidChangeListenerImpl(EventTarget&, const AtomString&, OnDidChangeListenerKind);

public:
    GlobalScope(ScriptExecutionContext* context)
        : EventTargetWithInlineData()
        , m_context(context)
    {
        this->onDidChangeListener = &onDidChangeListenerImpl;
    }

    using RefCounted::deref;
    using RefCounted::ref;

    static Ref<GlobalScope> create(ScriptExecutionContext* context)
    {
        return adoptRef(*new GlobalScope(context));
    }

    ~GlobalScope() = default;

    EventTargetInterface eventTargetInterface() const final { return EventTargetInterface::DOMWindowEventTargetInterfaceType; }
    ScriptExecutionContext* scriptExecutionContext() const final { return m_context; }
    void refEventTarget() final { ref(); }
    void derefEventTarget() final { deref(); }
    void eventListenersDidChange() final {}

    MessagePortChannelProvider& messagePortChannelProvider();

    ScriptExecutionContext* m_context;

private:
    MessagePortChannelProviderImpl* m_messagePortChannelProvider;
};
}