From be78266fb39214b7ab3f1d2353d358561dd8f1f8 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Tue, 11 Dec 2018 22:42:34 +0100 Subject: [PATCH] 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 Reviewed-By: Anna Henningsen Reviewed-By: Rich Trott --- lib/internal/encoding.js | 4 ++-- lib/internal/url.js | 2 +- test/parallel/test-whatwg-encoding-custom-textdecoder.js | 2 +- test/parallel/test-whatwg-url-custom-inspect.js | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/internal/encoding.js b/lib/internal/encoding.js index 0084c19b904a82..3fbbbe1a2fefbd 100644 --- a/lib/internal/encoding.js +++ b/lib/internal/encoding.js @@ -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 diff --git a/lib/internal/url.js b/lib/internal/url.js index 81a4966288657e..9727133ad1dd62 100644 --- a/lib/internal/url.js +++ b/lib/internal/url.js @@ -343,7 +343,7 @@ class URL { } if (typeof depth === 'number' && depth < 0) - return opts.stylize('[Object]', 'special'); + return this; var ctor = getConstructorOf(this); diff --git a/test/parallel/test-whatwg-encoding-custom-textdecoder.js b/test/parallel/test-whatwg-encoding-custom-textdecoder.js index ceee5b9cbbde30..63abd2506a5701 100644 --- a/test/parallel/test-whatwg-encoding-custom-textdecoder.js +++ b/test/parallel/test-whatwg-encoding-custom-textdecoder.js @@ -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]'); } { diff --git a/test/parallel/test-whatwg-url-custom-inspect.js b/test/parallel/test-whatwg-url-custom-inspect.js index 1083866d86f505..21c13582254e94 100644 --- a/test/parallel/test-whatwg-url-custom-inspect.js +++ b/test/parallel/test-whatwg-url-custom-inspect.js @@ -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 {'));