diff --git a/src/bun.js/bindings/DeleteCallbackDataTask.h b/src/bun.js/bindings/DeleteCallbackDataTask.h new file mode 100644 index 0000000000..4c3a5b05d3 --- /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 0000000000..965a36adc0 --- /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 87de0125a0..06e5b7ddba 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 4b60323594..e2cf419111 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 8f99baefca..38ac73c926 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 d3e2fadfd0..26e5f57f54 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 ec62cb049f..d688a82c2a 100644 --- a/src/bun.js/bindings/webcore/JSCallbackData.h +++ b/src/bun.js/bindings/webcore/JSCallbackData.h @@ -109,15 +109,4 @@ private: 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 de924d857d..d1b2821e1d 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;