Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
67 changes: 67 additions & 0 deletions Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2884,6 +2884,62 @@ public func _bjs_DataPoint_init(_ x: Float64, _ y: Float64, _ labelBytes: Int32,
#endif
}

extension PublicPoint: _BridgedSwiftStruct {
@_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter() -> PublicPoint {
let y = Int.bridgeJSLiftParameter()
let x = Int.bridgeJSLiftParameter()
return PublicPoint(x: x, y: y)
}

@_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() {
self.x.bridgeJSLowerStackReturn()
self.y.bridgeJSLowerStackReturn()
}

public init(unsafelyCopying jsObject: JSObject) {
let __bjs_cleanupId = _bjs_struct_lower_PublicPoint(jsObject.bridgeJSLowerParameter())
defer {
_swift_js_struct_cleanup(__bjs_cleanupId)
}
self = Self.bridgeJSLiftParameter()
}

public func toJSObject() -> JSObject {
let __bjs_self = self
__bjs_self.bridgeJSLowerReturn()
return JSObject(id: UInt32(bitPattern: _bjs_struct_lift_PublicPoint()))
}
}

#if arch(wasm32)
@_extern(wasm, module: "bjs", name: "swift_js_struct_lower_PublicPoint")
fileprivate func _bjs_struct_lower_PublicPoint(_ objectId: Int32) -> Int32
#else
fileprivate func _bjs_struct_lower_PublicPoint(_ objectId: Int32) -> Int32 {
fatalError("Only available on WebAssembly")
}
#endif

#if arch(wasm32)
@_extern(wasm, module: "bjs", name: "swift_js_struct_lift_PublicPoint")
fileprivate func _bjs_struct_lift_PublicPoint() -> Int32
#else
fileprivate func _bjs_struct_lift_PublicPoint() -> Int32 {
fatalError("Only available on WebAssembly")
}
#endif

@_expose(wasm, "bjs_PublicPoint_init")
@_cdecl("bjs_PublicPoint_init")
public func _bjs_PublicPoint_init(_ x: Int32, _ y: Int32) -> Void {
#if arch(wasm32)
let ret = PublicPoint(x: Int.bridgeJSLiftParameter(x), y: Int.bridgeJSLiftParameter(y))
return ret.bridgeJSLowerReturn()
#else
fatalError("Only available on WebAssembly")
#endif
}

extension Address: _BridgedSwiftStruct {
@_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter() -> Address {
let zipCode = Optional<Int>.bridgeJSLiftParameter()
Expand Down Expand Up @@ -5963,6 +6019,17 @@ public func _bjs_roundTripDataPoint() -> Void {
#endif
}

@_expose(wasm, "bjs_roundTripPublicPoint")
@_cdecl("bjs_roundTripPublicPoint")
public func _bjs_roundTripPublicPoint() -> Void {
#if arch(wasm32)
let ret = roundTripPublicPoint(_: PublicPoint.bridgeJSLiftParameter())
return ret.bridgeJSLowerReturn()
#else
fatalError("Only available on WebAssembly")
#endif
}

@_expose(wasm, "bjs_roundTripContact")
@_cdecl("bjs_roundTripContact")
public func _bjs_roundTripContact() -> Void {
Expand Down
83 changes: 83 additions & 0 deletions Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json
Original file line number Diff line number Diff line change
Expand Up @@ -11131,6 +11131,31 @@
}
}
},
{
"abiName" : "bjs_roundTripPublicPoint",
"effects" : {
"isAsync" : false,
"isStatic" : false,
"isThrows" : false
},
"name" : "roundTripPublicPoint",
"parameters" : [
{
"label" : "_",
"name" : "point",
"type" : {
"swiftStruct" : {
"_0" : "PublicPoint"
}
}
}
],
"returnType" : {
"swiftStruct" : {
"_0" : "PublicPoint"
}
}
},
{
"abiName" : "bjs_roundTripContact",
"effects" : {
Expand Down Expand Up @@ -12196,6 +12221,64 @@
],
"swiftCallName" : "DataPoint"
},
{
"constructor" : {
"abiName" : "bjs_PublicPoint_init",
"effects" : {
"isAsync" : false,
"isStatic" : false,
"isThrows" : false
},
"parameters" : [
{
"label" : "x",
"name" : "x",
"type" : {
"int" : {

}
}
},
{
"label" : "y",
"name" : "y",
"type" : {
"int" : {

}
}
}
]
},
"explicitAccessControl" : "public",
"methods" : [

],
"name" : "PublicPoint",
"properties" : [
{
"isReadonly" : true,
"isStatic" : false,
"name" : "x",
"type" : {
"int" : {

}
}
},
{
"isReadonly" : true,
"isStatic" : false,
"name" : "y",
"type" : {
"int" : {

}
}
}
],
"swiftCallName" : "PublicPoint"
},
{
"methods" : [

Expand Down
14 changes: 14 additions & 0 deletions Tests/BridgeJSRuntimeTests/StructAPIs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@
}
}

@JS public struct PublicPoint {
public var x: Int
public var y: Int

@JS public init(x: Int, y: Int) {
self.x = x
self.y = y
}
}

@JS struct Address {
var street: String
var city: String
Expand Down Expand Up @@ -168,6 +178,10 @@
return data
}

@JS public func roundTripPublicPoint(_ point: PublicPoint) -> PublicPoint {
point
}

@JS func roundTripContact(_ contact: Contact) -> Contact {
return contact
}
Expand Down
3 changes: 3 additions & 0 deletions Tests/prelude.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,9 @@ function testStructSupport(exports) {
const data2 = { x: 0.0, y: 0.0, label: "", optCount: null, optFlag: null };
assert.deepEqual(exports.roundTripDataPoint(data2), data2);

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

const pointerFields1 = { raw: 1, mutRaw: 4, opaque: 1024, ptr: 65536, mutPtr: 2 };
assert.deepEqual(exports.roundTripPointerFields(pointerFields1), pointerFields1);

Expand Down