-
-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathThrows.swift
More file actions
23 lines (23 loc) · 667 Bytes
/
Copy pathThrows.swift
File metadata and controls
23 lines (23 loc) · 667 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
@_expose(wasm, "bjs_throwsSomething")
@_cdecl("bjs_throwsSomething")
public func _bjs_throwsSomething() -> Void {
#if arch(wasm32)
do {
try throwsSomething()
} catch let error {
if let error = error.thrownValue.object {
withExtendedLifetime(error) {
_swift_js_throw(Int32(bitPattern: $0.id))
}
} else {
let jsError = JSError(message: error.description)
withExtendedLifetime(jsError.jsObject) {
_swift_js_throw(Int32(bitPattern: $0.id))
}
}
return
}
#else
fatalError("Only available on WebAssembly")
#endif
}