@@ -11,6 +11,7 @@ import {
1111import * as JSValue from "./js-value.js" ;
1212import { Memory } from "./memory.js" ;
1313import { deserializeError , MainToWorkerMessage , MessageBroker , ResponseMessage , ITCInterface , serializeError , SwiftRuntimeThreadChannel , WorkerToMainMessage } from "./itc.js" ;
14+ import { decodeObjectRefs } from "./js-value.js" ;
1415
1516export type SwiftRuntimeOptions = {
1617 /**
@@ -208,7 +209,7 @@ export class SwiftRuntime {
208209 } catch ( error ) {
209210 responseMessage . data . response = {
210211 ok : false ,
211- error : serializeError ( new TypeError ( `Failed to serialize response message: ${ error } ` ) )
212+ error : serializeError ( new TypeError ( `Failed to serialize message: ${ error } ` ) )
212213 } ;
213214 newBroker . reply ( responseMessage ) ;
214215 }
@@ -648,24 +649,56 @@ export class SwiftRuntime {
648649 // Main thread's tid is always -1
649650 return this . tid || - 1 ;
650651 } ,
651- swjs_request_transferring_object : (
652- object_ref : ref ,
652+ swjs_request_sending_object : (
653+ sending_object : ref ,
654+ transferring_objects : pointer ,
655+ transferring_objects_count : number ,
653656 object_source_tid : number ,
654- transferring : pointer ,
657+ sending_context : pointer ,
655658 ) => {
656659 if ( ! this . options . threadChannel ) {
657660 throw new Error ( "threadChannel is not set in options given to SwiftRuntime. Please set it to request transferring objects." ) ;
658661 }
659662 const broker = getMessageBroker ( this . options . threadChannel ) ;
663+ const memory = this . memory ;
664+ const transferringObjects = decodeObjectRefs ( transferring_objects , transferring_objects_count , memory ) ;
665+ broker . request ( {
666+ type : "request" ,
667+ data : {
668+ sourceTid : this . tid ?? MAIN_THREAD_TID ,
669+ targetTid : object_source_tid ,
670+ context : sending_context ,
671+ request : {
672+ method : "send" ,
673+ parameters : [ sending_object , transferringObjects , sending_context ] ,
674+ }
675+ }
676+ } )
677+ } ,
678+ swjs_request_sending_objects : (
679+ sending_objects : pointer ,
680+ sending_objects_count : number ,
681+ transferring_objects : pointer ,
682+ transferring_objects_count : number ,
683+ object_source_tid : number ,
684+ sending_context : pointer ,
685+ ) => {
686+ if ( ! this . options . threadChannel ) {
687+ throw new Error ( "threadChannel is not set in options given to SwiftRuntime. Please set it to request transferring objects." ) ;
688+ }
689+ const broker = getMessageBroker ( this . options . threadChannel ) ;
690+ const memory = this . memory ;
691+ const sendingObjects = decodeObjectRefs ( sending_objects , sending_objects_count , memory ) ;
692+ const transferringObjects = decodeObjectRefs ( transferring_objects , transferring_objects_count , memory ) ;
660693 broker . request ( {
661694 type : "request" ,
662695 data : {
663696 sourceTid : this . tid ?? MAIN_THREAD_TID ,
664697 targetTid : object_source_tid ,
665- context : transferring ,
698+ context : sending_context ,
666699 request : {
667- method : "transfer " ,
668- parameters : [ object_ref , transferring ] ,
700+ method : "sendObjects " ,
701+ parameters : [ sendingObjects , transferringObjects , sending_context ] ,
669702 }
670703 }
671704 } )
0 commit comments