[DOM] Simplify WorkerRunnable sanity checks and make them more readable.

This commit is contained in:
Martok 2024-04-08 08:43:23 +02:00 committed by roytam1
commit b518af4d45

View file

@ -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;