Bug 1108019 - Avoid console exception spew from nsPlacesAutoComplete.js. r=mak
authorJeffrey Tran <tranj23@gmail.com>
Wed, 10 Feb 2016 15:30:23 +0100
changeset 283751 e775f1fed03a8b690671138127215f8f54f5e462
parent 283750 bc6d63520f410db38eab8217c50947b78e4faa34
child 283752 4aaaefe703aeb1c4a86ebfbe003dba780982b3e4
push id29990
push usercbook@mozilla.com
push dateThu, 11 Feb 2016 10:47:29 +0000
treeherdermozilla-central@b21946a2e993 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs1108019
milestone47.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 1108019 - Avoid console exception spew from nsPlacesAutoComplete.js. r=mak
toolkit/components/places/nsPlacesAutoComplete.js
--- a/toolkit/components/places/nsPlacesAutoComplete.js
+++ b/toolkit/components/places/nsPlacesAutoComplete.js
@@ -167,17 +167,17 @@ function stripPrefix(aURIString)
 
   if (uri.indexOf("www.") == 0) {
     uri = uri.slice(4);
   }
   return uri;
 }
 
 /**
- * safePrefGetter get the pref with typo safety.
+ * safePrefGetter get the pref with type safety.
  * This will return the default value provided if no pref is set.
  *
  * @param aPrefBranch
  *        The nsIPrefBranch containing the required preference
  * @param aName
  *        A preference name
  * @param aDefault
  *        The preference's default value
@@ -189,17 +189,21 @@ function safePrefGetter(aPrefBranch, aNa
     boolean: "Bool",
     number: "Int",
     string: "Char"
   };
   let type = types[typeof(aDefault)];
   if (!type) {
     throw "Unknown type!";
   }
+
   // If the pref isn't set, we want to use the default.
+  if (aPrefBranch.getPrefType(aName) == Ci.nsIPrefBranch.PREF_INVALID) {
+    return aDefault;
+  }
   try {
     return aPrefBranch["get" + type + "Pref"](aName);
   }
   catch (e) {
     return aDefault;
   }
 }