@@ -141,7 +141,7 @@ export class SwiftRuntime {
141141 private instance : WebAssembly . Instance | null ;
142142 private heap : SwiftRuntimeHeap ;
143143 private _closureHeap : SwiftClosureHeap | null ;
144- private version : number = 702 ;
144+ private version : number = 703 ;
145145
146146 constructor ( ) {
147147 this . instance = null ;
@@ -154,7 +154,11 @@ export class SwiftRuntime {
154154 const exports = ( this . instance
155155 . exports as any ) as SwiftRuntimeExportedFunctions ;
156156 if ( exports . swjs_library_version ( ) != this . version ) {
157- throw new Error ( `The versions of JavaScriptKit are incompatible. ${ exports . swjs_library_version ( ) } != ${ this . version } ` ) ;
157+ throw new Error (
158+ `The versions of JavaScriptKit are incompatible. ${ exports . swjs_library_version ( ) } != ${
159+ this . version
160+ } `
161+ ) ;
158162 }
159163 }
160164 get closureHeap ( ) : SwiftClosureHeap | null {
@@ -386,6 +390,7 @@ export class SwiftRuntime {
386390 decodeValue ( kind , payload1 , payload2 )
387391 ) ;
388392 } ,
393+
389394 swjs_get_prop : (
390395 ref : ref ,
391396 name : ref ,
@@ -397,6 +402,7 @@ export class SwiftRuntime {
397402 const result = Reflect . get ( obj , readString ( name ) ) ;
398403 writeValue ( result , kind_ptr , payload1_ptr , payload2_ptr , false ) ;
399404 } ,
405+
400406 swjs_set_subscript : (
401407 ref : ref ,
402408 index : number ,
@@ -407,6 +413,7 @@ export class SwiftRuntime {
407413 const obj = this . heap . referenceHeap ( ref ) ;
408414 Reflect . set ( obj , index , decodeValue ( kind , payload1 , payload2 ) ) ;
409415 } ,
416+
410417 swjs_get_subscript : (
411418 ref : ref ,
412419 index : number ,
@@ -418,12 +425,14 @@ export class SwiftRuntime {
418425 const result = Reflect . get ( obj , index ) ;
419426 writeValue ( result , kind_ptr , payload1_ptr , payload2_ptr , false ) ;
420427 } ,
428+
421429 swjs_encode_string : ( ref : ref , bytes_ptr_result : pointer ) => {
422430 const bytes = textEncoder . encode ( this . heap . referenceHeap ( ref ) ) ;
423431 const bytes_ptr = this . heap . retain ( bytes ) ;
424432 writeUint32 ( bytes_ptr_result , bytes_ptr ) ;
425433 return bytes . length ;
426434 } ,
435+
427436 swjs_decode_string : ( bytes_ptr : pointer , length : number ) => {
428437 const uint8Memory = new Uint8Array ( memory ( ) . buffer ) ;
429438 const bytes = uint8Memory . subarray (
@@ -433,10 +442,12 @@ export class SwiftRuntime {
433442 const string = textDecoder . decode ( bytes ) ;
434443 return this . heap . retain ( string ) ;
435444 } ,
445+
436446 swjs_load_string : ( ref : ref , buffer : pointer ) => {
437447 const bytes = this . heap . referenceHeap ( ref ) ;
438448 writeString ( buffer , bytes ) ;
439449 } ,
450+
440451 swjs_call_function : (
441452 ref : ref ,
442453 argv : pointer ,
@@ -465,6 +476,7 @@ export class SwiftRuntime {
465476 }
466477 writeValue ( result , kind_ptr , payload1_ptr , payload2_ptr , false ) ;
467478 } ,
479+
468480 swjs_call_function_with_this : (
469481 obj_ref : ref ,
470482 func_ref : ref ,
@@ -491,33 +503,30 @@ export class SwiftRuntime {
491503 }
492504 writeValue ( result , kind_ptr , payload1_ptr , payload2_ptr , false ) ;
493505 } ,
494- swjs_create_function : (
495- host_func_id : number ,
496- func_ref_ptr : pointer
497- ) => {
498- const func = function ( ) {
499- return callHostFunction (
500- host_func_id ,
501- Array . prototype . slice . call ( arguments )
502- ) ;
503- } ;
504- const func_ref = this . heap . retain ( func ) ;
505- this . closureHeap ?. alloc ( func , func_ref ) ;
506- writeUint32 ( func_ref_ptr , func_ref ) ;
506+ swjs_call_new : ( ref : ref , argv : pointer , argc : number ) => {
507+ const constructor = this . heap . referenceHeap ( ref ) ;
508+ const instance = Reflect . construct (
509+ constructor ,
510+ decodeValues ( argv , argc )
511+ ) ;
512+ return this . heap . retain ( instance ) ;
507513 } ,
514+
508515 swjs_call_throwing_new : (
509516 ref : ref ,
510517 argv : pointer ,
511518 argc : number ,
512- result_obj : pointer ,
513519 exception_kind_ptr : pointer ,
514520 exception_payload1_ptr : pointer ,
515521 exception_payload2_ptr : pointer
516522 ) => {
517- const obj = this . heap . referenceHeap ( ref ) ;
523+ const constructor = this . heap . referenceHeap ( ref ) ;
518524 let result : any ;
519525 try {
520- result = Reflect . construct ( obj , decodeValues ( argv , argc ) ) ;
526+ result = Reflect . construct (
527+ constructor ,
528+ decodeValues ( argv , argc )
529+ ) ;
521530 } catch ( error ) {
522531 writeValue (
523532 error ,
@@ -526,30 +535,40 @@ export class SwiftRuntime {
526535 exception_payload2_ptr ,
527536 true
528537 ) ;
529- return ;
538+ return - 1 ;
530539 }
531- writeUint32 ( result_obj , this . heap . retain ( result ) ) ;
532- } ,
533- swjs_call_new : (
534- ref : ref ,
535- argv : pointer ,
536- argc : number ,
537- result_obj : pointer
538- ) => {
539- const obj = this . heap . referenceHeap ( ref ) ;
540- const result = Reflect . construct ( obj , decodeValues ( argv , argc ) ) ;
541- writeUint32 ( result_obj , this . heap . retain ( result ) ) ;
540+ writeValue (
541+ null ,
542+ exception_kind_ptr ,
543+ exception_payload1_ptr ,
544+ exception_payload2_ptr ,
545+ false
546+ ) ;
547+ return this . heap . retain ( result ) ;
542548 } ,
549+
543550 swjs_instanceof : ( obj_ref : ref , constructor_ref : ref ) => {
544551 const obj = this . heap . referenceHeap ( obj_ref ) ;
545552 const constructor = this . heap . referenceHeap ( constructor_ref ) ;
546553 return obj instanceof constructor ;
547554 } ,
555+
556+ swjs_create_function : ( host_func_id : number ) => {
557+ const func = function ( ) {
558+ return callHostFunction (
559+ host_func_id ,
560+ Array . prototype . slice . call ( arguments )
561+ ) ;
562+ } ;
563+ const func_ref = this . heap . retain ( func ) ;
564+ this . closureHeap ?. alloc ( func , func_ref ) ;
565+ return func_ref ;
566+ } ,
567+
548568 swjs_create_typed_array : (
549569 constructor_ref : ref ,
550570 elementsPtr : pointer ,
551- length : number ,
552- result_obj : pointer
571+ length : number
553572 ) => {
554573 const ArrayType : TypedArray = this . heap . referenceHeap (
555574 constructor_ref
@@ -560,8 +579,9 @@ export class SwiftRuntime {
560579 length
561580 ) ;
562581 // Call `.slice()` to copy the memory
563- writeUint32 ( result_obj , this . heap . retain ( array . slice ( ) ) ) ;
582+ return this . heap . retain ( array . slice ( ) ) ;
564583 } ,
584+
565585 swjs_release : ( ref : ref ) => {
566586 this . heap . release ( ref ) ;
567587 } ,
0 commit comments