Skip to content

Commit eddc81f

Browse files
BridgeJS: Utilities/bridge-js-generate.sh
1 parent c4c3ad8 commit eddc81f

File tree

6 files changed

+580
-490
lines changed

6 files changed

+580
-490
lines changed

Benchmarks/Sources/Generated/BridgeJS.ExportSwift.swift

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -362,18 +362,19 @@ public func _bjs_EnumRoundtrip_deinit(pointer: UnsafeMutableRawPointer) {
362362

363363
extension EnumRoundtrip: ConvertibleToJSValue, _BridgedSwiftHeapObject {
364364
var jsValue: JSValue {
365-
#if arch(wasm32)
366-
@_extern(wasm, module: "Benchmarks", name: "bjs_EnumRoundtrip_wrap")
367-
func _bjs_EnumRoundtrip_wrap(_: UnsafeMutableRawPointer) -> Int32
368-
#else
369-
func _bjs_EnumRoundtrip_wrap(_: UnsafeMutableRawPointer) -> Int32 {
370-
fatalError("Only available on WebAssembly")
371-
}
372-
#endif
373365
return .object(JSObject(id: UInt32(bitPattern: _bjs_EnumRoundtrip_wrap(Unmanaged.passRetained(self).toOpaque()))))
374366
}
375367
}
376368

369+
#if arch(wasm32)
370+
@_extern(wasm, module: "Benchmarks", name: "bjs_EnumRoundtrip_wrap")
371+
fileprivate func _bjs_EnumRoundtrip_wrap(_: UnsafeMutableRawPointer) -> Int32
372+
#else
373+
fileprivate func _bjs_EnumRoundtrip_wrap(_: UnsafeMutableRawPointer) -> Int32 {
374+
fatalError("Only available on WebAssembly")
375+
}
376+
#endif
377+
377378
@_expose(wasm, "bjs_ComplexResultRoundtrip_init")
378379
@_cdecl("bjs_ComplexResultRoundtrip_init")
379380
public func _bjs_ComplexResultRoundtrip_init() -> UnsafeMutableRawPointer {
@@ -491,18 +492,19 @@ public func _bjs_ComplexResultRoundtrip_deinit(pointer: UnsafeMutableRawPointer)
491492

492493
extension ComplexResultRoundtrip: ConvertibleToJSValue, _BridgedSwiftHeapObject {
493494
var jsValue: JSValue {
494-
#if arch(wasm32)
495-
@_extern(wasm, module: "Benchmarks", name: "bjs_ComplexResultRoundtrip_wrap")
496-
func _bjs_ComplexResultRoundtrip_wrap(_: UnsafeMutableRawPointer) -> Int32
497-
#else
498-
func _bjs_ComplexResultRoundtrip_wrap(_: UnsafeMutableRawPointer) -> Int32 {
499-
fatalError("Only available on WebAssembly")
500-
}
501-
#endif
502495
return .object(JSObject(id: UInt32(bitPattern: _bjs_ComplexResultRoundtrip_wrap(Unmanaged.passRetained(self).toOpaque()))))
503496
}
504497
}
505498

499+
#if arch(wasm32)
500+
@_extern(wasm, module: "Benchmarks", name: "bjs_ComplexResultRoundtrip_wrap")
501+
fileprivate func _bjs_ComplexResultRoundtrip_wrap(_: UnsafeMutableRawPointer) -> Int32
502+
#else
503+
fileprivate func _bjs_ComplexResultRoundtrip_wrap(_: UnsafeMutableRawPointer) -> Int32 {
504+
fatalError("Only available on WebAssembly")
505+
}
506+
#endif
507+
506508
@_expose(wasm, "bjs_StringRoundtrip_init")
507509
@_cdecl("bjs_StringRoundtrip_init")
508510
public func _bjs_StringRoundtrip_init() -> UnsafeMutableRawPointer {
@@ -543,14 +545,15 @@ public func _bjs_StringRoundtrip_deinit(pointer: UnsafeMutableRawPointer) {
543545

544546
extension StringRoundtrip: ConvertibleToJSValue, _BridgedSwiftHeapObject {
545547
var jsValue: JSValue {
546-
#if arch(wasm32)
547-
@_extern(wasm, module: "Benchmarks", name: "bjs_StringRoundtrip_wrap")
548-
func _bjs_StringRoundtrip_wrap(_: UnsafeMutableRawPointer) -> Int32
549-
#else
550-
func _bjs_StringRoundtrip_wrap(_: UnsafeMutableRawPointer) -> Int32 {
551-
fatalError("Only available on WebAssembly")
552-
}
553-
#endif
554548
return .object(JSObject(id: UInt32(bitPattern: _bjs_StringRoundtrip_wrap(Unmanaged.passRetained(self).toOpaque()))))
555549
}
556-
}
550+
}
551+
552+
#if arch(wasm32)
553+
@_extern(wasm, module: "Benchmarks", name: "bjs_StringRoundtrip_wrap")
554+
fileprivate func _bjs_StringRoundtrip_wrap(_: UnsafeMutableRawPointer) -> Int32
555+
#else
556+
fileprivate func _bjs_StringRoundtrip_wrap(_: UnsafeMutableRawPointer) -> Int32 {
557+
fatalError("Only available on WebAssembly")
558+
}
559+
#endif

Benchmarks/Sources/Generated/BridgeJS.ImportTS.swift

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,45 +6,48 @@
66

77
@_spi(BridgeJS) import JavaScriptKit
88

9+
#if arch(wasm32)
10+
@_extern(wasm, module: "Benchmarks", name: "bjs_benchmarkHelperNoop")
11+
func bjs_benchmarkHelperNoop() -> Void
12+
#else
13+
func bjs_benchmarkHelperNoop() -> Void {
14+
fatalError("Only available on WebAssembly")
15+
}
16+
#endif
17+
918
func benchmarkHelperNoop() throws(JSException) -> Void {
10-
#if arch(wasm32)
11-
@_extern(wasm, module: "Benchmarks", name: "bjs_benchmarkHelperNoop")
12-
func bjs_benchmarkHelperNoop() -> Void
13-
#else
14-
func bjs_benchmarkHelperNoop() -> Void {
15-
fatalError("Only available on WebAssembly")
16-
}
17-
#endif
1819
bjs_benchmarkHelperNoop()
1920
if let error = _swift_js_take_exception() {
2021
throw error
2122
}
2223
}
2324

25+
#if arch(wasm32)
26+
@_extern(wasm, module: "Benchmarks", name: "bjs_benchmarkHelperNoopWithNumber")
27+
func bjs_benchmarkHelperNoopWithNumber(_ n: Float64) -> Void
28+
#else
29+
func bjs_benchmarkHelperNoopWithNumber(_ n: Float64) -> Void {
30+
fatalError("Only available on WebAssembly")
31+
}
32+
#endif
33+
2434
func benchmarkHelperNoopWithNumber(_ n: Double) throws(JSException) -> Void {
25-
#if arch(wasm32)
26-
@_extern(wasm, module: "Benchmarks", name: "bjs_benchmarkHelperNoopWithNumber")
27-
func bjs_benchmarkHelperNoopWithNumber(_ n: Float64) -> Void
28-
#else
29-
func bjs_benchmarkHelperNoopWithNumber(_ n: Float64) -> Void {
30-
fatalError("Only available on WebAssembly")
31-
}
32-
#endif
3335
bjs_benchmarkHelperNoopWithNumber(n.bridgeJSLowerParameter())
3436
if let error = _swift_js_take_exception() {
3537
throw error
3638
}
3739
}
3840

41+
#if arch(wasm32)
42+
@_extern(wasm, module: "Benchmarks", name: "bjs_benchmarkRunner")
43+
func bjs_benchmarkRunner(_ name: Int32, _ body: Int32) -> Void
44+
#else
45+
func bjs_benchmarkRunner(_ name: Int32, _ body: Int32) -> Void {
46+
fatalError("Only available on WebAssembly")
47+
}
48+
#endif
49+
3950
func benchmarkRunner(_ name: String, _ body: JSObject) throws(JSException) -> Void {
40-
#if arch(wasm32)
41-
@_extern(wasm, module: "Benchmarks", name: "bjs_benchmarkRunner")
42-
func bjs_benchmarkRunner(_ name: Int32, _ body: Int32) -> Void
43-
#else
44-
func bjs_benchmarkRunner(_ name: Int32, _ body: Int32) -> Void {
45-
fatalError("Only available on WebAssembly")
46-
}
47-
#endif
4851
bjs_benchmarkRunner(name.bridgeJSLowerParameter(), body.bridgeJSLowerParameter())
4952
if let error = _swift_js_take_exception() {
5053
throw error

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

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,19 @@ public func _bjs_PlayBridgeJS_deinit(pointer: UnsafeMutableRawPointer) {
5050

5151
extension PlayBridgeJS: ConvertibleToJSValue, _BridgedSwiftHeapObject {
5252
var jsValue: JSValue {
53-
#if arch(wasm32)
54-
@_extern(wasm, module: "PlayBridgeJS", name: "bjs_PlayBridgeJS_wrap")
55-
func _bjs_PlayBridgeJS_wrap(_: UnsafeMutableRawPointer) -> Int32
56-
#else
57-
func _bjs_PlayBridgeJS_wrap(_: UnsafeMutableRawPointer) -> Int32 {
58-
fatalError("Only available on WebAssembly")
59-
}
60-
#endif
6153
return .object(JSObject(id: UInt32(bitPattern: _bjs_PlayBridgeJS_wrap(Unmanaged.passRetained(self).toOpaque()))))
6254
}
6355
}
6456

57+
#if arch(wasm32)
58+
@_extern(wasm, module: "PlayBridgeJS", name: "bjs_PlayBridgeJS_wrap")
59+
fileprivate func _bjs_PlayBridgeJS_wrap(_: UnsafeMutableRawPointer) -> Int32
60+
#else
61+
fileprivate func _bjs_PlayBridgeJS_wrap(_: UnsafeMutableRawPointer) -> Int32 {
62+
fatalError("Only available on WebAssembly")
63+
}
64+
#endif
65+
6566
@_expose(wasm, "bjs_PlayBridgeJSOutput_outputJs")
6667
@_cdecl("bjs_PlayBridgeJSOutput_outputJs")
6768
public func _bjs_PlayBridgeJSOutput_outputJs(_self: UnsafeMutableRawPointer) -> Void {
@@ -114,14 +115,15 @@ public func _bjs_PlayBridgeJSOutput_deinit(pointer: UnsafeMutableRawPointer) {
114115

115116
extension PlayBridgeJSOutput: ConvertibleToJSValue, _BridgedSwiftHeapObject {
116117
var jsValue: JSValue {
117-
#if arch(wasm32)
118-
@_extern(wasm, module: "PlayBridgeJS", name: "bjs_PlayBridgeJSOutput_wrap")
119-
func _bjs_PlayBridgeJSOutput_wrap(_: UnsafeMutableRawPointer) -> Int32
120-
#else
121-
func _bjs_PlayBridgeJSOutput_wrap(_: UnsafeMutableRawPointer) -> Int32 {
122-
fatalError("Only available on WebAssembly")
123-
}
124-
#endif
125118
return .object(JSObject(id: UInt32(bitPattern: _bjs_PlayBridgeJSOutput_wrap(Unmanaged.passRetained(self).toOpaque()))))
126119
}
127-
}
120+
}
121+
122+
#if arch(wasm32)
123+
@_extern(wasm, module: "PlayBridgeJS", name: "bjs_PlayBridgeJSOutput_wrap")
124+
fileprivate func _bjs_PlayBridgeJSOutput_wrap(_: UnsafeMutableRawPointer) -> Int32
125+
#else
126+
fileprivate func _bjs_PlayBridgeJSOutput_wrap(_: UnsafeMutableRawPointer) -> Int32 {
127+
fatalError("Only available on WebAssembly")
128+
}
129+
#endif

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

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,32 @@
66

77
@_spi(BridgeJS) import JavaScriptKit
88

9+
#if arch(wasm32)
10+
@_extern(wasm, module: "PlayBridgeJS", name: "bjs_createTS2Skeleton")
11+
func bjs_createTS2Skeleton() -> Int32
12+
#else
13+
func bjs_createTS2Skeleton() -> Int32 {
14+
fatalError("Only available on WebAssembly")
15+
}
16+
#endif
17+
918
func createTS2Skeleton() throws(JSException) -> TS2Skeleton {
10-
#if arch(wasm32)
11-
@_extern(wasm, module: "PlayBridgeJS", name: "bjs_createTS2Skeleton")
12-
func bjs_createTS2Skeleton() -> Int32
13-
#else
14-
func bjs_createTS2Skeleton() -> Int32 {
15-
fatalError("Only available on WebAssembly")
16-
}
17-
#endif
1819
let ret = bjs_createTS2Skeleton()
1920
if let error = _swift_js_take_exception() {
2021
throw error
2122
}
2223
return TS2Skeleton.bridgeJSLiftReturn(ret)
2324
}
2425

26+
#if arch(wasm32)
27+
@_extern(wasm, module: "PlayBridgeJS", name: "bjs_TS2Skeleton_convert")
28+
func bjs_TS2Skeleton_convert(_ self: Int32, _ ts: Int32) -> Int32
29+
#else
30+
func bjs_TS2Skeleton_convert(_ self: Int32, _ ts: Int32) -> Int32 {
31+
fatalError("Only available on WebAssembly")
32+
}
33+
#endif
34+
2535
struct TS2Skeleton: _JSBridgedClass {
2636
let jsObject: JSObject
2737

@@ -30,14 +40,6 @@ struct TS2Skeleton: _JSBridgedClass {
3040
}
3141

3242
func convert(_ ts: String) throws(JSException) -> String {
33-
#if arch(wasm32)
34-
@_extern(wasm, module: "PlayBridgeJS", name: "bjs_TS2Skeleton_convert")
35-
func bjs_TS2Skeleton_convert(_ self: Int32, _ ts: Int32) -> Int32
36-
#else
37-
func bjs_TS2Skeleton_convert(_ self: Int32, _ ts: Int32) -> Int32 {
38-
fatalError("Only available on WebAssembly")
39-
}
40-
#endif
4143
let ret = bjs_TS2Skeleton_convert(self.bridgeJSLowerParameter(), ts.bridgeJSLowerParameter())
4244
if let error = _swift_js_take_exception() {
4345
throw error

0 commit comments

Comments
 (0)