@@ -289,35 +289,27 @@ function cbProxy(cb, callPath = [], target = function () { }) {
289
289
}
290
290
} ) ;
291
291
}
292
- function isTransferable ( thing ) {
293
- return TRANSFERABLE_TYPES . some ( type => thing instanceof type ) ;
294
- }
295
- function * iterateAllProperties ( value , path = [ ] , visited = null ) {
296
- if ( ! value )
297
- return ;
298
- if ( ! visited )
299
- visited = new WeakSet ( ) ;
300
- if ( visited . has ( value ) )
301
- return ;
302
- if ( typeof value === "string" )
292
+ function findTransferables ( value , accumulator ) {
293
+ if ( typeof value !== "object" || value == null ) {
303
294
return ;
304
- if ( typeof value === "object" )
305
- visited . add ( value ) ;
295
+ }
306
296
if ( ArrayBuffer . isView ( value ) ) {
307
- yield { value : value . buffer , path : [ ... path , 'buffer' ] } ;
297
+ accumulator . push ( value . buffer ) ;
308
298
return ;
309
299
}
310
- yield { value, path } ;
311
- const keys = Object . keys ( value ) ;
312
- for ( const key of keys )
313
- yield * iterateAllProperties ( value [ key ] , [ ...path , key ] , visited ) ;
300
+ for ( const type of TRANSFERABLE_TYPES ) {
301
+ if ( value instanceof type ) {
302
+ accumulator . push ( value ) ;
303
+ return ;
304
+ }
305
+ }
306
+ for ( let key in obj ) {
307
+ findTransferables ( obj [ key ] , accumulator ) ;
308
+ }
314
309
}
315
310
function transferableProperties ( obj ) {
316
- const r = [ ] ;
317
- for ( const prop of iterateAllProperties ( obj ) ) {
318
- if ( isTransferable ( prop . value ) )
319
- r . push ( prop . value ) ;
320
- }
311
+ const accumulator = [ ] ;
312
+ findTransferables ( obj , accumulator ) ;
321
313
return r ;
322
314
}
323
315
function makeInvocationResult ( obj ) {
0 commit comments