forked from oven-sh/bun
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBunClientData.cpp
88 lines (70 loc) · 2.92 KB
/
BunClientData.cpp
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "root.h"
#include "BunClientData.h"
#include "ExtendedDOMClientIsoSubspaces.h"
#include "ExtendedDOMIsoSubspaces.h"
#include <JavaScriptCore/FastMallocAlignedMemoryAllocator.h>
#include <JavaScriptCore/HeapInlines.h>
#include <JavaScriptCore/IsoHeapCellType.h>
#include <JavaScriptCore/JSDestructibleObjectHeapCellType.h>
// #include <JavaScriptCore/MarkingConstraint.h>
#include <JavaScriptCore/SubspaceInlines.h>
#include <JavaScriptCore/VM.h>
#include <wtf/MainThread.h>
#include "JSDOMConstructorBase.h"
#include "JSDOMBuiltinConstructorBase.h"
#include "BunGCOutputConstraint.h"
#include "WebCoreTypedArrayController.h"
#include <JavaScriptCore/JSCInlines.h>
#include "JSDOMWrapper.h"
#include <JavaScriptCore/DeferredWorkTimer.h>
namespace WebCore {
using namespace JSC;
JSHeapData::JSHeapData(Heap& heap)
: m_heapCellTypeForJSWorkerGlobalScope(JSC::IsoHeapCellType::Args<Zig::GlobalObject>())
, m_domBuiltinConstructorSpace ISO_SUBSPACE_INIT(heap, heap.cellHeapCellType, JSDOMBuiltinConstructorBase)
, m_domConstructorSpace ISO_SUBSPACE_INIT(heap, heap.cellHeapCellType, JSDOMConstructorBase)
, m_domNamespaceObjectSpace ISO_SUBSPACE_INIT(heap, heap.cellHeapCellType, JSDOMObject)
, m_subspaces(makeUnique<ExtendedDOMIsoSubspaces>())
{
}
#define CLIENT_ISO_SUBSPACE_INIT(subspace) subspace(m_heapData->subspace)
JSVMClientData::JSVMClientData(VM& vm)
: m_builtinFunctions(vm)
, m_builtinNames(vm)
, m_heapData(JSHeapData::ensureHeapData(vm.heap))
, CLIENT_ISO_SUBSPACE_INIT(m_domBuiltinConstructorSpace)
, CLIENT_ISO_SUBSPACE_INIT(m_domConstructorSpace)
, CLIENT_ISO_SUBSPACE_INIT(m_domNamespaceObjectSpace)
, m_clientSubspaces(makeUnique<ExtendedDOMClientIsoSubspaces>())
{
}
#undef CLIENT_ISO_SUBSPACE_INIT
JSHeapData* JSHeapData::ensureHeapData(Heap& heap)
{
if (!Options::useGlobalGC())
return new JSHeapData(heap);
static JSHeapData* singleton = nullptr;
static std::once_flag onceFlag;
std::call_once(onceFlag, [&] {
singleton = new JSHeapData(heap);
});
return singleton;
}
JSVMClientData::~JSVMClientData()
{
ASSERT(m_normalWorld->hasOneRef());
m_normalWorld = nullptr;
}
void JSVMClientData::create(VM* vm, void* bunVM)
{
JSVMClientData* clientData = new JSVMClientData(*vm);
clientData->bunVM = bunVM;
vm->deferredWorkTimer->onAddPendingWork = Bun::JSCTaskScheduler::onAddPendingWork;
vm->deferredWorkTimer->onScheduleWorkSoon = Bun::JSCTaskScheduler::onScheduleWorkSoon;
vm->deferredWorkTimer->onCancelPendingWork = Bun::JSCTaskScheduler::onCancelPendingWork;
vm->clientData = clientData; // ~VM deletes this pointer.
clientData->m_normalWorld = DOMWrapperWorld::create(*vm, DOMWrapperWorld::Type::Normal);
vm->heap.addMarkingConstraint(makeUnique<WebCore::DOMGCOutputConstraint>(*vm, clientData->heapData()));
vm->m_typedArrayController = adoptRef(new WebCoreTypedArrayController(true));
}
} // namespace WebCore