Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 23967b2

Browse filesBrowse 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 <timothygu99@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 0afcea2 commit 23967b2
Copy full SHA for 23967b2

File tree

Expand file treeCollapse file tree

3 files changed

+29
-12
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+29
-12
lines changed
Open diff view settings
Collapse file

‎doc/api/console.md‎

Copy file name to clipboardExpand all lines: doc/api/console.md
+13-12Lines changed: 13 additions & 12 deletions
  • Display the source diff
  • Display the rich diff
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
Collapse file

‎lib/console.js‎

Copy file name to clipboardExpand all lines: lib/console.js
+3Lines changed: 3 additions & 0 deletions
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}`;
Collapse file

‎test/parallel/test-console.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-console.js
+13Lines changed: 13 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.