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: https://github.com/nodejs/node/pull/17152
Refs: https://github.com/nodejs/node/issues/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>
This commit is contained in:
Benjamin Zaslavsky 2017-11-20 17:12:20 +01:00 committed by Tobias Nießen
parent 254b5f04e7
commit c84710d062
No known key found for this signature in database
GPG Key ID: 718207F8FD156B70
3 changed files with 29 additions and 12 deletions

View File

@ -277,6 +277,19 @@ Defaults to `2`. To make it recurse indefinitely, pass `null`.
Defaults to `false`. Colors are customizable; see Defaults to `false`. Colors are customizable; see
[customizing `util.inspect()` colors][]. [customizing `util.inspect()` colors][].
### console.dirxml(...data)
<!-- YAML
added: v8.0.0
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/17152
description: "`console.dirxml` now calls `console.log` for its arguments."
-->
* `...data` {any}
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]) ### console.error([data][, ...args])
<!-- YAML <!-- YAML
added: v0.1.100 added: v0.1.100
@ -435,18 +448,6 @@ The following methods are exposed by the V8 engine in the general API but do
not display anything unless used in conjunction with the [inspector][] not display anything unless used in conjunction with the [inspector][]
(`--inspect` flag). (`--inspect` flag).
### console.dirxml(object)
<!-- YAML
added: v8.0.0
-->
* `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) ### console.markTimeline(label)
<!-- YAML <!-- YAML
added: v8.0.0 added: v8.0.0

View File

@ -162,6 +162,9 @@ Console.prototype.dir = function dir(object, options) {
}; };
Console.prototype.dirxml = Console.prototype.log;
Console.prototype.time = function time(label = 'default') { Console.prototype.time = function time(label = 'default') {
// Coerces everything other than Symbol to a string // Coerces everything other than Symbol to a string
label = `${label}`; label = `${label}`;

View File

@ -103,6 +103,14 @@ console.dir(custom_inspect, { showHidden: false });
console.dir({ foo: { bar: { baz: true } } }, { depth: 0 }); console.dir({ foo: { bar: { baz: true } } }, { depth: 0 });
console.dir({ foo: { bar: { baz: true } } }, { depth: 1 }); console.dir({ foo: { bar: { baz: true } } }, { depth: 1 });
// test console.dirxml()
console.dirxml(custom_inspect, custom_inspect);
console.dirxml(
{ foo: { bar: { baz: true } } },
{ foo: { bar: { quux: false } } },
{ foo: { bar: { quux: true } } }
);
// test console.trace() // test console.trace()
console.trace('This is a %j %d', { formatted: 'trace' }, 10, 'foo'); console.trace('This is a %j %d', { formatted: 'trace' }, 10, 'foo');
@ -171,6 +179,11 @@ assert.strictEqual(strings.shift(),
"{ foo: 'bar', inspect: [Function: inspect] }\n"); "{ foo: 'bar', inspect: [Function: inspect] }\n");
assert.ok(strings.shift().includes('foo: [Object]')); assert.ok(strings.shift().includes('foo: [Object]'));
assert.strictEqual(strings.shift().includes('baz'), false); assert.strictEqual(strings.shift().includes('baz'), false);
assert.strictEqual(strings.shift(), 'inspect inspect\n');
assert.ok(strings[0].includes('foo: { bar: { baz:'));
assert.ok(strings[0].includes('quux'));
assert.ok(strings.shift().includes('quux: true'));
assert.ok(/^label: \d+\.\d{3}ms$/.test(strings.shift().trim())); assert.ok(/^label: \d+\.\d{3}ms$/.test(strings.shift().trim()));
assert.ok(/^__proto__: \d+\.\d{3}ms$/.test(strings.shift().trim())); assert.ok(/^__proto__: \d+\.\d{3}ms$/.test(strings.shift().trim()));
assert.ok(/^constructor: \d+\.\d{3}ms$/.test(strings.shift().trim())); assert.ok(/^constructor: \d+\.\d{3}ms$/.test(strings.shift().trim()));