@@ -2,18 +2,35 @@ import type { ArrayBufferReader } from '../utils/reader';
2
2
import type { ObjectInfo } from './types' ;
3
3
import { AssetType } from './types' ;
4
4
5
- const dumpObject = ( obj : any , isTop = false ) : any => {
5
+ const dumpObject = ( obj : any ) : any => {
6
6
if ( typeof obj === 'object' ) {
7
- if ( ! isTop && typeof obj . dump === 'function' ) return obj . dump ( ) ;
8
7
if ( Array . isArray ( obj ) ) return obj . map ( item => dumpObject ( item ) ) ;
8
+ if ( obj instanceof Map ) {
9
+ return Object . fromEntries ( Array . from ( obj . entries ( ) ) . map ( ( [ k , v ] ) => [ k , dumpObject ( v ) ] ) ) ;
10
+ }
11
+ if ( obj instanceof Set ) {
12
+ return Array . from ( obj . values ( ) ) . map ( item => dumpObject ( item ) ) ;
13
+ }
9
14
10
15
const result : any = { } ;
16
+
11
17
const className : string | undefined = obj . __class ;
12
18
if ( className ) result . __class = className ;
19
+
13
20
for ( const key in obj ) {
14
- if ( key . startsWith ( '__' ) || typeof obj [ key ] === 'function' ) continue ;
15
- result [ key ] = dumpObject ( obj [ key ] ) ;
21
+ const cur = obj [ key ] ;
22
+ if (
23
+ key . startsWith ( '__' ) ||
24
+ typeof cur === 'function' ||
25
+ cur instanceof ArrayBuffer ||
26
+ cur instanceof Uint8Array ||
27
+ ( typeof cur === 'object' && cur . __doNotDump )
28
+ ) {
29
+ continue ;
30
+ }
31
+ result [ key ] = typeof cur ?. dump === 'function' ? cur . dump ( ) : dumpObject ( cur ) ;
16
32
}
33
+
17
34
return result ;
18
35
}
19
36
@@ -45,6 +62,6 @@ export abstract class AssetBase {
45
62
}
46
63
47
64
dump ( ) : Record < string , any > {
48
- return dumpObject ( this , true ) ;
65
+ return dumpObject ( this ) ;
49
66
}
50
67
}
0 commit comments