|
@@ -0,0 +1,84 @@
|
|
|
|
+# HG changeset patch
|
|
|
|
+# User Jens Stutte <jstutte@mozilla.com>
|
|
|
|
+# Date 1706285430 0
|
|
|
|
+# Node ID 233014f304aef171ed885462d999df30dce7d497
|
|
|
|
+# Parent 51f3e018ad5ae830eff13b15f49293d9d8f2e909
|
|
|
|
+Bug 1867982 - Check if WorkerRunnable::Run runs on top of WorkerThreadPrimaryRunnable::Run in a worker thread. r=dom-worker-reviewers,smaug,asuth
|
|
|
|
+
|
|
|
|
+Differential Revision: https://phabricator.services.mozilla.com/D199247
|
|
|
|
+
|
|
|
|
+diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp
|
|
|
|
+--- a/dom/workers/WorkerPrivate.cpp
|
|
|
|
++++ b/dom/workers/WorkerPrivate.cpp
|
|
|
|
+@@ -5568,17 +5568,19 @@ WorkerPrivate::ScheduleDeletion(WorkerRa
|
|
|
|
+ MOZ_ASSERT(mSyncLoopStack.IsEmpty());
|
|
|
|
+ MOZ_ASSERT(!mPendingEventQueueClearing);
|
|
|
|
+
|
|
|
|
+ ClearMainEventQueue(aRanOrNot);
|
|
|
|
+ #ifdef DEBUG
|
|
|
|
+ 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
|
|
|
|
+
|
|
|
|
+ if (WorkerPrivate* parent = GetParent()) {
|
|
|
|
+ RefPtr<WorkerFinishedRunnable> runnable =
|
|
|
|
+ new WorkerFinishedRunnable(parent, this);
|
|
|
|
+ if (!runnable->Dispatch()) {
|
|
|
|
+ NS_WARNING("Failed to dispatch runnable!");
|
|
|
|
+diff --git a/dom/workers/WorkerRunnable.cpp b/dom/workers/WorkerRunnable.cpp
|
|
|
|
+--- a/dom/workers/WorkerRunnable.cpp
|
|
|
|
++++ b/dom/workers/WorkerRunnable.cpp
|
|
|
|
+@@ -7,16 +7,17 @@
|
|
|
|
+ #include "WorkerRunnable.h"
|
|
|
|
+
|
|
|
|
+ #include "nsGlobalWindow.h"
|
|
|
|
+ #include "nsIEventTarget.h"
|
|
|
|
+ #include "nsIGlobalObject.h"
|
|
|
|
+ #include "nsIRunnable.h"
|
|
|
|
+ #include "nsThreadUtils.h"
|
|
|
|
+
|
|
|
|
++#include "mozilla/CycleCollectedJSContext.h"
|
|
|
|
+ #include "mozilla/DebugOnly.h"
|
|
|
|
+ #include "mozilla/ErrorResult.h"
|
|
|
|
+ #include "mozilla/dom/ScriptSettings.h"
|
|
|
|
+ #include "mozilla/Telemetry.h"
|
|
|
|
+
|
|
|
|
+ #include "js/RootingAPI.h"
|
|
|
|
+ #include "js/Value.h"
|
|
|
|
+
|
|
|
|
+@@ -223,16 +224,29 @@ NS_INTERFACE_MAP_BEGIN(WorkerRunnable)
|
|
|
|
+ NS_INTERFACE_MAP_END
|
|
|
|
+
|
|
|
|
+ NS_IMETHODIMP
|
|
|
|
+ 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) {
|
|
|
|
+ mWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ MOZ_ASSERT(mBehavior == ParentThreadUnchangedBusyCount);
|
|
|
|
+ mWorkerPrivate->AssertIsOnParentThread();
|