char/avril
(wip) why'd you have to go and make things so complicaaaaated?
git clone https://git.t4t.associates/char/avril
c42f8c8
main
1import { 2ObjectDefineProperty as define , 3ReflectApply as apply , 4SymbolIterator , 5TypeError , 6} from "ext:core/primordials" ; 7import { clone } from "ext:core/structured_clone" ; 8import { array , dictionary , isObject , required } from "ext:web/idl.js" ; 9import { 10classify , 11setStructuredClone , 12transferCallbacks , 13} from "ext:web/serialization.js" ; 14import { dataCloneError } from "ext:web/events.js" ; 15const structuredClone = { 16structuredClone ( value :unknown , options :unknown = undefined ) :unknown { 17required ( arguments . length , 1 ); 18const raw = dictionary ( options ). transfer , transfer = array < object >(); 19if ( raw !== undefined ) { 20if ( ! isObject ( raw )) { 21throw new TypeError ( "Transfer list must be a sequence" ); 22} 23const method = raw [ SymbolIterator ]; 24if ( typeof method !== "function" ) { 25throw new TypeError ( "Transfer list must be iterable" ); 26} 27const iterator = apply ( method , raw , []); 28if ( ! isObject ( iterator )) throw new TypeError ( "Invalid transfer iterator" ); 29const next = iterator . next ; 30if ( typeof next !== "function" ) { 31throw new TypeError ( "Invalid transfer iterator next method" ); 32} 33while ( true ) { 34const step = apply ( next , iterator , []); 35if ( ! isObject ( step )) { 36throw new TypeError ( "Invalid transfer iterator result" ); 37} 38if ( step . done ) break ; 39const item = step . value ; 40if ( ! isObject ( item )) { 41throw new TypeError ( "Transfer entries must be objects" ); 42} 43transfer [ transfer . length ] = item ; 44} 45} 46const callbacks = transferCallbacks ( transfer , dataCloneError ); 47try { 48return clone ( 49value , 50transfer , 51classify , 52callbacks . cloneHost , 53dataCloneError , 54callbacks . prepare , 55callbacks . validate , 56callbacks . commit , 57); 58} finally { 59callbacks . clear (); 60} 61}, 62}. structuredClone ; 63define ( globalThis , "structuredClone" , { 64value :structuredClone , 65writable :true , 66configurable :true , 67enumerable :true , 68}); 69setStructuredClone ( structuredClone ); 70export { structuredClone };