Skip to content

Commit 30d994d

Browse files
authored
BridgeJS: Add runtime test for instance method String returns on a struct (#800)
1 parent 83eae16 commit 30d994d

4 files changed

Lines changed: 33 additions & 0 deletions

File tree

Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7861,6 +7861,17 @@ public func _bjs_Vector2D_scaled(_ factor: Float64) -> Void {
78617861
#endif
78627862
}
78637863

7864+
@_expose(wasm, "bjs_Vector2D_describe")
7865+
@_cdecl("bjs_Vector2D_describe")
7866+
public func _bjs_Vector2D_describe() -> Void {
7867+
#if arch(wasm32)
7868+
let ret = Vector2D.bridgeJSLiftParameter().describe()
7869+
return ret.bridgeJSLowerReturn()
7870+
#else
7871+
fatalError("Only available on WebAssembly")
7872+
#endif
7873+
}
7874+
78647875
extension JSObjectContainer: _BridgedSwiftStruct {
78657876
@_spi(BridgeJS) @_transparent public static func bridgeJSStackPop() -> JSObjectContainer {
78667877
let optionalObject = Optional<JSObject>.bridgeJSStackPop()

Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19680,6 +19680,23 @@
1968019680
"_0" : "Vector2D"
1968119681
}
1968219682
}
19683+
},
19684+
{
19685+
"abiName" : "bjs_Vector2D_describe",
19686+
"effects" : {
19687+
"isAsync" : false,
19688+
"isStatic" : false,
19689+
"isThrows" : false
19690+
},
19691+
"name" : "describe",
19692+
"parameters" : [
19693+
19694+
],
19695+
"returnType" : {
19696+
"string" : {
19697+
19698+
}
19699+
}
1968319700
}
1968419701
],
1968519702
"name" : "Vector2D",

Tests/BridgeJSRuntimeTests/StructAPIs.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,10 @@ extension Vector2D {
200200
@JS func scaled(by factor: Double) -> Vector2D {
201201
return Vector2D(dx: dx * factor, dy: dy * factor)
202202
}
203+
204+
@JS func describe() -> String {
205+
return "Vector2D(\(dx), \(dy))"
206+
}
203207
}
204208

205209
@JS func roundTripDataPoint(_ data: DataPoint) -> DataPoint {

Tests/prelude.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,7 @@ function testStructSupport(exports) {
871871
const scaled = vec.scaled(2.0);
872872
assert.equal(scaled.dx, 6.0);
873873
assert.equal(scaled.dy, 8.0);
874+
assert.equal(vec.describe(), "Vector2D(3.0, 4.0)");
874875

875876
const publicPoint = { x: 9, y: -3 };
876877
assert.deepEqual(exports.roundTripPublicPoint(publicPoint), publicPoint);

0 commit comments

Comments
 (0)