diff --git a/src/bake/BakeGlobalObject.cpp b/src/bake/BakeGlobalObject.cpp index 4bd4a4647ed14d..2e3df0c2de1ba1 100644 --- a/src/bake/BakeGlobalObject.cpp +++ b/src/bake/BakeGlobalObject.cpp @@ -11,6 +11,7 @@ extern "C" BunString BakeProdResolve(JSC::JSGlobalObject*, BunString a, BunString b); namespace Bake { +using namespace JSC; JSC::JSInternalPromise* bakeModuleLoaderImportModule(JSC::JSGlobalObject* global, @@ -151,13 +152,14 @@ const JSC::GlobalObjectMethodTable GlobalObject::s_globalObjectMethodTable = { INHERIT_HOOK_METHOD(deriveShadowRealmGlobalObject), INHERIT_HOOK_METHOD(codeForEval), INHERIT_HOOK_METHOD(canCompileStrings), + INHERIT_HOOK_METHOD(trustedScriptStructure), }; GlobalObject* GlobalObject::create(JSC::VM& vm, JSC::Structure* structure, const JSC::GlobalObjectMethodTable* methodTable) { - GlobalObject* ptr = new (NotNull, JSC::allocateCell(vm)) - GlobalObject(vm, structure, methodTable); + Bake::GlobalObject* ptr = new (NotNull, JSC::allocateCell(vm)) + Bake::GlobalObject(vm, structure, methodTable); ptr->finishCreation(vm); return ptr; } @@ -168,6 +170,13 @@ void GlobalObject::finishCreation(JSC::VM& vm) ASSERT(inherits(info())); } +JSC::Structure* GlobalObject::createStructure(JSC::VM& vm) +{ + auto* structure = JSC::Structure::create(vm, nullptr, jsNull(), JSC::TypeInfo(JSC::GlobalObjectType, StructureFlags & ~IsImmutablePrototypeExoticObject), info()); + structure->setTransitionWatchpointIsLikelyToBeFired(true); + return structure; +} + struct BunVirtualMachine; extern "C" BunVirtualMachine* Bun__getVM(); @@ -181,9 +190,9 @@ extern "C" GlobalObject* BakeCreateProdGlobal(void* console) BunVirtualMachine* bunVM = Bun__getVM(); WebCore::JSVMClientData::create(&vm, bunVM); - JSC::Structure* structure = GlobalObject::createStructure(vm); - GlobalObject* global = GlobalObject::create( - vm, structure, &GlobalObject::s_globalObjectMethodTable); + JSC::Structure* structure = Bake::GlobalObject::createStructure(vm); + Bake::GlobalObject* global = Bake::GlobalObject::create( + vm, structure, &Bake::GlobalObject::s_globalObjectMethodTable); if (!global) BUN_PANIC("Failed to create BakeGlobalObject"); @@ -193,6 +202,7 @@ extern "C" GlobalObject* BakeCreateProdGlobal(void* console) global->setConsole(console); global->setStackTraceLimit(10); // Node.js defaults to 10 + global->isThreadLocalDefaultGlobalObject = true; // TODO: it segfaults! process.nextTick is scoped out for now i guess! // vm.setOnComputeErrorInfo(computeErrorInfoWrapper); @@ -214,4 +224,7 @@ extern "C" void BakeGlobalObject__attachPerThreadData(GlobalObject* global, Prod global->m_perThreadData = perThreadData; } +const JSC::ClassInfo Bake::GlobalObject::s_info = { "GlobalObject"_s, &Base::s_info, nullptr, nullptr, + CREATE_METHOD_TABLE(Bake::GlobalObject) }; + }; // namespace Bake diff --git a/src/bake/BakeGlobalObject.h b/src/bake/BakeGlobalObject.h index 0ac902422e646b..a4dcf04a0ac0f2 100644 --- a/src/bake/BakeGlobalObject.h +++ b/src/bake/BakeGlobalObject.h @@ -10,7 +10,8 @@ class GlobalObject : public Zig::GlobalObject { public: using Base = Zig::GlobalObject; - ProductionPerThread* m_perThreadData; + ProductionPerThread* m_perThreadData = nullptr; + DECLARE_INFO; template static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm) { @@ -22,16 +23,20 @@ class GlobalObject : public Zig::GlobalObject { [](auto& spaces, auto&& space) { spaces.m_clientSubspaceForBakeGlobalScope = std::forward(space); }, [](auto& spaces) { return spaces.m_subspaceForBakeGlobalScope.get(); }, [](auto& spaces, auto&& space) { spaces.m_subspaceForBakeGlobalScope = std::forward(space); }, - [](auto& server) -> JSC::HeapCellType& { return server.m_heapCellTypeForJSWorkerGlobalScope; }); + [](auto& server) -> JSC::HeapCellType& { return server.m_heapCellTypeForBakeGlobalObject; }); } static const JSC::GlobalObjectMethodTable s_globalObjectMethodTable; static GlobalObject* create(JSC::VM& vm, JSC::Structure* structure, const JSC::GlobalObjectMethodTable* methodTable); + static JSC::Structure* createStructure(JSC::VM& vm); + void finishCreation(JSC::VM& vm); - GlobalObject(JSC::VM& vm, JSC::Structure* structure, const JSC::GlobalObjectMethodTable* methodTable) - : Zig::GlobalObject(vm, structure, methodTable) { } + GlobalObject(JSC::VM& vm, JSC::Structure* structure, const JSC::GlobalObjectMethodTable* methodTable) + : Zig::GlobalObject(vm, structure, methodTable) + { + } }; }; // namespace Kit diff --git a/src/bun.js/bindings/BunClientData.cpp b/src/bun.js/bindings/BunClientData.cpp index 37f1e097f24b40..b5c037f0c2aae3 100644 --- a/src/bun.js/bindings/BunClientData.cpp +++ b/src/bun.js/bindings/BunClientData.cpp @@ -23,7 +23,7 @@ #include "JSDOMWrapper.h" #include #include "NodeVM.h" - +#include "../../bake/BakeGlobalObject.h" namespace WebCore { using namespace JSC; @@ -32,6 +32,7 @@ RefPtr createBuiltinsSourceProvider(); JSHeapData::JSHeapData(Heap& heap) : m_heapCellTypeForJSWorkerGlobalScope(JSC::IsoHeapCellType::Args()) , m_heapCellTypeForNodeVMGlobalObject(JSC::IsoHeapCellType::Args()) + , m_heapCellTypeForBakeGlobalObject(JSC::IsoHeapCellType::Args()) , 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) diff --git a/src/bun.js/bindings/BunClientData.h b/src/bun.js/bindings/BunClientData.h index 92fcad4ad45547..ef210b02ada063 100644 --- a/src/bun.js/bindings/BunClientData.h +++ b/src/bun.js/bindings/BunClientData.h @@ -59,6 +59,7 @@ class JSHeapData { JSC::IsoHeapCellType m_heapCellTypeForJSWorkerGlobalScope; JSC::IsoHeapCellType m_heapCellTypeForNodeVMGlobalObject; + JSC::IsoHeapCellType m_heapCellTypeForBakeGlobalObject; private: Lock m_lock;