Bug 1470646 - Silence missing nodeType property warning. r=whimboo
authorAndreas Tolfsen <ato@sny.no>
Sat, 23 Jun 2018 14:00:50 +0100
changeset 424867 608e35dbe664777332f5ed774c521678df32caf7
parent 424866 5049afd1f26a45cf3ea81636347cba4cd3ddfcc5
child 424868 da9689d7801b57bc79b6a82fa1b7678d44bed170
push id104933
push usershindli@mozilla.com
push dateTue, 03 Jul 2018 22:35:47 +0000
treeherdermozilla-inbound@00de580e868f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswhimboo
bugs1470646
milestone63.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 1470646 - Silence missing nodeType property warning. r=whimboo If val does not have a property nodeType, a warning is emitted to the browser console. This is observable when running the xpcshell unit tests because we mock out val without a nodeType property. MozReview-Commit-ID: GzqMoJQQdF8
testing/marionette/format.js
--- a/testing/marionette/format.js
+++ b/testing/marionette/format.js
@@ -7,42 +7,41 @@
 ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 
 const {Log} = ChromeUtils.import("chrome://marionette/content/log.js", {});
 
 XPCOMUtils.defineLazyGetter(this, "log", Log.get);
 
 this.EXPORTED_SYMBOLS = ["pprint", "truncate"];
 
+const ELEMENT_NODE = 1;
 const MAX_STRING_LENGTH = 250;
 
 /**
  * Pretty-print values passed to template strings.
  *
- * Usage:
+ * Usage::
  *
- * <pre><code>
  *     const {pprint} = Cu.import("chrome://marionette/content/error.js", {});
  *     let bool = {value: true};
  *     pprint`Expected boolean, got ${bool}`;
  *     => 'Expected boolean, got [object Object] {"value": true}'
  *
  *     let htmlElement = document.querySelector("input#foo");
  *     pprint`Expected element ${htmlElement}`;
  *     => 'Expected element <input id="foo" class="bar baz" type="input">'
  *
  *     pprint`Current window: ${window}`;
  *     => '[object Window https://www.mozilla.org/]'
- * </code></pre>
  */
 function pprint(ss, ...values) {
   function pretty(val) {
     let proto = Object.prototype.toString.call(val);
-
-    if (val && val.nodeType === 1) {
+    if (typeof val == "object" && val !== null &&
+        "nodeType" in val && val.nodeType === ELEMENT_NODE) {
       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);
   }