Move unhandledExceptionHook to kotlin code (#4704)

This commit is contained in:
Alexander Shabalin
2021-02-16 12:03:52 +03:00
committed by Vasily Levchenko
parent 3ee0dc112b
commit d5ca285a79
9 changed files with 62 additions and 64 deletions
@@ -2531,12 +2531,20 @@ standaloneTest("kt-37572") {
}
standaloneTest("custom_hook") {
enabled = (project.testTarget != 'wasm32') // Uses exceptions.
enabled = (project.testTarget != 'wasm32') && // Uses exceptions.
!isExperimentalMM // Experimental MM does not support freezing yet.
goldValue = "value 42: Error\n"
expectedExitStatus = 1
source = "runtime/exceptions/custom_hook.kt"
}
standaloneTest("exception_in_global_init") {
enabled = (project.testTarget != 'wasm32') // Uses exceptions.
source = "runtime/exceptions/exception_in_global_init.kt"
expectedExitStatusChecker = { it != 0 }
outputChecker = { s -> s.contains("Uncaught Kotlin exception: kotlin.IllegalStateException: FAIL") && !s.contains("in kotlin main") }
}
standaloneTest("runtime_math_exceptions") {
enabled = (project.testTarget != 'wasm32')
source = "stdlib_external/numbers/MathExceptionTest.kt"
@@ -6,31 +6,17 @@ import kotlin.test.*
import kotlin.native.concurrent.*
fun setHookLegacyMM(hook: ReportUnhandledExceptionHook) : ReportUnhandledExceptionHook? {
fun main(args : Array<String>) {
assertFailsWith<InvalidMutabilityException> {
setUnhandledExceptionHook { _ -> println("wrong") }
}
return setUnhandledExceptionHook(hook.freeze())
}
fun setHookNewMM(hook: ReportUnhandledExceptionHook) : ReportUnhandledExceptionHook? {
return setUnhandledExceptionHook(hook)
}
fun setHook(hook: ReportUnhandledExceptionHook) : ReportUnhandledExceptionHook? {
return when (kotlin.native.Platform.memoryModel) {
kotlin.native.MemoryModel.EXPERIMENTAL -> setHookNewMM(hook)
else -> setHookLegacyMM(hook)
}
}
fun main() {
val x = 42
val old = setHook {
val old = setUnhandledExceptionHook({
throwable: Throwable -> println("value $x: ${throwable::class.simpleName}")
}
}.freeze())
assertNull(old)
throw Error("an error")
}
}
@@ -0,0 +1,12 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
import kotlin.test.*
val p: Nothing = error("FAIL")
fun main() {
println("in kotlin main")
}