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; }