@@ -18,7 +18,7 @@ var functionToString = Function.prototype.toString;
18
18
var match = String . prototype . match ;
19
19
var bigIntValueOf = typeof BigInt === 'function' ? BigInt . prototype . valueOf : null ;
20
20
var gOPS = Object . getOwnPropertySymbols ;
21
- var symToString = typeof Symbol === 'function' ? Symbol . prototype . toString : null ;
21
+ var symToString = typeof Symbol === 'function' && typeof Symbol . iterator === 'symbol' ? Symbol . prototype . toString : null ;
22
22
var isEnumerable = Object . prototype . propertyIsEnumerable ;
23
23
24
24
var gPO = ( typeof Reflect === 'function' ? Reflect . getPrototypeOf : Object . getPrototypeOf ) || (
@@ -194,7 +194,7 @@ module.exports = function inspect_(obj, options, depth, seen) {
194
194
var ys = arrObjKeys ( obj , inspect ) ;
195
195
var isPlainObject = gPO ? gPO ( obj ) === Object . prototype : obj instanceof Object || obj . constructor === Object ;
196
196
var protoTag = obj instanceof Object ? '' : 'null prototype' ;
197
- var stringTag = ! isPlainObject && toStringTag && toStringTag in obj ? toStr ( obj ) . slice ( 8 , - 1 ) : protoTag ? 'Object' : '' ;
197
+ var stringTag = ! isPlainObject && toStringTag && Object ( obj ) === obj && toStringTag in obj ? toStr ( obj ) . slice ( 8 , - 1 ) : protoTag ? 'Object' : '' ;
198
198
var constructorTag = isPlainObject || typeof obj . constructor !== 'function' ? '' : obj . constructor . name ? obj . constructor . name + ' ' : '' ;
199
199
var tag = constructorTag + ( stringTag || protoTag ? '[' + [ ] . concat ( stringTag || [ ] , protoTag || [ ] ) . join ( ': ' ) + '] ' : '' ) ;
200
200
if ( ys . length === 0 ) { return tag + '{}' ; }
@@ -215,17 +215,28 @@ function quote(s) {
215
215
return String ( s ) . replace ( / " / g, '"' ) ;
216
216
}
217
217
218
- var hasToStringTag = typeof Symbol === 'function' && typeof Symbol . toStringTag === 'symbol' ;
218
+ function isArray ( obj ) { return toStr ( obj ) === '[object Array]' && ( ! toStringTag || ! ( typeof obj === 'object' && toStringTag in obj ) ) ; }
219
+ function isDate ( obj ) { return toStr ( obj ) === '[object Date]' && ( ! toStringTag || ! ( typeof obj === 'object' && toStringTag in obj ) ) ; }
220
+ function isRegExp ( obj ) { return toStr ( obj ) === '[object RegExp]' && ( ! toStringTag || ! ( typeof obj === 'object' && toStringTag in obj ) ) ; }
221
+ function isError ( obj ) { return toStr ( obj ) === '[object Error]' && ( ! toStringTag || ! ( typeof obj === 'object' && toStringTag in obj ) ) ; }
222
+ function isString ( obj ) { return toStr ( obj ) === '[object String]' && ( ! toStringTag || ! ( typeof obj === 'object' && toStringTag in obj ) ) ; }
223
+ function isNumber ( obj ) { return toStr ( obj ) === '[object Number]' && ( ! toStringTag || ! ( typeof obj === 'object' && toStringTag in obj ) ) ; }
224
+ function isBoolean ( obj ) { return toStr ( obj ) === '[object Boolean]' && ( ! toStringTag || ! ( typeof obj === 'object' && toStringTag in obj ) ) ; }
219
225
220
- function isArray ( obj ) { return toStr ( obj ) === '[object Array]' && ( ! hasToStringTag || ! ( Symbol . toStringTag in obj ) ) ; }
221
- function isDate ( obj ) { return toStr ( obj ) === '[object Date]' && ( ! hasToStringTag || ! ( Symbol . toStringTag in obj ) ) ; }
222
- function isRegExp ( obj ) { return toStr ( obj ) === '[object RegExp]' && ( ! hasToStringTag || ! ( Symbol . toStringTag in obj ) ) ; }
223
- function isError ( obj ) { return toStr ( obj ) === '[object Error]' && ( ! hasToStringTag || ! ( Symbol . toStringTag in obj ) ) ; }
224
- function isString ( obj ) { return toStr ( obj ) === '[object String]' && ( ! hasToStringTag || ! ( Symbol . toStringTag in obj ) ) ; }
225
- function isNumber ( obj ) { return toStr ( obj ) === '[object Number]' && ( ! hasToStringTag || ! ( Symbol . toStringTag in obj ) ) ; }
226
- function isBoolean ( obj ) { return toStr ( obj ) === '[object Boolean]' && ( ! hasToStringTag || ! ( Symbol . toStringTag in obj ) ) ; }
227
226
// Symbol and BigInt do have Symbol.toStringTag by spec, so that can't be used to eliminate false positives
228
- function isSymbol ( obj ) { return toStr ( obj ) === '[object Symbol]' ; }
227
+ function isSymbol ( obj ) {
228
+ if ( typeof obj === 'symbol' ) {
229
+ return true ;
230
+ }
231
+ if ( ! obj || typeof obj !== 'object' || ! symToString ) {
232
+ return false ;
233
+ }
234
+ try {
235
+ symToString . call ( obj ) ;
236
+ return true ;
237
+ } catch ( e ) { }
238
+ return false ;
239
+ }
229
240
230
241
function isBigInt ( obj ) {
231
242
if ( ! obj || typeof obj !== 'object' || ! bigIntValueOf ) {
0 commit comments