Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Benchmarks/Sources/Benchmarks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,22 @@ enum ComplexResult {
}
}

@JS class OptionalReturnRoundtrip {
@JS init() {}

@JS func makeIntSome() -> Int? { 42 }
@JS func makeIntNone() -> Int? { nil }

@JS func makeBoolSome() -> Bool? { true }
@JS func makeBoolNone() -> Bool? { nil }

@JS func makeDoubleSome() -> Double? { 0.5 }
@JS func makeDoubleNone() -> Double? { nil }

@JS func makeStringSome() -> String? { "Hello, world" }
@JS func makeStringNone() -> String? { nil }
}

// MARK: - Struct Performance Tests

@JS struct SimpleStruct {
Expand Down
124 changes: 124 additions & 0 deletions Benchmarks/Sources/Generated/BridgeJS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,130 @@ fileprivate func _bjs_StringRoundtrip_wrap(_ pointer: UnsafeMutableRawPointer) -
}
#endif

@_expose(wasm, "bjs_OptionalReturnRoundtrip_init")
@_cdecl("bjs_OptionalReturnRoundtrip_init")
public func _bjs_OptionalReturnRoundtrip_init() -> UnsafeMutableRawPointer {
#if arch(wasm32)
let ret = OptionalReturnRoundtrip()
return ret.bridgeJSLowerReturn()
#else
fatalError("Only available on WebAssembly")
#endif
}

@_expose(wasm, "bjs_OptionalReturnRoundtrip_makeIntSome")
@_cdecl("bjs_OptionalReturnRoundtrip_makeIntSome")
public func _bjs_OptionalReturnRoundtrip_makeIntSome(_ _self: UnsafeMutableRawPointer) -> Void {
#if arch(wasm32)
let ret = OptionalReturnRoundtrip.bridgeJSLiftParameter(_self).makeIntSome()
return ret.bridgeJSLowerReturn()
#else
fatalError("Only available on WebAssembly")
#endif
}

@_expose(wasm, "bjs_OptionalReturnRoundtrip_makeIntNone")
@_cdecl("bjs_OptionalReturnRoundtrip_makeIntNone")
public func _bjs_OptionalReturnRoundtrip_makeIntNone(_ _self: UnsafeMutableRawPointer) -> Void {
#if arch(wasm32)
let ret = OptionalReturnRoundtrip.bridgeJSLiftParameter(_self).makeIntNone()
return ret.bridgeJSLowerReturn()
#else
fatalError("Only available on WebAssembly")
#endif
}

@_expose(wasm, "bjs_OptionalReturnRoundtrip_makeBoolSome")
@_cdecl("bjs_OptionalReturnRoundtrip_makeBoolSome")
public func _bjs_OptionalReturnRoundtrip_makeBoolSome(_ _self: UnsafeMutableRawPointer) -> Void {
#if arch(wasm32)
let ret = OptionalReturnRoundtrip.bridgeJSLiftParameter(_self).makeBoolSome()
return ret.bridgeJSLowerReturn()
#else
fatalError("Only available on WebAssembly")
#endif
}

@_expose(wasm, "bjs_OptionalReturnRoundtrip_makeBoolNone")
@_cdecl("bjs_OptionalReturnRoundtrip_makeBoolNone")
public func _bjs_OptionalReturnRoundtrip_makeBoolNone(_ _self: UnsafeMutableRawPointer) -> Void {
#if arch(wasm32)
let ret = OptionalReturnRoundtrip.bridgeJSLiftParameter(_self).makeBoolNone()
return ret.bridgeJSLowerReturn()
#else
fatalError("Only available on WebAssembly")
#endif
}

@_expose(wasm, "bjs_OptionalReturnRoundtrip_makeDoubleSome")
@_cdecl("bjs_OptionalReturnRoundtrip_makeDoubleSome")
public func _bjs_OptionalReturnRoundtrip_makeDoubleSome(_ _self: UnsafeMutableRawPointer) -> Void {
#if arch(wasm32)
let ret = OptionalReturnRoundtrip.bridgeJSLiftParameter(_self).makeDoubleSome()
return ret.bridgeJSLowerReturn()
#else
fatalError("Only available on WebAssembly")
#endif
}

@_expose(wasm, "bjs_OptionalReturnRoundtrip_makeDoubleNone")
@_cdecl("bjs_OptionalReturnRoundtrip_makeDoubleNone")
public func _bjs_OptionalReturnRoundtrip_makeDoubleNone(_ _self: UnsafeMutableRawPointer) -> Void {
#if arch(wasm32)
let ret = OptionalReturnRoundtrip.bridgeJSLiftParameter(_self).makeDoubleNone()
return ret.bridgeJSLowerReturn()
#else
fatalError("Only available on WebAssembly")
#endif
}

@_expose(wasm, "bjs_OptionalReturnRoundtrip_makeStringSome")
@_cdecl("bjs_OptionalReturnRoundtrip_makeStringSome")
public func _bjs_OptionalReturnRoundtrip_makeStringSome(_ _self: UnsafeMutableRawPointer) -> Void {
#if arch(wasm32)
let ret = OptionalReturnRoundtrip.bridgeJSLiftParameter(_self).makeStringSome()
return ret.bridgeJSLowerReturn()
#else
fatalError("Only available on WebAssembly")
#endif
}

