@@ -47,4 +47,48 @@ func jsRoundTripString(_ v: String) -> String {
47
47
_init_memory_with_result ( b. baseAddress. unsafelyUnwrapped, Int32 ( ret) )
48
48
return Int ( ret)
49
49
}
50
+ }
51
+
52
+ struct JsGreeter {
53
+ let this : JSObject
54
+
55
+ init ( this: JSObject ) {
56
+ self . this = this
57
+ }
58
+
59
+ init ( takingThis this: Int32 ) {
60
+ self . this = JSObject ( id: UInt32 ( bitPattern: this) )
61
+ }
62
+
63
+ init ( _ name: String ) {
64
+ @_extern ( wasm, module: " BridgeJSRuntimeTests " , name: " bjs_JsGreeter_init " )
65
+ func bjs_JsGreeter_init( _ name: Int32 ) -> Int32
66
+ var name = name
67
+ let nameId = name. withUTF8 { b in
68
+ _make_jsstring ( b. baseAddress. unsafelyUnwrapped, Int32 ( b. count) )
69
+ }
70
+ let ret = bjs_JsGreeter_init ( nameId)
71
+ self . this = JSObject ( id: UInt32 ( bitPattern: ret) )
72
+ }
73
+
74
+ func greet( ) -> String {
75
+ @_extern ( wasm, module: " BridgeJSRuntimeTests " , name: " bjs_JsGreeter_greet " )
76
+ func bjs_JsGreeter_greet( _ self: Int32 ) -> Int32
77
+ let ret = bjs_JsGreeter_greet ( Int32 ( bitPattern: self . this. id) )
78
+ return String ( unsafeUninitializedCapacity: Int ( ret) ) { b in
79
+ _init_memory_with_result ( b. baseAddress. unsafelyUnwrapped, Int32 ( ret) )
80
+ return Int ( ret)
81
+ }
82
+ }
83
+
84
+ func changeName( _ name: String ) -> Void {
85
+ @_extern ( wasm, module: " BridgeJSRuntimeTests " , name: " bjs_JsGreeter_changeName " )
86
+ func bjs_JsGreeter_changeName( _ self: Int32 , _ name: Int32 ) -> Void
87
+ var name = name
88
+ let nameId = name. withUTF8 { b in
89
+ _make_jsstring ( b. baseAddress. unsafelyUnwrapped, Int32 ( b. count) )
90
+ }
91
+ bjs_JsGreeter_changeName ( Int32 ( bitPattern: self . this. id) , nameId)
92
+ }
93
+
50
94
}
0 commit comments