From 97baeb80f0f51551092ae61602a50366fe467e2d Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Wed, 11 Sep 2024 00:24:48 -0700 Subject: [PATCH] Move EventLoopTask into a separate file because it causes clangd to crash (#13875) --- src/bun.js/bindings/DeleteCallbackDataTask.h | 16 +++++++ src/bun.js/bindings/EventLoopTask.h | 44 +++++++++++++++++++ .../bindings/ScriptExecutionContext.cpp | 2 +- src/bun.js/bindings/ScriptExecutionContext.h | 39 +--------------- src/bun.js/bindings/ZigGlobalObject.cpp | 3 +- .../bindings/webcore/JSAbortAlgorithm.cpp | 1 + src/bun.js/bindings/webcore/JSCallbackData.h | 11 ----- .../bindings/webcore/JSErrorCallback.cpp | 1 + 8 files changed, 65 insertions(+), 52 deletions(-) create mode 100644 src/bun.js/bindings/DeleteCallbackDataTask.h create mode 100644 src/bun.js/bindings/EventLoopTask.h diff --git a/src/bun.js/bindings/DeleteCallbackDataTask.h b/src/bun.js/bindings/DeleteCallbackDataTask.h new file mode 100644 index 00000000000000..4c3a5b05d3e98c --- /dev/null +++ b/src/bun.js/bindings/DeleteCallbackDataTask.h @@ -0,0 +1,16 @@ +#include "root.h" +#include "EventLoopTask.h" + +namespace WebCore { +class DeleteCallbackDataTask : public EventLoopTask { +public: + template + explicit DeleteCallbackDataTask(CallbackDataType* data) + : EventLoopTask(EventLoopTask::CleanupTask, [data](ScriptExecutionContext&) mutable { + delete data; + }) + { + } +}; + +} \ No newline at end of file diff --git a/src/bun.js/bindings/EventLoopTask.h b/src/bun.js/bindings/EventLoopTask.h new file mode 100644 index 00000000000000..965a36adc05d8a --- /dev/null +++ b/src/bun.js/bindings/EventLoopTask.h @@ -0,0 +1,44 @@ +#include "root.h" +#include "ScriptExecutionContext.h" + +namespace WebCore { + +class EventLoopTask { + WTF_MAKE_ISO_ALLOCATED(EventLoopTask); + +public: + enum CleanupTaskTag { CleanupTask }; + + template::value && std::is_convertible>::value>::type> + EventLoopTask(T task) + : m_task(WTFMove(task)) + , m_isCleanupTask(false) + { + } + + EventLoopTask(Function&& task) + : m_task([task = WTFMove(task)](ScriptExecutionContext&) { task(); }) + , m_isCleanupTask(false) + { + } + + template>::value>::type> + EventLoopTask(CleanupTaskTag, T task) + : m_task(WTFMove(task)) + , m_isCleanupTask(true) + { + } + + void performTask(ScriptExecutionContext& context) + { + m_task(context); + delete this; + } + bool isCleanupTask() const { return m_isCleanupTask; } + +protected: + Function m_task; + bool m_isCleanupTask; +}; + +} \ No newline at end of file diff --git a/src/bun.js/bindings/ScriptExecutionContext.cpp b/src/bun.js/bindings/ScriptExecutionContext.cpp index 87de0125a0dda7..06e5b7ddba82cb 100644 --- a/src/bun.js/bindings/ScriptExecutionContext.cpp +++ b/src/bun.js/bindings/ScriptExecutionContext.cpp @@ -3,10 +3,10 @@ #include "ScriptExecutionContext.h" #include "MessagePort.h" -#include "webcore/WebSocket.h" #include "libusockets.h" #include "_libusockets.h" #include "BunClientData.h" +#include "EventLoopTask.h" extern "C" void Bun__startLoop(us_loop_t* loop); diff --git a/src/bun.js/bindings/ScriptExecutionContext.h b/src/bun.js/bindings/ScriptExecutionContext.h index 4b603235941339..e2cf419111e641 100644 --- a/src/bun.js/bindings/ScriptExecutionContext.h +++ b/src/bun.js/bindings/ScriptExecutionContext.h @@ -29,44 +29,7 @@ class WebSocket; class MessagePort; class ScriptExecutionContext; - -class EventLoopTask { - WTF_MAKE_ISO_ALLOCATED(EventLoopTask); - -public: - enum CleanupTaskTag { CleanupTask }; - - template::value && std::is_convertible>::value>::type> - EventLoopTask(T task) - : m_task(WTFMove(task)) - , m_isCleanupTask(false) - { - } - - EventLoopTask(Function&& task) - : m_task([task = WTFMove(task)](ScriptExecutionContext&) { task(); }) - , m_isCleanupTask(false) - { - } - - template>::value>::type> - EventLoopTask(CleanupTaskTag, T task) - : m_task(WTFMove(task)) - , m_isCleanupTask(true) - { - } - - void performTask(ScriptExecutionContext& context) - { - m_task(context); - delete this; - } - bool isCleanupTask() const { return m_isCleanupTask; } - -protected: - Function m_task; - bool m_isCleanupTask; -}; +class EventLoopTask; using ScriptExecutionContextIdentifier = uint32_t; diff --git a/src/bun.js/bindings/ZigGlobalObject.cpp b/src/bun.js/bindings/ZigGlobalObject.cpp index 8f99baefca47e0..38ac73c92692ad 100644 --- a/src/bun.js/bindings/ZigGlobalObject.cpp +++ b/src/bun.js/bindings/ZigGlobalObject.cpp @@ -1,5 +1,3 @@ - - #include "root.h" #include "ZigGlobalObject.h" #include "helpers.h" @@ -150,6 +148,7 @@ #include "wtf/text/OrdinalNumber.h" #include "ErrorCode.h" #include "v8/V8GlobalInternals.h" +#include "EventLoopTask.h" #if ENABLE(REMOTE_INSPECTOR) #include "JavaScriptCore/RemoteInspectorServer.h" diff --git a/src/bun.js/bindings/webcore/JSAbortAlgorithm.cpp b/src/bun.js/bindings/webcore/JSAbortAlgorithm.cpp index d3e2fadfd03a6a..26e5f57f54ef92 100644 --- a/src/bun.js/bindings/webcore/JSAbortAlgorithm.cpp +++ b/src/bun.js/bindings/webcore/JSAbortAlgorithm.cpp @@ -24,6 +24,7 @@ #include "JSDOMConvertBase.h" #include "JSDOMExceptionHandling.h" #include "ScriptExecutionContext.h" +#include "DeleteCallbackDataTask.h" namespace WebCore { using namespace JSC; diff --git a/src/bun.js/bindings/webcore/JSCallbackData.h b/src/bun.js/bindings/webcore/JSCallbackData.h index ec62cb049fcc76..d688a82c2ac643 100644 --- a/src/bun.js/bindings/webcore/JSCallbackData.h +++ b/src/bun.js/bindings/webcore/JSCallbackData.h @@ -109,15 +109,4 @@ class JSCallbackDataWeak : public JSCallbackData { JSC::Weak m_callback; }; -class DeleteCallbackDataTask : public EventLoopTask { -public: - template - explicit DeleteCallbackDataTask(CallbackDataType* data) - : EventLoopTask(EventLoopTask::CleanupTask, [data](ScriptExecutionContext&) mutable { - delete data; - }) - { - } -}; - } // namespace WebCore diff --git a/src/bun.js/bindings/webcore/JSErrorCallback.cpp b/src/bun.js/bindings/webcore/JSErrorCallback.cpp index de924d857d6ec9..d1b2821e1d8753 100644 --- a/src/bun.js/bindings/webcore/JSErrorCallback.cpp +++ b/src/bun.js/bindings/webcore/JSErrorCallback.cpp @@ -27,6 +27,7 @@ #include "JSDOMExceptionHandling.h" #include "JSDOMGlobalObject.h" #include "ScriptExecutionContext.h" +#include "DeleteCallbackDataTask.h" namespace WebCore { using namespace JSC;