Skip to content

Commit d1ed185

Browse files
committed
BridgeJS: Add e2e test for static method and property on namespaced class
Extends the existing `__Swift.Foundation.UUID` class (which already has an `@JS init` and an `@JS func`) with a static factory `fromValue(_:)` and a static readonly property `placeholder`, then asserts both are reachable via `exports.__Swift.Foundation.UUID.fromValue` and `exports.__Swift.Foundation.UUID.placeholder` in `prelude.mjs`. This is the e2e counterpart to the snapshot regression added in the previous commit — it proves the generated JavaScript actually routes calls to the correct static thunks at runtime, not just that the `.d.ts` types are well-formed.
1 parent 9a56b28 commit d1ed185

4 files changed

Lines changed: 79 additions & 0 deletions

File tree

Tests/BridgeJSRuntimeTests/ExportAPITests.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,12 @@ class UUID {
433433
@JS func uuidString() -> String {
434434
return value
435435
}
436+
437+
@JS static func fromValue(_ value: String) -> UUID {
438+
return UUID(value: value)
439+
}
440+
441+
@JS static var placeholder: String { "00000000-0000-0000-0000-000000000000" }
436442
}
437443

438444
@JS func createUUID(value: String) -> UUID {

Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8602,6 +8602,28 @@ public func _bjs___Swift_Foundation_UUID_uuidString(_ _self: UnsafeMutableRawPoi
86028602
#endif
86038603
}
86048604

8605+
@_expose(wasm, "bjs___Swift_Foundation_UUID_static_fromValue")
8606+
@_cdecl("bjs___Swift_Foundation_UUID_static_fromValue")
8607+
public func _bjs___Swift_Foundation_UUID_static_fromValue(_ valueBytes: Int32, _ valueLength: Int32) -> UnsafeMutableRawPointer {
8608+
#if arch(wasm32)
8609+
let ret = UUID.fromValue(_: String.bridgeJSLiftParameter(valueBytes, valueLength))
8610+
return ret.bridgeJSLowerReturn()
8611+
#else
8612+
fatalError("Only available on WebAssembly")
8613+
#endif
8614+
}
8615+
8616+
@_expose(wasm, "bjs___Swift_Foundation_UUID_static_placeholder_get")
8617+
@_cdecl("bjs___Swift_Foundation_UUID_static_placeholder_get")
8618+
public func _bjs___Swift_Foundation_UUID_static_placeholder_get() -> Void {
8619+
#if arch(wasm32)
8620+
let ret = __Swift_Foundation_UUID.placeholder
8621+
return ret.bridgeJSLowerReturn()
8622+
#else
8623+
fatalError("Only available on WebAssembly")
8624+
#endif
8625+
}
8626+
86058627
@_expose(wasm, "bjs___Swift_Foundation_UUID_deinit")
86068628
@_cdecl("bjs___Swift_Foundation_UUID_deinit")
86078629
public func _bjs___Swift_Foundation_UUID_deinit(_ pointer: UnsafeMutableRawPointer) -> Void {

Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,6 +1108,36 @@
11081108

11091109
}
11101110
}
1111+
},
1112+
{
1113+
"abiName" : "bjs___Swift_Foundation_UUID_static_fromValue",
1114+
"effects" : {
1115+
"isAsync" : false,
1116+
"isStatic" : true,
1117+
"isThrows" : false
1118+
},
1119+
"name" : "fromValue",
1120+
"parameters" : [
1121+
{
1122+
"label" : "_",
1123+
"name" : "value",
1124+
"type" : {
1125+
"string" : {
1126+
1127+
}
1128+
}
1129+
}
1130+
],
1131+
"returnType" : {
1132+
"swiftHeapObject" : {
1133+
"_0" : "UUID"
1134+
}
1135+
},
1136+
"staticContext" : {
1137+
"className" : {
1138+
"_0" : "__Swift_Foundation_UUID"
1139+
}
1140+
}
11111141
}
11121142
],
11131143
"name" : "UUID",
@@ -1116,7 +1146,21 @@
11161146
"Foundation"
11171147
],
11181148
"properties" : [
1149+
{
1150+
"isReadonly" : true,
1151+
"isStatic" : true,
1152+
"name" : "placeholder",
1153+
"staticContext" : {
1154+
"className" : {
1155+
"_0" : "__Swift_Foundation_UUID"
1156+
}
1157+
},
1158+
"type" : {
1159+
"string" : {
11191160

1161+
}
1162+
}
1163+
}
11201164
],
11211165
"swiftCallName" : "UUID"
11221166
},

Tests/prelude.mjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,13 @@ function BridgeJSRuntimeTests_runJsWorks(instance, exports) {
624624
roundTrippedUUID.release();
625625
uuid.release();
626626

627+
// Static method and property on a namespaced class (@JS(namespace:) + @JS static).
628+
// These must be callable via the namespace path, not as instance members.
629+
const uuidFromStatic = exports.__Swift.Foundation.UUID.fromValue("aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee");
630+
assert.equal(uuidFromStatic.uuidString(), "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee");
631+
uuidFromStatic.release();
632+
assert.equal(exports.__Swift.Foundation.UUID.placeholder, "00000000-0000-0000-0000-000000000000");
633+
627634
const createdServer = exports.createHTTPServer();
628635
createdServer.call(exports.Networking.API.Method.Get);
629636
createdServer.release();

0 commit comments

Comments
 (0)