Files
kotlin-fork/compiler/testData/codegen/boxWasmJsInterop/jsException.kt
T
Igor Yakovlev 8fe5cf2641 [WasmJs] Support catching JS exceptions
Fixed #KT-65660
2024-03-11 14:27:12 +00:00

43 lines
736 B
Kotlin
Vendored

// 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"
}