@@ -134,6 +134,9 @@ const builtInObjects = new Set(
134134 ObjectGetOwnPropertyNames ( global ) . filter ( ( e ) => / ^ [ A - Z ] [ a - z A - Z 0 - 9 ] + $ / . test ( e ) )
135135) ;
136136
137+ // https://tc39.es/ecma262/#sec-IsHTMLDDA-internal-slot
138+ const isUndetectableObject = ( v ) => typeof v === 'undefined' && v !== undefined ;
139+
137140// These options must stay in sync with `getUserOptions`. So if any option will
138141// be added or removed, `getUserOptions` must also be updated accordingly.
139142const inspectDefaultOptions = ObjectSeal ( {
@@ -482,7 +485,7 @@ function getEmptyFormatArray() {
482485function getConstructorName ( obj , ctx , recurseTimes , protoProps ) {
483486 let firstProto ;
484487 const tmp = obj ;
485- while ( obj ) {
488+ while ( obj || isUndetectableObject ( obj ) ) {
486489 const descriptor = ObjectGetOwnPropertyDescriptor ( obj , 'constructor' ) ;
487490 if ( descriptor !== undefined &&
488491 typeof descriptor . value === 'function' &&
@@ -680,7 +683,9 @@ function findTypedConstructor(value) {
680683// value afterwards again.
681684function formatValue ( ctx , value , recurseTimes , typedArray ) {
682685 // Primitive types cannot have properties.
683- if ( typeof value !== 'object' && typeof value !== 'function' ) {
686+ if ( typeof value !== 'object' &&
687+ typeof value !== 'function' &&
688+ ! isUndetectableObject ( value ) ) {
684689 return formatPrimitive ( ctx . stylize , value , ctx ) ;
685690 }
686691 if ( value === null ) {
0 commit comments