[DOM] Check if WorkerRunnable::Run runs on top of WorkerThreadPrimaryRunnable::Run in a worker thread.

This commit is contained in:
Jens Stutte 2024-02-22 19:53:24 +01:00 committed by roytam1
commit d1b0f59de4
2 changed files with 17 additions and 1 deletions

View file

@ -11,6 +11,7 @@
#include "nsIRunnable.h"
#include "nsThreadUtils.h"
#include "mozilla/CycleCollectedJSContext.h"
#include "mozilla/DebugOnly.h"
#include "mozilla/ErrorResult.h"
#include "mozilla/Unused.h"
@ -231,6 +232,19 @@ WorkerRunnable::Run()
bool targetIsWorkerThread = mBehavior == WorkerThreadModifyBusyCount ||
mBehavior == WorkerThreadUnchangedBusyCount;
if (targetIsWorkerThread) {
// On a worker thread, a WorkerRunnable should only run when there is an
// underlying WorkerThreadPrimaryRunnable active, which means we should
// find a CycleCollectedJSContext.
if (!CycleCollectedJSContext::Get()) {
MOZ_DIAGNOSTIC_ASSERT(false,
"A WorkerRunnable was executed after "
"WorkerThreadPrimaryRunnable ended.");
return NS_OK;
}
}
#ifdef DEBUG
MOZ_ASSERT_IF(mCallingCancelWithinRun, targetIsWorkerThread);
if (targetIsWorkerThread) {