Skip to content

Commit 7696d1f

Browse 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

1 file changed

Lines changed: 12 additions & 11 deletions

File tree

‎lib/internal/util/inspect.js‎

Lines 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-
returnformatValue(ctx,value,ctx.depth);
196+
returnformatValue(ctx,value,0);
197197
}
198198
inspect.custom=customInspectSymbol;
199199

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

409409
functionformatProxy(ctx,proxy,recurseTimes){
410-
if(recurseTimes!=null){
411-
if(recurseTimes<0)
412-
returnctx.stylize('Proxy [Array]','special');
413-
recurseTimes-=1;
410+
if(recurseTimes>ctx.depth&&ctx.depth!==null){
411+
returnctx.stylize('Proxy [Array]','special');
414412
}
413+
recurseTimes+=1;
415414
ctx.indentationLvl+=2;
416415
constres=[
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-
constret=maybeCustom.call(value,recurseTimes,ctx);
528+
// This makes sure the recurseTimes are reported as before while using
529+
// a counter internally.
530+
constdepth=ctx.depth===null ? null : ctx.depth-recurseTimes;
531+
constret=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
constprefix=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
returnctx.stylize(base,'regexp');
648650
}elseif(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-
returnctx.stylize(`[${getCtxStyle(constructor,tag)}]`,'special');
763-
recurseTimes-=1;
762+
if(recurseTimes>ctx.depth&&ctx.depth!==null){
763+
returnctx.stylize(`[${getCtxStyle(constructor,tag)}]`,'special');
764764
}
765+
recurseTimes+=1;
765766

766767
ctx.seen.push(value);
767768
letoutput;

0 commit comments

Comments
 (0)