diff --git a/Source/WTF/wtf/RunLoop.h b/Source/WTF/wtf/RunLoop.h index ab69d5d2a9fdc..9f5ff8a3cd1d1 100644 --- a/Source/WTF/wtf/RunLoop.h +++ b/Source/WTF/wtf/RunLoop.h @@ -144,6 +144,9 @@ class WTF_CAPABILITY("is current") RunLoop final : public GuaranteedSerialFuncti #if USE(GLIB_EVENT_LOOP) WTF_EXPORT_PRIVATE void setName(ASCIILiteral); WTF_EXPORT_PRIVATE void setPriority(int); +#elif USE(BUN_EVENT_LOOP) + // WTFTimer in Timer.zig + struct Bun__WTFTimer; #endif private: @@ -172,6 +175,7 @@ class WTF_CAPABILITY("is current") RunLoop final : public GuaranteedSerialFuncti class ScheduledTask; Ref m_scheduledTask; #elif USE(BUN_EVENT_LOOP) + Bun__WTFTimer* m_zigTimer; #endif }; diff --git a/Source/WTF/wtf/bun/RunLoopBun.cpp b/Source/WTF/wtf/bun/RunLoopBun.cpp index 2a61b09608fa1..2f7387715cc90 100644 --- a/Source/WTF/wtf/bun/RunLoopBun.cpp +++ b/Source/WTF/wtf/bun/RunLoopBun.cpp @@ -1,24 +1,66 @@ #include "config.h" #include + namespace WTF { +// Functions exported by Timer.zig +extern "C" __attribute__((weak)) RunLoop::TimerBase::Bun__WTFTimer* WTFTimer__create(RunLoop::TimerBase*); +extern "C" __attribute__((weak)) void WTFTimer__update(RunLoop::TimerBase::Bun__WTFTimer*, double seconds, bool repeat); +extern "C" __attribute__((weak)) void WTFTimer__deinit(RunLoop::TimerBase::Bun__WTFTimer*); +extern "C" __attribute__((weak)) bool WTFTimer__isActive(const RunLoop::TimerBase::Bun__WTFTimer*); +extern "C" __attribute__((weak)) double WTFTimer__secondsUntilTimer(const RunLoop::TimerBase::Bun__WTFTimer*); +extern "C" __attribute__((weak)) void WTFTimer__cancel(RunLoop::TimerBase::Bun__WTFTimer*); + RunLoop::TimerBase::TimerBase(Ref&& loop) : m_runLoop(WTFMove(loop)) + // check if the zig function is actually available (it won't be in JSC shell, since that doesn't + // link Bun's zig code) + , m_zigTimer(&WTFTimer__create ? WTFTimer__create(this) : nullptr) { } RunLoop::TimerBase::~TimerBase() { + if (&WTFTimer__deinit) { + ASSERT(m_zigTimer); + WTFTimer__deinit(m_zigTimer); + } } -void RunLoop::TimerBase::stop() {} +void RunLoop::TimerBase::stop() { + if (&WTFTimer__cancel) { + ASSERT(m_zigTimer); + WTFTimer__cancel(m_zigTimer); + } +} -bool RunLoop::TimerBase::isActive() const {} +bool RunLoop::TimerBase::isActive() const { + if (&WTFTimer__isActive) { + ASSERT(m_zigTimer); + return WTFTimer__isActive(m_zigTimer); + } + return false; +} -Seconds RunLoop::TimerBase::secondsUntilFire() const {} +Seconds RunLoop::TimerBase::secondsUntilFire() const { + if (&WTFTimer__secondsUntilTimer) { + ASSERT(m_zigTimer); + return Seconds(WTFTimer__secondsUntilTimer(m_zigTimer)); + } + return -1.0_s; +} + +void RunLoop::TimerBase::start(Seconds interval, bool repeat) { + if (&WTFTimer__update) { + ASSERT(m_zigTimer); + WTFTimer__update(m_zigTimer, interval.value(), repeat); + } +} -void RunLoop::TimerBase::start(Seconds interval, bool repeat) {} +extern "C" void WTFTimer__fire(RunLoop::TimerBase* timer) { + timer->fired(); +} // probably more Bun-specific TimerBase methods @@ -26,14 +68,26 @@ RunLoop::RunLoop() { } -RunLoop::~RunLoop() {} +RunLoop::~RunLoop() +{ +} -void RunLoop::run() {} +void RunLoop::run() { + ASSERT_NOT_REACHED(); +} -void RunLoop::stop() {} +void RunLoop::stop() { + ASSERT_NOT_REACHED(); +} -void RunLoop::wakeUp() {} +void RunLoop::wakeUp() { + ASSERT_NOT_REACHED(); +} -RunLoop::CycleResult RunLoop::cycle(RunLoopMode mode) {} +RunLoop::CycleResult RunLoop::cycle(RunLoopMode mode) { + (void) mode; + ASSERT_NOT_REACHED(); + return RunLoop::CycleResult::Stop; +} } // namespace WTF diff --git a/Source/cmake/WebKitCompilerFlags.cmake b/Source/cmake/WebKitCompilerFlags.cmake index 0307c68e5fc43..e8b26d2ebf9a4 100644 --- a/Source/cmake/WebKitCompilerFlags.cmake +++ b/Source/cmake/WebKitCompilerFlags.cmake @@ -228,6 +228,15 @@ if (COMPILER_IS_GCC_OR_CLANG) # Makes builds faster. The GCC manual warns about the possibility that the assembler being # used may not support input from a pipe, but in practice the toolchains we support all do. WEBKIT_PREPEND_GLOBAL_COMPILER_FLAGS(-pipe) + + if (USE_BUN_JSC_ADDITIONS) + WEBKIT_PREPEND_GLOBAL_COMPILER_FLAGS(-Wl,-U,_WTFTimer__create + -Wl,-U,_WTFTimer__update + -Wl,-U,_WTFTimer__deinit + -Wl,-U,_WTFTimer__isActive + -Wl,-U,_WTFTimer__secondsUntilTimer + -Wl,-U,_WTFTimer__cancel) + endif () endif () if (COMPILER_IS_GCC_OR_CLANG AND NOT MSVC)