@_expose(wasm, "bjs_OptionalReturnRoundtrip_makeStringNone")
@_cdecl("bjs_OptionalReturnRoundtrip_makeStringNone")
public func _bjs_OptionalReturnRoundtrip_makeStringNone(_ _self: UnsafeMutableRawPointer) -> Void {
#if arch(wasm32)
let ret = OptionalReturnRoundtrip.bridgeJSLiftParameter(_self).makeStringNone()
return ret.bridgeJSLowerReturn()
#else
fatalError("Only available on WebAssembly")
#endif
}

@_expose(wasm, "bjs_OptionalReturnRoundtrip_deinit")
@_cdecl("bjs_OptionalReturnRoundtrip_deinit")
public func _bjs_OptionalReturnRoundtrip_deinit(_ pointer: UnsafeMutableRawPointer) -> Void {
#if arch(wasm32)
Unmanaged<OptionalReturnRoundtrip>.fromOpaque(pointer).release()
#else
fatalError("Only available on WebAssembly")
#endif
}

extension OptionalReturnRoundtrip: ConvertibleToJSValue, _BridgedSwiftHeapObject {
var jsValue: JSValue {
return .object(JSObject(id: UInt32(bitPattern: _bjs_OptionalReturnRoundtrip_wrap(Unmanaged.passRetained(self).toOpaque()))))
}
}

#if arch(wasm32)
@_extern(wasm, module: "Benchmarks", name: "bjs_OptionalReturnRoundtrip_wrap")
fileprivate func _bjs_OptionalReturnRoundtrip_wrap(_ pointer: UnsafeMutableRawPointer) -> Int32
#else
fileprivate func _bjs_OptionalReturnRoundtrip_wrap(_ pointer: UnsafeMutableRawPointer) -> Int32 {
fatalError("Only available on WebAssembly")
}
#endif

@_expose(wasm, "bjs_StructRoundtrip_init")
@_cdecl("bjs_StructRoundtrip_init")
public func _bjs_StructRoundtrip_init() -> UnsafeMutableRawPointer {
Expand Down
188 changes: 188 additions & 0 deletions Benchmarks/Sources/Generated/JavaScript/BridgeJS.json
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,194 @@
],
"swiftCallName" : "StringRoundtrip"
},
{
"constructor" : {
"abiName" : "bjs_OptionalReturnRoundtrip_init",
"effects" : {
"isAsync" : false,
"isStatic" : false,
"isThrows" : false
},
"parameters" : [

]
},
"methods" : [
{
"abiName" : "bjs_OptionalReturnRoundtrip_makeIntSome",
"effects" : {
"isAsync" : false,
"isStatic" : false,
"isThrows" : false
},
"name" : "makeIntSome",
"parameters" : [

],
"returnType" : {
"optional" : {
"_0" : {
"int" : {

}
}
}
}
},
{
"abiName" : "bjs_OptionalReturnRoundtrip_makeIntNone",
"effects" : {
"isAsync" : false,
"isStatic" : false,
"isThrows" : false
},
"name" : "makeIntNone",
"parameters" : [

],
"returnType" : {
"optional" : {
"_0" : {
"int" : {

}
}
}
}
},
{
"abiName" : "bjs_OptionalReturnRoundtrip_makeBoolSome",
"effects" : {
"isAsync" : false,
"isStatic" : false,
"isThrows" : false
},
"name" : "makeBoolSome",
"parameters" : [

],
"returnType" : {
"optional" : {
"_0" : {
"bool" : {

}
}
}
}
},
{
"abiName" : "bjs_OptionalReturnRoundtrip_makeBoolNone",
"effects" : {
"isAsync" : false,
"isStatic" : false,
"isThrows" : false
},
"name" : "makeBoolNone",
"parameters" : [

],
"returnType" : {
"optional" : {
"_0" : {
"bool" : {

}
}
}
}
},
{
"abiName" : "bjs_OptionalReturnRoundtrip_makeDoubleSome",
"effects" : {
"isAsync" : false,
"isStatic" : false,
"isThrows" : false
},
"name" : "makeDoubleSome",
"parameters" : [

],
"returnType" : {
"optional" : {
"_0" : {
"double" : {

}
}
}
}
},
{
"abiName" : "bjs_OptionalReturnRoundtrip_makeDoubleNone",
"effects" : {
"isAsync" : false,
"isStatic" : false,
"isThrows" : false
},
"name" : "makeDoubleNone",
"parameters" : [

],
"returnType" : {
"optional" : {
"_0" : {
"double" : {

}
}
}
}
},
{
"abiName" : "bjs_OptionalReturnRoundtrip_makeStringSome",
"effects" : {
"isAsync" : false,
"isStatic" : false,
"isThrows" : false
},
"name" : "makeStringSome",
"parameters" : [

],
"returnType" : {
"optional" : {
"_0" : {
"string" : {

}
}
}
}
},
{
"abiName" : "bjs_OptionalReturnRoundtrip_makeStringNone",
"effects" : {
"isAsync" : false,
"isStatic" : false,
"isThrows" : false
},
"name" : "makeStringNone",
"parameters" : [

],
"returnType" : {
"optional" : {
"_0" : {
"string" : {

}
}
}
}
}
],
"name" : "OptionalReturnRoundtrip",
"properties" : [

],
"swiftCallName" : "OptionalReturnRoundtrip"
},
{
"constructor" : {
"abiName" : "bjs_StructRoundtrip_init",
Expand Down
Loading
Loading