From 52fefd42462aec15d7173019c23cb7e7f1c309f8 Mon Sep 17 00:00:00 2001 From: Benjamin Zaslavsky Date: Mon, 20 Nov 2017 17:12:20 +0100 Subject: [PATCH 1/3] console: add dirxml method This method was previously exposed by V8 (since Node v8.0.0) and not implemented in Node directly. Tests coming soon. Refs: https://github.com/nodejs/node/issues/17128 --- lib/console.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/console.js b/lib/console.js index 4ac0634eee221b..0310cbae40ce8d 100644 --- a/lib/console.js +++ b/lib/console.js @@ -162,6 +162,25 @@ Console.prototype.dir = function dir(object, options) { }; +Console.prototype.dirxml = function dirxml(...data) { + const optionProps = ['showHidden', 'depth', 'colors'], + maybeOptions = Object.getOwnPropertyNames(data.slice(-1)), + isOption = maybeOptions.some((p) => optionProps.indexOf(p) !== -1); + let options = { customInspect: false }; + + if (isOption) { + options = Object.assign(data.splice(-1), options); + } + for (const item of data) { + write(this._ignoreErrors, + this._stdout, + util.inspect(item, options), + this._stdoutErrorHandler, + this[kGroupIndent]); + } +}; + + Console.prototype.time = function time(label = 'default') { // Coerces everything other than Symbol to a string label = `${label}`; From 6319499514475a9c91a9e279bd9af4b6246ef008 Mon Sep 17 00:00:00 2001 From: Benjamin Zaslavsky Date: Wed, 22 Nov 2017 22:53:20 +0100 Subject: [PATCH 2/3] console: rework console.dirxml to call console.dir on each argument received. Minimal implementation following the Living Standard specs, following reviews. Fixes: https://github.com/nodejs/node/issues/17128 --- doc/api/console.md | 28 ++++++++++++++++------------ lib/console.js | 14 +------------- test/parallel/test-console.js | 16 ++++++++++++++++ 3 files changed, 33 insertions(+), 25 deletions(-) diff --git a/doc/api/console.md b/doc/api/console.md index ba1505ec1d0f21..ac020c6b1bf9d0 100644 --- a/doc/api/console.md +++ b/doc/api/console.md @@ -277,6 +277,21 @@ Defaults to `2`. To make it recurse indefinitely, pass `null`. Defaults to `false`. Colors are customizable; see [customizing `util.inspect()` colors][]. +### console.dirxml(...data) + +* `...data` {any} + +This method calls `console.dir()` with default options for each argument it +receives. See [`console.dir()`][] for more details about said defaults. +Please note that this method doesn't produce any xml formatting and uses the +default `console.dir()` formatting resolution instead. + ### console.error([data][, ...args]) -* `object` {string} - -This method does not display anything unless used in the inspector. The -`console.dirxml()` method displays in `stdout` an XML interactive tree -representation of the descendants of the specified `object` if possible, or the -JavaScript representation if not. Calling `console.dirxml()` on an HTML or XML -element is equivalent to calling `console.log()`. - ### console.markTimeline(label) * `...data` {any} -This method calls `console.dir()` with default options for each argument it -receives. See [`console.dir()`][] for more details about said defaults. -Please note that this method doesn't produce any xml formatting and uses the -default `console.dir()` formatting resolution instead. +This method calls `console.log()` passing it the arguments received. +Please note that this method does not produce any XML formatting. ### console.error([data][, ...args])