@@ -418,8 +418,15 @@ function getKeys(value, showHidden) {
418
418
return keys ;
419
419
}
420
420
421
- function getCtxStyle ( constructor , tag ) {
422
- return constructor || tag || 'Object' ;
421
+ function getCtxStyle ( value , constructor , tag ) {
422
+ let fallback = '' ;
423
+ if ( constructor === null ) {
424
+ fallback = internalGetConstructorName ( value ) ;
425
+ if ( fallback === tag ) {
426
+ fallback = 'Object' ;
427
+ }
428
+ }
429
+ return getPrefix ( constructor , tag , fallback ) ;
423
430
}
424
431
425
432
function formatProxy ( ctx , proxy , recurseTimes ) {
@@ -723,25 +730,21 @@ function formatRaw(ctx, value, recurseTimes, typedArray) {
723
730
formatter = formatIterator ;
724
731
// Handle other regular objects again.
725
732
} else {
726
- let fallback = '' ;
727
- if ( constructor === null ) {
728
- fallback = internalGetConstructorName ( value ) ;
729
- if ( fallback === tag ) {
730
- fallback = 'Object' ;
731
- }
732
- }
733
733
if ( keys . length === 0 ) {
734
734
if ( isExternal ( value ) )
735
735
return ctx . stylize ( '[External]' , 'special' ) ;
736
- return `${ getPrefix ( constructor , tag , fallback ) } {}` ;
736
+ return `${ getCtxStyle ( value , constructor , tag ) } {}` ;
737
737
}
738
- braces [ 0 ] = `${ getPrefix ( constructor , tag , fallback ) } {` ;
738
+ braces [ 0 ] = `${ getCtxStyle ( value , constructor , tag ) } {` ;
739
739
}
740
740
}
741
741
}
742
742
743
743
if ( recurseTimes > ctx . depth && ctx . depth !== null ) {
744
- return ctx . stylize ( `[${ getCtxStyle ( constructor , tag ) } ]` , 'special' ) ;
744
+ let constructorName = getCtxStyle ( value , constructor , tag ) . slice ( 0 , - 1 ) ;
745
+ if ( constructor !== null )
746
+ constructorName = `[${ constructorName } ]` ;
747
+ return ctx . stylize ( constructorName , 'special' ) ;
745
748
}
746
749
recurseTimes += 1 ;
747
750
@@ -756,7 +759,8 @@ function formatRaw(ctx, value, recurseTimes, typedArray) {
756
759
formatProperty ( ctx , value , recurseTimes , keys [ i ] , extrasType ) ) ;
757
760
}
758
761
} catch ( err ) {
759
- return handleMaxCallStackSize ( ctx , err , constructor , tag , indentationLvl ) ;
762
+ const constructorName = getCtxStyle ( value , constructor , tag ) . slice ( 0 , - 1 ) ;
763
+ return handleMaxCallStackSize ( ctx , err , constructorName , indentationLvl ) ;
760
764
}
761
765
ctx . seen . pop ( ) ;
762
766
@@ -1014,12 +1018,12 @@ function groupArrayElements(ctx, output) {
1014
1018
return output ;
1015
1019
}
1016
1020
1017
- function handleMaxCallStackSize ( ctx , err , constructor , tag , indentationLvl ) {
1021
+ function handleMaxCallStackSize ( ctx , err , constructorName , indentationLvl ) {
1018
1022
if ( isStackOverflowError ( err ) ) {
1019
1023
ctx . seen . pop ( ) ;
1020
1024
ctx . indentationLvl = indentationLvl ;
1021
1025
return ctx . stylize (
1022
- `[${ getCtxStyle ( constructor , tag ) } : Inspection interrupted ` +
1026
+ `[${ constructorName } : Inspection interrupted ` +
1023
1027
'prematurely. Maximum call stack size exceeded.]' ,
1024
1028
'special'
1025
1029
) ;
0 commit comments