diff --git a/dom/performance/Performance.cpp b/dom/performance/Performance.cpp index c6a2f5740d59..ecbc3b4c6875 100644 --- a/dom/performance/Performance.cpp +++ b/dom/performance/Performance.cpp @@ -80,20 +80,25 @@ already_AddRefed Performance::CreateForWorker( already_AddRefed Performance::Get(JSContext* aCx, nsIGlobalObject* aGlobal) { RefPtr performance; - nsCOMPtr window = do_QueryInterface(aGlobal); - if (window) { - performance = window->GetPerformance(); - } else { - const WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(aCx); - if (!workerPrivate) { + if (NS_IsMainThread()) { + nsCOMPtr window = do_QueryInterface(aGlobal); + if (!window) { return nullptr; } - WorkerGlobalScope* scope = workerPrivate->GlobalScope(); - MOZ_ASSERT(scope); - performance = scope->GetPerformance(); + performance = window->GetPerformance(); + return performance.forget(); } + const WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(aCx); + if (!workerPrivate) { + return nullptr; + } + + WorkerGlobalScope* scope = workerPrivate->GlobalScope(); + MOZ_ASSERT(scope); + performance = scope->GetPerformance(); + return performance.forget(); }