diff --git a/xpcom/build/XPCOMInit.cpp b/xpcom/build/XPCOMInit.cpp index e36a71cbe9ac..56ce24fef5fa 100644 --- a/xpcom/build/XPCOMInit.cpp +++ b/xpcom/build/XPCOMInit.cpp @@ -649,6 +649,17 @@ nsresult ShutdownXPCOM(nsIServiceManager* aServMgr) { NS_ProcessPendingEvents(thread); + if (observerService) { + mozilla::KillClearOnShutdown(ShutdownPhase::ShutdownLoaders); + observerService->Shutdown(); + } + + // Free ClearOnShutdown()'ed smart pointers. This needs to happen *after* + // we've finished notifying observers of XPCOM shutdown, because shutdown + // observers themselves might call ClearOnShutdown(). + // Some destructors may fire extra runnables that will be processed below. + mozilla::KillClearOnShutdown(ShutdownPhase::ShutdownFinal); + // Shutdown all remaining threads. This method does not return until // all threads created using the thread manager (with the exception of // the main thread) have exited. @@ -662,18 +673,8 @@ nsresult ShutdownXPCOM(nsIServiceManager* aServMgr) { BackgroundHangMonitor().NotifyActivity(); mozilla::dom::JSExecutionManager::Shutdown(); - - if (observerService) { - mozilla::KillClearOnShutdown(ShutdownPhase::ShutdownLoaders); - observerService->Shutdown(); - } } - // Free ClearOnShutdown()'ed smart pointers. This needs to happen *after* - // we've finished notifying observers of XPCOM shutdown, because shutdown - // observers themselves might call ClearOnShutdown(). - mozilla::KillClearOnShutdown(ShutdownPhase::ShutdownFinal); - AbstractThread::ShutdownMainThread(); mozilla::AppShutdown::MaybeFastShutdown(