File tree Expand file tree Collapse file tree 4 files changed +17
-3
lines changed Expand file tree Collapse file tree 4 files changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -19,7 +19,9 @@ let package = Package(
1919 " -Xlinker " ,
2020 " --export=swjs_prepare_host_function_call " ,
2121 " -Xlinker " ,
22- " --export=swjs_cleanup_host_function_call "
22+ " --export=swjs_cleanup_host_function_call " ,
23+ " -Xlinker " ,
24+ " --export=swjs_library_version " ,
2325 ] ,
2426 . when( platforms: [ . wasi] )
2527 )
Original file line number Diff line number Diff line change @@ -19,7 +19,9 @@ let package = Package(
1919 " -Xlinker " ,
2020 " --export=swjs_prepare_host_function_call " ,
2121 " -Xlinker " ,
22- " --export=swjs_cleanup_host_function_call "
22+ " --export=swjs_cleanup_host_function_call " ,
23+ " -Xlinker " ,
24+ " --export=swjs_library_version " ,
2325 ]
2426 )
2527 ] ) ,
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ declare const window: GlobalVariable;
1010declare const global : GlobalVariable ;
1111
1212interface SwiftRuntimeExportedFunctions {
13+ swjs_library_version ( ) : number ;
1314 swjs_prepare_host_function_call ( size : number ) : pointer ;
1415 swjs_cleanup_host_function_call ( argv : pointer ) : void ;
1516 swjs_call_host_function (
@@ -84,6 +85,7 @@ class SwiftRuntimeHeap {
8485export class SwiftRuntime {
8586 private instance : WebAssembly . Instance | null ;
8687 private heap : SwiftRuntimeHeap
88+ private version : number = 400
8789
8890 constructor ( ) {
8991 this . instance = null ;
@@ -92,6 +94,10 @@ export class SwiftRuntime {
9294
9395 setInstance ( instance : WebAssembly . Instance ) {
9496 this . instance = instance
97+ const exports = this . instance . exports as any as SwiftRuntimeExportedFunctions ;
98+ if ( exports . swjs_library_version ( ) != this . version ) {
99+ throw new Error ( "The versions of JavaScriptKit are incompatible." )
100+ }
95101 }
96102
97103 importObjects ( ) {
@@ -351,4 +357,4 @@ export class SwiftRuntime {
351357 }
352358 }
353359 }
354- }
360+ }
Original file line number Diff line number Diff line change 1+ @_cdecl ( " swjs_library_version " )
2+ func _library_version( ) -> Double {
3+ return 400
4+ }
You can’t perform that action at this time.
0 commit comments