@@ -11,6 +11,7 @@ import {
11
11
import * as JSValue from "./js-value.js" ;
12
12
import { Memory } from "./memory.js" ;
13
13
import { deserializeError , MainToWorkerMessage , MessageBroker , ResponseMessage , ITCInterface , serializeError , SwiftRuntimeThreadChannel , WorkerToMainMessage } from "./itc.js" ;
14
+ import { decodeObjectRefs } from "./js-value.js" ;
14
15
15
16
export type SwiftRuntimeOptions = {
16
17
/**
@@ -208,7 +209,7 @@ export class SwiftRuntime {
208
209
} catch ( error ) {
209
210
responseMessage . data . response = {
210
211
ok : false ,
211
- error : serializeError ( new TypeError ( `Failed to serialize response message: ${ error } ` ) )
212
+ error : serializeError ( new TypeError ( `Failed to serialize message: ${ error } ` ) )
212
213
} ;
213
214
newBroker . reply ( responseMessage ) ;
214
215
}
@@ -648,24 +649,56 @@ export class SwiftRuntime {
648
649
// Main thread's tid is always -1
649
650
return this . tid || - 1 ;
650
651
} ,
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 ,
653
656
object_source_tid : number ,
654
- transferring : pointer ,
657
+ sending_context : pointer ,
655
658
) => {
656
659
if ( ! this . options . threadChannel ) {
657
660
throw new Error ( "threadChannel is not set in options given to SwiftRuntime. Please set it to request transferring objects." ) ;
658
661
}
659
662
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 ) ;
660
693
broker . request ( {
661
694
type : "request" ,
662
695
data : {
663
696
sourceTid : this . tid ?? MAIN_THREAD_TID ,
664
697
targetTid : object_source_tid ,
665
- context : transferring ,
698
+ context : sending_context ,
666
699
request : {
667
- method : "transfer " ,
668
- parameters : [ object_ref , transferring ] ,
700
+ method : "sendObjects " ,
701
+ parameters : [ sendingObjects , transferringObjects , sending_context ] ,
669
702
}
670
703
}
671
704
} )
0 commit comments