From 25447426f19702a0fff808b3d426d66f4d8e558d Mon Sep 17 00:00:00 2001 From: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Date: Wed, 17 May 2023 18:51:50 -0700 Subject: Make `BuildError` and `ResolveError` use C++ instead of JSC C API Fixes memory leak with private data never being cleared Fixes a case where a ResolveError could actually be a BuildError --- src/bun.js/bindings/ZigGeneratedClasses.h | 119 ++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) (limited to 'src/bun.js/bindings/ZigGeneratedClasses.h') diff --git a/src/bun.js/bindings/ZigGeneratedClasses.h b/src/bun.js/bindings/ZigGeneratedClasses.h index 02fef6d3c..cf5446a1a 100644 --- a/src/bun.js/bindings/ZigGeneratedClasses.h +++ b/src/bun.js/bindings/ZigGeneratedClasses.h @@ -132,6 +132,64 @@ public: mutable JSC::WriteBarrier m_type; }; +class JSBuildMessage final : public JSC::JSDestructibleObject { +public: + using Base = JSC::JSDestructibleObject; + static JSBuildMessage* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, void* ctx); + + DECLARE_EXPORT_INFO; + template static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm) + { + if constexpr (mode == JSC::SubspaceAccess::Concurrently) + return nullptr; + return WebCore::subspaceForImpl( + vm, + [](auto& spaces) { return spaces.m_clientSubspaceForBuildMessage.get(); }, + [](auto& spaces, auto&& space) { spaces.m_clientSubspaceForBuildMessage = std::forward(space); }, + [](auto& spaces) { return spaces.m_subspaceForBuildMessage.get(); }, + [](auto& spaces, auto&& space) { spaces.m_subspaceForBuildMessage = std::forward(space); }); + } + + static void destroy(JSC::JSCell*); + static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) + { + return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(static_cast(0b11101110), StructureFlags), info()); + } + + static JSObject* createPrototype(VM& vm, JSDOMGlobalObject* globalObject); + static JSObject* createConstructor(VM& vm, JSGlobalObject* globalObject, JSValue prototype); + + ~JSBuildMessage(); + + void* wrapped() const { return m_ctx; } + + void detach() + { + m_ctx = nullptr; + } + + static void analyzeHeap(JSCell*, JSC::HeapAnalyzer&); + static ptrdiff_t offsetOfWrapped() { return OBJECT_OFFSETOF(JSBuildMessage, m_ctx); } + + void* m_ctx { nullptr }; + + JSBuildMessage(JSC::VM& vm, JSC::Structure* structure, void* sinkPtr) + : Base(vm, structure) + { + m_ctx = sinkPtr; + } + + void finishCreation(JSC::VM&); + + DECLARE_VISIT_CHILDREN; + template void visitAdditionalChildren(Visitor&); + DECLARE_VISIT_OUTPUT_CONSTRAINTS; + + mutable JSC::WriteBarrier m_level; + mutable JSC::WriteBarrier m_message; + mutable JSC::WriteBarrier m_position; +}; + class JSCryptoHasher final : public JSC::JSDestructibleObject { public: using Base = JSC::JSDestructibleObject; @@ -744,6 +802,67 @@ public: mutable JSC::WriteBarrier m_url; }; +class JSResolveMessage final : public JSC::JSDestructibleObject { +public: + using Base = JSC::JSDestructibleObject; + static JSResolveMessage* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, void* ctx); + + DECLARE_EXPORT_INFO; + template static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm) + { + if constexpr (mode == JSC::SubspaceAccess::Concurrently) + return nullptr; + return WebCore::subspaceForImpl( + vm, + [](auto& spaces) { return spaces.m_clientSubspaceForResolveMessage.get(); }, + [](auto& spaces, auto&& space) { spaces.m_clientSubspaceForResolveMessage = std::forward(space); }, + [](auto& spaces) { return spaces.m_subspaceForResolveMessage.get(); }, + [](auto& spaces, auto&& space) { spaces.m_subspaceForResolveMessage = std::forward(space); }); + } + + static void destroy(JSC::JSCell*); + static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) + { + return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(static_cast(0b11101110), StructureFlags), info()); + } + + static JSObject* createPrototype(VM& vm, JSDOMGlobalObject* globalObject); + static JSObject* createConstructor(VM& vm, JSGlobalObject* globalObject, JSValue prototype); + + ~JSResolveMessage(); + + void* wrapped() const { return m_ctx; } + + void detach() + { + m_ctx = nullptr; + } + + static void analyzeHeap(JSCell*, JSC::HeapAnalyzer&); + static ptrdiff_t offsetOfWrapped() { return OBJECT_OFFSETOF(JSResolveMessage, m_ctx); } + + void* m_ctx { nullptr }; + + JSResolveMessage(JSC::VM& vm, JSC::Structure* structure, void* sinkPtr) + : Base(vm, structure) + { + m_ctx = sinkPtr; + } + + void finishCreation(JSC::VM&); + + DECLARE_VISIT_CHILDREN; + template void visitAdditionalChildren(Visitor&); + DECLARE_VISIT_OUTPUT_CONSTRAINTS; + + mutable JSC::WriteBarrier m_importKind; + mutable JSC::WriteBarrier m_level; + mutable JSC::WriteBarrier m_message; + mutable JSC::WriteBarrier m_position; + mutable JSC::WriteBarrier m_referrer; + mutable JSC::WriteBarrier m_specifier; +}; + class JSResponse final : public JSC::JSDestructibleObject { public: using Base = JSC::JSDestructibleObject; -- cgit v1.2.3