mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-30 16:22:00 +00:00
Bug 1867982 - Check if WorkerRunnable::Run runs on top of WorkerThreadPrimaryRunnable::Run in a worker thread. a=RyanVM
Original Revision: https://phabricator.services.mozilla.com/D199247 Differential Revision: https://phabricator.services.mozilla.com/D199970
This commit is contained in:
parent
1a80728c87
commit
a807e3f1ea
@ -3770,7 +3770,9 @@ void 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
|
||||
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include "mozilla/AlreadyAddRefed.h"
|
||||
#include "mozilla/AppShutdown.h"
|
||||
#include "mozilla/Assertions.h"
|
||||
#include "mozilla/CycleCollectedJSContext.h"
|
||||
#include "mozilla/DebugOnly.h"
|
||||
#include "mozilla/ErrorResult.h"
|
||||
#include "mozilla/Maybe.h"
|
||||
@ -224,6 +225,33 @@ 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()) {
|
||||
#if (defined(MOZ_COLLECTING_RUNNABLE_TELEMETRY) && defined(DEBUG))
|
||||
// Temporarily set the LogLevel high enough to be certain the messages
|
||||
// are visible.
|
||||
LogModule* module = sWorkerRunnableLog;
|
||||
LogLevel prevLevel = module->Level();
|
||||
if (prevLevel < LogLevel::Error) {
|
||||
module->SetLevel(LogLevel::Error);
|
||||
}
|
||||
MOZ_LOG(sWorkerRunnableLog, LogLevel::Error,
|
||||
("Runnable '%s' was executed after WorkerThreadPrimaryRunnable "
|
||||
"ended.",
|
||||
"WorkerRunnable"));
|
||||
module->SetLevel(prevLevel);
|
||||
#endif
|
||||
MOZ_DIAGNOSTIC_ASSERT(false,
|
||||
"A WorkerRunnable was executed after "
|
||||
"WorkerThreadPrimaryRunnable ended.");
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
MOZ_ASSERT_IF(mCallingCancelWithinRun, targetIsWorkerThread);
|
||||
if (targetIsWorkerThread) {
|
||||
|
Loading…
Reference in New Issue
Block a user