From 666a1b73db31582227c0f0f59be31e382b8bebd7 Mon Sep 17 00:00:00 2001 From: Eden Chuang Date: Mon, 15 Jan 2024 15:53:56 +0000 Subject: [PATCH] Bug 1874080 - Nullify WebTaskSchedulerWorker::mWorkerPrivate while Disconnect(). r=smaug, a=RyanVM Differential Revision: https://phabricator.services.mozilla.com/D198569 --- dom/webscheduling/WebTaskScheduler.h | 2 +- dom/webscheduling/WebTaskSchedulerWorker.cpp | 13 +++++++++++++ dom/webscheduling/WebTaskSchedulerWorker.h | 2 ++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/dom/webscheduling/WebTaskScheduler.h b/dom/webscheduling/WebTaskScheduler.h index fcddd09d365b..92e0bb6a44b3 100644 --- a/dom/webscheduling/WebTaskScheduler.h +++ b/dom/webscheduling/WebTaskScheduler.h @@ -113,7 +113,7 @@ class WebTaskScheduler : public nsWrapperCache, public SupportsWeakPtr { WebTask* GetNextTask() const; - void Disconnect(); + virtual void Disconnect(); void RunTaskSignalPriorityChange(TaskSignal* aTaskSignal); diff --git a/dom/webscheduling/WebTaskSchedulerWorker.cpp b/dom/webscheduling/WebTaskSchedulerWorker.cpp index 89fbb6169f0d..479d12cf7bb9 100644 --- a/dom/webscheduling/WebTaskSchedulerWorker.cpp +++ b/dom/webscheduling/WebTaskSchedulerWorker.cpp @@ -36,6 +36,9 @@ bool WebTaskWorkerRunnable::WorkerRun(JSContext* aCx, nsresult WebTaskSchedulerWorker::SetTimeoutForDelayedTask(WebTask* aTask, uint64_t aDelay) { + if (!mWorkerPrivate) { + return NS_ERROR_UNEXPECTED; + } JSContext* cx = nsContentUtils::GetCurrentJSContext(); if (!cx) { return NS_ERROR_UNEXPECTED; @@ -52,8 +55,18 @@ nsresult WebTaskSchedulerWorker::SetTimeoutForDelayedTask(WebTask* aTask, } bool WebTaskSchedulerWorker::DispatchEventLoopRunnable() { + if (!mWorkerPrivate) { + return false; + } RefPtr runnable = new WebTaskWorkerRunnable(mWorkerPrivate, this); return runnable->Dispatch(); } + +void WebTaskSchedulerWorker::Disconnect() { + if (mWorkerPrivate) { + mWorkerPrivate = nullptr; + } + WebTaskScheduler::Disconnect(); +} } // namespace mozilla::dom diff --git a/dom/webscheduling/WebTaskSchedulerWorker.h b/dom/webscheduling/WebTaskSchedulerWorker.h index 4af987736ea5..b27b1250ffa9 100644 --- a/dom/webscheduling/WebTaskSchedulerWorker.h +++ b/dom/webscheduling/WebTaskSchedulerWorker.h @@ -34,6 +34,8 @@ class WebTaskSchedulerWorker final : public WebTaskScheduler { public: explicit WebTaskSchedulerWorker(WorkerPrivate* aWorkerPrivate); + void Disconnect() override; + private: ~WebTaskSchedulerWorker() = default;