Skip to content

Commit 3c55783

Browse files
Added runtime coverage for the removed @JS protocol flows using @JSClass:
- Introduced a JSClass-based interface and manager to exercise property/method dispatch from Swift into plain JS objects (`Tests/BridgeJSRuntimeTests/ExportAPITests.swift`), using throwing JS calls via `try!` where required. - Added a new JS-side scenario to drive the manager and verify interactions, backup swapping, tagging, labeling, and message passing (`Tests/prelude.mjs`). - Regenerated BridgeJS outputs to reflect the new runtime APIs (`Tests/BridgeJSRuntimeTests/Generated/*`). Tests: `make unittest SWIFT_SDK_ID=DEVELOPMENT-SNAPSHOT-2025-11-03-a-wasm32-unknown-wasip1` passed.
1 parent 07ab30d commit 3c55783

File tree

4 files changed

+1107
-0
lines changed

4 files changed

+1107
-0
lines changed

Tests/BridgeJSRuntimeTests/ExportAPITests.swift

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,86 @@ enum APIOptionalResult {
954954
}
955955
}
956956

957+
// MARK: - JSClass Interface Tests
958+
959+
@JSClass struct DataProcessor {
960+
@JSGetter var count: Int
961+
@JSGetter var name: String
962+
@JSGetter var tag: String
963+
964+
@JSFunction func increment(by amount: Int) throws(JSException)
965+
@JSFunction func getValue() throws(JSException) -> Int
966+
@JSFunction func setLabel(_ labelPrefix: String, _ labelSuffix: String) throws(JSException)
967+
@JSFunction func getLabel() throws(JSException) -> String
968+
@JSFunction func isEven() throws(JSException) -> Bool
969+
@JSFunction func processNote(_ note: String) throws(JSException) -> String
970+
@JSFunction func createNote(_ prefix: String) throws(JSException) -> String
971+
@JSFunction func handleMessage(_ message: String) throws(JSException)
972+
@JSFunction func getMessage() throws(JSException) -> String
973+
974+
@JSFunction func setTag(_ tag: String) throws(JSException)
975+
}
976+
977+
@JS class DataProcessorManager {
978+
979+
@JS var processor: DataProcessor
980+
@JS var backupProcessor: DataProcessor
981+
982+
@JS init(processor: DataProcessor) {
983+
self.processor = processor
984+
self.backupProcessor = processor
985+
}
986+
987+
@JS func incrementByAmount(_ amount: Int) {
988+
try! processor.increment(by: amount)
989+
}
990+
991+
@JS func setProcessorLabel(_ prefix: String, _ suffix: String) {
992+
try! processor.setLabel(prefix, suffix)
993+
}
994+
995+
@JS func isProcessorEven() -> Bool {
996+
return try! processor.isEven()
997+
}
998+
999+
@JS func getProcessorLabel() -> String {
1000+
return try! processor.getLabel()
1001+
}
1002+
1003+
@JS func getCurrentValue() -> Int {
1004+
return try! processor.getValue()
1005+
}
1006+
1007+
@JS func incrementBoth() {
1008+
try! processor.increment(by: 1)
1009+
try! backupProcessor.increment(by: 1)
1010+
}
1011+
1012+
@JS func getBackupValue() -> Int {
1013+
return try! backupProcessor.getValue()
1014+
}
1015+
1016+
@JS func hasBackup() -> Bool {
1017+
return true
1018+
}
1019+
1020+
@JS func getProcessorTag() -> String {
1021+
return try! processor.tag
1022+
}
1023+
1024+
@JS func setProcessorTag(_ tag: String) {
1025+
try! processor.setTag(tag)
1026+
}
1027+
1028+
@JS func getProcessorMessage() -> String {
1029+
return try! processor.getMessage()
1030+
}
1031+
1032+
@JS func setProcessorMessage(_ message: String) {
1033+
try! processor.handleMessage(message)
1034+
}
1035+
}
1036+
9571037
// MARK: - Closure Tests
9581038

9591039
// @JS func makeFormatter(prefix: String) -> (String) -> String {

0 commit comments

Comments
 (0)