Skip to content

Commit

Permalink
Move EventLoopTask into a separate file because it causes clangd to c…
Browse files Browse the repository at this point in the history
…rash (#13875)
  • Loading branch information
Jarred-Sumner authored Sep 11, 2024
1 parent 4a58a97 commit 97baeb8
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 52 deletions.
16 changes: 16 additions & 0 deletions src/bun.js/bindings/DeleteCallbackDataTask.h
Original file line number Diff line number Diff line change
@@ -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 changes: 44 additions & 0 deletions src/bun.js/bindings/EventLoopTask.h
Original file line number Diff line number Diff line change
@@ -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;
};

}
2 changes: 1 addition & 1 deletion src/bun.js/bindings/ScriptExecutionContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
39 changes: 1 addition & 38 deletions src/bun.js/bindings/ScriptExecutionContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
3 changes: 1 addition & 2 deletions src/bun.js/bindings/ZigGlobalObject.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


#include "root.h"
#include "ZigGlobalObject.h"
#include "helpers.h"
Expand Down Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions src/bun.js/bindings/webcore/JSAbortAlgorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "JSDOMConvertBase.h"
#include "JSDOMExceptionHandling.h"
#include "ScriptExecutionContext.h"
#include "DeleteCallbackDataTask.h"

namespace WebCore {
using namespace JSC;
Expand Down
11 changes: 0 additions & 11 deletions src/bun.js/bindings/webcore/JSCallbackData.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,4 @@ class JSCallbackDataWeak : public JSCallbackData {
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
1 change: 1 addition & 0 deletions src/bun.js/bindings/webcore/JSErrorCallback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "JSDOMExceptionHandling.h"
#include "JSDOMGlobalObject.h"
#include "ScriptExecutionContext.h"
#include "DeleteCallbackDataTask.h"

namespace WebCore {
using namespace JSC;
Expand Down

0 comments on commit 97baeb8

Please sign in to comment.