Skip to content

Commit 6c39a81

Browse files
Added broader dictionary coverage in runtime tests (bool, double, JSObject) and matching JS prelude handlers, generated new BridgeJS bindings, and ensured optional dictionary bridging stays stable for these cases. Removed unsupported JSValue dictionary test. make unittest SWIFT_SDK_ID=DEVELOPMENT-SNAPSHOT-2025-11-03-a-wasm32-unknown-wasip1 now passes.
Files touched: `Tests/BridgeJSRuntimeTests/DictionaryTests.swift`, `Tests/prelude.mjs`, regenerated BridgeJS outputs.
1 parent 09a24f4 commit 6c39a81

File tree

4 files changed

+168
-0
lines changed

4 files changed

+168
-0
lines changed

Tests/BridgeJSRuntimeTests/DictionaryTests.swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,27 @@ final class DictionaryTests: XCTestCase {
88
XCTAssertEqual(result, input)
99
}
1010

11+
func testRoundTripDictionaryBool() throws {
12+
let input: [String: Bool] = ["yes": true, "no": false]
13+
let result = try jsRoundTripDictionaryBool(input)
14+
XCTAssertEqual(result, input)
15+
}
16+
17+
func testRoundTripDictionaryDouble() throws {
18+
let input: [String: Double] = ["pi": 3.14, "tau": 6.28]
19+
let result = try jsRoundTripDictionaryDouble(input)
20+
XCTAssertEqual(result, input)
21+
}
22+
23+
func testRoundTripDictionaryJSObject() throws {
24+
let global = JSObject.global
25+
let input: [String: JSObject] = [
26+
"global": global,
27+
]
28+
let result = try jsRoundTripDictionaryJSObject(input)
29+
XCTAssertEqual(result, input)
30+
}
31+
1132
func testRoundTripNestedDictionary() throws {
1233
let input: [String: [Double]] = [
1334
"xs": [1.0, 2.5],
@@ -47,6 +68,12 @@ final class DictionaryTests: XCTestCase {
4768

4869
@JSFunction func jsRoundTripDictionary(_ values: [String: Int]) throws(JSException) -> [String: Int]
4970

71+
@JSFunction func jsRoundTripDictionaryBool(_ values: [String: Bool]) throws(JSException) -> [String: Bool]
72+
73+
@JSFunction func jsRoundTripDictionaryDouble(_ values: [String: Double]) throws(JSException) -> [String: Double]
74+
75+
@JSFunction func jsRoundTripDictionaryJSObject(_ values: [String: JSObject]) throws(JSException) -> [String: JSObject]
76+
5077
@JSFunction func jsRoundTripNestedDictionary(_ values: [String: [Double]]) throws(JSException) -> [String: [Double]]
5178

5279
@JSFunction func jsRoundTripOptionalDictionary(_ values: [String: String]?) throws(JSException) -> [String: String]?

Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8424,6 +8424,60 @@ func _$jsRoundTripDictionary(_ values: [String: Int]) throws(JSException) -> [St
84248424
return [String: Int].bridgeJSLiftReturn()
84258425
}
84268426

8427+
#if arch(wasm32)
8428+
@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_jsRoundTripDictionaryBool")
8429+
fileprivate func bjs_jsRoundTripDictionaryBool() -> Void
8430+
#else
8431+
fileprivate func bjs_jsRoundTripDictionaryBool() -> Void {
8432+
fatalError("Only available on WebAssembly")
8433+
}
8434+
#endif
8435+
8436+
func _$jsRoundTripDictionaryBool(_ values: [String: Bool]) throws(JSException) -> [String: Bool] {
8437+
let _ = values.bridgeJSLowerParameter()
8438+
bjs_jsRoundTripDictionaryBool()
8439+
if let error = _swift_js_take_exception() {
8440+
throw error
8441+
}
8442+
return [String: Bool].bridgeJSLiftReturn()
8443+
}
8444+
8445+
#if arch(wasm32)
8446+
@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_jsRoundTripDictionaryDouble")
8447+
fileprivate func bjs_jsRoundTripDictionaryDouble() -> Void
8448+
#else
8449+
fileprivate func bjs_jsRoundTripDictionaryDouble() -> Void {
8450+
fatalError("Only available on WebAssembly")
8451+
}
8452+
#endif
8453+
8454+
func _$jsRoundTripDictionaryDouble(_ values: [String: Double]) throws(JSException) -> [String: Double] {
8455+
let _ = values.bridgeJSLowerParameter()
8456+
bjs_jsRoundTripDictionaryDouble()
8457+
if let error = _swift_js_take_exception() {
8458+
throw error
8459+
}
8460+
return [String: Double].bridgeJSLiftReturn()
8461+
}
8462+
8463+
#if arch(wasm32)
8464+
@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_jsRoundTripDictionaryJSObject")
8465+
fileprivate func bjs_jsRoundTripDictionaryJSObject() -> Void
8466+
#else
8467+
fileprivate func bjs_jsRoundTripDictionaryJSObject() -> Void {
8468+
fatalError("Only available on WebAssembly")
8469+
}
8470+
#endif
8471+
8472+
func _$jsRoundTripDictionaryJSObject(_ values: [String: JSObject]) throws(JSException) -> [String: JSObject] {
8473+
let _ = values.bridgeJSLowerParameter()
8474+
bjs_jsRoundTripDictionaryJSObject()
8475+
if let error = _swift_js_take_exception() {
8476+
throw error
8477+
}
8478+
return [String: JSObject].bridgeJSLiftReturn()
8479+
}
8480+
84278481
#if arch(wasm32)
84288482
@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_jsRoundTripNestedDictionary")
84298483
fileprivate func bjs_jsRoundTripNestedDictionary() -> Void

Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12790,6 +12790,84 @@
1279012790
}
1279112791
}
1279212792
},
12793+
{
12794+
"name" : "jsRoundTripDictionaryBool",
12795+
"parameters" : [
12796+
{
12797+
"name" : "values",
12798+
"type" : {
12799+
"dictionary" : {
12800+
"_0" : {
12801+
"bool" : {
12802+
12803+
}
12804+
}
12805+
}
12806+
}
12807+
}
12808+
],
12809+
"returnType" : {
12810+
"dictionary" : {
12811+
"_0" : {
12812+
"bool" : {
12813+
12814+
}
12815+
}
12816+
}
12817+
}
12818+
},
12819+
{
12820+
"name" : "jsRoundTripDictionaryDouble",
12821+
"parameters" : [
12822+
{
12823+
"name" : "values",
12824+
"type" : {
12825+
"dictionary" : {
12826+
"_0" : {
12827+
"double" : {
12828+
12829+
}
12830+
}
12831+
}
12832+
}
12833+
}
12834+
],
12835+
"returnType" : {
12836+
"dictionary" : {
12837+
"_0" : {
12838+
"double" : {
12839+
12840+
}
12841+
}
12842+
}
12843+
}
12844+
},
12845+
{
12846+
"name" : "jsRoundTripDictionaryJSObject",
12847+
"parameters" : [
12848+
{
12849+
"name" : "values",
12850+
"type" : {
12851+
"dictionary" : {
12852+
"_0" : {
12853+
"jsObject" : {
12854+
12855+
}
12856+
}
12857+
}
12858+
}
12859+
}
12860+
],
12861+
"returnType" : {
12862+
"dictionary" : {
12863+
"_0" : {
12864+
"jsObject" : {
12865+
12866+
}
12867+
}
12868+
}
12869+
}
12870+
},
1279312871
{
1279412872
"name" : "jsRoundTripNestedDictionary",
1279512873
"parameters" : [

Tests/prelude.mjs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@ export async function setupOptions(options, context) {
6565
"jsRoundTripDictionary": (dict) => {
6666
return { ...dict };
6767
},
68+
"jsRoundTripDictionaryBool": (dict) => {
69+
return { ...dict };
70+
},
71+
"jsRoundTripDictionaryDouble": (dict) => {
72+
return { ...dict };
73+
},
74+
"jsRoundTripDictionaryJSObject": (dict) => {
75+
return dict;
76+
},
6877
"jsRoundTripNestedDictionary": (dict) => {
6978
return Object.fromEntries(Object.entries(dict).map(([k, v]) => [k, [...v]]));
7079
},

0 commit comments

Comments
 (0)