Bug 1403348: Include details about AsyncShutdown failure in crash reason. r?baku
MozReview-Commit-ID: L6U2MVshZl8
--- 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();