Bug 1435927 - Add some more assertions to Preferences.cpp. r=glandium
authorNicholas Nethercote <nnethercote@mozilla.com>
Fri, 02 Feb 2018 16:50:56 +1100
changeset 402674 841e2c5855e2358893481d4b9b4fef13253de150
parent 402673 dd4ffa63228df3ab4b1e6de7eceb671c32c39978
child 402675 6ac8adb83f39278fe8e3dad9134fde133e142c62
push id33397
push userdluca@mozilla.com
push dateWed, 07 Feb 2018 09:58:42 +0000
treeherdermozilla-central@4fe6f6560083 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglandium
bugs1435927
milestone60.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1435927 - Add some more assertions to Preferences.cpp. r=glandium MozReview-Commit-ID: 12sTvb4JJuS
modules/libpref/Preferences.cpp
--- a/modules/libpref/Preferences.cpp
+++ b/modules/libpref/Preferences.cpp
@@ -416,16 +416,18 @@ public:
       aResult = mUserValue.mStringVal;
     }
 
     return NS_OK;
   }
 
   void ToDomPref(dom::Pref* aDomPref)
   {
+    MOZ_ASSERT(XRE_IsParentProcess());
+
     aDomPref->name() = mName;
 
     aDomPref->isLocked() = mIsLocked;
 
     if (mHasDefaultValue) {
       aDomPref->defaultValue() = dom::PrefValue();
       mDefaultValue.ToDomPrefValue(Type(),
                                    &aDomPref->defaultValue().get_PrefValue());
@@ -444,16 +446,17 @@ public:
                  dom::MaybePrefValue::Tnull_t ||
                aDomPref->userValue().type() == dom::MaybePrefValue::Tnull_t ||
                (aDomPref->defaultValue().get_PrefValue().type() ==
                 aDomPref->userValue().get_PrefValue().type()));
   }
 
   void FromDomPref(const dom::Pref& aDomPref, bool* aValueChanged)
   {
+    MOZ_ASSERT(!XRE_IsParentProcess());
     MOZ_ASSERT(strcmp(mName, aDomPref.name().get()) == 0);
 
     mIsLocked = aDomPref.isLocked();
 
     const dom::MaybePrefValue& defaultValue = aDomPref.defaultValue();
     bool defaultValueChanged = false;
     if (defaultValue.type() == dom::MaybePrefValue::TPrefValue) {
       PrefValue value;
@@ -487,16 +490,18 @@ public:
 
     if (userValueChanged || (defaultValueChanged && !mHasUserValue)) {
       *aValueChanged = true;
     }
   }
 
   bool HasAdvisablySizedValues()
   {
+    MOZ_ASSERT(XRE_IsParentProcess());
+
     if (!IsTypeString()) {
       return true;
     }
 
     const char* stringVal;
     if (mHasDefaultValue) {
       stringVal = mDefaultValue.mStringVal;
       if (strlen(stringVal) > MAX_ADVISABLE_PREF_LENGTH) {
@@ -704,16 +709,18 @@ pref_HashTableLookup(const char* aPrefNa
 static void
 NotifyCallbacks(const char* aPrefName);
 
 #define PREF_HASHTABLE_INITIAL_LENGTH 1024
 
 static PrefSaveData
 pref_savePrefs()
 {
+  MOZ_ASSERT(NS_IsMainThread());
+
   PrefSaveData savedPrefs(gHashTable->EntryCount());
 
   for (auto iter = gHashTable->Iter(); !iter.Done(); iter.Next()) {
     auto pref = static_cast<Pref*>(iter.Get());
 
     nsAutoCString prefValueStr;
     if (!pref->UserValueToStringForSaving(prefValueStr)) {
       continue;
@@ -1976,16 +1983,18 @@ nsPrefBranch::GetChildList(const char* a
   int32_t numPrefs;
   int32_t dwIndex;
   AutoTArray<nsCString, 32> prefArray;
 
   NS_ENSURE_ARG(aStartingAt);
   NS_ENSURE_ARG_POINTER(aCount);
   NS_ENSURE_ARG_POINTER(aChildArray);
 
+  MOZ_ASSERT(NS_IsMainThread());
+
   *aChildArray = nullptr;
   *aCount = 0;
 
   // This will contain a list of all the pref name strings. Allocated on the
   // stack for speed.
 
   const PrefName& parent = GetPrefName(aStartingAt);
   size_t parentLen = parent.Length();
@@ -3218,16 +3227,17 @@ Preferences::GetPreference(dom::Pref* aD
     pref->ToDomPref(aDomPref);
   }
 }
 
 void
 Preferences::GetPreferences(InfallibleTArray<dom::Pref>* aDomPrefs)
 {
   MOZ_ASSERT(XRE_IsParentProcess());
+  MOZ_ASSERT(NS_IsMainThread());
 
   aDomPrefs->SetCapacity(gHashTable->EntryCount());
   for (auto iter = gHashTable->Iter(); !iter.Done(); iter.Next()) {
     auto pref = static_cast<Pref*>(iter.Get());
 
     if (pref->HasAdvisablySizedValues()) {
       dom::Pref* setting = aDomPrefs->AppendElement();
       pref->ToDomPref(setting);