[WasmJs] Support catching JS exceptions

Fixed #KT-65660
This commit is contained in:
Igor Yakovlev
2024-02-12 20:41:38 +01:00
committed by Space Team
parent c6aac835e5
commit 8fe5cf2641
18 changed files with 216 additions and 26 deletions
@@ -0,0 +1,42 @@
// TARGET_BACKEND: WASM
fun throwSomeJsException(): Int = js("{ throw 42; }")
fun withFinally(): Boolean {
try {
throwSomeJsException()
return false
} finally {
return true
}
return false
}
fun withThrowable(): Boolean {
try {
throwSomeJsException()
return false
} catch (_: Throwable) {
return true
}
return false
}
fun withJsException(): Boolean {
try {
throwSomeJsException()
return false
} catch (_: JsException) {
return true
}
return false
}
fun box(): String {
if (!withFinally()) return "FAIL1"
if (!withThrowable()) return "FAIL2"
if (!withJsException()) return "FAIL3"
return "OK"
}