From b518af4d45314f3ec33810a26343329333b0cbf4 Mon Sep 17 00:00:00 2001 From: Martok Date: Mon, 8 Apr 2024 08:43:23 +0200 Subject: [PATCH] [DOM] Simplify WorkerRunnable sanity checks and make them more readable. --- dom/workers/WorkerRunnable.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/dom/workers/WorkerRunnable.cpp b/dom/workers/WorkerRunnable.cpp index eb56650b51..9049878710 100644 --- a/dom/workers/WorkerRunnable.cpp +++ b/dom/workers/WorkerRunnable.cpp @@ -231,8 +231,13 @@ WorkerRunnable::Run() { bool targetIsWorkerThread = mBehavior == WorkerThreadModifyBusyCount || mBehavior == WorkerThreadUnchangedBusyCount; + bool alreadyCanceled = IsCanceled() && !mCallingCancelWithinRun; + bool shouldCancelWorker = targetIsWorkerThread && + mWorkerPrivate->AllPendingRunnablesShouldBeCanceled() && + !IsCanceled() && !mCallingCancelWithinRun; + bool runnableWillRun = !alreadyCanceled && !shouldCancelWorker; - if (targetIsWorkerThread) { + if (targetIsWorkerThread && runnableWillRun) { // On a worker thread, a WorkerRunnable should only run when there is an // underlying WorkerThreadPrimaryRunnable active, which means we should // find a CycleCollectedJSContext. @@ -256,14 +261,11 @@ WorkerRunnable::Run() } #endif - if (IsCanceled() && !mCallingCancelWithinRun) { + if (alreadyCanceled) { return NS_OK; } - if (targetIsWorkerThread && - mWorkerPrivate->AllPendingRunnablesShouldBeCanceled() && - !IsCanceled() && !mCallingCancelWithinRun) { - + if (shouldCancelWorker) { // Prevent recursion. mCallingCancelWithinRun = true;