Move EventLoopTask into a separate file because it causes clangd to crash (#13875)

This commit is contained in:
Jarred Sumner
2024-09-11 00:24:48 -07:00
committed by GitHub
parent 4a58a97fa0
commit 97baeb80f0
8 changed files with 65 additions and 52 deletions

View 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;
})
{
}
};
}

View 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;
};
}

View File

@@ -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);

View File

@@ -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;

View File

@@ -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"

View File

@@ -24,6 +24,7 @@
#include "JSDOMConvertBase.h"
#include "JSDOMExceptionHandling.h"
#include "ScriptExecutionContext.h"
#include "DeleteCallbackDataTask.h"
namespace WebCore {
using namespace JSC;

View File

@@ -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

View File

@@ -27,6 +27,7 @@
#include "JSDOMExceptionHandling.h"
#include "JSDOMGlobalObject.h"
#include "ScriptExecutionContext.h"
#include "DeleteCallbackDataTask.h"
namespace WebCore {
using namespace JSC;