@@ -141,7 +141,7 @@ export class SwiftRuntime {
141
141
private instance : WebAssembly . Instance | null ;
142
142
private heap : SwiftRuntimeHeap ;
143
143
private _closureHeap : SwiftClosureHeap | null ;
144
- private version : number = 702 ;
144
+ private version : number = 703 ;
145
145
146
146
constructor ( ) {
147
147
this . instance = null ;
@@ -154,7 +154,11 @@ export class SwiftRuntime {
154
154
const exports = ( this . instance
155
155
. exports as any ) as SwiftRuntimeExportedFunctions ;
156
156
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
+ ) ;
158
162
}
159
163
}
160
164
get closureHeap ( ) : SwiftClosureHeap | null {
@@ -386,6 +390,7 @@ export class SwiftRuntime {
386
390
decodeValue ( kind , payload1 , payload2 )
387
391
) ;
388
392
} ,
393
+
389
394
swjs_get_prop : (
390
395
ref : ref ,
391
396
name : ref ,
@@ -397,6 +402,7 @@ export class SwiftRuntime {
397
402
const result = Reflect . get ( obj , readString ( name ) ) ;
398
403
writeValue ( result , kind_ptr , payload1_ptr , payload2_ptr , false ) ;
399
404
} ,
405
+
400
406
swjs_set_subscript : (
401
407
ref : ref ,
402
408
index : number ,
@@ -407,6 +413,7 @@ export class SwiftRuntime {
407
413
const obj = this . heap . referenceHeap ( ref ) ;
408
414
Reflect . set ( obj , index , decodeValue ( kind , payload1 , payload2 ) ) ;
409
415
} ,
416
+
410
417
swjs_get_subscript : (
411
418
ref : ref ,
412
419
index : number ,
@@ -418,12 +425,14 @@ export class SwiftRuntime {
418
425
const result = Reflect . get ( obj , index ) ;
419
426
writeValue ( result , kind_ptr , payload1_ptr , payload2_ptr , false ) ;
420
427
} ,
428
+
421
429
swjs_encode_string : ( ref : ref , bytes_ptr_result : pointer ) => {
422
430
const bytes = textEncoder . encode ( this . heap . referenceHeap ( ref ) ) ;
423
431
const bytes_ptr = this . heap . retain ( bytes ) ;
424
432
writeUint32 ( bytes_ptr_result , bytes_ptr ) ;
425
433
return bytes . length ;
426
434
} ,
435
+
427
436
swjs_decode_string : ( bytes_ptr : pointer , length : number ) => {
428
437
const uint8Memory = new Uint8Array ( memory ( ) . buffer ) ;
429
438
const bytes = uint8Memory . subarray (
@@ -433,10 +442,12 @@ export class SwiftRuntime {
433
442
const string = textDecoder . decode ( bytes ) ;
434
443
return this . heap . retain ( string ) ;
435
444
} ,
445
+
436
446
swjs_load_string : ( ref : ref , buffer : pointer ) => {
437
447
const bytes = this . heap . referenceHeap ( ref ) ;
438
448
writeString ( buffer , bytes ) ;
439
449
} ,
450
+
440
451
swjs_call_function : (
441
452
ref : ref ,
442
453
argv : pointer ,
@@ -465,6 +476,7 @@ export class SwiftRuntime {
465
476
}
466
477
writeValue ( result , kind_ptr , payload1_ptr , payload2_ptr , false ) ;
467
478
} ,
479
+
468
480
swjs_call_function_with_this : (
469
481
obj_ref : ref ,
470
482
func_ref : ref ,
@@ -491,33 +503,30 @@ export class SwiftRuntime {
491
503
}
492
504
writeValue ( result , kind_ptr , payload1_ptr , payload2_ptr , false ) ;
493
505
} ,
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 ) ;
507
513
} ,
514
+
508
515
swjs_call_throwing_new : (
509
516
ref : ref ,
510
517
argv : pointer ,
511
518
argc : number ,
512
- result_obj : pointer ,
513
519
exception_kind_ptr : pointer ,
514
520
exception_payload1_ptr : pointer ,
515
521
exception_payload2_ptr : pointer
516
522
) => {
517
- const obj = this . heap . referenceHeap ( ref ) ;
523
+ const constructor = this . heap . referenceHeap ( ref ) ;
518
524
let result : any ;
519
525
try {
520
- result = Reflect . construct ( obj , decodeValues ( argv , argc ) ) ;
526
+ result = Reflect . construct (
527
+ constructor ,
528
+ decodeValues ( argv , argc )
529
+ ) ;
521
530
} catch ( error ) {
522
531
writeValue (
523
532
error ,
@@ -526,30 +535,40 @@ export class SwiftRuntime {
526
535
exception_payload2_ptr ,
527
536
true
528
537
) ;
529
- return ;
538
+ return - 1 ;
530
539
}
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 ) ;
542
548
} ,
549
+
543
550
swjs_instanceof : ( obj_ref : ref , constructor_ref : ref ) => {
544
551
const obj = this . heap . referenceHeap ( obj_ref ) ;
545
552
const constructor = this . heap . referenceHeap ( constructor_ref ) ;
546
553
return obj instanceof constructor ;
547
554
} ,
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
+
548
568
swjs_create_typed_array : (
549
569
constructor_ref : ref ,
550
570
elementsPtr : pointer ,
551
- length : number ,
552
- result_obj : pointer
571
+ length : number
553
572
) => {
554
573
const ArrayType : TypedArray = this . heap . referenceHeap (
555
574
constructor_ref
@@ -560,8 +579,9 @@ export class SwiftRuntime {
560
579
length
561
580
) ;
562
581
// Call `.slice()` to copy the memory
563
- writeUint32 ( result_obj , this . heap . retain ( array . slice ( ) ) ) ;
582
+ return this . heap . retain ( array . slice ( ) ) ;
564
583
} ,
584
+
565
585
swjs_release : ( ref : ref ) => {
566
586
this . heap . release ( ref ) ;
567
587
} ,
0 commit comments