diff --git a/eval4j/src/org/jetbrains/eval4j/interpreterLoop.kt b/eval4j/src/org/jetbrains/eval4j/interpreterLoop.kt index 1d68944431f..02d98e7be9e 100644 --- a/eval4j/src/org/jetbrains/eval4j/interpreterLoop.kt +++ b/eval4j/src/org/jetbrains/eval4j/interpreterLoop.kt @@ -32,7 +32,7 @@ public trait InterpreterResult { override fun toString(): String } -public class ExceptionThrown(public val exception: Value, public val kind: ExceptionKind): InterpreterResult { +public class ExceptionThrown(public val exception: ObjectValue, public val kind: ExceptionKind): InterpreterResult { override fun toString(): String = "Thrown $exception: $kind" public enum class ExceptionKind { @@ -74,7 +74,7 @@ abstract class ThrownFromEvalExceptionBase(cause: Throwable): RuntimeException(c class BrokenCode(cause: Throwable): ThrownFromEvalExceptionBase(cause) class ThrownFromEvalException(cause: Throwable): ThrownFromEvalExceptionBase(cause) -class ThrownFromEvaluatedCodeException(val exception: Value): RuntimeException() { +class ThrownFromEvaluatedCodeException(val exception: ObjectValue): RuntimeException() { override fun toString(): String = "Thrown from evaluated code: $exception" } @@ -212,7 +212,7 @@ public fun interpreterLoop( } ATHROW -> { - val exceptionValue = frame.getStackTop() + val exceptionValue = frame.getStackTop() as ObjectValue val handled = handler.exceptionThrown(frame, currentInsn, exceptionValue) if (handled != null) return handled if (exceptionCaught(exceptionValue)) continue diff --git a/eval4j/src/org/jetbrains/eval4j/jdi/jdiValues.kt b/eval4j/src/org/jetbrains/eval4j/jdi/jdiValues.kt index 46c5581dbd5..d9528d41ca8 100644 --- a/eval4j/src/org/jetbrains/eval4j/jdi/jdiValues.kt +++ b/eval4j/src/org/jetbrains/eval4j/jdi/jdiValues.kt @@ -51,6 +51,13 @@ class JDIFailureException(message: String?, cause: Throwable? = null): RuntimeEx fun T?.sure(message: String? = null): T = this ?: throw JDIFailureException(message) +public fun jdi.ObjectReference?.asValue(): ObjectValue { + return when (this) { + null -> NULL_VALUE + else -> ObjectValue(this, type().asType()) + } +} + public fun jdi.Value?.asValue(): Value { return when (this) { null -> NULL_VALUE @@ -63,7 +70,7 @@ public fun jdi.Value?.asValue(): Value { is jdi.LongValue -> LongValue(longValue()) is jdi.FloatValue -> FloatValue(floatValue()) is jdi.DoubleValue -> DoubleValue(doubleValue()) - is jdi.ObjectReference -> ObjectValue(this, type().asType()) + is jdi.ObjectReference -> this.asValue() else -> throw JDIFailureException("Unknown value: $this") } } diff --git a/eval4j/test/org/jetbrains/eval4j/test/suiteBuilder.kt b/eval4j/test/org/jetbrains/eval4j/test/suiteBuilder.kt index eecfeac02f1..78af3c3f509 100644 --- a/eval4j/test/org/jetbrains/eval4j/test/suiteBuilder.kt +++ b/eval4j/test/org/jetbrains/eval4j/test/suiteBuilder.kt @@ -82,7 +82,7 @@ fun buildTestCase(ownerClass: Class, } catch (e: Throwable) { val cause = e.getCause() ?: e - expected = ExceptionThrown(objectToValue(cause, Type.getType(cause.javaClass)), ExceptionThrown.ExceptionKind.FROM_EVALUATOR) + expected = ExceptionThrown(objectToValue(cause, Type.getType(cause.javaClass)) as ObjectValue, ExceptionThrown.ExceptionKind.FROM_EVALUATOR) } } }