Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7696d1f

Browse filesBrowse files
BridgeARaddaleax
authored andcommitted
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: #25255 Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 6e716ed commit 7696d1f
Copy full SHA for 7696d1f

File tree

Expand file treeCollapse file tree

1 file changed

+12
-11
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+12
-11
lines changed
Open diff view settings
Collapse file

‎lib/internal/util/inspect.js‎

Copy file name to clipboardExpand all lines: lib/internal/util/inspect.js
+12-11Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ function inspect(value, opts) {
193193
}
194194
if (ctx.colors) ctx.stylize = stylizeWithColor;
195195
if (ctx.maxArrayLength === null) ctx.maxArrayLength = Infinity;
196-
return formatValue(ctx, value, ctx.depth);
196+
return formatValue(ctx, value, 0);
197197
}
198198
inspect.custom = customInspectSymbol;
199199

@@ -407,11 +407,10 @@ function getCtxStyle(constructor, tag) {
407407
}
408408

409409
function formatProxy(ctx, proxy, recurseTimes) {
410-
if (recurseTimes != null) {
411-
if (recurseTimes < 0)
412-
return ctx.stylize('Proxy [Array]', 'special');
413-
recurseTimes -= 1;
410+
if (recurseTimes > ctx.depth && ctx.depth !== null) {
411+
return ctx.stylize('Proxy [Array]', 'special');
414412
}
413+
recurseTimes += 1;
415414
ctx.indentationLvl += 2;
416415
const res = [
417416
formatValue(ctx, proxy[0], recurseTimes),
@@ -526,7 +525,10 @@ function formatValue(ctx, value, recurseTimes, typedArray) {
526525
maybeCustom !== inspect &&
527526
// Also filter out any prototype objects using the circular check.
528527
!(value.constructor && value.constructor.prototype === value)) {
529-
const ret = maybeCustom.call(value, recurseTimes, ctx);
528+
// This makes sure the recurseTimes are reported as before while using
529+
// a counter internally.
530+
const depth = ctx.depth === null ? null : ctx.depth - recurseTimes;
531+
const ret = maybeCustom.call(value, depth, ctx);
530532

531533
// If the custom inspection method returned `this`, don't go into
532534
// infinite recursion.
@@ -643,7 +645,7 @@ function formatRaw(ctx, value, recurseTimes, typedArray) {
643645
const prefix = getPrefix(constructor, tag, 'RegExp');
644646
if (prefix !== 'RegExp ')
645647
base = `${prefix}${base}`;
646-
if (keys.length === 0 || recurseTimes < 0)
648+
if (keys.length === 0 || recurseTimes > ctx.depth && ctx.depth !== null)
647649
return ctx.stylize(base, 'regexp');
648650
} else if (isDate(value)) {
649651
// Make dates with properties first say the date
@@ -757,11 +759,10 @@ function formatRaw(ctx, value, recurseTimes, typedArray) {
757759
}
758760
}
759761

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

766767
ctx.seen.push(value);
767768
let output;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.