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. PR-URL: https://github.com/nodejs/node/pull/25255 Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
7237eaa335
commit
eca2760ab1
@ -193,7 +193,7 @@ function inspect(value, opts) {
|
|||||||
}
|
}
|
||||||
if (ctx.colors) ctx.stylize = stylizeWithColor;
|
if (ctx.colors) ctx.stylize = stylizeWithColor;
|
||||||
if (ctx.maxArrayLength === null) ctx.maxArrayLength = Infinity;
|
if (ctx.maxArrayLength === null) ctx.maxArrayLength = Infinity;
|
||||||
return formatValue(ctx, value, ctx.depth);
|
return formatValue(ctx, value, 0);
|
||||||
}
|
}
|
||||||
inspect.custom = customInspectSymbol;
|
inspect.custom = customInspectSymbol;
|
||||||
|
|
||||||
@ -407,11 +407,10 @@ function getCtxStyle(constructor, tag) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function formatProxy(ctx, proxy, recurseTimes) {
|
function formatProxy(ctx, proxy, recurseTimes) {
|
||||||
if (recurseTimes != null) {
|
if (recurseTimes > ctx.depth && ctx.depth !== null) {
|
||||||
if (recurseTimes < 0)
|
return ctx.stylize('Proxy [Array]', 'special');
|
||||||
return ctx.stylize('Proxy [Array]', 'special');
|
|
||||||
recurseTimes -= 1;
|
|
||||||
}
|
}
|
||||||
|
recurseTimes += 1;
|
||||||
ctx.indentationLvl += 2;
|
ctx.indentationLvl += 2;
|
||||||
const res = [
|
const res = [
|
||||||
formatValue(ctx, proxy[0], recurseTimes),
|
formatValue(ctx, proxy[0], recurseTimes),
|
||||||
@ -526,7 +525,10 @@ function formatValue(ctx, value, recurseTimes, typedArray) {
|
|||||||
maybeCustom !== inspect &&
|
maybeCustom !== inspect &&
|
||||||
// Also filter out any prototype objects using the circular check.
|
// Also filter out any prototype objects using the circular check.
|
||||||
!(value.constructor && value.constructor.prototype === value)) {
|
!(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
|
// If the custom inspection method returned `this`, don't go into
|
||||||
// infinite recursion.
|
// infinite recursion.
|
||||||
@ -643,7 +645,7 @@ function formatRaw(ctx, value, recurseTimes, typedArray) {
|
|||||||
const prefix = getPrefix(constructor, tag, 'RegExp');
|
const prefix = getPrefix(constructor, tag, 'RegExp');
|
||||||
if (prefix !== 'RegExp ')
|
if (prefix !== 'RegExp ')
|
||||||
base = `${prefix}${base}`;
|
base = `${prefix}${base}`;
|
||||||
if (keys.length === 0 || recurseTimes < 0)
|
if (keys.length === 0 || recurseTimes > ctx.depth && ctx.depth !== null)
|
||||||
return ctx.stylize(base, 'regexp');
|
return ctx.stylize(base, 'regexp');
|
||||||
} else if (isDate(value)) {
|
} else if (isDate(value)) {
|
||||||
// Make dates with properties first say the date
|
// Make dates with properties first say the date
|
||||||
@ -757,11 +759,10 @@ function formatRaw(ctx, value, recurseTimes, typedArray) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (recurseTimes != null) {
|
if (recurseTimes > ctx.depth && ctx.depth !== null) {
|
||||||
if (recurseTimes < 0)
|
return ctx.stylize(`[${getCtxStyle(constructor, tag)}]`, 'special');
|
||||||
return ctx.stylize(`[${getCtxStyle(constructor, tag)}]`, 'special');
|
|
||||||
recurseTimes -= 1;
|
|
||||||
}
|
}
|
||||||
|
recurseTimes += 1;
|
||||||
|
|
||||||
ctx.seen.push(value);
|
ctx.seen.push(value);
|
||||||
let output;
|
let output;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user