bug 1228792 - use standard version of catch r=mossop
authorRobert Helmer <rhelmer@mozilla.com>
Wed, 02 Dec 2015 18:42:16 -0800
changeset 309653 9abfe93bfd41bb77d7435e1495c24dbc7ed47771
parent 309652 07267b96720ad327d60b0900d546b785e99d059c
child 309654 5ada25e1f3196f90feb0a930f6c3ef40cb7c141d
push id5513
push userraliiev@mozilla.com
push dateMon, 25 Jan 2016 13:55:34 +0000
treeherdermozilla-beta@5ee97dd05b5c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmossop
bugs1228792
milestone45.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 1228792 - use standard version of catch r=mossop
toolkit/mozapps/extensions/internal/AddonRepository.jsm
toolkit/mozapps/extensions/internal/AddonUpdateChecker.jsm
toolkit/mozapps/extensions/internal/GMPProvider.jsm
toolkit/mozapps/extensions/internal/PluginProvider.jsm
toolkit/mozapps/extensions/internal/XPIProvider.jsm
toolkit/mozapps/extensions/nsBlocklistService.js
toolkit/mozapps/extensions/test/xpcshell/head_addons.js
toolkit/mozapps/extensions/test/xpcshell/test_mapURIToAddonID.js
--- a/toolkit/mozapps/extensions/internal/AddonRepository.jsm
+++ b/toolkit/mozapps/extensions/internal/AddonRepository.jsm
@@ -1596,44 +1596,44 @@ var AddonDatabase = {
          }
 
          schema = parseInt(inputDB.schema, 10);
 
          if (!Number.isInteger(schema) ||
              schema < DB_MIN_JSON_SCHEMA) {
            throw new Error("Invalid schema value.");
          }
