lib: don't use util.inspect() internals

This makes sure the internal `stylize` function is not used to render
anything and instead just uses the regular inspect function in case
of reaching the maximum depth level.

PR-URL: https://github.com/nodejs/node/pull/24971
Refs: https://github.com/nodejs/node/issues/24765
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is contained in:
Ruben Bridgewater 2018-12-11 22:42:34 +01:00
parent 6c52ef9825
commit be78266fb3
No known key found for this signature in database
GPG Key ID: F07496B3EB3C1762
4 changed files with 5 additions and 5 deletions

View File

@ -320,7 +320,7 @@ class TextEncoder {
[inspect](depth, opts) {
validateEncoder(this);
if (typeof depth === 'number' && depth < 0)
return opts.stylize('[Object]', 'special');
return this;
var ctor = getConstructorOf(this);
var obj = Object.create({
constructor: ctor === null ? TextEncoder : ctor
@ -517,7 +517,7 @@ function makeTextDecoderJS() {
[inspect](depth, opts) {
validateDecoder(this);
if (typeof depth === 'number' && depth < 0)
return opts.stylize('[Object]', 'special');
return this;
var ctor = getConstructorOf(this);
var obj = Object.create({
constructor: ctor === null ? TextDecoder : ctor

View File

@ -343,7 +343,7 @@ class URL {
}
if (typeof depth === 'number' && depth < 0)
return opts.stylize('[Object]', 'special');
return this;
var ctor = getConstructorOf(this);

View File

@ -134,7 +134,7 @@ if (common.hasIntl) {
// Test TextDecoder inspect with negative depth
{
const dec = new TextDecoder();
assert.strictEqual(util.inspect(dec, { depth: -1 }), '[Object]');
assert.strictEqual(util.inspect(dec, { depth: -1 }), '[TextDecoder]');
}
{

View File

@ -63,7 +63,7 @@ assert.strictEqual(
assert.strictEqual(
util.inspect({ a: url }, { depth: 0 }),
'{ a: [Object] }');
'{ a: [URL] }');
class MyURL extends URL {}
assert(util.inspect(new MyURL(url.href)).startsWith('MyURL {'));