Skip to content

Commit 23967b2

Browse files
TirielMylesBorins
authored andcommitted
console: make dirxml an alias for console.log
This method was previously exposed by V8 (since node 8.0.0) but not implemented in node. PR-URL: #17152 Refs: #17128 Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 0afcea2 commit 23967b2

File tree

3 files changed

+29
-12
lines changed

3 files changed

+29
-12
lines changed

doc/api/console.md

+13-12
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,19 @@ Defaults to `2`. To make it recurse indefinitely, pass `null`.
277277
Defaults to `false`. Colors are customizable; see
278278
[customizing `util.inspect()` colors][].
279279

280+
### console.dirxml(...data)
281+
<!-- YAML
282+
added: v8.0.0
283+
changes:
284+
- version: REPLACEME
285+
pr-url: https://github.com/nodejs/node/pull/17152
286+
description: "`console.dirxml` now calls `console.log` for its arguments."
287+
-->
288+
* `...data` {any}
289+
290+
This method calls `console.log()` passing it the arguments received.
291+
Please note that this method does not produce any XML formatting.
292+
280293
### console.error([data][, ...args])
281294
<!-- YAML
282295
added: v0.1.100
@@ -435,18 +448,6 @@ The following methods are exposed by the V8 engine in the general API but do
435448
not display anything unless used in conjunction with the [inspector][]
436449
(`--inspect` flag).
437450

438-
### console.dirxml(object)
439-
<!-- YAML
440-
added: v8.0.0
441-
-->
442-
* `object` {string}
443-
444-
This method does not display anything unless used in the inspector. The
445-
`console.dirxml()` method displays in `stdout` an XML interactive tree
446-
representation of the descendants of the specified `object` if possible, or the
447-
JavaScript representation if not. Calling `console.dirxml()` on an HTML or XML
448-
element is equivalent to calling `console.log()`.
449-
450451
### console.markTimeline(label)
451452
<!-- YAML
452453
added: v8.0.0

lib/console.js

+3
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ Console.prototype.dir = function dir(object, options) {
162162
};
163163

164164

165+
Console.prototype.dirxml = Console.prototype.log;
166+
167+
165168
Console.prototype.time = function time(label = 'default') {
166169
// Coerces everything other than Symbol to a string
167170
label = `${label}`;

test/parallel/test-console.js

+13
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,14 @@ console.dir(custom_inspect, { showHidden: false });
103103
console.dir({ foo: { bar: { baz: true } } }, { depth: 0 });
104104
console.dir({ foo: { bar: { baz: true } } }, { depth: 1 });
105105

106+
// test console.dirxml()
107+
console.dirxml(custom_inspect, custom_inspect);
108+
console.dirxml(
109+
{ foo: { bar: { baz: true } } },
110+
{ foo: { bar: { quux: false } } },
111+
{ foo: { bar: { quux: true } } }
112+
);
113+
106114
// test console.trace()
107115
console.trace('This is a %j %d', { formatted: 'trace' }, 10, 'foo');
108116

@@ -171,6 +179,11 @@ assert.strictEqual(strings.shift(),
171179
"{ foo: 'bar', inspect: [Function: inspect] }\n");
172180
assert.ok(strings.shift().includes('foo: [Object]'));
173181
assert.strictEqual(strings.shift().includes('baz'), false);
182+
assert.strictEqual(strings.shift(), 'inspect inspect\n');
183+
assert.ok(strings[0].includes('foo: { bar: { baz:'));
184+
assert.ok(strings[0].includes('quux'));
185+
assert.ok(strings.shift().includes('quux: true'));
186+
174187
assert.ok(/^label: \d+\.\d{3}ms$/.test(strings.shift().trim()));
175188
assert.ok(/^__proto__: \d+\.\d{3}ms$/.test(strings.shift().trim()));
176189
assert.ok(/^constructor: \d+\.\d{3}ms$/.test(strings.shift().trim()));

0 commit comments

Comments
 (0)