Skip to content

Commit 9608e46

Browse files
BridgeJS: Add support for Void return type in exported functions
1 parent c7550b8 commit 9608e46

File tree

5 files changed

+30
-0
lines changed

5 files changed

+30
-0
lines changed

Plugins/BridgeJS/Sources/BridgeJSTool/ExportSwift.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,8 @@ extension BridgeType {
564564
self = .string
565565
case "Bool":
566566
self = .bool
567+
case "Void":
568+
self = .void
567569
default:
568570
return nil
569571
}

Tests/BridgeJSRuntimeTests/ExportAPITests.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import JavaScriptKit
55
@_extern(c)
66
func runJsWorks() -> Void
77

8+
@JS func roundTripVoid() -> Void {
9+
return
10+
}
11+
812
@JS func roundTripInt(v: Int) -> Int {
913
return v
1014
}

Tests/BridgeJSRuntimeTests/Generated/ExportSwift.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
1+
// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit,
2+
// DO NOT EDIT.
3+
//
4+
// To update this file, just rebuild your project or run
5+
// `swift package bridge-js`.
16
@_extern(wasm, module: "bjs", name: "return_string")
27
private func _return_string(_ ptr: UnsafePointer<UInt8>?, _ len: Int32)
38
@_extern(wasm, module: "bjs", name: "init_memory")
49
private func _init_memory(_ sourceId: Int32, _ ptr: UnsafeMutablePointer<UInt8>?)
510
11+
@_expose(wasm, "bjs_roundTripVoid")
12+
@_cdecl("bjs_roundTripVoid")
13+
public func _bjs_roundTripVoid() -> Void {
14+
roundTripVoid()
15+
}
16+
617
@_expose(wasm, "bjs_roundTripInt")
718
@_cdecl("bjs_roundTripInt")
819
public func _bjs_roundTripInt(v: Int32) -> Int32 {

Tests/BridgeJSRuntimeTests/Generated/JavaScript/ExportSwift.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,18 @@
5353
}
5454
],
5555
"functions" : [
56+
{
57+
"abiName" : "bjs_roundTripVoid",
58+
"name" : "roundTripVoid",
59+
"parameters" : [
60+
61+
],
62+
"returnType" : {
63+
"void" : {
64+
65+
}
66+
}
67+
},
5668
{
5769
"abiName" : "bjs_roundTripInt",
5870
"name" : "roundTripInt",

Tests/prelude.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import assert from "node:assert";
2222

2323
/** @param {import('./../.build/plugins/PackageToJS/outputs/PackageTests/bridge.d.ts').Exports} exports */
2424
function BridgeJSRuntimeTests_runJsWorks(instance, exports) {
25+
exports.roundTripVoid();
2526
for (const v of [0, 1, -1, 2147483647, -2147483648]) {
2627
assert.equal(exports.roundTripInt(v), v);
2728
}

0 commit comments

Comments
 (0)