Bug 1876138: Check if in main thread before attempting to create PerformanceMark. r=dom-worker-reviewers,asuth

Differential Revision: https://phabricator.services.mozilla.com/D199384
This commit is contained in:
Jason Kratzer 2024-01-29 17:25:25 +00:00
parent afc13a8606
commit ec1792d1a2

View file

@ -80,20 +80,25 @@ already_AddRefed<Performance> Performance::CreateForWorker(
already_AddRefed<Performance> Performance::Get(JSContext* aCx, already_AddRefed<Performance> Performance::Get(JSContext* aCx,
nsIGlobalObject* aGlobal) { nsIGlobalObject* aGlobal) {
RefPtr<Performance> performance; RefPtr<Performance> performance;
nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(aGlobal); if (NS_IsMainThread()) {
if (window) { nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(aGlobal);
performance = window->GetPerformance(); if (!window) {
} else {
const WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(aCx);
if (!workerPrivate) {
return nullptr; return nullptr;
} }
WorkerGlobalScope* scope = workerPrivate->GlobalScope(); performance = window->GetPerformance();
MOZ_ASSERT(scope); return performance.forget();
performance = scope->GetPerformance();
} }
const WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(aCx);
if (!workerPrivate) {
return nullptr;
}
WorkerGlobalScope* scope = workerPrivate->GlobalScope();
MOZ_ASSERT(scope);
performance = scope->GetPerformance();
return performance.forget(); return performance.forget();
} }