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
--- 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) {}
},