Bug 1357517 - Remove Preferences.jsm usage from XPCOMUtils.jsm. r=kmag
authorMarco Castelluccio <mcastelluccio@mozilla.com>
Fri, 28 Jul 2017 23:04:47 +0200
changeset 420589 65105a4351d19736d45d6dbef38acd2e9313d7db
parent 420588 68c4c9c19f3c2fc32f2542a95cccd75bbe6f39f2
child 420590 e05ac296ea1472fd8f2ec7f2347e25348275e76c
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskmag
bugs1357517
milestone56.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 1357517 - Remove Preferences.jsm usage from XPCOMUtils.jsm. r=kmag
js/xpconnect/loader/XPCOMUtils.jsm
--- a/js/xpconnect/loader/XPCOMUtils.jsm
+++ b/js/xpconnect/loader/XPCOMUtils.jsm
@@ -379,17 +379,42 @@ this.XPCOMUtils = {
         configurable: true,
         enumerable: true,
         get,
       });
     };
 
     function lazyGetter() {
       if (observer.value === undefined) {
-        observer.value = aTransform(Preferences.get(aPreference, aDefaultValue));
+        let prefValue;
+        switch (Services.prefs.getPrefType(aPreference)) {
+          case Ci.nsIPrefBranch.PREF_STRING:
+            prefValue = Services.prefs.getStringPref(aPreference);
+            break;
+
+          case Ci.nsIPrefBranch.PREF_INT:
+            prefValue = Services.prefs.getIntPref(aPreference);
+            break;
+
+          case Ci.nsIPrefBranch.PREF_BOOL:
+            prefValue = Services.prefs.getBoolPref(aPreference);
+            break;
+
+          case Ci.nsIPrefBranch.PREF_INVALID:
+            prefValue = aDefaultValue;
+            break;
+
+          default:
+            // This should never happen.
+            throw new Error(`Error getting pref ${aPreference}; its value's type is ` +
+                            `${Services.prefs.getPrefType(aPreference)}, which I don't ` +
+                            `know how to handle.`);
+        }
+
+        observer.value = aTransform(prefValue);
       }
       return observer.value;
     }
 
     defineGetter(() => {
       Services.prefs.addObserver(aPreference, observer, true);
 
       defineGetter(lazyGetter);
@@ -495,18 +520,16 @@ this.XPCOMUtils = {
     Object.defineProperty(aObj, aName, {
       value: aValue,
       enumerable: true,
       writable: false
     });
   },
 };
 
-XPCOMUtils.defineLazyModuleGetter(this, "Preferences",
-                                  "resource://gre/modules/Preferences.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "Services",
                                   "resource://gre/modules/Services.jsm");
 
 XPCOMUtils.defineLazyServiceGetter(XPCOMUtils, "categoryManager",
                                    "@mozilla.org/categorymanager;1",
                                    "nsICategoryManager");
 
 /**