@@ -418,8 +418,15 @@ function getKeys(value, showHidden) {
418418 return keys ;
419419}
420420
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 ) ;
423430}
424431
425432function formatProxy ( ctx , proxy , recurseTimes ) {
@@ -723,25 +730,21 @@ function formatRaw(ctx, value, recurseTimes, typedArray) {
723730 formatter = formatIterator ;
724731 // Handle other regular objects again.
725732 } else {
726- let fallback = '' ;
727- if ( constructor === null ) {
728- fallback = internalGetConstructorName ( value ) ;
729- if ( fallback === tag ) {
730- fallback = 'Object' ;
731- }
732- }
733733 if ( keys . length === 0 ) {
734734 if ( isExternal ( value ) )
735735 return ctx . stylize ( '[External]' , 'special' ) ;
736- return `${ getPrefix ( constructor , tag , fallback ) } {}` ;
736+ return `${ getCtxStyle ( value , constructor , tag ) } {}` ;
737737 }
738- braces [ 0 ] = `${ getPrefix ( constructor , tag , fallback ) } {` ;
738+ braces [ 0 ] = `${ getCtxStyle ( value , constructor , tag ) } {` ;
739739 }
740740 }
741741 }
742742
743743 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' ) ;
745748 }
746749 recurseTimes += 1 ;
747750
@@ -756,7 +759,8 @@ function formatRaw(ctx, value, recurseTimes, typedArray) {
756759 formatProperty ( ctx , value , recurseTimes , keys [ i ] , extrasType ) ) ;
757760 }
758761 } 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 ) ;
760764 }
761765 ctx . seen . pop ( ) ;
762766
@@ -1014,12 +1018,12 @@ function groupArrayElements(ctx, output) {
10141018 return output ;
10151019}
10161020
1017- function handleMaxCallStackSize ( ctx , err , constructor , tag , indentationLvl ) {
1021+ function handleMaxCallStackSize ( ctx , err , constructorName , indentationLvl ) {
10181022 if ( isStackOverflowError ( err ) ) {
10191023 ctx . seen . pop ( ) ;
10201024 ctx . indentationLvl = indentationLvl ;
10211025 return ctx . stylize (
1022- `[${ getCtxStyle ( constructor , tag ) } : Inspection interrupted ` +
1026+ `[${ constructorName } : Inspection interrupted ` +
10231027 'prematurely. Maximum call stack size exceeded.]' ,
10241028 'special'
10251029 ) ;
0 commit comments