Bug 1403348: Include details about AsyncShutdown failure in crash reason. r?baku draft
authorKris Maglione <maglione.k@gmail.com>
Wed, 27 Sep 2017 15:11:43 -0700
changeset 671379 3ab2bb7f54f79a24a8ced4edc931fb8db100314e
parent 671003 e0356189e6d130f3aae4da7f737b4503482602db
child 733524 5c25b0fdf5525d33158d647fb5bdbc0e206d21bd
push id81944
push usermaglione.k@gmail.com
push dateWed, 27 Sep 2017 22:11:57 +0000
reviewersbaku
bugs1403348
milestone58.0a1
Bug 1403348: Include details about AsyncShutdown failure in crash reason. r?baku MozReview-Commit-ID: L6U2MVshZl8
dom/workers/ServiceWorkerRegistrar.cpp
--- a/dom/workers/ServiceWorkerRegistrar.cpp
+++ b/dom/workers/ServiceWorkerRegistrar.cpp
@@ -12,16 +12,18 @@
 #include "nsIInputStream.h"
 #include "nsILineInputStream.h"
 #include "nsIObserverService.h"
 #include "nsIOutputStream.h"
 #include "nsISafeOutputStream.h"
 
 #include "MainThreadUtils.h"
 #include "mozilla/ClearOnShutdown.h"
+#include "mozilla/CycleCollectedJSContext.h"
+#include "mozilla/ErrorNames.h"
 #include "mozilla/ipc/BackgroundChild.h"
 #include "mozilla/ipc/BackgroundParent.h"
 #include "mozilla/ipc/PBackgroundChild.h"
 #include "mozilla/ModuleUtils.h"
 #include "mozilla/Services.h"
 #include "mozilla/StaticPtr.h"
 #include "nsAppDirectoryServiceDefs.h"
 #include "nsContentUtils.h"
@@ -1119,17 +1121,38 @@ ServiceWorkerRegistrar::GetState(nsIProp
 
 nsCOMPtr<nsIAsyncShutdownClient>
 ServiceWorkerRegistrar::GetShutdownPhase() const
 {
   nsCOMPtr<nsIAsyncShutdownService> svc = services::GetAsyncShutdown();
   MOZ_RELEASE_ASSERT(svc);
 
   nsCOMPtr<nsIAsyncShutdownClient> client;
-  Unused << svc->GetProfileBeforeChange(getter_AddRefs(client));
+  nsresult rv = svc->GetProfileBeforeChange(getter_AddRefs(client));
+  // If this fails, something is very wrong on the JS side (or we're out of
+  // memory), and there's no point in continuing startup. Include as much
+  // information as possible in the crash report.
+  if (NS_FAILED(rv)) {
+    if (rv == NS_ERROR_XPC_JAVASCRIPT_ERROR_WITH_DETAILS) {
+      CycleCollectedJSContext* context = CycleCollectedJSContext::Get();
+      if (nsCOMPtr<nsIException> exn = context->GetPendingException()) {
+        nsAutoCString msg;
+        if (NS_SUCCEEDED(exn->GetMessageMoz(msg))) {
+          MOZ_CRASH_UNSAFE_PRINTF("Failed to get profileBeforeChange shutdown blocker: %s",
+                                  msg.get());
+
+        }
+      }
+    }
+
+    nsAutoCString errorName;
+    GetErrorName(rv, errorName);
+    MOZ_CRASH_UNSAFE_PRINTF("Failed to get profileBeforeChange shutdown blocker: %s",
+                            errorName.get());
+  }
   MOZ_RELEASE_ASSERT(client);
   return Move(client);
 }
 
 void
 ServiceWorkerRegistrar::Shutdown()
 {
   AssertIsOnBackgroundThread();