Rewrite exception handler to catch null pointer exception in js ir

For now null check works as !! operator called in jvm.
So it throw KotlinNullPointerException, but js ir require
NullPointerException
This commit is contained in:
Ivan Kylchik
2020-01-21 13:28:14 +03:00
parent 5209f4a9c0
commit a6cc7cdc23
@@ -118,8 +118,17 @@ class IrInterpreter(irModule: IrModuleFragment) {
} }
} catch (e: Exception) { // TODO catch Throwable } catch (e: Exception) { // TODO catch Throwable
// catch exception from JVM such as: ArithmeticException, StackOverflowError and others // catch exception from JVM such as: ArithmeticException, StackOverflowError and others
val irExceptionClass = irExceptions.firstOrNull { it.name.asString() == e::class.java.simpleName } val exceptionName = e::class.java.simpleName
irExceptionClass?.let { data.pushReturnValue(Wrapper(e, it)) } ?: throw AssertionError("Cannot handle exception $e") val irExceptionClass = irExceptions.firstOrNull { it.name.asString() == exceptionName }
if (irExceptionClass == null && exceptionName == "KotlinNullPointerException") {
// this block is used to replace jvm null pointer exception with common one
// TODO figure something better
data.pushReturnValue(Wrapper(e, irExceptions.first { it.name.asString() == "NullPointerException" }))
} else {
irExceptionClass?.let { data.pushReturnValue(Wrapper(e, it)) } ?: throw AssertionError("Cannot handle exception $e")
}
return Code.EXCEPTION return Code.EXCEPTION
} }
} }