Skip to content

Commit 453b841

Browse files
authored
Fix error descriptions Embedded Swift compatibility (#759)
The BridgeJS generator emits `JSError(message: String(describing: error))` for throwing `@JS` exports, but `String.init(describing:)` is unavailable in Embedded Swift, so embedded Wasm builds of any package with a throwing export fail. The caught error is statically a `JSException` with a stored `description`, so the generated glue now uses `error.description` for identical output. Snapshots regenerated.
1 parent 9706c4c commit 453b841

7 files changed

Lines changed: 15 additions & 15 deletions

File tree

Examples/PlayBridgeJS/Sources/PlayBridgeJS/Generated/BridgeJS.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ public func _bjs_PlayBridgeJS_updateDetailed(_ _self: UnsafeMutableRawPointer, _
188188
_swift_js_throw(Int32(bitPattern: $0.id))
189189
}
190190
} else {
191-
let jsError = JSError(message: String(describing: error))
191+
let jsError = JSError(message: error.description)
192192
withExtendedLifetime(jsError.jsObject) {
193193
_swift_js_throw(Int32(bitPattern: $0.id))
194194
}

Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ public class ExportSwift {
453453
_swift_js_throw(Int32(bitPattern: $0.id))
454454
}
455455
} else {
456-
let jsError = JSError(message: String(describing: error))
456+
let jsError = JSError(message: error.description)
457457
withExtendedLifetime(jsError.jsObject) {
458458
_swift_js_throw(Int32(bitPattern: $0.id))
459459
}

Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumNamespace.Global.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public func _bjs_Services_Graph_GraphOperations_static_validate(_ graphId: Int32
117117
_swift_js_throw(Int32(bitPattern: $0.id))
118118
}
119119
} else {
120-
let jsError = JSError(message: String(describing: error))
120+
let jsError = JSError(message: error.description)
121121
withExtendedLifetime(jsError.jsObject) {
122122
_swift_js_throw(Int32(bitPattern: $0.id))
123123
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public func _bjs_Services_Graph_GraphOperations_static_validate(_ graphId: Int32
117117
_swift_js_throw(Int32(bitPattern: $0.id))
118118
}
119119
} else {
120-
let jsError = JSError(message: String(describing: error))
120+
let jsError = JSError(message: error.description)
121121
withExtendedLifetime(jsError.jsObject) {
122122
_swift_js_throw(Int32(bitPattern: $0.id))
123123
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public func _bjs_makeFoo() -> Int32 {
5959
_swift_js_throw(Int32(bitPattern: $0.id))
6060
}
6161
} else {
62-
let jsError = JSError(message: String(describing: error))
62+
let jsError = JSError(message: error.description)
6363
withExtendedLifetime(jsError.jsObject) {
6464
_swift_js_throw(Int32(bitPattern: $0.id))
6565
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public func _bjs_throwsSomething() -> Void {
1010
_swift_js_throw(Int32(bitPattern: $0.id))
1111
}
1212
} else {
13-
let jsError = JSError(message: String(describing: error))
13+
let jsError = JSError(message: error.description)
1414
withExtendedLifetime(jsError.jsObject) {
1515
_swift_js_throw(Int32(bitPattern: $0.id))
1616
}

Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6967,7 +6967,7 @@ public func _bjs_makeImportedFoo(_ valueBytes: Int32, _ valueLength: Int32) -> I
69676967
_swift_js_throw(Int32(bitPattern: $0.id))
69686968
}
69696969
} else {
6970-
let jsError = JSError(message: String(describing: error))
6970+
let jsError = JSError(message: error.description)
69716971
withExtendedLifetime(jsError.jsObject) {
69726972
_swift_js_throw(Int32(bitPattern: $0.id))
69736973
}
@@ -7002,7 +7002,7 @@ public func _bjs_throwsSwiftError(_ shouldThrow: Int32) -> Void {
70027002
_swift_js_throw(Int32(bitPattern: $0.id))
70037003
}
70047004
} else {
7005-
let jsError = JSError(message: String(describing: error))
7005+
let jsError = JSError(message: error.description)
70067006
withExtendedLifetime(jsError.jsObject) {
70077007
_swift_js_throw(Int32(bitPattern: $0.id))
70087008
}
@@ -7027,7 +7027,7 @@ public func _bjs_throwsWithIntResult() -> Int32 {
70277027
_swift_js_throw(Int32(bitPattern: $0.id))
70287028
}
70297029
} else {
7030-
let jsError = JSError(message: String(describing: error))
7030+
let jsError = JSError(message: error.description)
70317031
withExtendedLifetime(jsError.jsObject) {
70327032
_swift_js_throw(Int32(bitPattern: $0.id))
70337033
}
@@ -7052,7 +7052,7 @@ public func _bjs_throwsWithStringResult() -> Void {
70527052
_swift_js_throw(Int32(bitPattern: $0.id))
70537053
}
70547054
} else {
7055-
let jsError = JSError(message: String(describing: error))
7055+
let jsError = JSError(message: error.description)
70567056
withExtendedLifetime(jsError.jsObject) {
70577057
_swift_js_throw(Int32(bitPattern: $0.id))
70587058
}
@@ -7077,7 +7077,7 @@ public func _bjs_throwsWithBoolResult() -> Int32 {
70777077
_swift_js_throw(Int32(bitPattern: $0.id))
70787078
}
70797079
} else {
7080-
let jsError = JSError(message: String(describing: error))
7080+
let jsError = JSError(message: error.description)
70817081
withExtendedLifetime(jsError.jsObject) {
70827082
_swift_js_throw(Int32(bitPattern: $0.id))
70837083
}
@@ -7102,7 +7102,7 @@ public func _bjs_throwsWithFloatResult() -> Float32 {
71027102
_swift_js_throw(Int32(bitPattern: $0.id))
71037103
}
71047104
} else {
7105-
let jsError = JSError(message: String(describing: error))
7105+
let jsError = JSError(message: error.description)
71067106
withExtendedLifetime(jsError.jsObject) {
71077107
_swift_js_throw(Int32(bitPattern: $0.id))
71087108
}
@@ -7127,7 +7127,7 @@ public func _bjs_throwsWithDoubleResult() -> Float64 {
71277127
_swift_js_throw(Int32(bitPattern: $0.id))
71287128
}
71297129
} else {
7130-
let jsError = JSError(message: String(describing: error))
7130+
let jsError = JSError(message: error.description)
71317131
withExtendedLifetime(jsError.jsObject) {
71327132
_swift_js_throw(Int32(bitPattern: $0.id))
71337133
}
@@ -7152,7 +7152,7 @@ public func _bjs_throwsWithSwiftHeapObjectResult() -> UnsafeMutableRawPointer {
71527152
_swift_js_throw(Int32(bitPattern: $0.id))
71537153
}
71547154
} else {
7155-
let jsError = JSError(message: String(describing: error))
7155+
let jsError = JSError(message: error.description)
71567156
withExtendedLifetime(jsError.jsObject) {
71577157
_swift_js_throw(Int32(bitPattern: $0.id))
71587158
}
@@ -7177,7 +7177,7 @@ public func _bjs_throwsWithJSObjectResult() -> Int32 {
71777177
_swift_js_throw(Int32(bitPattern: $0.id))
71787178
}
71797179
} else {
7180-
let jsError = JSError(message: String(describing: error))
7180+
let jsError = JSError(message: error.description)
71817181
withExtendedLifetime(jsError.jsObject) {
71827182
_swift_js_throw(Int32(bitPattern: $0.id))
71837183
}

0 commit comments

Comments
 (0)