From 3bc71ac699a1d61487d4d07aa32b9c7814940fb7 Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Fri, 2 Aug 2024 03:55:11 -0700 Subject: [PATCH] Update --- src/bun.js/bindings/BunClientData.cpp | 12 +++++++++--- src/bun.js/bindings/JSCTaskScheduler.cpp | 12 ++++-------- src/bun.js/bindings/JSCTaskScheduler.h | 10 +++++++--- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/bun.js/bindings/BunClientData.cpp b/src/bun.js/bindings/BunClientData.cpp index 3aaf738664bcfb..ee48afd07fb414 100644 --- a/src/bun.js/bindings/BunClientData.cpp +++ b/src/bun.js/bindings/BunClientData.cpp @@ -76,9 +76,15 @@ void JSVMClientData::create(VM* vm, void* bunVM) auto provider = WebCore::createBuiltinsSourceProvider(); JSVMClientData* clientData = new JSVMClientData(*vm, provider); clientData->bunVM = bunVM; - vm->deferredWorkTimer->onAddPendingWork = Bun::JSCTaskScheduler::onAddPendingWork; - vm->deferredWorkTimer->onScheduleWorkSoon = Bun::JSCTaskScheduler::onScheduleWorkSoon; - vm->deferredWorkTimer->onCancelPendingWork = Bun::JSCTaskScheduler::onCancelPendingWork; + vm->deferredWorkTimer->onAddPendingWork = [clientData](Ref&& ticket, JSC::DeferredWorkTimer::WorkType kind) -> void { + Bun::JSCTaskScheduler::onAddPendingWork(clientData, WTFMove(ticket), kind); + }; + vm->deferredWorkTimer->onScheduleWorkSoon = [clientData](JSC::DeferredWorkTimer::Ticket ticket, JSC::DeferredWorkTimer::Task&& task) -> void { + Bun::JSCTaskScheduler::onScheduleWorkSoon(clientData, ticket, WTFMove(task)); + }; + vm->deferredWorkTimer->onCancelPendingWork = [clientData](JSC::DeferredWorkTimer::Ticket ticket) -> void { + Bun::JSCTaskScheduler::onCancelPendingWork(clientData, ticket); + }; vm->clientData = clientData; // ~VM deletes this pointer. clientData->m_normalWorld = DOMWrapperWorld::create(*vm, DOMWrapperWorld::Type::Normal); diff --git a/src/bun.js/bindings/JSCTaskScheduler.cpp b/src/bun.js/bindings/JSCTaskScheduler.cpp index 5474113a45187d..22125a19bf3cab 100644 --- a/src/bun.js/bindings/JSCTaskScheduler.cpp +++ b/src/bun.js/bindings/JSCTaskScheduler.cpp @@ -39,10 +39,8 @@ static JSC::VM& getVM(Ticket& ticket) return ticket->scriptExecutionOwner()->vm(); } -void JSCTaskScheduler::onAddPendingWork(Ref&& ticket, JSC::DeferredWorkTimer::WorkType kind) +void JSCTaskScheduler::onAddPendingWork(WebCore::JSVMClientData* clientData, Ref&& ticket, JSC::DeferredWorkTimer::WorkType kind) { - JSC::VM& vm = ticket->scriptExecutionOwner()->vm(); - auto clientData = WebCore::clientData(vm); auto& scheduler = clientData->deferredWorkTimer; Locker holder { scheduler.m_lock }; if (kind == DeferredWorkTimer::WorkType::ImminentlyScheduled) { @@ -52,16 +50,14 @@ void JSCTaskScheduler::onAddPendingWork(Ref&& ticket, JSC::DeferredW scheduler.m_pendingTicketsOther.add(WTFMove(ticket)); } } -void JSCTaskScheduler::onScheduleWorkSoon(Ticket ticket, Task&& task) +void JSCTaskScheduler::onScheduleWorkSoon(WebCore::JSVMClientData* clientData, Ticket ticket, Task&& task) { auto* job = new JSCDeferredWorkTask(*ticket, WTFMove(task)); - Bun__queueJSCDeferredWorkTaskConcurrently(WebCore::clientData(job->vm())->bunVM, job); + Bun__queueJSCDeferredWorkTaskConcurrently(clientData->bunVM, job); } -void JSCTaskScheduler::onCancelPendingWork(Ticket ticket) +void JSCTaskScheduler::onCancelPendingWork(WebCore::JSVMClientData* clientData, Ticket ticket) { - JSC::VM& vm = getVM(ticket); - auto* clientData = WebCore::clientData(vm); auto* bunVM = clientData->bunVM; auto& scheduler = clientData->deferredWorkTimer; diff --git a/src/bun.js/bindings/JSCTaskScheduler.h b/src/bun.js/bindings/JSCTaskScheduler.h index 3276da653a136a..45a6d3888de2f2 100644 --- a/src/bun.js/bindings/JSCTaskScheduler.h +++ b/src/bun.js/bindings/JSCTaskScheduler.h @@ -1,5 +1,9 @@ #pragma once +namespace WebCore { +class JSVMClientData; +} + #include namespace Bun { @@ -12,9 +16,9 @@ class JSCTaskScheduler { { } - static void onAddPendingWork(Ref&& ticket, JSC::DeferredWorkTimer::WorkType kind); - static void onScheduleWorkSoon(JSC::DeferredWorkTimer::Ticket ticket, JSC::DeferredWorkTimer::Task&& task); - static void onCancelPendingWork(JSC::DeferredWorkTimer::Ticket ticket); + static void onAddPendingWork(WebCore::JSVMClientData* clientData, Ref&& ticket, JSC::DeferredWorkTimer::WorkType kind); + static void onScheduleWorkSoon(WebCore::JSVMClientData* clientData, JSC::DeferredWorkTimer::Ticket ticket, JSC::DeferredWorkTimer::Task&& task); + static void onCancelPendingWork(WebCore::JSVMClientData* clientData, JSC::DeferredWorkTimer::Ticket ticket); public: Lock m_lock;