From 335a97840464a2dcb30612ce418641d65fcade98 Mon Sep 17 00:00:00 2001 From: Bobby Holley Date: Mon, 18 Aug 2014 10:57:28 -0700 Subject: [PATCH] Bug 1052089 - Sprinkle some assert against using nsContentUtils too early. r=billm And earlier version of these patches called nsContentUtils::GetSystemPrincipal() too early, which returned null, and caused xpc::CreateSandboxObject to create an nsNullPrincipal. Let's avoid having that happen again. --- content/base/src/nsContentUtils.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/content/base/src/nsContentUtils.cpp b/content/base/src/nsContentUtils.cpp index 972aeb79492..1029a092582 100644 --- a/content/base/src/nsContentUtils.cpp +++ b/content/base/src/nsContentUtils.cpp @@ -2632,6 +2632,7 @@ nsContentUtils::GenerateStateKey(nsIContent* aContent, nsIPrincipal* nsContentUtils::SubjectPrincipal() { + MOZ_ASSERT(IsInitialized()); JSContext* cx = GetCurrentJSContext(); if (!cx) { return GetSystemPrincipal(); @@ -4697,6 +4698,7 @@ nsContentUtils::CheckSecurityBeforeLoad(nsIURI* aURIToLoad, bool nsContentUtils::IsSystemPrincipal(nsIPrincipal* aPrincipal) { + MOZ_ASSERT(IsInitialized()); return aPrincipal == sSystemPrincipal; } @@ -4710,6 +4712,7 @@ nsContentUtils::IsExpandedPrincipal(nsIPrincipal* aPrincipal) nsIPrincipal* nsContentUtils::GetSystemPrincipal() { + MOZ_ASSERT(IsInitialized()); return sSystemPrincipal; } @@ -5521,6 +5524,7 @@ JSContext * nsContentUtils::GetCurrentJSContext() { MOZ_ASSERT(NS_IsMainThread()); + MOZ_ASSERT(IsInitialized()); return sXPConnect->GetCurrentJSContext(); } @@ -5529,6 +5533,7 @@ JSContext * nsContentUtils::GetSafeJSContext() { MOZ_ASSERT(NS_IsMainThread()); + MOZ_ASSERT(IsInitialized()); return sXPConnect->GetSafeJSContext(); } @@ -5536,6 +5541,7 @@ nsContentUtils::GetSafeJSContext() JSContext * nsContentUtils::GetDefaultJSContextForThread() { + MOZ_ASSERT(IsInitialized()); if (MOZ_LIKELY(NS_IsMainThread())) { return GetSafeJSContext(); } else { @@ -5547,6 +5553,7 @@ nsContentUtils::GetDefaultJSContextForThread() JSContext * nsContentUtils::GetCurrentJSContextForThread() { + MOZ_ASSERT(IsInitialized()); if (MOZ_LIKELY(NS_IsMainThread())) { return GetCurrentJSContext(); } else {