Bug 1469307 - Pretty-print Attr objects in format.pprint. r?whimboo draft
authorAndreas Tolfsen <ato@sny.no>
Mon, 18 Jun 2018 16:05:39 +0100
changeset 808156 c0486e55cae0fc9a44d569fdefaeda547a2744f6
parent 808097 f804cc575bba9c6dcb4e3770f7dafe4d8934e73c
push id113291
push userbmo:ato@sny.no
push dateMon, 18 Jun 2018 15:07:35 +0000
reviewerswhimboo
bugs1469307
milestone62.0a1
Bug 1469307 - Pretty-print Attr objects in format.pprint. r?whimboo Attr objects are returned from Node.getAttribute() and this provides a readable string like the one offered in devtools for them. MozReview-Commit-ID: 60Pb0AV1tjt
testing/marionette/format.js
--- a/testing/marionette/format.js
+++ b/testing/marionette/format.js
@@ -34,16 +34,18 @@ const MAX_STRING_LENGTH = 250;
 function pprint(ss, ...values) {
   function pretty(val) {
     let proto = Object.prototype.toString.call(val);
 
     if (val && val.nodeType === 1) {
       return prettyElement(val);
     } else if (["[object Window]", "[object ChromeWindow]"].includes(proto)) {
       return prettyWindowGlobal(val);
+    } else if (proto == "[object Attr]") {
+      return prettyAttr(val);
     }
     return prettyObject(val);
   }
 
   function prettyElement(el) {
     let attrs = ["id", "class", "href", "name", "src", "type"];
 
     let idents = "";
@@ -56,16 +58,20 @@ function pprint(ss, ...values) {
     return `<${el.localName}${idents}>`;
   }
 
   function prettyWindowGlobal(win) {
     let proto = Object.prototype.toString.call(win);
     return `[${proto.substring(1, proto.length - 1)} ${win.location}]`;
   }
 
+  function prettyAttr(obj) {
+    return `[object Attr ${obj.name}="${obj.value}"]`;
+  }
+
   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}>`;