Skip to content

Commit be78266

Browse files
committed
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: #24971 Refs: #24765 Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent 6c52ef9 commit be78266

File tree

4 files changed

+5
-5
lines changed

4 files changed

+5
-5
lines changed

lib/internal/encoding.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ class TextEncoder {
320320
[inspect](depth, opts) {
321321
validateEncoder(this);
322322
if (typeof depth === 'number' && depth < 0)
323-
return opts.stylize('[Object]', 'special');
323+
return this;
324324
var ctor = getConstructorOf(this);
325325
var obj = Object.create({
326326
constructor: ctor === null ? TextEncoder : ctor
@@ -517,7 +517,7 @@ function makeTextDecoderJS() {
517517
[inspect](depth, opts) {
518518
validateDecoder(this);
519519
if (typeof depth === 'number' && depth < 0)
520-
return opts.stylize('[Object]', 'special');
520+
return this;
521521
var ctor = getConstructorOf(this);
522522
var obj = Object.create({
523523
constructor: ctor === null ? TextDecoder : ctor

lib/internal/url.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ class URL {
343343
}
344344

345345
if (typeof depth === 'number' && depth < 0)
346-
return opts.stylize('[Object]', 'special');
346+
return this;
347347

348348
var ctor = getConstructorOf(this);
349349

test/parallel/test-whatwg-encoding-custom-textdecoder.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ if (common.hasIntl) {
134134
// Test TextDecoder inspect with negative depth
135135
{
136136
const dec = new TextDecoder();
137-
assert.strictEqual(util.inspect(dec, { depth: -1 }), '[Object]');
137+
assert.strictEqual(util.inspect(dec, { depth: -1 }), '[TextDecoder]');
138138
}
139139

140140
{

test/parallel/test-whatwg-url-custom-inspect.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ assert.strictEqual(
6363

6464
assert.strictEqual(
6565
util.inspect({ a: url }, { depth: 0 }),
66-
'{ a: [Object] }');
66+
'{ a: [URL] }');
6767

6868
class MyURL extends URL {}
6969
assert(util.inspect(new MyURL(url.href)).startsWith('MyURL {'));

0 commit comments

Comments
 (0)