Skip to content

Commit f9a09a3

Browse files
Merge pull request #436 from PassiveLogic/feat/enum-associated-values-primitive
BridgeJS: Support for multiple associated values in enums using binary buffer format
2 parents eb33e5d + 4489d91 commit f9a09a3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+6555
-517
lines changed

Benchmarks/Sources/Benchmarks.swift

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,99 @@ class Benchmark {
1818
}
1919
}
2020

21+
@JS enum APIResult {
22+
case success(String)
23+
case failure(Int)
24+
case flag(Bool)
25+
case rate(Float)
26+
case precise(Double)
27+
case info
28+
}
29+
30+
@JS class EnumRoundtrip {
31+
@JS init() {}
32+
33+
@JS func take(_ value: APIResult) {}
34+
@JS func makeSuccess() -> APIResult {
35+
return .success("Hello, world")
36+
}
37+
@JS func makeFailure() -> APIResult {
38+
return .failure(42)
39+
}
40+
@JS func makeFlag() -> APIResult {
41+
return .flag(true)
42+
}
43+
@JS func makeRate() -> APIResult {
44+
return .rate(0.5)
45+
}
46+
@JS func makePrecise() -> APIResult {
47+
return .precise(0.5)
48+
}
49+
@JS func makeInfo() -> APIResult {
50+
return .info
51+
}
52+
53+
@JS func roundtrip(_ result: APIResult) -> APIResult {
54+
return result
55+
}
56+
}
57+
58+
@JS
59+
enum ComplexResult {
60+
case success(String)
61+
case error(String, Int)
62+
case location(Double, Double, String)
63+
case status(Bool, Int, String)
64+
case coordinates(Double, Double, Double)
65+
case comprehensive(Bool, Bool, Int, Int, Double, Double, String, String, String)
66+
case info
67+
}
68+
69+
@JS class ComplexResultRoundtrip {
70+
@JS init() {}
71+
72+
@JS func take(_ value: ComplexResult) {}
73+
74+
@JS func makeSuccess() -> ComplexResult {
75+
return .success("Hello, world")
76+
}
77+
78+
@JS func makeError() -> ComplexResult {
79+
return .error("Network timeout", 503)
80+
}
81+
82+
@JS func makeLocation() -> ComplexResult {
83+
return .location(37.7749, -122.4194, "San Francisco")
84+
}
85+
86+
@JS func makeStatus() -> ComplexResult {
87+
return .status(true, 200, "OK")
88+
}
89+
90+
@JS func makeCoordinates() -> ComplexResult {
91+
return .coordinates(10.5, 20.3, 30.7)
92+
}
93+
94+
@JS func makeComprehensive() -> ComplexResult {
95+
return .comprehensive(true, false, 42, 100, 3.14, 2.718, "Hello", "World", "Test")
96+
}
97+
98+
@JS func makeInfo() -> ComplexResult {
99+
return .info
100+
}
101+
102+
@JS func roundtrip(_ result: ComplexResult) -> ComplexResult {
103+
return result
104+
}
105+
}
106+
@JS class StringRoundtrip {
107+
@JS init() {}
108+
@JS func take(_ value: String) {}
109+
@JS func make() -> String {
110+
return "Hello, world"
111+
}
112+
}
113+
21114
@JS func run() {
22115

23116
let call = Benchmark("Call")

0 commit comments

Comments
 (0)