Eval4j: return ObjectValue as argument of ExceptionThrown

This commit is contained in:
Natalia Ukhorskaya
2014-12-23 19:05:11 +03:00
parent a894979c81
commit b6095eca58
3 changed files with 12 additions and 5 deletions
@@ -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
@@ -51,6 +51,13 @@ class JDIFailureException(message: String?, cause: Throwable? = null): RuntimeEx
fun <T: Any> 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")
}
}
@@ -82,7 +82,7 @@ fun buildTestCase(ownerClass: Class<TestData>,
}
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)
}
}
}