@@ -198,6 +198,7 @@ function ensureDebugIsInitialized() {
198
198
199
199
function inspectPromise ( p ) {
200
200
ensureDebugIsInitialized ( ) ;
201
+ // Only create a mirror if the object is a Promise.
201
202
if ( ! binding . isPromise ( p ) )
202
203
return null ;
203
204
const mirror = Debug . MakeMirror ( p , true ) ;
@@ -299,16 +300,19 @@ function formatValue(ctx, value, recurseTimes) {
299
300
var base = '' , empty = false , braces ;
300
301
var formatter = formatObject ;
301
302
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.
302
308
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.
306
310
if ( constructor && constructor . name === 'Array' )
307
311
constructor = null ;
308
312
braces = [ '[' , ']' ] ;
309
313
empty = value . length === 0 ;
310
314
formatter = formatArray ;
311
- } else if ( value instanceof Set ) {
315
+ } else if ( objectToString ( value ) === '[object Set]' ) {
312
316
braces = [ '{' , '}' ] ;
313
317
// With `showHidden`, `length` will display as a hidden property for
314
318
// arrays. For consistency's sake, do the same for `size`, even though this
@@ -317,7 +321,7 @@ function formatValue(ctx, value, recurseTimes) {
317
321
keys . unshift ( 'size' ) ;
318
322
empty = value . size === 0 ;
319
323
formatter = formatSet ;
320
- } else if ( value instanceof Map ) {
324
+ } else if ( objectToString ( value ) === '[object Map]' ) {
321
325
braces = [ '{' , '}' ] ;
322
326
// Ditto.
323
327
if ( ctx . showHidden )
@@ -347,8 +351,7 @@ function formatValue(ctx, value, recurseTimes) {
347
351
'buffer' ) ;
348
352
}
349
353
} 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 ) ;
352
355
if ( promiseInternals ) {
353
356
braces = [ '{' , '}' ] ;
354
357
formatter = formatPromise ;
@@ -364,7 +367,8 @@ function formatValue(ctx, value, recurseTimes) {
364
367
empty = false ;
365
368
formatter = formatCollectionIterator ;
366
369
} else {
367
- if ( constructor === Object )
370
+ // Unset the constructor to prevent "Object {...}" for ordinary objects.
371
+ if ( constructor && constructor . name === 'Object' )
368
372
constructor = null ;
369
373
braces = [ '{' , '}' ] ;
370
374
empty = true ; // No other data than keys.
0 commit comments