Skip to content

Commit a93a686

Browse files
committed
Update test code to avoid accidentally introduced failure
1 parent 825f695 commit a93a686

File tree

7 files changed

+361
-66
lines changed

7 files changed

+361
-66
lines changed

Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/SwiftStruct.swift

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,22 @@
6161

6262
@JS func roundtripContainer(_ container: Container) -> Container
6363

64-
extension DataPoint {
65-
@JS func distanceFromOrigin() -> Double {
66-
return (x * x + y * y).squareRoot()
64+
@JS struct Vector2D {
65+
var dx: Double
66+
var dy: Double
67+
}
68+
69+
extension Vector2D {
70+
@JS func magnitude() -> Double {
71+
return (dx * dx + dy * dy).squareRoot()
6772
}
6873

74+
@JS func scaled(by factor: Double) -> Vector2D {
75+
return Vector2D(dx: dx * factor, dy: dy * factor)
76+
}
77+
}
78+
79+
extension DataPoint {
6980
@JS static func origin() -> DataPoint {
7081
return DataPoint(x: 0, y: 0, label: "origin", optCount: nil, optFlag: nil)
7182
}

Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftStruct.json

Lines changed: 70 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -211,23 +211,6 @@
211211
]
212212
},
213213
"methods" : [
214-
{
215-
"abiName" : "bjs_DataPoint_distanceFromOrigin",
216-
"effects" : {
217-
"isAsync" : false,
218-
"isStatic" : false,
219-
"isThrows" : false
220-
},
221-
"name" : "distanceFromOrigin",
222-
"parameters" : [
223-
224-
],
225-
"returnType" : {
226-
"double" : {
227-
228-
}
229-
}
230-
},
231214
{
232215
"abiName" : "bjs_DataPoint_static_origin",
233216
"effects" : {
@@ -635,6 +618,76 @@
635618
}
636619
],
637620
"swiftCallName" : "Container"
621+
},
622+
{
623+
"methods" : [
624+
{
625+
"abiName" : "bjs_Vector2D_magnitude",
626+
"effects" : {
627+
"isAsync" : false,
628+
"isStatic" : false,
629+
"isThrows" : false
630+
},
631+
"name" : "magnitude",
632+
"parameters" : [
633+
634+
],
635+
"returnType" : {
636+
"double" : {
637+
638+
}
639+
}
640+
},
641+
{
642+
"abiName" : "bjs_Vector2D_scaled",
643+
"effects" : {
644+
"isAsync" : false,
645+
"isStatic" : false,
646+
"isThrows" : false
647+
},
648+
"name" : "scaled",
649+
"parameters" : [
650+
{
651+
"label" : "by",
652+
"name" : "factor",
653+
"type" : {
654+
"double" : {
655+
656+
}
657+
}
658+
}
659+
],
660+
"returnType" : {
661+
"swiftStruct" : {
662+
"_0" : "Vector2D"
663+
}
664+
}
665+
}
666+
],
667+
"name" : "Vector2D",
668+
"properties" : [
669+
{
670+
"isReadonly" : true,
671+
"isStatic" : false,
672+
"name" : "dx",
673+
"type" : {
674+
"double" : {
675+
676+
}
677+
}
678+
},
679+
{
680+
"isReadonly" : true,
681+
"isStatic" : false,
682+
"name" : "dy",
683+
"type" : {
684+
"double" : {
685+
686+
}
687+
}
688+
}
689+
],
690+
"swiftCallName" : "Vector2D"
638691
}
639692
]
640693
},

Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftStruct.swift

Lines changed: 70 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,6 @@ public func _bjs_DataPoint_static_dimensions_get() -> Int32 {
7777
#endif
7878
}
7979

