[Wasm] Add compiler flag to disable exception handling proposal

Fail with unreachable instead of throwing an exception

Merge-request: KT-MR-11481
Merged-by: Svyatoslav Kuzmich <svyatoslav.kuzmich@jetbrains.com>
This commit is contained in:
Svyatoslav Kuzmich
2023-08-07 16:19:29 +00:00
committed by Space Team
parent ec73815f80
commit 47ade4530c
17 changed files with 118 additions and 13 deletions
+2
View File
@@ -60,6 +60,8 @@ where advanced options include:
-Xwasm-generate-wat Generate wat file
-Xwasm-kclass-fqn Enable support for FQ names in KClass
-Xwasm-target Set up Wasm target (wasm-js or wasm-wasi)
-Xwasm-use-traps-instead-of-exceptions
Trap instead of throwing exceptions
-Xallow-any-scripts-in-source-roots
Allow to compile any scripts along with regular Kotlin sources
-Xallow-kotlin-package Allow compiling code in package 'kotlin' and allow not requiring kotlin.stdlib in module-info
@@ -0,0 +1,46 @@
// TARGET_BACKEND: WASM
// DISABLE_WASM_EXCEPTION_HANDLING
// MODULE: main
// FILE: foo.kt
@JsExport
fun sumNumbers(x: Int): Int =
(0..x).toList().sum()
@JsExport
fun add(x: Int, y: Int): Int =
x + y
@JsExport
fun throws() {
try {
error("Test Error")
} catch (e: Throwable) {
// This code normally catches the error,
// but with exception handling disabled it should fail with trap
}
}
// FILE: entry.mjs
import wasmExports from "./index.mjs";
if (wasmExports.add(10, 20) !== 30) {
throw "Fail add";
}
if (wasmExports.sumNumbers(10) !== 55) {
throw "Fail sumNumbers";
}
var thrown = false;
try {
wasmExports.throws();
} catch(e) {
thrown = true;
}
if (!thrown) {
throw "Fail exception was not thrown";
}