@@ -6,6 +6,10 @@ var hasSet = typeof Set === 'function' && Set.prototype;
66var setSizeDescriptor = Object . getOwnPropertyDescriptor && hasSet ? Object . getOwnPropertyDescriptor ( Set . prototype , 'size' ) : null ;
77var setSize = hasSet && setSizeDescriptor && typeof setSizeDescriptor . get === 'function' ? setSizeDescriptor . get : null ;
88var setForEach = hasSet && Set . prototype . forEach ;
9+ var hasWeakMap = typeof WeakMap === 'function' && WeakMap . prototype ;
10+ var weakMapHas = hasWeakMap ? WeakMap . prototype . has : null ;
11+ var hasWeakSet = typeof WeakSet === 'function' && WeakSet . prototype ;
12+ var weakSetHas = hasWeakSet ? WeakSet . prototype . has : null ;
913var booleanValueOf = Boolean . prototype . valueOf ;
1014var objectToString = Object . prototype . toString ;
1115var match = String . prototype . match ;
@@ -113,6 +117,12 @@ module.exports = function inspect_(obj, options, depth, seen) {
113117 } ) ;
114118 return collectionOf ( 'Set' , setSize . call ( obj ) , setParts ) ;
115119 }
120+ if ( isWeakMap ( obj ) ) {
121+ return weakCollectionOf ( 'WeakMap' ) ;
122+ }
123+ if ( isWeakSet ( obj ) ) {
124+ return weakCollectionOf ( 'WeakSet' ) ;
125+ }
116126 if ( isNumber ( obj ) ) {
117127 return markBoxed ( inspect ( Number ( obj ) ) ) ;
118128 }
@@ -192,6 +202,22 @@ function isMap(x) {
192202 return false ;
193203}
194204
205+ function isWeakMap ( x ) {
206+ if ( ! weakMapHas || ! x || typeof x !== 'object' ) {
207+ return false ;
208+ }
209+ try {
210+ weakMapHas . call ( x , weakMapHas ) ;
211+ try {
212+ weakSetHas . call ( x , weakSetHas ) ;
213+ } catch ( s ) {
214+ return true ;
215+ }
216+ return x instanceof WeakMap ; // core-js workaround, pre-v2.5.0
217+ } catch ( e ) { }
218+ return false ;
219+ }
220+
195221function isSet ( x ) {
196222 if ( ! setSize || ! x || typeof x !== 'object' ) {
197223 return false ;
@@ -208,6 +234,22 @@ function isSet(x) {
208234 return false ;
209235}
210236
237+ function isWeakSet ( x ) {
238+ if ( ! weakSetHas || ! x || typeof x !== 'object' ) {
239+ return false ;
240+ }
241+ try {
242+ weakSetHas . call ( x , weakSetHas ) ;
243+ try {
244+ weakMapHas . call ( x , weakMapHas ) ;
245+ } catch ( s ) {
246+ return true ;
247+ }
248+ return x instanceof WeakSet ; // core-js workaround, pre-v2.5.0
249+ } catch ( e ) { }
250+ return false ;
251+ }
252+
211253function isElement ( x ) {
212254 if ( ! x || typeof x !== 'object' ) { return false ; }
213255 if ( typeof HTMLElement !== 'undefined' && x instanceof HTMLElement ) {
@@ -235,6 +277,10 @@ function markBoxed(str) {
235277 return 'Object(' + str + ')' ;
236278}
237279
280+ function weakCollectionOf ( type ) {
281+ return type + ' { ? }' ;
282+ }
283+
238284function collectionOf ( type , size , entries ) {
239285 return type + ' (' + size + ') {' + entries . join ( ', ' ) + '}' ;
240286}
0 commit comments