зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1632303 - Replace SearchUtils.fail with direct throws. r=daleharvey
Depends on D77649 Differential Revision: https://phabricator.services.mozilla.com/D77650
This commit is contained in:
Родитель
ed636bbf8b
Коммит
4cc3eda832
|
@ -278,10 +278,6 @@ function getVerificationHash(name) {
|
|||
* @returns {object}
|
||||
*/
|
||||
function getDir(key, iface) {
|
||||
if (!key) {
|
||||
SearchUtils.fail("getDir requires a directory key!");
|
||||
}
|
||||
|
||||
return Services.dirsvc.get(key, iface || Ci.nsIFile);
|
||||
}
|
||||
|
||||
|
@ -362,7 +358,10 @@ class QueryParameter {
|
|||
*/
|
||||
constructor(name, value, purpose) {
|
||||
if (!name || value == null) {
|
||||
SearchUtils.fail("missing name or value for QueryParameter!");
|
||||
throw Components.Exception(
|
||||
"missing name or value for QueryParameter!",
|
||||
Cr.NS_ERROR_INVALID_ARG
|
||||
);
|
||||
}
|
||||
|
||||
this.name = name;
|
||||
|
@ -559,14 +558,20 @@ function getInternalAliases(engine) {
|
|||
*/
|
||||
function EngineURL(mimeType, requestMethod, template, resultDomain) {
|
||||
if (!mimeType || !requestMethod || !template) {
|
||||
SearchUtils.fail("missing mimeType, method or template for EngineURL!");
|
||||
throw Components.Exception(
|
||||
"missing mimeType, method or template for EngineURL!",
|
||||
Cr.NS_ERROR_INVALID_ARG
|
||||
);
|
||||
}
|
||||
|
||||
var method = requestMethod.toUpperCase();
|
||||
var type = mimeType.toLowerCase();
|
||||
|
||||
if (method != "GET" && method != "POST") {
|
||||
SearchUtils.fail('method passed to EngineURL must be "GET" or "POST"');
|
||||
throw Components.Exception(
|
||||
'method passed to EngineURL must be "GET" or "POST"',
|
||||
Cr.NS_ERROR_INVALID_ARG
|
||||
);
|
||||
}
|
||||
|
||||
this.type = type;
|
||||
|
@ -576,7 +581,7 @@ function EngineURL(mimeType, requestMethod, template, resultDomain) {
|
|||
|
||||
var templateURI = SearchUtils.makeURI(template);
|
||||
if (!templateURI) {
|
||||
SearchUtils.fail(
|
||||
throw Components.Exception(
|
||||
"new EngineURL: template is not a valid URI!",
|
||||
Cr.NS_ERROR_FAILURE
|
||||
);
|
||||
|
@ -591,7 +596,7 @@ function EngineURL(mimeType, requestMethod, template, resultDomain) {
|
|||
this.template = template;
|
||||
break;
|
||||
default:
|
||||
SearchUtils.fail(
|
||||
throw Components.Exception(
|
||||
"new EngineURL: template uses invalid scheme!",
|
||||
Cr.NS_ERROR_FAILURE
|
||||
);
|
||||
|
@ -920,7 +925,7 @@ SearchEngine.prototype = {
|
|||
*/
|
||||
async _initFromFile(file) {
|
||||
if (!file || !(await OS.File.exists(file.path))) {
|
||||
SearchUtils.fail(
|
||||
throw Components.Exception(
|
||||
"File must exist before calling initFromFile!",
|
||||
Cr.NS_ERROR_UNEXPECTED
|
||||
);
|
||||
|
@ -1391,7 +1396,7 @@ SearchEngine.prototype = {
|
|||
this._parse();
|
||||
} else {
|
||||
Cu.reportError("Invalid search plugin due to namespace not matching.");
|
||||
SearchUtils.fail(
|
||||
throw Components.Exception(
|
||||
this._location + " is not a valid search plugin.",
|
||||
Cr.NS_ERROR_FILE_CORRUPTED
|
||||
);
|
||||
|
@ -1613,7 +1618,7 @@ SearchEngine.prototype = {
|
|||
try {
|
||||
var url = new EngineURL(type, method, template, resultDomain);
|
||||
} catch (ex) {
|
||||
SearchUtils.fail(
|
||||
throw Components.Exception(
|
||||
"_parseURL: failed to add " + template + " as a URL",
|
||||
Cr.NS_ERROR_FAILURE
|
||||
);
|
||||
|
@ -1755,10 +1760,13 @@ SearchEngine.prototype = {
|
|||
}
|
||||
}
|
||||
if (!this.name || !this._urls.length) {
|
||||
SearchUtils.fail("_parse: No name, or missing URL!", Cr.NS_ERROR_FAILURE);
|
||||
throw Components.Exception(
|
||||
"_parse: No name, or missing URL!",
|
||||
Cr.NS_ERROR_FAILURE
|
||||
);
|
||||
}
|
||||
if (!this.supportsResponseType(SearchUtils.URL_TYPE.SEARCH)) {
|
||||
SearchUtils.fail(
|
||||
throw Components.Exception(
|
||||
"_parse: No text/html result type!",
|
||||
Cr.NS_ERROR_FAILURE
|
||||
);
|
||||
|
@ -2156,7 +2164,10 @@ SearchEngine.prototype = {
|
|||
// from nsISearchEngine
|
||||
addParam(name, value, responseType) {
|
||||
if (!name || value == null) {
|
||||
SearchUtils.fail("missing name or value for nsISearchEngine::addParam!");
|
||||
throw Components.Exception(
|
||||
"missing name or value for nsISearchEngine::addParam",
|
||||
Cr.NS_ERROR_INVALID_ARG
|
||||
);
|
||||
}
|
||||
ENSURE_WARN(
|
||||
!this._isBuiltin,
|
||||
|
@ -2169,7 +2180,7 @@ SearchEngine.prototype = {
|
|||
|
||||
var url = this._getURLOfType(responseType);
|
||||
if (!url) {
|
||||
SearchUtils.fail(
|
||||
throw Components.Exception(
|
||||
"Engine object has no URL for response type " + responseType,
|
||||
Cr.NS_ERROR_FAILURE
|
||||
);
|
||||
|
|
|
@ -2385,9 +2385,21 @@ SearchService.prototype = {
|
|||
},
|
||||
|
||||
async addEngineWithDetails(name, details, isReload = false) {
|
||||
if (!name) {
|
||||
throw Components.Exception(
|
||||
"Empty name passed to addEngineWithDetails!",
|
||||
Cr.NS_ERROR_INVALID_ARG
|
||||
);
|
||||
}
|
||||
let params = details;
|
||||
if (!params.template) {
|
||||
throw Components.Exception(
|
||||
"Empty template passed to addEngineWithDetails!",
|
||||
Cr.NS_ERROR_INVALID_ARG
|
||||
);
|
||||
}
|
||||
logConsole.debug("addEngineWithDetails: Adding", name);
|
||||
let isCurrent = false;
|
||||
var params = details;
|
||||
|
||||
let isBuiltin = !!params.isBuiltin;
|
||||
// We install search extensions during the init phase, both built in
|
||||
|
@ -2396,12 +2408,6 @@ SearchService.prototype = {
|
|||
if (!gInitialized && !isBuiltin && !params.initEngine) {
|
||||
await this.init();
|
||||
}
|
||||
if (!name) {
|
||||
SearchUtils.fail("Invalid name passed to addEngineWithDetails!");
|
||||
}
|
||||
if (!params.template) {
|
||||
SearchUtils.fail("Invalid template passed to addEngineWithDetails!");
|
||||
}
|
||||
let existingEngine = this._engines.get(name);
|
||||
// In the modern configuration, distributions are app-provided engines,
|
||||
// so we don't need this separate check.
|
||||
|
@ -2410,7 +2416,7 @@ SearchService.prototype = {
|
|||
existingEngine &&
|
||||
existingEngine._loadPath.startsWith("[distribution]")
|
||||
) {
|
||||
SearchUtils.fail(
|
||||
throw Components.Exception(
|
||||
"Not loading engine due to having a distribution engine with the same name",
|
||||
Cr.NS_ERROR_FILE_ALREADY_EXISTS
|
||||
);
|
||||
|
@ -2426,7 +2432,7 @@ SearchService.prototype = {
|
|||
isCurrent = this.defaultEngine == existingEngine;
|
||||
await this.removeEngine(existingEngine);
|
||||
} else {
|
||||
SearchUtils.fail(
|
||||
throw Components.Exception(
|
||||
"An engine with that name already exists!",
|
||||
Cr.NS_ERROR_FILE_ALREADY_EXISTS
|
||||
);
|
||||
|
@ -2727,7 +2733,7 @@ SearchService.prototype = {
|
|||
if (engine) {
|
||||
engine._installCallback = null;
|
||||
}
|
||||
SearchUtils.fail(
|
||||
throw Components.Exception(
|
||||
"addEngine: Error adding engine:\n" + ex,
|
||||
errCode || Cr.NS_ERROR_FAILURE
|
||||
);
|
||||
|
@ -2745,7 +2751,10 @@ SearchService.prototype = {
|
|||
async removeEngine(engine) {
|
||||
await this.init();
|
||||
if (!engine) {
|
||||
SearchUtils.fail("no engine passed to removeEngine!");
|
||||
throw Components.Exception(
|
||||
"no engine passed to removeEngine!",
|
||||
Cr.NS_ERROR_INVALID_ARG
|
||||
);
|
||||
}
|
||||
|
||||
var engineToRemove = null;
|
||||
|
@ -2756,7 +2765,7 @@ SearchService.prototype = {
|
|||
}
|
||||
|
||||
if (!engineToRemove) {
|
||||
SearchUtils.fail(
|
||||
throw Components.Exception(
|
||||
"removeEngine: Can't find engine to remove!",
|
||||
Cr.NS_ERROR_FILE_NOT_FOUND
|
||||
);
|
||||
|
@ -2797,7 +2806,7 @@ SearchService.prototype = {
|
|||
// Remove the engine from _sortedEngines
|
||||
var index = this._sortedEngines.indexOf(engineToRemove);
|
||||
if (index == -1) {
|
||||
SearchUtils.fail(
|
||||
throw Components.Exception(
|
||||
"Can't find engine to remove in _sortedEngines!",
|
||||
Cr.NS_ERROR_FAILURE
|
||||
);
|
||||
|
@ -2816,16 +2825,19 @@ SearchService.prototype = {
|
|||
async moveEngine(engine, newIndex) {
|
||||
await this.init();
|
||||
if (newIndex > this._sortedEngines.length || newIndex < 0) {
|
||||
SearchUtils.fail("moveEngine: Index out of bounds!");
|
||||
throw Components.Exception("moveEngine: Index out of bounds!");
|
||||
}
|
||||
if (
|
||||
!(engine instanceof Ci.nsISearchEngine) &&
|
||||
!(engine instanceof SearchEngine)
|
||||
) {
|
||||
SearchUtils.fail("moveEngine: Invalid engine passed to moveEngine!");
|
||||
throw Components.Exception(
|
||||
"moveEngine: Invalid engine passed to moveEngine!",
|
||||
Cr.NS_ERROR_INVALID_ARG
|
||||
);
|
||||
}
|
||||
if (engine.hidden) {
|
||||
SearchUtils.fail(
|
||||
throw Components.Exception(
|
||||
"moveEngine: Can't move a hidden engine!",
|
||||
Cr.NS_ERROR_FAILURE
|
||||
);
|
||||
|
@ -2835,7 +2847,7 @@ SearchService.prototype = {
|
|||
|
||||
var currentIndex = this._sortedEngines.indexOf(engine);
|
||||
if (currentIndex == -1) {
|
||||
SearchUtils.fail(
|
||||
throw Components.Exception(
|
||||
"moveEngine: Can't find engine to move!",
|
||||
Cr.NS_ERROR_UNEXPECTED
|
||||
);
|
||||
|
@ -2854,7 +2866,7 @@ SearchService.prototype = {
|
|||
// newIndexEngine directly instead of newIndex.
|
||||
var newIndexEngine = this._getSortedEngines(false)[newIndex];
|
||||
if (!newIndexEngine) {
|
||||
SearchUtils.fail(
|
||||
throw Components.Exception(
|
||||
"moveEngine: Can't find engine to replace!",
|
||||
Cr.NS_ERROR_UNEXPECTED
|
||||
);
|
||||
|
@ -2988,12 +3000,18 @@ SearchService.prototype = {
|
|||
!(newEngine instanceof Ci.nsISearchEngine) &&
|
||||
!(newEngine instanceof SearchEngine)
|
||||
) {
|
||||
SearchUtils.fail("Invalid argument passed to defaultEngine setter");
|
||||
throw Components.Exception(
|
||||
"Invalid argument passed to defaultEngine setter",
|
||||
Cr.NS_ERROR_INVALID_ARG
|
||||
);
|
||||
}
|
||||
|
||||
const newCurrentEngine = this.getEngineByName(newEngine.name);
|
||||
if (!newCurrentEngine) {
|
||||
SearchUtils.fail("Can't find engine in store!", Cr.NS_ERROR_UNEXPECTED);
|
||||
throw Components.Exception(
|
||||
"Can't find engine in store!",
|
||||
Cr.NS_ERROR_UNEXPECTED
|
||||
);
|
||||
}
|
||||
|
||||
if (!newCurrentEngine.isAppProvided) {
|
||||
|
|
|
@ -108,21 +108,6 @@ var SearchUtils = {
|
|||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Logs the failure message (if browser.search.log is enabled) and throws.
|
||||
* @param {string} message
|
||||
* A message to display
|
||||
* @param {number} resultCode
|
||||
* The NS_ERROR_* value to throw.
|
||||
* @throws resultCode or NS_ERROR_INVALID_ARG if resultCode isn't specified.
|
||||
*/
|
||||
fail(message, resultCode) {
|
||||
if (SearchUtils.loggingEnabled) {
|
||||
Services.console.logStringMessage(message);
|
||||
}
|
||||
throw Components.Exception(message, resultCode || Cr.NS_ERROR_INVALID_ARG);
|
||||
},
|
||||
|
||||
/**
|
||||
* Wrapper function for nsIIOService::newURI.
|
||||
* @param {string} urlSpec
|
||||
|
|
Загрузка…
Ссылка в новой задаче