4
4
// To update this file, just rebuild your project or run
5
5
// `swift package bridge-js`.
6
6
7
- @_spi ( JSObject_id ) import JavaScriptKit
7
+ @_spi ( BridgeJS ) import JavaScriptKit
8
8
9
- #if arch(wasm32)
10
- @_extern ( wasm, module: " bjs " , name: " return_string " )
11
- private func _return_string( _ ptr: UnsafePointer < UInt8 > ? , _ len: Int32 )
12
- @_extern( wasm, module: " bjs" , name: " init_memory" )
13
- private func _init_memory(_ sourceId: Int32, _ ptr: UnsafeMutablePointer<UInt8>?)
9
+ @_expose ( wasm, " bjs_PlayBridgeJS_init " )
10
+ @_cdecl ( " bjs_PlayBridgeJS_init " )
11
+ public func _bjs_PlayBridgeJS_init( ) -> UnsafeMutableRawPointer {
12
+ #if arch(wasm32)
13
+ let ret = PlayBridgeJS ( )
14
+ return Unmanaged . passRetained ( ret) . toOpaque ( )
15
+ #else
16
+ fatalError ( " Only available on WebAssembly " )
17
+ #endif
18
+ }
14
19
15
- @_extern(wasm, module: " bjs" , name: " swift_js_retain" )
16
- private func _swift_js_retain(_ ptr: Int32) -> Int32
17
- @_extern(wasm, module: " bjs" , name: " swift_js_throw " )
18
- private func _swift_js_throw(_ id: Int32)
19
- #endif
20
+ @_expose ( wasm, " bjs_PlayBridgeJS_update " )
21
+ @_cdecl ( " bjs_PlayBridgeJS_update " )
22
+ public func _bjs_PlayBridgeJS_update( _self: UnsafeMutableRawPointer , swiftSourceBytes: Int32 , swiftSourceLen: Int32 , dtsSourceBytes: Int32 , dtsSourceLen: Int32 ) -> UnsafeMutableRawPointer {
23
+ #if arch(wasm32)
24
+ do {
25
+ let swiftSource = String ( unsafeUninitializedCapacity: Int ( swiftSourceLen) ) { b in
26
+ _swift_js_init_memory ( swiftSourceBytes, b. baseAddress. unsafelyUnwrapped)
27
+ return Int ( swiftSourceLen)
28
+ }
29
+ let dtsSource = String ( unsafeUninitializedCapacity: Int ( dtsSourceLen) ) { b in
30
+ _swift_js_init_memory ( dtsSourceBytes, b. baseAddress. unsafelyUnwrapped)
31
+ return Int ( dtsSourceLen)
32
+ }
33
+ let ret = try Unmanaged < PlayBridgeJS > . fromOpaque ( _self) . takeUnretainedValue ( ) . update ( swiftSource: swiftSource, dtsSource: dtsSource)
34
+ return Unmanaged . passRetained ( ret) . toOpaque ( )
35
+ } catch let error {
36
+ if let error = error. thrownValue. object {
37
+ withExtendedLifetime ( error) {
38
+ _swift_js_throw ( Int32 ( bitPattern: $0. id) )
39
+ }
40
+ } else {
41
+ let jsError = JSError ( message: String ( describing: error) )
42
+ withExtendedLifetime ( jsError. jsObject) {
43
+ _swift_js_throw ( Int32 ( bitPattern: $0. id) )
44
+ }
45
+ }
46
+ return UnsafeMutableRawPointer ( bitPattern: - 1 ) . unsafelyUnwrapped
47
+ }
48
+ #else
49
+ fatalError ( " Only available on WebAssembly " )
50
+ #endif
51
+ }
52
+
53
+ @_expose ( wasm, " bjs_PlayBridgeJS_deinit " )
54
+ @_cdecl ( " bjs_PlayBridgeJS_deinit " )
55
+ public func _bjs_PlayBridgeJS_deinit( pointer: UnsafeMutableRawPointer ) {
56
+ Unmanaged < PlayBridgeJS > . fromOpaque ( pointer) . release ( )
57
+ }
20
58
21
59
@_expose ( wasm, " bjs_PlayBridgeJSOutput_outputJs " )
22
60
@_cdecl ( " bjs_PlayBridgeJSOutput_outputJs " )
23
61
public func _bjs_PlayBridgeJSOutput_outputJs( _self: UnsafeMutableRawPointer ) -> Void {
24
62
#if arch(wasm32)
25
63
var ret = Unmanaged < PlayBridgeJSOutput > . fromOpaque ( _self) . takeUnretainedValue ( ) . outputJs ( )
26
64
return ret. withUTF8 { ptr in
27
- _return_string ( ptr. baseAddress, Int32 ( ptr. count) )
65
+ _swift_js_return_string ( ptr. baseAddress, Int32 ( ptr. count) )
28
66
}
29
67
#else
30
68
fatalError ( " Only available on WebAssembly " )
@@ -37,7 +75,7 @@ public func _bjs_PlayBridgeJSOutput_outputDts(_self: UnsafeMutableRawPointer) ->
37
75
#if arch(wasm32)
38
76
var ret = Unmanaged < PlayBridgeJSOutput > . fromOpaque ( _self) . takeUnretainedValue ( ) . outputDts ( )
39
77
return ret. withUTF8 { ptr in
40
- _return_string ( ptr. baseAddress, Int32 ( ptr. count) )
78
+ _swift_js_return_string ( ptr. baseAddress, Int32 ( ptr. count) )
41
79
}
42
80
#else
43
81
fatalError ( " Only available on WebAssembly " )
@@ -50,7 +88,7 @@ public func _bjs_PlayBridgeJSOutput_importSwiftGlue(_self: UnsafeMutableRawPoint
50
88
#if arch(wasm32)
51
89
var ret = Unmanaged < PlayBridgeJSOutput > . fromOpaque ( _self) . takeUnretainedValue ( ) . importSwiftGlue ( )
52
90
return ret. withUTF8 { ptr in
53
- _return_string ( ptr. baseAddress, Int32 ( ptr. count) )
91
+ _swift_js_return_string ( ptr. baseAddress, Int32 ( ptr. count) )
54
92
}
55
93
#else
56
94
fatalError ( " Only available on WebAssembly " )
@@ -63,7 +101,7 @@ public func _bjs_PlayBridgeJSOutput_exportSwiftGlue(_self: UnsafeMutableRawPoint
63
101
#if arch(wasm32)
64
102
var ret = Unmanaged < PlayBridgeJSOutput > . fromOpaque ( _self) . takeUnretainedValue ( ) . exportSwiftGlue ( )
65
103
return ret. withUTF8 { ptr in
66
- _return_string ( ptr. baseAddress, Int32 ( ptr. count) )
104
+ _swift_js_return_string ( ptr. baseAddress, Int32 ( ptr. count) )
67
105
}
68
106
#else
69
107
fatalError ( " Only available on WebAssembly " )
@@ -74,54 +112,4 @@ public func _bjs_PlayBridgeJSOutput_exportSwiftGlue(_self: UnsafeMutableRawPoint
74
112
@_cdecl ( " bjs_PlayBridgeJSOutput_deinit " )
75
113
public func _bjs_PlayBridgeJSOutput_deinit( pointer: UnsafeMutableRawPointer ) {
76
114
Unmanaged < PlayBridgeJSOutput > . fromOpaque ( pointer) . release ( )
77
- }
78
-
79
- @_expose ( wasm, " bjs_PlayBridgeJS_init " )
80
- @_cdecl ( " bjs_PlayBridgeJS_init " )
81
- public func _bjs_PlayBridgeJS_init( ) -> UnsafeMutableRawPointer {
82
- #if arch(wasm32)
83
- let ret = PlayBridgeJS ( )
84
- return Unmanaged . passRetained ( ret) . toOpaque ( )
85
- #else
86
- fatalError ( " Only available on WebAssembly " )
87
- #endif
88
- }
89
-
90
- @_expose ( wasm, " bjs_PlayBridgeJS_update " )
91
- @_cdecl ( " bjs_PlayBridgeJS_update " )
92
- public func _bjs_PlayBridgeJS_update( _self: UnsafeMutableRawPointer , swiftSourceBytes: Int32 , swiftSourceLen: Int32 , dtsSourceBytes: Int32 , dtsSourceLen: Int32 ) -> UnsafeMutableRawPointer {
93
- #if arch(wasm32)
94
- do {
95
- let swiftSource = String ( unsafeUninitializedCapacity: Int ( swiftSourceLen) ) { b in
96
- _init_memory ( swiftSourceBytes, b. baseAddress. unsafelyUnwrapped)
97
- return Int ( swiftSourceLen)
98
- }
99
- let dtsSource = String ( unsafeUninitializedCapacity: Int ( dtsSourceLen) ) { b in
100
- _init_memory ( dtsSourceBytes, b. baseAddress. unsafelyUnwrapped)
101
- return Int ( dtsSourceLen)
102
- }
103
- let ret = try Unmanaged < PlayBridgeJS > . fromOpaque ( _self) . takeUnretainedValue ( ) . update ( swiftSource: swiftSource, dtsSource: dtsSource)
104
- return Unmanaged . passRetained ( ret) . toOpaque ( )
105
- } catch let error {
106
- if let error = error. thrownValue. object {
107
- withExtendedLifetime ( error) {
108
- _swift_js_throw ( Int32 ( bitPattern: $0. id) )
109
- }
110
- } else {
111
- let jsError = JSError ( message: String ( describing: error) )
112
- withExtendedLifetime ( jsError. jsObject) {
113
- _swift_js_throw ( Int32 ( bitPattern: $0. id) )
114
- }
115
- }
116
- return UnsafeMutableRawPointer ( bitPattern: - 1 ) . unsafelyUnwrapped
117
- }
118
- #else
119
- fatalError ( " Only available on WebAssembly " )
120
- #endif
121
- }
122
-
123
- @_expose ( wasm, " bjs_PlayBridgeJS_deinit " )
124
- @_cdecl ( " bjs_PlayBridgeJS_deinit " )
125
- public func _bjs_PlayBridgeJS_deinit( pointer: UnsafeMutableRawPointer ) {
126
- Unmanaged < PlayBridgeJS > . fromOpaque ( pointer) . release ( )
127
115
}
0 commit comments