mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
Move EventLoopTask into a separate file because it causes clangd to crash (#13875)
This commit is contained in:
16
src/bun.js/bindings/DeleteCallbackDataTask.h
Normal file
16
src/bun.js/bindings/DeleteCallbackDataTask.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#include "root.h"
|
||||
#include "EventLoopTask.h"
|
||||
|
||||
namespace WebCore {
|
||||
class DeleteCallbackDataTask : public EventLoopTask {
|
||||
public:
|
||||
template<typename CallbackDataType>
|
||||
explicit DeleteCallbackDataTask(CallbackDataType* data)
|
||||
: EventLoopTask(EventLoopTask::CleanupTask, [data](ScriptExecutionContext&) mutable {
|
||||
delete data;
|
||||
})
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
44
src/bun.js/bindings/EventLoopTask.h
Normal file
44
src/bun.js/bindings/EventLoopTask.h
Normal file
@@ -0,0 +1,44 @@
|
||||
#include "root.h"
|
||||
#include "ScriptExecutionContext.h"
|
||||
|
||||
namespace WebCore {
|
||||
|
||||
class EventLoopTask {
|
||||
WTF_MAKE_ISO_ALLOCATED(EventLoopTask);
|
||||
|
||||
public:
|
||||
enum CleanupTaskTag { CleanupTask };
|
||||
|
||||
template<typename T, typename = typename std::enable_if<!std::is_base_of<EventLoopTask, T>::value && std::is_convertible<T, Function<void(ScriptExecutionContext&)>>::value>::type>
|
||||
EventLoopTask(T task)
|
||||
: m_task(WTFMove(task))
|
||||
, m_isCleanupTask(false)
|
||||
{
|
||||
}
|
||||
|
||||
EventLoopTask(Function<void()>&& task)
|
||||
: m_task([task = WTFMove(task)](ScriptExecutionContext&) { task(); })
|
||||
, m_isCleanupTask(false)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename T, typename = typename std::enable_if<std::is_convertible<T, Function<void(ScriptExecutionContext&)>>::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<void(ScriptExecutionContext&)> m_task;
|
||||
bool m_isCleanupTask;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -29,44 +29,7 @@ class WebSocket;
|
||||
class MessagePort;
|
||||
|
||||
class ScriptExecutionContext;
|
||||
|
||||
class EventLoopTask {
|
||||
WTF_MAKE_ISO_ALLOCATED(EventLoopTask);
|
||||
|
||||
public:
|
||||
enum CleanupTaskTag { CleanupTask };
|
||||
|
||||
template<typename T, typename = typename std::enable_if<!std::is_base_of<EventLoopTask, T>::value && std::is_convertible<T, Function<void(ScriptExecutionContext&)>>::value>::type>
|
||||
EventLoopTask(T task)
|
||||
: m_task(WTFMove(task))
|
||||
, m_isCleanupTask(false)
|
||||
{
|
||||
}
|
||||
|
||||
EventLoopTask(Function<void()>&& task)
|
||||
: m_task([task = WTFMove(task)](ScriptExecutionContext&) { task(); })
|
||||
, m_isCleanupTask(false)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename T, typename = typename std::enable_if<std::is_convertible<T, Function<void(ScriptExecutionContext&)>>::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<void(ScriptExecutionContext&)> m_task;
|
||||
bool m_isCleanupTask;
|
||||
};
|
||||
class EventLoopTask;
|
||||
|
||||
using ScriptExecutionContextIdentifier = uint32_t;
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "JSDOMConvertBase.h"
|
||||
#include "JSDOMExceptionHandling.h"
|
||||
#include "ScriptExecutionContext.h"
|
||||
#include "DeleteCallbackDataTask.h"
|
||||
|
||||
namespace WebCore {
|
||||
using namespace JSC;
|
||||
|
||||
@@ -109,15 +109,4 @@ private:
|
||||
JSC::Weak<JSC::JSObject> m_callback;
|
||||
};
|
||||
|
||||
class DeleteCallbackDataTask : public EventLoopTask {
|
||||
public:
|
||||
template<typename CallbackDataType>
|
||||
explicit DeleteCallbackDataTask(CallbackDataType* data)
|
||||
: EventLoopTask(EventLoopTask::CleanupTask, [data](ScriptExecutionContext&) mutable {
|
||||
delete data;
|
||||
})
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace WebCore
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "JSDOMExceptionHandling.h"
|
||||
#include "JSDOMGlobalObject.h"
|
||||
#include "ScriptExecutionContext.h"
|
||||
#include "DeleteCallbackDataTask.h"
|
||||
|
||||
namespace WebCore {
|
||||
using namespace JSC;
|
||||
|
||||
Reference in New Issue
Block a user