-       } catch (e if e instanceof OS.File.Error && e.becauseNoSuchFile) {
-         logger.debug("No " + FILE_DATABASE + " found.");
+       } catch (e) {
+         if (e instanceof OS.File.Error && e.becauseNoSuchFile) {
+           logger.debug("No " + FILE_DATABASE + " found.");
 
-         // Create a blank addons.json file
-         this._saveDBToDisk();
+           // Create a blank addons.json file
+           this._saveDBToDisk();
 
-         let dbSchema = 0;
-         try {
-           dbSchema = Services.prefs.getIntPref(PREF_GETADDONS_DB_SCHEMA);
-         } catch (e) {}
+           let dbSchema = 0;
+           try {
+             dbSchema = Services.prefs.getIntPref(PREF_GETADDONS_DB_SCHEMA);
+           } catch (e) {}
 
-         if (dbSchema < DB_MIN_JSON_SCHEMA) {
-           let results = yield new Promise((resolve, reject) => {
-             AddonRepository_SQLiteMigrator.migrate(resolve);
-           });
+           if (dbSchema < DB_MIN_JSON_SCHEMA) {
+             let results = yield new Promise((resolve, reject) => {
+               AddonRepository_SQLiteMigrator.migrate(resolve);
+             });
 
-           if (results.length) {
-             yield this._insertAddons(results);
+             if (results.length) {
+               yield this._insertAddons(results);
+             }
+
            }
 
            Services.prefs.setIntPref(PREF_GETADDONS_DB_SCHEMA, DB_SCHEMA);
+         } else {
+           logger.error("Malformed " + FILE_DATABASE + ": " + e);
+           this.databaseOk = false;
          }
-
-         return this.DB;
-       } catch (e) {
-         logger.error("Malformed " + FILE_DATABASE + ": " + e);
-         this.databaseOk = false;
-
          return this.DB;
        }
 
        Services.prefs.setIntPref(PREF_GETADDONS_DB_SCHEMA, DB_SCHEMA);
 
        // We use _insertAddon manually instead of calling
        // insertAddons to avoid the write to disk which would
        // be a waste since this is the data that was just read.
--- a/toolkit/mozapps/extensions/internal/AddonUpdateChecker.jsm
+++ b/toolkit/mozapps/extensions/internal/AddonUpdateChecker.jsm
@@ -640,17 +640,19 @@ UpdateParser.prototype = {
     // Detect the manifest type by first attempting to parse it as
     // JSON, and falling back to parsing it as XML if that fails.
     let parser;
     try {
       try {
         let json = JSON.parse(request.responseText);
 
         parser = () => parseJSONManifest(this.id, this.updateKey, request, json);
-      } catch (e if e instanceof SyntaxError) {
+      } catch (e) {
+        if (!(e instanceof SyntaxError))
+          throw e;
         let domParser = Cc["@mozilla.org/xmlextras/domparser;1"].createInstance(Ci.nsIDOMParser);
         let xml = domParser.parseFromString(request.responseText, "text/xml");
 
         if (xml.documentElement.namespaceURI == XMLURI_PARSE_ERROR)
           throw new Error("Update manifest was not valid XML or JSON");
 
         parser = () => parseRDFManifest(this.id, this.updateKey, request, xml);
       }
--- a/toolkit/mozapps/extensions/internal/GMPProvider.jsm
+++ b/toolkit/mozapps/extensions/internal/GMPProvider.jsm
@@ -567,17 +567,19 @@ var GMPProvider = {
                          " missing [" + validation.missing + "], uninstalling");
           telemetryService.getHistogramById(wrapper.missingKey).add(true);
           wrapper.uninstallPlugin();
           continue;
         }
         this._log.info("startup - adding gmp directory " + gmpPath);
         try {
           gmpService.addPluginDirectory(gmpPath);
-        } catch (e if e.name == 'NS_ERROR_NOT_AVAILABLE') {
+        } catch (e) {
+          if (e.name != 'NS_ERROR_NOT_AVAILABLE')
+            throw e;
           this._log.warn("startup - adding gmp directory failed with " +
                          e.name + " - sandboxing not available?", e);
         }
       }
 
       if (this.isEnabled) {
         telemetry[id] = {
           userDisabled: wrapper.userDisabled,
--- a/toolkit/mozapps/extensions/internal/PluginProvider.jsm
+++ b/toolkit/mozapps/extensions/internal/PluginProvider.jsm
@@ -494,17 +494,19 @@ PluginWrapper.prototype = {
       return AddonManager.SCOPE_PROFILE;
 
     // Plugins anywhere else in the user's home are in the user scope,
     // but not all platforms have a home directory.
     try {
       dir = Services.dirsvc.get("Home", Ci.nsIFile);
       if (path.startsWith(dir.path))
         return AddonManager.SCOPE_USER;
-    } catch (e if (e.result && e.result == Components.results.NS_ERROR_FAILURE)) {
+    } catch (e) {
+      if (!e.result || e.result != Components.results.NS_ERROR_FAILURE)
+        throw e;
       // Do nothing: missing "Home".
     }
 
     // Any other locations are system scope
     return AddonManager.SCOPE_SYSTEM;
   },
 
   get pendingOperations() {
--- a/toolkit/mozapps/extensions/internal/XPIProvider.jsm
+++ b/toolkit/mozapps/extensions/internal/XPIProvider.jsm
@@ -881,17 +881,19 @@ var loadManifestFromWebManifest = Task.a
       throw new SyntaxError(`Expected property ${path} to be of type ${type}`);
     return val;
   }
 
   function getOptionalProp(path, defValue = null, type = "String") {
     try {
       return getProp(path, type);
     }
-    catch (e if !(e instanceof SyntaxError)) {
+    catch (e) {
+      if (e instanceof SyntaxError)
+        throw e;
       return defValue;
     }
   }
 
   let mVersion = getProp("manifest_version", "Number");
   if (mVersion != 2) {
     throw new Error("Expected manifest_version to be 2 but was " + mVersion);
   }
@@ -1799,17 +1801,19 @@ function removeAsync(aFile) {
     let info = null;
     try {
       info = yield OS.File.stat(aFile.path);
       if (info.isDir)
         yield OS.File.removeDir(aFile.path);
       else
         yield OS.File.remove(aFile.path);
     }
-    catch (e if e instanceof OS.File.Error && e.becauseNoSuchFile) {
+    catch (e) {
+      if (!(e instanceof OS.File.Error) || ! e.becauseNoSuchFile)
+        throw e;
       // The file has already gone away
       return;
     }
   });
 }
 
 /**
  * Recursively removes a directory or file fixing permissions when necessary.
@@ -3195,17 +3199,19 @@ this.XPIProvider = {
       let stagingDirEntries = getDirectoryEntries(stagingDir, true);
       for (let stageDirEntry of stagingDirEntries) {
         let id = stageDirEntry.leafName;
 
         let isDir;
         try {
           isDir = stageDirEntry.isDirectory();
         }
-        catch (e if e.result == Cr.NS_ERROR_FILE_TARGET_DOES_NOT_EXIST) {
+        catch (e) {
+          if (e.result != Cr.NS_ERROR_FILE_TARGET_DOES_NOT_EXIST)
+            throw e;
           // If the file has already gone away then don't worry about it, this
           // can happen on OSX where the resource fork is automatically moved
           // with the data fork for the file. See bug 733436.
           continue;
         }
 
         if (!isDir) {
           if (id.substring(id.length - 4).toLowerCase() == ".xpi") {
--- a/toolkit/mozapps/extensions/nsBlocklistService.js
+++ b/toolkit/mozapps/extensions/nsBlocklistService.js
@@ -91,19 +91,21 @@ XPCOMUtils.defineLazyGetter(this, "gPref
 // Services.jsm since it will not successfully QueryInterface nsIXULAppInfo in
 // xpcshell tests due to other code calling Services.appinfo before the
 // nsIXULAppInfo is created by the tests.
 XPCOMUtils.defineLazyGetter(this, "gApp", function() {
   let appinfo = Cc["@mozilla.org/xre/app-info;1"]
                   .getService(Ci.nsIXULRuntime);
   try {
     appinfo.QueryInterface(Ci.nsIXULAppInfo);
-  } catch (ex if ex instanceof Components.Exception &&
-                 ex.result == Cr.NS_NOINTERFACE) {
+  } catch (ex) {
     // Not all applications implement nsIXULAppInfo (e.g. xpcshell doesn't).
+    if (!(ex instanceof Components.Exception) ||
+        ex.result != Cr.NS_NOINTERFACE)
+      throw ex;
   }
   return appinfo;
 });
 
 XPCOMUtils.defineLazyGetter(this, "gABI", function() {
   let abi = null;
   try {
     abi = gApp.XPCOMABI;
--- a/toolkit/mozapps/extensions/test/xpcshell/head_addons.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/head_addons.js
@@ -1128,17 +1128,19 @@ function setExtensionModifiedTime(aExt, 
 }
 function promiseSetExtensionModifiedTime(aPath, aTime) {
   return Task.spawn(function* () {
     yield OS.File.setDates(aPath, aTime, aTime);
     let entries, iterator;
     try {
       let iterator = new OS.File.DirectoryIterator(aPath);
       entries = yield iterator.nextBatch();
-    } catch (ex if ex instanceof OS.File.Error) {
+    } catch (ex) {
+      if (!(ex instanceof OS.File.Error))
+        throw ex;
       return;
     } finally {
       if (iterator) {
         iterator.close();
       }
     }
     for (let entry of entries) {
       yield promiseSetExtensionModifiedTime(entry.path, aTime);
--- a/toolkit/mozapps/extensions/test/xpcshell/test_mapURIToAddonID.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_mapURIToAddonID.js
@@ -262,21 +262,22 @@ function run_test_invalidarg() {
                "chrome://global/content/",
                function() {}
                ];
   for (var test of tests) {
     try {
       AddonManager.mapURIToAddonID(test);
       throw new Error("Shouldn't be able to map the URI in question");
     }
-    catch (ex if ex.result) {
-      do_check_eq(ex.result, Components.results.NS_ERROR_INVALID_ARG);
-    }
     catch (ex) {
-      do_throw(ex);
+      if (ex.result) {
+        do_check_eq(ex.result, Components.results.NS_ERROR_INVALID_ARG);
+      } else {
+        do_throw(ex);
+      }
     }
   }
 
   run_test_provider();
 }
 
 // Tests that custom providers are correctly handled
 function run_test_provider() {