[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:
committed by
Space Team
parent
ec73815f80
commit
47ade4530c
@@ -123,9 +123,11 @@ class WasmIrToBinary(
|
||||
}
|
||||
|
||||
// tag section
|
||||
appendSection(WasmBinary.Section.TAG) {
|
||||
appendVectorSize(tags.size)
|
||||
tags.forEach { appendTag(it) }
|
||||
if (tags.isNotEmpty()) {
|
||||
appendSection(WasmBinary.Section.TAG) {
|
||||
appendVectorSize(tags.size)
|
||||
tags.forEach { appendTag(it) }
|
||||
}
|
||||
}
|
||||
|
||||
appendSection(WasmBinary.Section.GLOBAL) {
|
||||
@@ -607,7 +609,7 @@ abstract class ByteWriter {
|
||||
fun writeUByte(v: UByte) {
|
||||
writeByte(v.toByte())
|
||||
}
|
||||
|
||||
|
||||
fun writeUInt32(v: UInt) {
|
||||
writeByte(v.toByte())
|
||||
writeByte((v shr 8).toByte())
|
||||
|
||||
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.js.JavaScript
|
||||
import org.jetbrains.kotlin.test.DebugMode
|
||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
||||
import org.jetbrains.kotlin.test.directives.WasmEnvironmentConfigurationDirectives
|
||||
import org.jetbrains.kotlin.test.directives.WasmEnvironmentConfigurationDirectives.DISABLE_WASM_EXCEPTION_HANDLING
|
||||
import org.jetbrains.kotlin.test.directives.WasmEnvironmentConfigurationDirectives.RUN_UNIT_TESTS
|
||||
import org.jetbrains.kotlin.test.model.TestFile
|
||||
import org.jetbrains.kotlin.test.services.TestServices
|
||||
@@ -191,6 +192,8 @@ class WasmBoxRunner(
|
||||
val testFileText = originalFile.readText()
|
||||
val failsIn: List<String> = InTextDirectivesUtils.findListWithPrefixes(testFileText, "// WASM_FAILS_IN: ")
|
||||
|
||||
val disableExceptions = DISABLE_WASM_EXCEPTION_HANDLING in testServices.moduleStructure.allDirectives
|
||||
|
||||
val exceptions = listOf(WasmVM.V8, WasmVM.SpiderMonkey).mapNotNull map@{ vm ->
|
||||
try {
|
||||
if (debugMode >= DebugMode.DEBUG) {
|
||||
@@ -199,7 +202,8 @@ class WasmBoxRunner(
|
||||
vm.run(
|
||||
"./${entryMjs}",
|
||||
jsFilePaths,
|
||||
workingDirectory = dir
|
||||
workingDirectory = dir,
|
||||
disableExceptionHandlingIfPossible = disableExceptions
|
||||
)
|
||||
if (vm.shortName in failsIn) {
|
||||
return@map AssertionError("The test expected to fail in ${vm.name}. Please update the testdata.")
|
||||
|
||||
@@ -17,10 +17,10 @@ internal sealed class WasmVM(val shortName: String) {
|
||||
val name: String = javaClass.simpleName
|
||||
protected val tool = ExternalTool(System.getProperty("javascript.engine.path.$name"))
|
||||
|
||||
abstract fun run(entryMjs: String, jsFiles: List<String>, workingDirectory: File?)
|
||||
abstract fun run(entryMjs: String, jsFiles: List<String>, workingDirectory: File?, disableExceptionHandlingIfPossible: Boolean = false)
|
||||
|
||||
object V8 : WasmVM("V8") {
|
||||
override fun run(entryMjs: String, jsFiles: List<String>, workingDirectory: File?) {
|
||||
override fun run(entryMjs: String, jsFiles: List<String>, workingDirectory: File?, disableExceptionHandlingIfPossible: Boolean) {
|
||||
tool.run(
|
||||
"--experimental-wasm-gc",
|
||||
"--wasm-final-types",
|
||||
@@ -34,10 +34,11 @@ internal sealed class WasmVM(val shortName: String) {
|
||||
}
|
||||
|
||||
object SpiderMonkey : WasmVM("SM") {
|
||||
override fun run(entryMjs: String, jsFiles: List<String>, workingDirectory: File?) {
|
||||
override fun run(entryMjs: String, jsFiles: List<String>, workingDirectory: File?, disableExceptionHandlingIfPossible: Boolean) {
|
||||
tool.run(
|
||||
"--wasm-verbose",
|
||||
"--wasm-gc",
|
||||
*if (disableExceptionHandlingIfPossible) arrayOf("--no-wasm-exceptions") else emptyArray(),
|
||||
"--wasm-function-references",
|
||||
*jsFiles.flatMap { listOf("-f", it) }.toTypedArray(),
|
||||
"--module=$entryMjs",
|
||||
|
||||
+6
@@ -139,6 +139,12 @@ public class FirWasmCodegenWasmJsInteropTestGenerated extends AbstractFirWasmCod
|
||||
runTest("compiler/testData/codegen/boxWasmJsInterop/nameClash.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("noExceptions.kt")
|
||||
public void testNoExceptions() throws Exception {
|
||||
runTest("compiler/testData/codegen/boxWasmJsInterop/noExceptions.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("nullableExternRefs.kt")
|
||||
public void testNullableExternRefs() throws Exception {
|
||||
|
||||
+6
@@ -139,6 +139,12 @@ public class K1WasmCodegenWasmJsInteropTestGenerated extends AbstractK1WasmCodeg
|
||||
runTest("compiler/testData/codegen/boxWasmJsInterop/nameClash.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("noExceptions.kt")
|
||||
public void testNoExceptions() throws Exception {
|
||||
runTest("compiler/testData/codegen/boxWasmJsInterop/noExceptions.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("nullableExternRefs.kt")
|
||||
public void testNullableExternRefs() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user