Bug 1314373 - Fix parser issues raised by eslint for nsSearchService.js. r=mak

MozReview-Commit-ID: FRTCMgRtjTG

--HG--
extra : rebase_source : 6d8600f7f8943817b63d943076eafdafe1f6305e
This commit is contained in:
Mark Banner 2016-11-01 18:35:46 +00:00
parent 087dcd711e
commit 7e8abd3ad9
2 changed files with 300 additions and 298 deletions

View File

@ -241,7 +241,6 @@ toolkit/components/reader/JSDOMParser.js
# Uses preprocessing
toolkit/content/widgets/wizard.xml
toolkit/components/jsdownloads/src/DownloadIntegration.jsm
toolkit/components/search/nsSearchService.js
toolkit/components/url-classifier/**
toolkit/components/urlformatter/nsURLFormatter.js
toolkit/identity/FirefoxAccounts.jsm

View File

@ -1407,8 +1407,7 @@ Engine.prototype = {
* @returns {Promise} A promise, resolved successfully if initializing from
* data succeeds, rejected if it fails.
*/
_asyncInitFromFile: function SRCH_ENG__asyncInitFromFile(file) {
return Task.spawn(function() {
_asyncInitFromFile: Task.async(function* (file) {
if (!file || !(yield OS.File.exists(file.path)))
FAIL("File must exist before calling initFromFile!", Cr.NS_ERROR_UNEXPECTED);
@ -1417,8 +1416,7 @@ Engine.prototype = {
// Now that the data is loaded, initialize the engine object
this._initFromData();
}.bind(this));
},
}),
/**
* Retrieves the engine data from a URI. Initializes the engine, flushes to
@ -1457,14 +1455,12 @@ Engine.prototype = {
* @returns {Promise} A promise, resolved successfully if retrieveing data
* succeeds.
*/
_asyncInitFromURI: function SRCH_ENG__asyncInitFromURI(uri) {
return Task.spawn(function() {
_asyncInitFromURI: Task.async(function* (uri) {
LOG("_asyncInitFromURI: Loading engine from: \"" + uri.spec + "\".");
yield this._retrieveSearchXMLData(uri.spec);
// Now that the data is loaded, initialize the engine object
this._initFromData();
}.bind(this));
},
}),
/**
* Retrieves the engine data for a given URI asynchronously.
@ -2765,11 +2761,11 @@ SearchService.prototype = {
* @returns {Promise} A promise, resolved successfully if the initialization
* succeeds.
*/
_asyncInit: function SRCH_SVC__asyncInit() {
migrateRegionPrefs();
return Task.spawn(function() {
_asyncInit: Task.async(function* () {
LOG("_asyncInit start");
migrateRegionPrefs();
// See if we have a cache file so we don't have to parse a bunch of XML.
let cache = {};
// Not using checkForSyncCompletion here because we want to ensure we
@ -2782,12 +2778,18 @@ SearchService.prototype = {
try {
yield checkForSyncCompletion(ensureKnownCountryCode(this));
} catch (ex if ex.result != Cr.NS_ERROR_ALREADY_INITIALIZED) {
} catch (ex) {
if (ex.result == Cr.NS_ERROR_ALREADY_INITIALIZED) {
throw ex;
}
LOG("_asyncInit: failure determining country code: " + ex);
}
try {
yield checkForSyncCompletion(this._asyncLoadEngines(cache));
} catch (ex if ex.result != Cr.NS_ERROR_ALREADY_INITIALIZED) {
} catch (ex) {
if (ex.result == Cr.NS_ERROR_ALREADY_INITIALIZED) {
throw ex;
}
this._initRV = Cr.NS_ERROR_FAILURE;
LOG("_asyncInit: failure loading engines: " + ex);
}
@ -2800,8 +2802,7 @@ SearchService.prototype = {
this._recordEngineTelemetry();
LOG("_asyncInit: Completed _asyncInit");
}.bind(this));
},
}),
_metaData: { },
setGlobalAttr(name, val) {
@ -2995,8 +2996,7 @@ SearchService.prototype = {
* @returns {Promise} A promise, resolved successfully if loading data
* succeeds.
*/
_asyncLoadEngines: function SRCH_SVC__asyncLoadEngines(cache) {
return Task.spawn(function() {
_asyncLoadEngines: Task.async(function* (cache) {
LOG("_asyncLoadEngines: start");
Services.obs.notifyObservers(null, SEARCH_SERVICE_TOPIC, "find-jar-engines");
let chromeURIs =
@ -3021,8 +3021,11 @@ SearchService.prototype = {
// Add dir to distDirs if it contains any files.
yield checkForSyncCompletion(iterator.next());
distDirs.push(dir);
} catch (ex if ex.result != Cr.NS_ERROR_ALREADY_INITIALIZED) {
} catch (ex) {
// Catch for StopIteration exception.
if (ex.result == Cr.NS_ERROR_ALREADY_INITIALIZED) {
throw ex;
}
} finally {
iterator.close();
}
@ -3043,15 +3046,17 @@ SearchService.prototype = {
// Add dir to otherDirs if it contains any files.
yield checkForSyncCompletion(iterator.next());
otherDirs.push(dir);
} catch (ex if ex.result != Cr.NS_ERROR_ALREADY_INITIALIZED) {
} catch (ex) {
// Catch for StopIteration exception.
if (ex.result == Cr.NS_ERROR_ALREADY_INITIALIZED) {
throw ex;
}
} finally {
iterator.close();
}
}
function hasModifiedDir(aList) {
return Task.spawn(function() {
let hasModifiedDir = Task.async(function* (aList) {
let modifiedDir = false;
for (let dir of aList) {
@ -3066,9 +3071,8 @@ SearchService.prototype = {
break;
}
}
throw new Task.Result(modifiedDir);
return modifiedDir;
});
}
function notInCacheVisibleEngines(aEngineName) {
return cache.visibleDefaultEngines.indexOf(aEngineName) == -1;
@ -3123,8 +3127,7 @@ SearchService.prototype = {
this._loadEnginesFromCache(cache);
LOG("_asyncLoadEngines: done");
}.bind(this));
},
}),
_asyncReInit: function () {
LOG("_asyncReInit");
@ -3256,8 +3259,7 @@ SearchService.prototype = {
* @returns {Promise} A promise, resolved successfully if retrieveing data
* succeeds.
*/
_asyncReadCacheFile: function SRCH_SVC__asyncReadCacheFile() {
return Task.spawn(function() {
_asyncReadCacheFile: Task.async(function* () {
let json;
try {
let cacheFilePath = OS.Path.join(OS.Constants.Path.profileDir, CACHE_FILENAME);
@ -3292,9 +3294,8 @@ SearchService.prototype = {
json._oldMetadata = metadata;
} catch (ex) {}
}
throw new Task.Result(json);
}.bind(this));
},
return json;
}),
_batchTask: null,
get batchTask() {
@ -3470,14 +3471,14 @@ SearchService.prototype = {
* @returns {Promise} A promise, resolved successfully if retrieveing data
* succeeds.
*/
_asyncLoadEnginesFromDir: function SRCH_SVC__asyncLoadEnginesFromDir(aDir) {
_asyncLoadEnginesFromDir: Task.async(function* (aDir) {
LOG("_asyncLoadEnginesFromDir: Searching in " + aDir.path + " for search engines.");
// Check whether aDir is the user profile dir
let isInProfile = aDir.equals(getDir(NS_APP_USER_SEARCH_DIR));
let dirPath = aDir.path;
let iterator = new OS.File.DirectoryIterator(dirPath);
return Task.spawn(function() {
let osfiles = yield iterator.nextBatch();
iterator.close();
@ -3507,15 +3508,16 @@ SearchService.prototype = {
addedEngine._dirLastModifiedTime =
info.lastModificationDate.getTime();
}
} catch (ex if ex.result != Cr.NS_ERROR_ALREADY_INITIALIZED) {
LOG("_asyncLoadEnginesFromDir: Failed to load " + osfile.path + "!\n" + ex);
continue;
}
engines.push(addedEngine);
} catch (ex) {
if (ex.result == Cr.NS_ERROR_ALREADY_INITIALIZED) {
throw ex;
}
throw new Task.Result(engines);
}.bind(this));
},
LOG("_asyncLoadEnginesFromDir: Failed to load " + osfile.path + "!\n" + ex);
}
}
return engines;
}),
_loadFromChromeURLs: function SRCH_SVC_loadFromChromeURLs(aURLs) {
aURLs.forEach(function (url) {
@ -3542,8 +3544,7 @@ SearchService.prototype = {
* @returns {Promise} A promise, resolved successfully if loading data
* succeeds.
*/
_asyncLoadFromChromeURLs: function SRCH_SVC__asyncLoadFromChromeURLs(aURLs) {
return Task.spawn(function() {
_asyncLoadFromChromeURLs: Task.async(function* (aURLs) {
let engines = [];
for (let url of aURLs) {
try {
@ -3552,13 +3553,15 @@ SearchService.prototype = {
let engine = new Engine(uri, true);
yield checkForSyncCompletion(engine._asyncInitFromURI(uri));
engines.push(engine);
} catch (ex if ex.result != Cr.NS_ERROR_ALREADY_INITIALIZED) {
} catch (ex) {
if (ex.result == Cr.NS_ERROR_ALREADY_INITIALIZED) {
throw ex;
}
LOG("_asyncLoadFromChromeURLs: failed to load engine: " + ex);
}
}
throw new Task.Result(engines);
}.bind(this));
},
return engines;
}),
_convertChannelToFile: function(chan) {
let fileURI = chan.URI;
@ -3602,15 +3605,14 @@ SearchService.prototype = {
* @returns {Promise} A promise, resolved successfully if finding jar engines
* succeeds.
*/
_asyncFindJAREngines: function SRCH_SVC__asyncFindJAREngines() {
return Task.spawn(function() {
_asyncFindJAREngines: Task.async(function* () {
LOG("_asyncFindJAREngines: looking for engines in JARs")
let listURL = APP_SEARCH_PREFIX + "list.json";
let chan = makeChannel(listURL);
if (!chan) {
LOG("_asyncFindJAREngines: " + APP_SEARCH_PREFIX + " isn't registered");
throw new Task.Result([]);
return [];
}
let uris = [];
@ -3642,9 +3644,8 @@ SearchService.prototype = {
} else {
this._parseListJSON(list, uris);
}
throw new Task.Result(uris);
}.bind(this));
},
return uris;
}),
_parseListJSON: function SRCH_SVC_parseListJSON(list, uris) {
let searchSettings;
@ -3898,19 +3899,21 @@ SearchService.prototype = {
if (!this._initStarted) {
TelemetryStopwatch.start("SEARCH_SERVICE_INIT_MS");
this._initStarted = true;
Task.spawn(function task() {
Task.spawn(function* task() {
try {
// Complete initialization by calling asynchronous initializer.
yield self._asyncInit();
TelemetryStopwatch.finish("SEARCH_SERVICE_INIT_MS");
} catch (ex if ex.result == Cr.NS_ERROR_ALREADY_INITIALIZED) {
} catch (ex) {
if (ex.result == Cr.NS_ERROR_ALREADY_INITIALIZED) {
// No need to pursue asynchronous because synchronous fallback was
// called and has finished.
TelemetryStopwatch.finish("SEARCH_SERVICE_INIT_MS");
} catch (ex) {
} else {
self._initObservers.reject(ex);
TelemetryStopwatch.cancel("SEARCH_SERVICE_INIT_MS");
}
}
});
}
if (observer) {