diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp index 85bcc2ffef..fb2e4d7b56 100644 --- a/dom/workers/WorkerPrivate.cpp +++ b/dom/workers/WorkerPrivate.cpp @@ -5161,7 +5161,9 @@ WorkerPrivate::ScheduleDeletion(WorkerRanOrNot aRanOrNot) if (WorkerRan == aRanOrNot) { nsIThread* currentThread = NS_GetCurrentThread(); MOZ_ASSERT(currentThread); - MOZ_ASSERT(!NS_HasPendingEvents(currentThread)); + // On the worker thread WorkerRunnable will refuse to run if not nested + // on top of a WorkerThreadPrimaryRunnable. + Unused << NS_WARN_IF(NS_HasPendingEvents(currentThread)); } #endif diff --git a/dom/workers/WorkerRunnable.cpp b/dom/workers/WorkerRunnable.cpp index be0171b768..eb56650b51 100644 --- a/dom/workers/WorkerRunnable.cpp +++ b/dom/workers/WorkerRunnable.cpp @@ -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) {