@@ -14,7 +14,7 @@ export class SwiftRuntime {
1414 private _instance : WebAssembly . Instance | null ;
1515 private _memory : Memory | null ;
1616 private _closureDeallocator : SwiftClosureDeallocator | null ;
17- private version : number = 706 ;
17+ private version : number = 707 ;
1818
1919 private textDecoder = new TextDecoder ( "utf-8" ) ;
2020 private textEncoder = new TextEncoder ( ) ; // Only support utf-8
@@ -114,7 +114,6 @@ export class SwiftRuntime {
114114 const value = JSValue . decode ( kind , payload1 , payload2 , this . memory ) ;
115115 obj [ key ] = value ;
116116 } ,
117-
118117 swjs_get_prop : (
119118 ref : ref ,
120119 name : ref ,
@@ -146,7 +145,6 @@ export class SwiftRuntime {
146145 const value = JSValue . decode ( kind , payload1 , payload2 , this . memory ) ;
147146 obj [ index ] = value ;
148147 } ,
149-
150148 swjs_get_subscript : (
151149 ref : ref ,
152150 index : number ,
@@ -172,15 +170,13 @@ export class SwiftRuntime {
172170 this . memory . writeUint32 ( bytes_ptr_result , bytes_ptr ) ;
173171 return bytes . length ;
174172 } ,
175-
176173 swjs_decode_string : ( bytes_ptr : pointer , length : number ) => {
177174 const bytes = this . memory
178175 . bytes ( )
179176 . subarray ( bytes_ptr , bytes_ptr + length ) ;
180177 const string = this . textDecoder . decode ( bytes ) ;
181178 return this . memory . retain ( string ) ;
182179 } ,
183-
184180 swjs_load_string : ( ref : ref , buffer : pointer ) => {
185181 const bytes = this . memory . getObject ( ref ) ;
186182 this . memory . writeBytes ( buffer , bytes ) ;
@@ -290,7 +286,6 @@ export class SwiftRuntime {
290286 this . memory
291287 ) ;
292288 } ,
293-
294289 swjs_call_function_with_this_no_catch : (
295290 obj_ref : ref ,
296291 func_ref : ref ,
@@ -328,13 +323,13 @@ export class SwiftRuntime {
328323 }
329324 }
330325 } ,
326+
331327 swjs_call_new : ( ref : ref , argv : pointer , argc : number ) => {
332328 const constructor = this . memory . getObject ( ref ) ;
333329 const args = JSValue . decodeArray ( argv , argc , this . memory ) ;
334330 const instance = new constructor ( ...args ) ;
335331 return this . memory . retain ( instance ) ;
336332 } ,
337-
338333 swjs_call_throwing_new : (
339334 ref : ref ,
340335 argv : pointer ,
@@ -409,5 +404,25 @@ export class SwiftRuntime {
409404 swjs_release : ( ref : ref ) => {
410405 this . memory . release ( ref ) ;
411406 } ,
407+
408+ swjs_i64_to_bigint : ( value : bigint , signed : number ) => {
409+ return this . memory . retain (
410+ signed ? value : BigInt . asUintN ( 64 , value )
411+ ) ;
412+ } ,
413+ swjs_bigint_to_i64 : ( ref : ref , signed : number ) => {
414+ const object = this . memory . getObject ( ref ) ;
415+ if ( typeof object !== "bigint" ) {
416+ throw new Error ( `Expected a BigInt, but got ${ typeof object } ` ) ;
417+ }
418+ if ( signed ) {
419+ return object ;
420+ } else {
421+ if ( object < BigInt ( 0 ) ) {
422+ return BigInt ( 0 ) ;
423+ }
424+ return BigInt . asIntN ( 64 , object ) ;
425+ }
426+ } ,
412427 } ;
413428}
0 commit comments