From 5202c08cfb4a6c2b6eae21cd981b94448ac65c42 Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Sun, 7 Jan 2024 07:34:05 -0600 Subject: [PATCH] Issue #2402 - Don't call WorkerPrivate::WorkerName() to get service worker scope. https://bugzilla.mozilla.org/show_bug.cgi?id=1350433 --- dom/console/Console.cpp | 2 +- dom/fetch/Fetch.cpp | 2 +- dom/workers/ServiceWorkerEvents.cpp | 2 +- dom/workers/WorkerPrivate.cpp | 6 +++--- dom/workers/WorkerPrivate.h | 9 ++++++++- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/dom/console/Console.cpp b/dom/console/Console.cpp index 715e9fe84d..b5e3565dba 100755 --- a/dom/console/Console.cpp +++ b/dom/console/Console.cpp @@ -598,7 +598,7 @@ private: innerID = NS_LITERAL_STRING("ServiceWorker"); // Use scope as ID so the webconsole can decide if the message should // show up per tab - id.AssignWithConversion(mWorkerPrivate->WorkerName()); + id.AssignWithConversion(mWorkerPrivate->ServiceWorkerScope()); } else { innerID = NS_LITERAL_STRING("Worker"); } diff --git a/dom/fetch/Fetch.cpp b/dom/fetch/Fetch.cpp index a9d8514765..0b31e0c84b 100644 --- a/dom/fetch/Fetch.cpp +++ b/dom/fetch/Fetch.cpp @@ -710,7 +710,7 @@ WorkerFetchResolver::FlushConsoleReport() return; } - swm->FlushReportsToAllClients(worker->WorkerName(), mReporter); + swm->FlushReportsToAllClients(worker->ServiceWorkerScope(), mReporter); return; } diff --git a/dom/workers/ServiceWorkerEvents.cpp b/dom/workers/ServiceWorkerEvents.cpp index 569422da25..f017f2936a 100644 --- a/dom/workers/ServiceWorkerEvents.cpp +++ b/dom/workers/ServiceWorkerEvents.cpp @@ -805,7 +805,7 @@ public: WaitUntilHandler(WorkerPrivate* aWorkerPrivate, JSContext* aCx) : mWorkerPrivate(aWorkerPrivate) - , mScope(mWorkerPrivate->WorkerName()) + , mScope(mWorkerPrivate->ServiceWorkerScope()) , mLine(0) , mColumn(0) { diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp index 7e96fc6ad3..7a0c272f56 100644 --- a/dom/workers/WorkerPrivate.cpp +++ b/dom/workers/WorkerPrivate.cpp @@ -550,7 +550,7 @@ private: RefPtr swm = ServiceWorkerManager::GetInstance(); if (swm) { swm->HandleError(aCx, aWorkerPrivate->GetPrincipal(), - aWorkerPrivate->WorkerName(), + aWorkerPrivate->ServiceWorkerScope(), aWorkerPrivate->ScriptURL(), EmptyString(), EmptyString(), EmptyString(), 0, 0, JSREPORT_ERROR, JSEXN_ERR); @@ -1255,7 +1255,7 @@ private: RefPtr swm = ServiceWorkerManager::GetInstance(); if (swm) { swm->HandleError(aCx, aWorkerPrivate->GetPrincipal(), - aWorkerPrivate->WorkerName(), + aWorkerPrivate->ServiceWorkerScope(), aWorkerPrivate->ScriptURL(), mReport.mMessage, mReport.mFilename, mReport.mLine, mReport.mLineNumber, @@ -6727,7 +6727,7 @@ WorkerPrivate::GetOrCreateGlobalScope(JSContext* aCx) if (IsSharedWorker()) { globalScope = new SharedWorkerGlobalScope(this, WorkerName()); } else if (IsServiceWorker()) { - globalScope = new ServiceWorkerGlobalScope(this, WorkerName()); + globalScope = new ServiceWorkerGlobalScope(this, ServiceWorkerScope()); } else { globalScope = new DedicatedWorkerGlobalScope(this); } diff --git a/dom/workers/WorkerPrivate.h b/dom/workers/WorkerPrivate.h index 1c9cb10ded..dda81beb57 100644 --- a/dom/workers/WorkerPrivate.h +++ b/dom/workers/WorkerPrivate.h @@ -535,6 +535,13 @@ public: return mLoadInfo.mServiceWorkerID; } + const nsCString& + ServiceWorkerScope() const + { + MOZ_DIAGNOSTIC_ASSERT(IsServiceWorker()); + return mWorkerName; + } + nsIURI* GetBaseURI() const { @@ -831,7 +838,7 @@ public: const nsCString& WorkerName() const { - MOZ_ASSERT(IsServiceWorker() || IsSharedWorker()); + MOZ_ASSERT(IsSharedWorker()); return mWorkerName; }