@@ -198,6 +198,7 @@ function ensureDebugIsInitialized() {
198198
199199function inspectPromise ( p ) {
200200 ensureDebugIsInitialized ( ) ;
201+ // Only create a mirror if the object is a Promise.
201202 if ( ! binding . isPromise ( p ) )
202203 return null ;
203204 const mirror = Debug . MakeMirror ( p , true ) ;
@@ -299,16 +300,19 @@ function formatValue(ctx, value, recurseTimes) {
299300 var base = '' , empty = false , braces ;
300301 var formatter = formatObject ;
301302
303+ // We can't compare constructors for various objects using a comparison like
304+ // `constructor === Array` because the object could have come from a different
305+ // context and thus the constructor won't match. Instead we check the
306+ // constructor names (including those up the prototype chain where needed) to
307+ // determine object types.
302308 if ( Array . isArray ( value ) ) {
303- // We can't use `constructor === Array` because this could
304- // have come from a Debug context.
305- // Otherwise, an Array will print "Array [...]".
309+ // Unset the constructor to prevent "Array [...]" for ordinary arrays.
306310 if ( constructor && constructor . name === 'Array' )
307311 constructor = null ;
308312 braces = [ '[' , ']' ] ;
309313 empty = value . length === 0 ;
310314 formatter = formatArray ;
311- } else if ( value instanceof Set ) {
315+ } else if ( objectToString ( value ) === '[object Set]' ) {
312316 braces = [ '{' , '}' ] ;
313317 // With `showHidden`, `length` will display as a hidden property for
314318 // arrays. For consistency's sake, do the same for `size`, even though this
@@ -317,7 +321,7 @@ function formatValue(ctx, value, recurseTimes) {
317321 keys . unshift ( 'size' ) ;
318322 empty = value . size === 0 ;
319323 formatter = formatSet ;
320- } else if ( value instanceof Map ) {
324+ } else if ( objectToString ( value ) === '[object Map]' ) {
321325 braces = [ '{' , '}' ] ;
322326 // Ditto.
323327 if ( ctx . showHidden )
@@ -347,8 +351,7 @@ function formatValue(ctx, value, recurseTimes) {
347351 'buffer' ) ;
348352 }
349353 } else {
350- // Only create a mirror if the object superficially looks like a Promise.
351- var promiseInternals = value instanceof Promise && inspectPromise ( value ) ;
354+ var promiseInternals = inspectPromise ( value ) ;
352355 if ( promiseInternals ) {
353356 braces = [ '{' , '}' ] ;
354357 formatter = formatPromise ;
@@ -364,7 +367,8 @@ function formatValue(ctx, value, recurseTimes) {
364367 empty = false ;
365368 formatter = formatCollectionIterator ;
366369 } else {
367- if ( constructor === Object )
370+ // Unset the constructor to prevent "Object {...}" for ordinary objects.
371+ if ( constructor && constructor . name === 'Object' )
368372 constructor = null ;
369373 braces = [ '{' , '}' ] ;
370374 empty = true ; // No other data than keys.
0 commit comments