80-
@_expose(wasm, "bjs_DataPoint_distanceFromOrigin")
81-
@_cdecl("bjs_DataPoint_distanceFromOrigin")
82-
public func _bjs_DataPoint_distanceFromOrigin() -> Float64 {
83-
#if arch(wasm32)
84-
let ret = DataPoint.bridgeJSLiftParameter().distanceFromOrigin()
85-
return ret.bridgeJSLowerReturn()
86-
#else
87-
fatalError("Only available on WebAssembly")
88-
#endif
89-
}
90-
9180
@_expose(wasm, "bjs_DataPoint_static_origin")
9281
@_cdecl("bjs_DataPoint_static_origin")
9382
public func _bjs_DataPoint_static_origin() -> Void {
@@ -466,6 +455,76 @@ fileprivate func _bjs_struct_lift_Container_extern() -> Int32 {
466455
return _bjs_struct_lift_Container_extern()
467456
}
468457

458+
extension Vector2D: _BridgedSwiftStruct {
459+
@_spi(BridgeJS) @_transparent public static func bridgeJSStackPop() -> Vector2D {
460+
let dy = Double.bridgeJSStackPop()
461+
let dx = Double.bridgeJSStackPop()
462+
return Vector2D(dx: dx, dy: dy)
463+
}
464+
465+
@_spi(BridgeJS) @_transparent public consuming func bridgeJSStackPush() {
466+
self.dx.bridgeJSStackPush()
467+
self.dy.bridgeJSStackPush()
468+
}
469+
470+
init(unsafelyCopying jsObject: JSObject) {
471+
_bjs_struct_lower_Vector2D(jsObject.bridgeJSLowerParameter())
472+
self = Self.bridgeJSStackPop()
473+
}
474+
475+
func toJSObject() -> JSObject {
476+
let __bjs_self = self
477+
__bjs_self.bridgeJSStackPush()
478+
return JSObject(id: UInt32(bitPattern: _bjs_struct_lift_Vector2D()))
479+
}
480+
}
481+
482+
#if arch(wasm32)
483+
@_extern(wasm, module: "bjs", name: "swift_js_struct_lower_Vector2D")
484+
fileprivate func _bjs_struct_lower_Vector2D_extern(_ objectId: Int32) -> Void
485+
#else
486+
fileprivate func _bjs_struct_lower_Vector2D_extern(_ objectId: Int32) -> Void {
487+
fatalError("Only available on WebAssembly")
488+
}
489+
#endif
490+
@inline(never) fileprivate func _bjs_struct_lower_Vector2D(_ objectId: Int32) -> Void {
491+
return _bjs_struct_lower_Vector2D_extern(objectId)
492+
}
493+
494+
#if arch(wasm32)
495+
@_extern(wasm, module: "bjs", name: "swift_js_struct_lift_Vector2D")
496+
fileprivate func _bjs_struct_lift_Vector2D_extern() -> Int32
497+
#else
498+
fileprivate func _bjs_struct_lift_Vector2D_extern() -> Int32 {
499+
fatalError("Only available on WebAssembly")
500+
}
501+
#endif
502+
@inline(never) fileprivate func _bjs_struct_lift_Vector2D() -> Int32 {
503+
return _bjs_struct_lift_Vector2D_extern()
504+
}
505+
506+
@_expose(wasm, "bjs_Vector2D_magnitude")
507+
@_cdecl("bjs_Vector2D_magnitude")
508+
public func _bjs_Vector2D_magnitude() -> Float64 {
509+
#if arch(wasm32)
510+
let ret = Vector2D.bridgeJSLiftParameter().magnitude()
511+
return ret.bridgeJSLowerReturn()
512+
#else
513+
fatalError("Only available on WebAssembly")
514+
#endif
515+
}
516+
517+
@_expose(wasm, "bjs_Vector2D_scaled")
518+
@_cdecl("bjs_Vector2D_scaled")
519+
public func _bjs_Vector2D_scaled(_ factor: Float64) -> Void {
520+
#if arch(wasm32)
521+
let ret = Vector2D.bridgeJSLiftParameter().scaled(by: Double.bridgeJSLiftParameter(factor))
522+
return ret.bridgeJSLowerReturn()
523+
#else
524+
fatalError("Only available on WebAssembly")
525+
#endif
526+
}
527+
469528
@_expose(wasm, "bjs_roundtrip")
470529
@_cdecl("bjs_roundtrip")
471530
public func _bjs_roundtrip() -> Void {

Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift

Lines changed: 81 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4266,17 +4266,6 @@ public func _bjs_DataPoint_static_dimensions_get() -> Int32 {
42664266
#endif
42674267
}
42684268

4269-
@_expose(wasm, "bjs_DataPoint_distanceFromOrigin")
4270-
@_cdecl("bjs_DataPoint_distanceFromOrigin")
4271-
public func _bjs_DataPoint_distanceFromOrigin() -> Float64 {
4272-
#if arch(wasm32)
4273-
let ret = DataPoint.bridgeJSLiftParameter().distanceFromOrigin()
4274-
return ret.bridgeJSLowerReturn()
4275-
#else
4276-
fatalError("Only available on WebAssembly")
4277-
#endif
4278-
}
4279-
42804269
@_expose(wasm, "bjs_DataPoint_static_origin")
42814270
@_cdecl("bjs_DataPoint_static_origin")
42824271
public func _bjs_DataPoint_static_origin() -> Void {
@@ -5089,6 +5078,87 @@ public func _bjs_ConfigStruct_static_computedSetting_get() -> Void {
50895078
#endif
50905079
}
50915080

5081+
extension Vector2D: _BridgedSwiftStruct {
5082+
@_spi(BridgeJS) @_transparent public static func bridgeJSStackPop() -> Vector2D {
5083+
let dy = Double.bridgeJSStackPop()
5084+
let dx = Double.bridgeJSStackPop()
5085+
return Vector2D(dx: dx, dy: dy)
5086+
}
5087+
5088+
@_spi(BridgeJS) @_transparent public consuming func bridgeJSStackPush() {
5089+
self.dx.bridgeJSStackPush()
5090+
self.dy.bridgeJSStackPush()
5091+
}
5092+
5093+
init(unsafelyCopying jsObject: JSObject) {
5094+
_bjs_struct_lower_Vector2D(jsObject.bridgeJSLowerParameter())
5095+
self = Self.bridgeJSStackPop()
5096+
}
5097+
5098+
func toJSObject() -> JSObject {
5099+
let __bjs_self = self
5100+
__bjs_self.bridgeJSStackPush()
5101+
return JSObject(id: UInt32(bitPattern: _bjs_struct_lift_Vector2D()))
5102+
}
5103+
}
5104+
5105+
#if arch(wasm32)
5106+
@_extern(wasm, module: "bjs", name: "swift_js_struct_lower_Vector2D")
5107+
fileprivate func _bjs_struct_lower_Vector2D_extern(_ objectId: Int32) -> Void
5108+
#else
5109+
fileprivate func _bjs_struct_lower_Vector2D_extern(_ objectId: Int32) -> Void {
5110+
fatalError("Only available on WebAssembly")
5111+
}
5112+
#endif
5113+
@inline(never) fileprivate func _bjs_struct_lower_Vector2D(_ objectId: Int32) -> Void {
5114+
return _bjs_struct_lower_Vector2D_extern(objectId)
5115+
}
5116+
5117+
#if arch(wasm32)
5118+
@_extern(wasm, module: "bjs", name: "swift_js_struct_lift_Vector2D")
5119+
fileprivate func _bjs_struct_lift_Vector2D_extern() -> Int32
5120+
#else
5121+
fileprivate func _bjs_struct_lift_Vector2D_extern() -> Int32 {
5122+
fatalError("Only available on WebAssembly")
5123+
}
5124+
#endif
5125+
@inline(never) fileprivate func _bjs_struct_lift_Vector2D() -> Int32 {
5126+
return _bjs_struct_lift_Vector2D_extern()
5127+
}
5128+
5129+
@_expose(wasm, "bjs_Vector2D_init")
5130+
@_cdecl("bjs_Vector2D_init")
5131+
public func _bjs_Vector2D_init(_ dx: Float64, _ dy: Float64) -> Void {
5132+
#if arch(wasm32)
5133+
let ret = Vector2D(dx: Double.bridgeJSLiftParameter(dx), dy: Double.bridgeJSLiftParameter(dy))
5134+
return ret.bridgeJSLowerReturn()
5135+
#else
5136+
fatalError("Only available on WebAssembly")
5137+
#endif
5138+
}
5139+
5140+
@_expose(wasm, "bjs_Vector2D_magnitude")
5141+
@_cdecl("bjs_Vector2D_magnitude")
5142+
public func _bjs_Vector2D_magnitude() -> Float64 {
5143+
#if arch(wasm32)
5144+
let ret = Vector2D.bridgeJSLiftParameter().magnitude()
5145+
return ret.bridgeJSLowerReturn()
5146+
#else
5147+
fatalError("Only available on WebAssembly")
5148+
#endif
5149+
}
5150+
5151+
@_expose(wasm, "bjs_Vector2D_scaled")
5152+
@_cdecl("bjs_Vector2D_scaled")
5153+
public func _bjs_Vector2D_scaled(_ factor: Float64) -> Void {
5154+
#if arch(wasm32)
5155+
let ret = Vector2D.bridgeJSLiftParameter().scaled(by: Double.bridgeJSLiftParameter(factor))
5156+
return ret.bridgeJSLowerReturn()
5157+
#else
5158+
fatalError("Only available on WebAssembly")
5159+
#endif
5160+
}
5161+
50925162
extension JSObjectContainer: _BridgedSwiftStruct {
50935163
@_spi(BridgeJS) @_transparent public static func bridgeJSStackPop() -> JSObjectContainer {
50945164
let optionalObject = Optional<JSObject>.bridgeJSStackPop()

0 commit comments

Comments
 (0)