[Wasm] Support throwIAE and throwNoBranchMatchedException

Add a couple of test stubs
Unmute tests
This commit is contained in:
Svyatoslav Kuzmich
2021-10-01 19:42:20 +03:00
committed by Space
parent 6eb81517a0
commit fa3e75463e
10 changed files with 23 additions and 16 deletions
@@ -44,6 +44,9 @@ class WasmSymbols(
override val throwNullPointerException = getInternalFunction("THROW_NPE") override val throwNullPointerException = getInternalFunction("THROW_NPE")
override val throwISE = getInternalFunction("THROW_ISE") override val throwISE = getInternalFunction("THROW_ISE")
override val throwTypeCastException = getInternalFunction("THROW_CCE") override val throwTypeCastException = getInternalFunction("THROW_CCE")
val throwIAE = getInternalFunction("THROW_IAE")
val throwNoBranchMatchedException =
getInternalFunction("throwNoBranchMatchedException")
override val throwUninitializedPropertyAccessException = override val throwUninitializedPropertyAccessException =
getInternalFunction("throwUninitializedPropertyAccessException") getInternalFunction("throwUninitializedPropertyAccessException")
override val defaultConstructorMarker = override val defaultConstructorMarker =
@@ -102,13 +102,11 @@ class BuiltInsLowering(val context: WasmBackendContext) : FileLoweringPass {
return irCall(call, newSymbol) return irCall(call, newSymbol)
} }
// TODO: Implement
irBuiltins.noWhenBranchMatchedExceptionSymbol -> irBuiltins.noWhenBranchMatchedExceptionSymbol ->
return builder.irCall(symbols.wasmUnreachable, irBuiltins.nothingType) return builder.irCall(symbols.throwNoBranchMatchedException, irBuiltins.nothingType)
// TODO: Implement
irBuiltins.illegalArgumentExceptionSymbol -> irBuiltins.illegalArgumentExceptionSymbol ->
return builder.irCall(symbols.wasmUnreachable, irBuiltins.nothingType) return builder.irCall(symbols.throwIAE, irBuiltins.nothingType)
irBuiltins.dataClassArrayMemberHashCodeSymbol -> { irBuiltins.dataClassArrayMemberHashCodeSymbol -> {
// TODO: Implement // TODO: Implement
@@ -1,5 +1,3 @@
// IGNORE_BACKEND: WASM
// WASM_MUTE_REASON: KOTLIN_TEST_LIB
// WITH_RUNTIME // WITH_RUNTIME
import kotlin.test.* import kotlin.test.*
@@ -1,5 +1,3 @@
// IGNORE_BACKEND: WASM
// WASM_MUTE_REASON: KOTLIN_TEST_LIB
// WITH_RUNTIME // WITH_RUNTIME
import kotlin.test.* import kotlin.test.*
@@ -1,5 +1,3 @@
// IGNORE_BACKEND: WASM
// WASM_MUTE_REASON: KOTLIN_TEST_LIB
// WITH_RUNTIME // WITH_RUNTIME
import kotlin.test.* import kotlin.test.*
@@ -1,5 +1,3 @@
// IGNORE_BACKEND: WASM
// WASM_MUTE_REASON: KOTLIN_TEST_LIB
// WITH_RUNTIME // WITH_RUNTIME
import kotlin.test.* import kotlin.test.*
@@ -1,5 +1,3 @@
// IGNORE_BACKEND: WASM
// WASM_MUTE_REASON: KOTLIN_TEST_LIB
// WITH_RUNTIME // WITH_RUNTIME
import kotlin.test.* import kotlin.test.*
@@ -1,5 +1,3 @@
// IGNORE_BACKEND: WASM
// WASM_MUTE_REASON: KOTLIN_TEST_LIB
// IGNORE_BACKEND: NATIVE // IGNORE_BACKEND: NATIVE
// WITH_RUNTIME // WITH_RUNTIME
import kotlin.test.assertTrue import kotlin.test.assertTrue
@@ -21,6 +21,10 @@ internal fun THROW_IAE(): Nothing {
throw IllegalArgumentException() throw IllegalArgumentException()
} }
internal fun throwNoBranchMatchedException(): Nothing {
throw NoWhenBranchMatchedException()
}
@PublishedApi @PublishedApi
internal fun throwUninitializedPropertyAccessException(name: String): Nothing { internal fun throwUninitializedPropertyAccessException(name: String): Nothing {
throw UninitializedPropertyAccessException("lateinit property $name has not been initialized") throw UninitializedPropertyAccessException("lateinit property $name has not been initialized")
@@ -5,6 +5,7 @@
package kotlin.test package kotlin.test
import kotlin.internal.InlineOnly
import kotlin.internal.OnlyInputTypes import kotlin.internal.OnlyInputTypes
public fun assert(x: Boolean) { public fun assert(x: Boolean) {
@@ -20,3 +21,16 @@ public fun <@OnlyInputTypes T> assertEquals(expected: T, actual: T, message: Str
public fun <@OnlyInputTypes T> assertNotEquals(illegal: T, actual: T, message: String? = null) { public fun <@OnlyInputTypes T> assertNotEquals(illegal: T, actual: T, message: String? = null) {
if (illegal == actual) throw AssertionError("assertNotEquals failed: illegal:$illegal, actual:$actual, message=$message") if (illegal == actual) throw AssertionError("assertNotEquals failed: illegal:$illegal, actual:$actual, message=$message")
} }
@InlineOnly
public inline fun <reified T : Throwable> assertFailsWith(message: String? = null, block: () -> Unit): T {
var throwable: Throwable? = null
try {
block()
} catch (e: Throwable) {
throwable = e
}
return throwable as? T ?: throw AssertionError("assertFailsWith failed: $message")
}
public fun assertTrue(x: Boolean) = assert(x)