@@ -19,8 +19,17 @@ var gOPS = Object.getOwnPropertySymbols;
19
19
var symToString = typeof Symbol === 'function' ? Symbol . prototype . toString : null ;
20
20
var isEnumerable = Object . prototype . propertyIsEnumerable ;
21
21
22
+ var gPO = ( typeof Reflect === 'function' ? Reflect . getPrototypeOf : Object . getPrototypeOf ) || (
23
+ [ ] . __proto__ === Array . prototype // eslint-disable-line no-proto
24
+ ? function ( O ) {
25
+ return O . __proto__ ; // eslint-disable-line no-proto
26
+ }
27
+ : null
28
+ ) ;
29
+
22
30
var inspectCustom = require ( './util.inspect' ) . custom ;
23
31
var inspectSymbol = inspectCustom && isSymbol ( inspectCustom ) ? inspectCustom : null ;
32
+ var toStringTag = typeof Symbol === 'function' && typeof Symbol . toStringTag === 'symbol' ? Symbol . toStringTag : null ;
24
33
25
34
module . exports = function inspect_ ( obj , options , depth , seen ) {
26
35
var opts = options || { } ;
@@ -178,11 +187,16 @@ module.exports = function inspect_(obj, options, depth, seen) {
178
187
}
179
188
if ( ! isDate ( obj ) && ! isRegExp ( obj ) ) {
180
189
var ys = arrObjKeys ( obj , inspect ) ;
181
- if ( ys . length === 0 ) { return '{}' ; }
190
+ var isPlainObject = gPO ? gPO ( obj ) === Object . prototype : obj instanceof Object || obj . constructor === Object ;
191
+ var protoTag = obj instanceof Object ? '' : 'null prototype' ;
192
+ var stringTag = ! isPlainObject && toStringTag && toStringTag in obj ? toStr ( obj ) . slice ( 8 , - 1 ) : protoTag ? 'Object' : '' ;
193
+ var constructorTag = isPlainObject || typeof obj . constructor !== 'function' ? '' : obj . constructor . name ? obj . constructor . name + ' ' : '' ;
194
+ var tag = constructorTag + ( stringTag || protoTag ? '[' + [ ] . concat ( stringTag || [ ] , protoTag || [ ] ) . join ( ': ' ) + '] ' : '' ) ;
195
+ if ( ys . length === 0 ) { return tag + '{}' ; }
182
196
if ( indent ) {
183
- return '{' + indentedJoin ( ys , indent ) + '}' ;
197
+ return tag + '{' + indentedJoin ( ys , indent ) + '}' ;
184
198
}
185
- return '{ ' + ys . join ( ', ' ) + ' }' ;
199
+ return tag + '{ ' + ys . join ( ', ' ) + ' }' ;
186
200
}
187
201
return String ( obj ) ;
188
202
} ;
0 commit comments