Bug 1376128 - Avoid use of proprietary catch-if statement; r?automatedtester draft
authorAndreas Tolfsen <ato@sny.no>
Wed, 28 Jun 2017 11:22:29 -0700
changeset 602395 1cc1fe3b40eccc75515241091f136892ca590ca7
parent 602394 196043413dcfeb1edcbb4faedde4cd376a4c8eda
child 602396 721d04358b8c5fb22d8511542115120704abb320
push id66419
push userbmo:ato@sny.no
push dateThu, 29 Jun 2017 23:42:10 +0000
reviewersautomatedtester
bugs1376128
milestone56.0a1
Bug 1376128 - Avoid use of proprietary catch-if statement; r?automatedtester Whilst try...catch (e if foo) { ... } is a very nice construct, it has not been standardised and we should avoid using non-web platform features. MozReview-Commit-ID: 9qzHtBdlPfw
testing/marionette/error.js
testing/marionette/evaluate.js
testing/marionette/listener.js
--- a/testing/marionette/error.js
+++ b/testing/marionette/error.js
@@ -157,18 +157,22 @@ error.stringify = function (err) {
  *     => 'Expected element <input id="foo" class="bar baz">'
  */
 error.pprint = function (ss, ...values) {
   function prettyObject (obj) {
     let proto = Object.prototype.toString.call(obj);
     let s = "";
     try {
       s = JSON.stringify(obj);
-    } catch (e if e instanceof TypeError) {
-      s = `<${e.message}>`;
+    } catch (e) {
+      if (e instanceof TypeError) {
+        s = `<${e.message}>`;
+      } else {
+        throw e;
+      }
     }
     return proto + " " + s;
   }
 
   function prettyElement (el) {
     let ident = [];
     if (el.id) {
       ident.push(`id="${el.id}"`);
--- a/testing/marionette/evaluate.js
+++ b/testing/marionette/evaluate.js
@@ -277,23 +277,25 @@ evaluate.toJSON = function (obj, seenEls
 
   // custom JSON representation
   else if (typeof obj["toJSON"] == "function") {
     let unsafeJSON = obj.toJSON();
     return evaluate.toJSON(unsafeJSON, seenEls);
   }
 
   // arbitrary objects + files
-  else {
-    let rv = {};
-    for (let prop in obj) {
-      try {
-        rv[prop] = evaluate.toJSON(obj[prop], seenEls);
-      } catch (e if (e.result == Cr.NS_ERROR_NOT_IMPLEMENTED)) {
+  let rv = {};
+  for (let prop in obj) {
+    try {
+      rv[prop] = evaluate.toJSON(obj[prop], seenEls);
+    } catch (e) {
+      if (e.result == Cr.NS_ERROR_NOT_IMPLEMENTED) {
         logger.debug(`Skipping ${prop}: ${e.message}`);
+      } else {
+        throw e;
       }
     }
     return rv;
   }
 };
 
 this.sandbox = {};
 
--- a/testing/marionette/listener.js
+++ b/testing/marionette/listener.js
@@ -193,17 +193,21 @@ var loadListener = {
     removeEventListener("DOMContentLoaded", this);
     removeEventListener("pageshow", this);
 
     // If the original content window, where the navigation was triggered,
     // doesn't exist anymore, exceptions can be silently ignored.
     try {
       curContainer.frame.removeEventListener("beforeunload", this);
       curContainer.frame.removeEventListener("unload", this);
-    } catch (e if e.name == "TypeError") {}
+    } catch (e) {
+      if (e.name != "TypeError") {
+        throw e;
+      }
+    }
 
     // In the case when the observer was added before a remoteness change,
     // it will no longer be available. Exceptions can be silently ignored.
     try {
       Services.obs.removeObserver(this, "outer-window-destroyed");
     } catch (e) {}
   },