@@ -212,7 +212,7 @@ export function debugObject (head) { return debugObjectNest(head); }
212212export function debugObjectHard ( head ) { return debugObjectNest ( head , 1 , true ) ; }
213213export function debugObjectType ( head ) { return debugObjectNest ( head , false , false ) ; }
214214
215- export function debugObjectNest ( head , nest = 1 , alwaysStringify = false ) {
215+ export function debugObjectNest ( head , nest = 1 , alwaysStringify = false , cache_ : ? Object ) {
216216 try {
217217 if ( head === null ) return "<null>" ;
218218 if ( head === undefined ) return "<undefined>" ;
@@ -243,17 +243,23 @@ export function debugObjectNest (head, nest = 1, alwaysStringify = false) {
243243 return `<${ ( head . constructor && head . constructor . name ) || "no-constructor" } keys.length=${
244244 Object . keys ( head ) . length } >`;
245245 }
246- return ( ( Array . isArray ( head )
247- && `[${ head . map ( entry => debugObjectNest ( entry , nest , alwaysStringify ) ) . join ( ", " ) } ]` )
248- || ( isIterable ( head ) && debugObjectNest ( head . toJS ( ) , nest , alwaysStringify ) )
249- || ( head [ Symbol . iterator ] && debugObjectNest ( [ ...head ] , nest , alwaysStringify ) )
246+ const cache = cache_ || new Map ( ) ;
247+ const circularIndex = cache . get ( head ) ;
248+ if ( circularIndex ) return `<Circular #${ circularIndex } : ${ debugObjectNest ( head , 0 ) } >` ;
249+ cache . set ( head , ( cache . objectIndex = ( cache . objectIndex || 0 ) + 1 ) ) ;
250+ return ( ( Array . isArray ( head ) && `[${
251+ head . map ( entry => debugObjectNest ( entry , nest , alwaysStringify , cache ) ) . join ( ", " ) } ]`)
252+ || ( isIterable ( head ) && debugObjectNest ( head . toJS ( ) , nest , alwaysStringify , cache ) )
253+ || ( head [ Symbol . iterator ] && debugObjectNest ( [ ...head ] , nest , alwaysStringify , cache ) )
250254 || `{ ${ Object . keys ( head )
251255 . map ( key => `${ isSymbol ( key ) ? key . toString ( ) : key } : ${
252- debugObjectNest ( head [ key ] , nest - 1 , alwaysStringify ) } `)
256+ debugObjectNest ( head [ key ] , nest - 1 , alwaysStringify , cache ) } `)
253257 . join ( ", " )
254258 } }`) ;
255259 } catch ( error ) {
256- console . error ( "Suppressed an error in debugObjectNest:" , error ,
260+ console . error ( "Suppressed an error in debugObjectNest:" ,
261+ "\n\terror.message:" , error . message ,
262+ "\n\terror.stack:" , error . stack ,
257263 "\n\treturning head:" , head ) ;
258264 }
259265 return head ;
0 commit comments