Skip to content

Commit e546582

Browse files
BridgeJS: Add protocol-based intrinsic system
Introduce _BridgedSwiftTypeLoweredIntoSingleWasmCoreType protocol to formalize lift/lower operations. All basic types (Bool, Int, Float, Double) now conform to this protocol with standardized bridgeJS* methods. Add _BridgedSwiftHeapObject and _BridgedSwiftEnumNoPayload protocols for heap objects and enums respectively. Update generated code and test snapshots to use new protocol-based intrinsic functions.
1 parent 0df766e commit e546582

File tree

18 files changed

+870
-478
lines changed

18 files changed

+870
-478
lines changed

Examples/PlayBridgeJS/Sources/PlayBridgeJS/Generated/BridgeJS.ExportSwift.swift

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@
1111
public func _bjs_PlayBridgeJS_init() -> UnsafeMutableRawPointer {
1212
#if arch(wasm32)
1313
let ret = PlayBridgeJS()
14-
return Unmanaged.passRetained(ret).toOpaque()
14+
return ret.bridgeJSLowerReturn()
1515
#else
1616
fatalError("Only available on WebAssembly")
1717
#endif
1818
}
1919

2020
@_expose(wasm, "bjs_PlayBridgeJS_update")
2121
@_cdecl("bjs_PlayBridgeJS_update")
22-
public func _bjs_PlayBridgeJS_update(_self: UnsafeMutableRawPointer, swiftSourceBytes: Int32, swiftSourceLen: Int32, dtsSourceBytes: Int32, dtsSourceLen: Int32) -> UnsafeMutableRawPointer {
22+
public func _bjs_PlayBridgeJS_update(_self: UnsafeMutableRawPointer, swiftSourceBytes: Int32, swiftSourceLength: Int32, dtsSourceBytes: Int32, dtsSourceLength: Int32) -> UnsafeMutableRawPointer {
2323
#if arch(wasm32)
2424
do {
25-
let ret = try Unmanaged<PlayBridgeJS>.fromOpaque(_self).takeUnretainedValue().update(swiftSource: String.bridgeJSLiftParameter(swiftSourceBytes, swiftSourceLen), dtsSource: String.bridgeJSLiftParameter(dtsSourceBytes, dtsSourceLen))
26-
return Unmanaged.passRetained(ret).toOpaque()
25+
let ret = try PlayBridgeJS.bridgeJSLiftParameter(_self).update(swiftSource: String.bridgeJSLiftParameter(swiftSourceBytes, swiftSourceLength), dtsSource: String.bridgeJSLiftParameter(dtsSourceBytes, dtsSourceLength))
26+
return ret.bridgeJSLowerReturn()
2727
} catch let error {
2828
if let error = error.thrownValue.object {
2929
withExtendedLifetime(error) {
@@ -48,10 +48,16 @@ public func _bjs_PlayBridgeJS_deinit(pointer: UnsafeMutableRawPointer) {
4848
Unmanaged<PlayBridgeJS>.fromOpaque(pointer).release()
4949
}
5050

51-
extension PlayBridgeJS: ConvertibleToJSValue {
51+
extension PlayBridgeJS: ConvertibleToJSValue, _BridgedSwiftHeapObject {
5252
var jsValue: JSValue {
53+
#if arch(wasm32)
5354
@_extern(wasm, module: "PlayBridgeJS", name: "bjs_PlayBridgeJS_wrap")
5455
func _bjs_PlayBridgeJS_wrap(_: UnsafeMutableRawPointer) -> Int32
56+
#else
57+
func _bjs_PlayBridgeJS_wrap(_: UnsafeMutableRawPointer) -> Int32 {
58+
fatalError("Only available on WebAssembly")
59+
}
60+
#endif
5561
return .object(JSObject(id: UInt32(bitPattern: _bjs_PlayBridgeJS_wrap(Unmanaged.passRetained(self).toOpaque()))))
5662
}
5763
}
@@ -60,7 +66,7 @@ extension PlayBridgeJS: ConvertibleToJSValue {
6066
@_cdecl("bjs_PlayBridgeJSOutput_outputJs")
6167
public func _bjs_PlayBridgeJSOutput_outputJs(_self: UnsafeMutableRawPointer) -> Void {
6268
#if arch(wasm32)
63-
let ret = Unmanaged<PlayBridgeJSOutput>.fromOpaque(_self).takeUnretainedValue().outputJs()
69+
let ret = PlayBridgeJSOutput.bridgeJSLiftParameter(_self).outputJs()
6470
return ret.bridgeJSLowerReturn()
6571
#else
6672
fatalError("Only available on WebAssembly")
@@ -71,7 +77,7 @@ public func _bjs_PlayBridgeJSOutput_outputJs(_self: UnsafeMutableRawPointer) ->
7177
@_cdecl("bjs_PlayBridgeJSOutput_outputDts")
7278
public func _bjs_PlayBridgeJSOutput_outputDts(_self: UnsafeMutableRawPointer) -> Void {
7379
#if arch(wasm32)
74-
let ret = Unmanaged<PlayBridgeJSOutput>.fromOpaque(_self).takeUnretainedValue().outputDts()
80+
let ret = PlayBridgeJSOutput.bridgeJSLiftParameter(_self).outputDts()
7581
return ret.bridgeJSLowerReturn()
7682
#else
7783
fatalError("Only available on WebAssembly")
@@ -82,7 +88,7 @@ public func _bjs_PlayBridgeJSOutput_outputDts(_self: UnsafeMutableRawPointer) ->
8288
@_cdecl("bjs_PlayBridgeJSOutput_importSwiftGlue")
8389
public func _bjs_PlayBridgeJSOutput_importSwiftGlue(_self: UnsafeMutableRawPointer) -> Void {
8490
#if arch(wasm32)
85-
let ret = Unmanaged<PlayBridgeJSOutput>.fromOpaque(_self).takeUnretainedValue().importSwiftGlue()
91+
let ret = PlayBridgeJSOutput.bridgeJSLiftParameter(_self).importSwiftGlue()
8692
return ret.bridgeJSLowerReturn()
8793
#else
8894
fatalError("Only available on WebAssembly")
@@ -93,7 +99,7 @@ public func _bjs_PlayBridgeJSOutput_importSwiftGlue(_self: UnsafeMutableRawPoint
9399
@_cdecl("bjs_PlayBridgeJSOutput_exportSwiftGlue")
94100
public func _bjs_PlayBridgeJSOutput_exportSwiftGlue(_self: UnsafeMutableRawPointer) -> Void {
95101
#if arch(wasm32)
96-
let ret = Unmanaged<PlayBridgeJSOutput>.fromOpaque(_self).takeUnretainedValue().exportSwiftGlue()
102+
let ret = PlayBridgeJSOutput.bridgeJSLiftParameter(_self).exportSwiftGlue()
97103
return ret.bridgeJSLowerReturn()
98104
#else
99105
fatalError("Only available on WebAssembly")
@@ -106,10 +112,16 @@ public func _bjs_PlayBridgeJSOutput_deinit(pointer: UnsafeMutableRawPointer) {
106112
Unmanaged<PlayBridgeJSOutput>.fromOpaque(pointer).release()
107113
}
108114

109-
extension PlayBridgeJSOutput: ConvertibleToJSValue {
115+
extension PlayBridgeJSOutput: ConvertibleToJSValue, _BridgedSwiftHeapObject {
110116
var jsValue: JSValue {
117+
#if arch(wasm32)
111118
@_extern(wasm, module: "PlayBridgeJS", name: "bjs_PlayBridgeJSOutput_wrap")
112119
func _bjs_PlayBridgeJSOutput_wrap(_: UnsafeMutableRawPointer) -> Int32
120+
#else
121+
func _bjs_PlayBridgeJSOutput_wrap(_: UnsafeMutableRawPointer) -> Int32 {
122+
fatalError("Only available on WebAssembly")
123+
}
124+
#endif
113125
return .object(JSObject(id: UInt32(bitPattern: _bjs_PlayBridgeJSOutput_wrap(Unmanaged.passRetained(self).toOpaque()))))
114126
}
115127
}

0 commit comments

Comments
 (0)