Skip to content

Commit

Permalink
lib: don't use util.inspect() internals
Browse files Browse the repository at this point in the history
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 <me@gus.host>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
  • Loading branch information
BridgeAR committed Feb 28, 2019
1 parent 6c52ef9 commit be78266
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/internal/encoding.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ class URL {
}

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

var ctor = getConstructorOf(this);

Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-whatwg-encoding-custom-textdecoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]');
}

{
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-whatwg-url-custom-inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {'));

0 comments on commit be78266

Please sign in to comment.