@@ -678,22 +678,29 @@ export function inspect(v) {
678
678
if ( t === "string" ) return inspectString ( v ) ;
679
679
if ( t === "bigint" || Number . isInteger ( v ) ) return v . toString ( ) ;
680
680
if ( t === "number" ) return float_to_string ( v ) ;
681
- if ( Array . isArray ( v ) ) return `#(${ v . map ( inspect ) . join ( ", " ) } )` ;
682
- if ( v instanceof List ) return inspectList ( v ) ;
683
681
if ( v instanceof UtfCodepoint ) return inspectUtfCodepoint ( v ) ;
684
682
if ( v instanceof BitArray ) return `<<${ bit_array_inspect ( v , "" ) } >>` ;
685
- if ( v instanceof CustomType ) return inspectCustomType ( v ) ;
686
- if ( v instanceof Dict ) return inspectDict ( v ) ;
687
- if ( v instanceof Set ) return `//js(Set(${ [ ...v ] . map ( inspect ) . join ( ", " ) } ))` ;
688
683
if ( v instanceof RegExp ) return `//js(${ v } )` ;
689
684
if ( v instanceof Date ) return `//js(Date("${ v . toISOString ( ) } "))` ;
685
+ if ( v instanceof globalThis . Error ) return `//js(${ v . toString ( ) } )` ;
690
686
if ( v instanceof Function ) {
691
687
const args = [ ] ;
692
688
for ( const i of Array ( v . length ) . keys ( ) )
693
689
args . push ( String . fromCharCode ( i + 97 ) ) ;
694
690
return `//fn(${ args . join ( ", " ) } ) { ... }` ;
695
691
}
696
- return inspectObject ( v ) ;
692
+
693
+ try {
694
+ if ( Array . isArray ( v ) ) return `#(${ v . map ( inspect ) . join ( ", " ) } )` ;
695
+ if ( v instanceof List ) return inspectList ( v ) ;
696
+ if ( v instanceof CustomType ) return inspectCustomType ( v ) ;
697
+ if ( v instanceof Dict ) return inspectDict ( v ) ;
698
+ if ( v instanceof Set ) return `//js(Set(${ [ ...v ] . map ( inspect ) . join ( ", " ) } ))` ;
699
+ return inspectObject ( v ) ;
700
+ } catch ( e ) {
701
+ if ( e instanceof RangeError ) return "//js(circular)" ;
702
+ throw e ;
703
+ }
697
704
}
698
705
699
706
function inspectString ( str ) {
0 commit comments