--- a/toolkit/components/search/nsSearchService.js
+++ b/toolkit/components/search/nsSearchService.js
@@ -227,17 +227,17 @@ function DO_LOG(aText) {
}
/**
* In debug builds, use a live, pref-based (browser.search.log) LOG function
* to allow enabling/disabling without a restart. Otherwise, don't log at all by
* default. This can be overridden at startup by the pref, see SearchService's
* _init method.
*/
-var LOG = function(){};
+var LOG = function() {};
if (AppConstants.DEBUG) {
LOG = function (aText) {
if (getBoolPref(BROWSER_SEARCH_PREF + "log", false)) {
DO_LOG(aText);
}
};
}
@@ -395,17 +395,17 @@ function isPartnerBuild() {
return false;
}
// Method to determine if we should be using geo-specific defaults
function geoSpecificDefaultsEnabled() {
let geoSpecificDefaults = false;
try {
geoSpecificDefaults = Services.prefs.getBoolPref("browser.search.geoSpecificDefaults");
- } catch(e) {}
+ } catch (e) {}
return geoSpecificDefaults;
}
// Some notes on countryCode and region prefs:
// * A "countryCode" pref is set via a geoip lookup. It always reflects the
// result of that geoip request.
// * A "region" pref, once set, is the region actually used for search. In
@@ -460,17 +460,17 @@ function getIsUS() {
// considered to be in the US from the POV of the search service.
if (getLocale() != "en-US") {
return false;
}
// If we've got a region pref, trust it.
try {
return Services.prefs.getCharPref("browser.search.region") == "US";
- } catch(e) {}
+ } catch (e) {}
// So we are en-US but have no region pref - fallback to hacky timezone check.
let isNA = isUSTimezone();
LOG("getIsUS() fell back to a timezone check with the result=" + isNA);
return isNA;
}
// Helper method to modify preference keys with geo-specific modifiers, if needed.
@@ -505,17 +505,17 @@ function isUSTimezone() {
// If this succeeds and we are using an en-US locale, we set the pref used by
// the hacky method above, so isUS() can avoid the hacky timezone method.
// If it fails we don't touch that pref so isUS() does its normal thing.
var ensureKnownCountryCode = Task.async(function* (ss) {
// If we have a country-code already stored in our prefs we trust it.
let countryCode;
try {
countryCode = Services.prefs.getCharPref("browser.search.countryCode");
- } catch(e) {}
+ } catch (e) {}
if (!countryCode) {
// We don't have it cached, so fetch it. fetchCountryCode() will call
// storeCountryCode if it gets a result (even if that happens after the
// promise resolves) and fetchRegionDefault.
yield fetchCountryCode(ss);
} else {
// if nothing to do, return early.
@@ -731,17 +731,17 @@ var fetchRegionDefault = (ss) => new Pro
return;
}
// Append the optional cohort value.
const cohortPref = "browser.search.cohort";
let cohort;
try {
cohort = Services.prefs.getCharPref(cohortPref);
- } catch(e) {}
+ } catch (e) {}
if (cohort)
endpoint += "/" + cohort;
LOG("fetchRegionDefault starting with endpoint " + endpoint);
let startTime = Date.now();
let request = new XMLHttpRequest();
request.timeout = 100000; // 100 seconds as the last-chance fallback
@@ -2259,17 +2259,17 @@ Engine.prototype = {
let id;
let enginePath = file.path;
for (let key in knownDirs) {
let path;
try {
path = getDir(knownDirs[key]).path;
- } catch(e) {
+ } catch (e) {
// Getting XRE_APP_DISTRIBUTION_DIR throws during unit tests.
continue;
}
if (enginePath.startsWith(path)) {
id = "[" + key + "]" + enginePath.slice(path.length).replace(/\\/g, "/");
break;
}
}
@@ -3209,17 +3209,17 @@ SearchService.prototype = {
let array = new Uint8Array(count);
bis.readArrayBuffer(count, array.buffer);
let bytes = Lz4.decompressFileContent(array);
let json = JSON.parse(new TextDecoder().decode(bytes));
if (!json.engines || !json.engines.length)
throw "no engine in the file";
return json;
- } catch(ex) {
+ } catch (ex) {
LOG("_readCacheFile: Error reading cache file: " + ex);
} finally {
stream.close();
}
try {
cacheFile.leafName = "search-metadata.json";
stream = Cc["@mozilla.org/network/file-input-stream;1"].
@@ -3239,17 +3239,17 @@ SearchService.prototype = {
if (name in data)
json.metaData[field] = data[name];
}
}
delete metadata["[global]"];
json._oldMetadata = metadata;
return json;
- } catch(ex) {
+ } catch (ex) {
LOG("_readCacheFile: failed to read old metadata: " + ex);
return {};
} finally {
stream.close();
}
},
/**
@@ -3646,17 +3646,17 @@ SearchService.prototype = {
}
return uris;
}),
_parseListJSON: function SRCH_SVC_parseListJSON(list, uris) {
let searchSettings;
try {
searchSettings = JSON.parse(list);
- } catch(e) {
+ } catch (e) {
LOG("failing to parse list.json: " + e);
return;
}
let jarNames = new Set();
for (let region in searchSettings) {
// Artifact builds use the full list.json which parses
// slightly differently
@@ -3952,17 +3952,17 @@ SearchService.prototype = {
aCount.value = engines.length;
return engines;
},
getDefaultEngines: function SRCH_SVC_getDefault(aCount) {
this._ensureInitialized();
function isDefault(engine) {
return engine._isDefault;
- };
+ }
var engines = this._sortedEngines.filter(isDefault);
var engineOrder = {};
var engineName;
var i = 1;
// Build a list of engines which we have ordering information for.
// We're rebuilding the list here because _sortedEngines contain the
// current order, but we want the original order.
@@ -4288,17 +4288,17 @@ SearchService.prototype = {
},
getDefaultEngineInfo() {
let result = {};
let engine;
try {
engine = this.defaultEngine;
- } catch(e) {
+ } catch (e) {
// The defaultEngine getter will throw if there's no engine at all,
// which shouldn't happen unless an add-on or a test deleted all of them.
// Our preferences UI doesn't let users do that.
Cu.reportError("getDefaultEngineInfo: No default engine");
}
if (!engine) {
result.name = "NONE";
@@ -4331,17 +4331,17 @@ SearchService.prototype = {
Services.prefs.getChildList(BROWSER_SEARCH_PREF + "order.extra.");
for (let prefName of extras) {
try {
if (result.name == Services.prefs.getCharPref(prefName)) {
sendSubmissionURL = true;
break;
}
- } catch(e) {}
+ } catch (e) {}
}
let prefNameBase = getGeoSpecificPrefName(BROWSER_SEARCH_PREF + "order");
let i = 0;
while (!sendSubmissionURL) {
let prefName = prefNameBase + "." + (++i);
let engineName = getLocalizedPref(prefName);
if (!engineName)
@@ -4464,48 +4464,54 @@ SearchService.prototype = {
* for this request-method, template URL, and query params.
*/
hasEngineWithURL: function(method, template, formData) {
this._ensureInitialized();
// Quick helper method to ensure formData filtered/sorted for compares.
let getSortedFormData = data => {
return data.filter(a => a.name && a.value).sort((a, b) => {
- return (a.name > b.name) ? 1 : (b.name > a.name) ? -1 :
- (a.value > b.value) ? 1 : (b.value > a.value) ? -1 : 0;
+ if (a.name > b.name) {
+ return 1;
+ } else if (b.name > a.name) {
+ return -1;
+ } else if (a.value > b.value) {
+ return 1;
+ }
+ return (b.value > a.value) ? -1 : 0;
});
};
// Sanitize method, ensure formData is pre-sorted.
let methodUpper = method.toUpperCase();
let sortedFormData = getSortedFormData(formData);
let sortedFormLength = sortedFormData.length;
return this._getSortedEngines(false).some(engine => {
return engine._urls.some(url => {
// Not an engineURL match if type, method, url, #params don't match.
if (url.type != URLTYPE_SEARCH_HTML ||
url.method != methodUpper ||
url.template != template ||
url.params.length != sortedFormLength) {
return false;
- };
+ }
// Ensure engineURL formData is pre-sorted. Then, we're
// not an engineURL match if any queryParam doesn't compare.
let sortedParams = getSortedFormData(url.params);
for (let i = 0; i < sortedFormLength; i++) {
let formData = sortedFormData[i];
let param = sortedParams[i];
if (param.name != formData.name ||
param.value != formData.value ||
param.purpose != formData.purpose) {
return false;
- };
- };
+ }
+ }
// Else we're a match.
return true;
});
});
},
parseSubmissionURL: function SRCH_SVC_parseSubmissionURL(aURL) {
this._ensureInitialized();