Bug 1224941 Don't crash during ServiceWorker life cycle event dispatch if window is gone. r=baku a=ritu
authorBen Kelly <ben@wanderview.com>
Mon, 16 Nov 2015 08:41:57 -0800
changeset 305535 2c5f51e5d0afeff3b547ecaa3d45965a4f5a8cda
parent 305534 e792fb3161930b312a413fe92ae53da747f3cc89
child 305536 8e13fe7ab3da6658e6dcb184950b412367fbaeba
push id1001
push userraliiev@mozilla.com
push dateMon, 18 Jan 2016 19:06:03 +0000
treeherdermozilla-release@8b89261f3ac4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku, ritu
bugs1224941
milestone44.0a2
Bug 1224941 Don't crash during ServiceWorker life cycle event dispatch if window is gone. r=baku a=ritu
dom/workers/ServiceWorkerManager.cpp
--- a/dom/workers/ServiceWorkerManager.cpp
+++ b/dom/workers/ServiceWorkerManager.cpp
@@ -3362,18 +3362,27 @@ EnumControlledDocuments(nsISupports* aKe
 
 static void
 FireControllerChangeOnDocument(nsIDocument* aDocument)
 {
   AssertIsOnMainThread();
   MOZ_ASSERT(aDocument);
 
   nsCOMPtr<nsPIDOMWindow> w = aDocument->GetWindow();
-  MOZ_ASSERT(w);
+  if (!w) {
+    NS_WARNING("Failed to dispatch controllerchange event");
+    return;
+  }
+
   w = w->GetCurrentInnerWindow();
+  if (!w) {
+    NS_WARNING("Failed to dispatch controllerchange event");
+    return;
+  }
+
   auto* window = static_cast<nsGlobalWindow*>(w.get());
 
   ErrorResult result;
   dom::Navigator* navigator = window->GetNavigator(result);
   if (NS_WARN_IF(result.Failed())) {
     result.SuppressException();
     return;
   }