Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
util: switch recurseTimes counter
This makes sure the counter goes up instead of going down. This allows
to properly track the current inspection depth no matter what the
`depth` option was set to.
  • Loading branch information
BridgeAR committed Dec 28, 2018
commit 17aa99f367bca778b30943ca983945be81f22781
23 changes: 12 additions & 11 deletions lib/internal/util/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ function inspect(value, opts) {
}
if (ctx.colors) ctx.stylize = stylizeWithColor;
if (ctx.maxArrayLength === null) ctx.maxArrayLength = Infinity;
return formatValue(ctx, value, ctx.depth);
return formatValue(ctx, value, 0);
}
inspect.custom = customInspectSymbol;

Expand Down Expand Up @@ -405,11 +405,10 @@ function getCtxStyle(constructor, tag) {
}

function formatProxy(ctx, proxy, recurseTimes) {
if (recurseTimes != null) {
if (recurseTimes < 0)
return ctx.stylize('Proxy [Array]', 'special');
recurseTimes -= 1;
if (recurseTimes > ctx.depth && ctx.depth !== null) {
return ctx.stylize('Proxy [Array]', 'special');
}
recurseTimes += 1;
ctx.indentationLvl += 2;
const res = [
formatValue(ctx, proxy[0], recurseTimes),
Expand Down Expand Up @@ -524,7 +523,10 @@ function formatValue(ctx, value, recurseTimes) {
maybeCustom !== inspect &&
// Also filter out any prototype objects using the circular check.
!(value.constructor && value.constructor.prototype === value)) {
const ret = maybeCustom.call(value, recurseTimes, ctx);
// This makes sure the recurseTimes are reported as before while using
// a counter internally.
const depth = ctx.depth === null ? null : ctx.depth - recurseTimes;
const ret = maybeCustom.call(value, depth, ctx);

// If the custom inspection method returned `this`, don't go into
// infinite recursion.
Expand Down Expand Up @@ -638,7 +640,7 @@ function formatRaw(ctx, value, recurseTimes) {
const prefix = getPrefix(constructor, tag, 'RegExp');
if (prefix !== 'RegExp ')
base = `${prefix}${base}`;
if (keys.length === 0 || recurseTimes < 0)
if (keys.length === 0 || recurseTimes > ctx.depth && ctx.depth !== null)
return ctx.stylize(base, 'regexp');
} else if (isDate(value)) {
// Make dates with properties first say the date
Expand Down Expand Up @@ -746,11 +748,10 @@ function formatRaw(ctx, value, recurseTimes) {
}
}

if (recurseTimes != null) {
if (recurseTimes < 0)
return ctx.stylize(`[${getCtxStyle(constructor, tag)}]`, 'special');
recurseTimes -= 1;
if (recurseTimes > ctx.depth && ctx.depth !== null) {
return ctx.stylize(`[${getCtxStyle(constructor, tag)}]`, 'special');
}
recurseTimes += 1;

ctx.seen.push(value);
let output;
Expand Down