From 470af6ba50152c415f10081880771f75d9e90b7d Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Thu, 7 Sep 2023 15:31:26 -0500 Subject: [PATCH] Issue #2282 - Performance observer safety checks. Both fixes from later revisions, without the Dispatch API changes. --- dom/performance/Performance.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/dom/performance/Performance.cpp b/dom/performance/Performance.cpp index c903f3ec78..6803219985 100755 --- a/dom/performance/Performance.cpp +++ b/dom/performance/Performance.cpp @@ -675,7 +675,8 @@ public: NS_IMETHOD Run() override { MOZ_ASSERT(mPerformance); - mPerformance->NotifyObservers(); + RefPtr performance(mPerformance); + performance->NotifyObservers(); return NS_OK; } @@ -699,7 +700,12 @@ Performance::RunNotificationObserversTask() { mPendingNotificationObserversTask = true; nsCOMPtr task = new NotifyObserversTask(this); - nsresult rv = NS_DispatchToCurrentThread(task); + nsresult rv; + if (NS_IsMainThread()) { + rv = NS_DispatchToCurrentThread(task); + } else { + rv = NS_DispatchToMainThread(task); + } if (NS_WARN_IF(NS_FAILED(rv))) { mPendingNotificationObserversTask = false; }