From 646e9152c001702b980204c1c53513f9a7f17829 Mon Sep 17 00:00:00 2001 From: Nathan Froyd Date: Thu, 16 Jan 2014 09:53:50 -0500 Subject: [PATCH] Bug 960619 - part 4 - explicitly return values from SpecialPowersObserverAPI._receiveMessageAPI to avoid warning spew; r=jmaher --- .../content/SpecialPowersObserverAPI.js | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/testing/specialpowers/content/SpecialPowersObserverAPI.js b/testing/specialpowers/content/SpecialPowersObserverAPI.js index a6133ff99503..0403b46b7c82 100644 --- a/testing/specialpowers/content/SpecialPowersObserverAPI.js +++ b/testing/specialpowers/content/SpecialPowersObserverAPI.js @@ -165,6 +165,9 @@ SpecialPowersObserverAPI.prototype = { * This will get requests from our API in the window and process them in chrome for it **/ _receiveMessageAPI: function(aMessage) { + // We explicitly return values in the below code so that this function + // doesn't trigger a flurry of warnings about "does not always return + // a value". switch(aMessage.name) { case "SPPrefService": var prefs = Services.prefs; @@ -178,7 +181,7 @@ SpecialPowersObserverAPI.prototype = { // return null if the pref doesn't exist if (prefs.getPrefType(prefName) == prefs.PREF_INVALID) - return; + return null; } else if (aMessage.json.op == "set") { if (!prefName || !prefType || prefValue === null) throw new SpecialPowersException("Invalid parameters for set in SPPrefService"); @@ -214,10 +217,10 @@ SpecialPowersObserverAPI.prototype = { case "": if (aMessage.json.op == "clear") { prefs.clearUserPref(prefName); - return; + return undefined; } } - break; + return undefined; // See comment at the beginning of this function. case "SPProcessCrashService": switch (aMessage.json.op) { @@ -234,7 +237,7 @@ SpecialPowersObserverAPI.prototype = { default: throw new SpecialPowersException("Invalid operation for SPProcessCrashService"); } - break; + return undefined; // See comment at the beginning of this function. case "SPPermissionManager": let msg = aMessage.json; @@ -266,7 +269,7 @@ SpecialPowersObserverAPI.prototype = { throw new SpecialPowersException("Invalid operation for " + "SPPermissionManager"); } - break; + return undefined; // See comment at the beginning of this function. case "SPWebAppService": let Webapps = {}; @@ -279,7 +282,7 @@ SpecialPowersObserverAPI.prototype = { default: throw new SpecialPowersException("Invalid operation for SPWebAppsService"); } - break; + return undefined; // See comment at the beginning of this function. case "SPObserverService": switch (aMessage.json.op) { @@ -291,7 +294,7 @@ SpecialPowersObserverAPI.prototype = { default: throw new SpecialPowersException("Invalid operation for SPObserverervice"); } - break; + return undefined; // See comment at the beginning of this function. case "SPLoadChromeScript": var url = aMessage.json.url; @@ -331,7 +334,7 @@ SpecialPowersObserverAPI.prototype = { throw new SpecialPowersException("Error while executing chrome " + "script '" + url + "':\n" + e); } - break; + return undefined; // See comment at the beginning of this function. case "SPChromeScriptMessage": var id = aMessage.json.id; @@ -340,11 +343,16 @@ SpecialPowersObserverAPI.prototype = { this._chromeScriptListeners .filter(o => (o.name == name && o.id == id)) .forEach(o => o.listener(message)); - break; + return undefined; // See comment at the beginning of this function. default: throw new SpecialPowersException("Unrecognized Special Powers API"); } + + // We throw an exception before reaching this explicit return because + // we should never be arriving here anyway. + throw new SpecialPowersException("Unreached code"); + return undefined; } };