@@ -109,6 +109,10 @@ function replacer (key) {
109
109
return NEGATIVE_INFINITY
110
110
} else if ( Number . isNaN ( val ) ) {
111
111
return NAN
112
+ } else if ( isMap ( val ) ) {
113
+ return encodeCache . cache ( val , ( ) => getCustomMapDetails ( val ) )
114
+ } else if ( isSet ( val ) ) {
115
+ return encodeCache . cache ( val , ( ) => getCustomSetDetails ( val ) )
112
116
} else if ( val instanceof RegExp ) {
113
117
// special handling of native type
114
118
return `[native RegExp ${ val . toString ( ) } ]`
@@ -131,6 +135,67 @@ function replacer (key) {
131
135
return sanitize ( val )
132
136
}
133
137
138
+ export function isMap ( obj ) {
139
+ return obj instanceof Map
140
+ }
141
+
142
+ export function getCustomMapDetails ( val ) {
143
+ const list = [ ]
144
+ val . forEach (
145
+ ( key , value ) => list . push ( {
146
+ key,
147
+ value
148
+ } )
149
+ )
150
+ return {
151
+ _custom : {
152
+ type : 'map' ,
153
+ display : 'Map' ,
154
+ value : list ,
155
+ readOnly : true ,
156
+ fields : {
157
+ abstract : true
158
+ }
159
+ }
160
+ }
161
+ }
162
+
163
+ export function reviveMap ( val ) {
164
+ const result = new Map ( )
165
+ const list = val . _custom . value
166
+ for ( let i = 0 ; i < list . length ; i ++ ) {
167
+ const { key, value } = list [ i ]
168
+ result . set ( key , reviver ( null , value ) )
169
+ }
170
+ return result
171
+ }
172
+
173
+ export function isSet ( obj ) {
174
+ return obj instanceof Set
175
+ }
176
+
177
+ export function getCustomSetDetails ( val ) {
178
+ const list = Array . from ( val )
179
+ return {
180
+ _custom : {
181
+ type : 'set' ,
182
+ display : `Set[${ list . length } ]` ,
183
+ value : list ,
184
+ readOnly : true
185
+ }
186
+ }
187
+ }
188
+
189
+ export function reviveSet ( val ) {
190
+ const result = new Set ( )
191
+ const list = val . _custom . value
192
+ for ( let i = 0 ; i < list . length ; i ++ ) {
193
+ const value = list [ i ]
194
+ result . add ( reviver ( null , value ) )
195
+ }
196
+ return result
197
+ }
198
+
134
199
export function isComponentDefinition ( val ) {
135
200
return val && typeof val . render === 'function'
136
201
}
@@ -206,6 +271,10 @@ function reviver (key, val) {
206
271
} else if ( val && val . _custom ) {
207
272
if ( val . _custom . type === 'component' ) {
208
273
return instanceMap . get ( val . _custom . id )
274
+ } else if ( val . _custom . type === 'map' ) {
275
+ return reviveMap ( val )
276
+ } else if ( val . _custom . type === 'set' ) {
277
+ return reviveSet ( val )
209
278
}
210
279
} else if ( specialTypeRE . test ( val ) ) {
211
280
const [ , type , string ] = specialTypeRE . exec ( val )
0 commit comments