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

--HG--
extra : rebase_source : b5b7c4ec6d48421078085cbd89b7667399c9f05b
This commit is contained in:
Andreas Tolfsen 2018-06-23 14:00:50 +01:00
Родитель 91d8af86bd
Коммит 248e715a91
1 изменённых файлов: 4 добавлений и 5 удалений

Просмотреть файл

@ -12,14 +12,14 @@ 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}`;
@ -31,13 +31,12 @@ const MAX_STRING_LENGTH = 250;
*
* 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);