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,
nsIGlobalObject* aGlobal) {
RefPtr<Performance> performance;
nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(aGlobal);
if (window) {
performance = window->GetPerformance();
} else {
const WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(aCx);
if (!workerPrivate) {
if (NS_IsMainThread()) {
nsCOMPtr<nsPIDOMWindowInner> 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();
}