Eval4j: return ObjectValue as argument of ExceptionThrown
This commit is contained in:
@@ -32,7 +32,7 @@ public trait InterpreterResult {
|
|||||||
override fun toString(): String
|
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"
|
override fun toString(): String = "Thrown $exception: $kind"
|
||||||
|
|
||||||
public enum class ExceptionKind {
|
public enum class ExceptionKind {
|
||||||
@@ -74,7 +74,7 @@ abstract class ThrownFromEvalExceptionBase(cause: Throwable): RuntimeException(c
|
|||||||
class BrokenCode(cause: Throwable): ThrownFromEvalExceptionBase(cause)
|
class BrokenCode(cause: Throwable): ThrownFromEvalExceptionBase(cause)
|
||||||
class ThrownFromEvalException(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"
|
override fun toString(): String = "Thrown from evaluated code: $exception"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,7 +212,7 @@ public fun interpreterLoop(
|
|||||||
}
|
}
|
||||||
|
|
||||||
ATHROW -> {
|
ATHROW -> {
|
||||||
val exceptionValue = frame.getStackTop()
|
val exceptionValue = frame.getStackTop() as ObjectValue
|
||||||
val handled = handler.exceptionThrown(frame, currentInsn, exceptionValue)
|
val handled = handler.exceptionThrown(frame, currentInsn, exceptionValue)
|
||||||
if (handled != null) return handled
|
if (handled != null) return handled
|
||||||
if (exceptionCaught(exceptionValue)) continue
|
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)
|
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 {
|
public fun jdi.Value?.asValue(): Value {
|
||||||
return when (this) {
|
return when (this) {
|
||||||
null -> NULL_VALUE
|
null -> NULL_VALUE
|
||||||
@@ -63,7 +70,7 @@ public fun jdi.Value?.asValue(): Value {
|
|||||||
is jdi.LongValue -> LongValue(longValue())
|
is jdi.LongValue -> LongValue(longValue())
|
||||||
is jdi.FloatValue -> FloatValue(floatValue())
|
is jdi.FloatValue -> FloatValue(floatValue())
|
||||||
is jdi.DoubleValue -> DoubleValue(doubleValue())
|
is jdi.DoubleValue -> DoubleValue(doubleValue())
|
||||||
is jdi.ObjectReference -> ObjectValue(this, type().asType())
|
is jdi.ObjectReference -> this.asValue()
|
||||||
else -> throw JDIFailureException("Unknown value: $this")
|
else -> throw JDIFailureException("Unknown value: $this")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ fun buildTestCase(ownerClass: Class<TestData>,
|
|||||||
}
|
}
|
||||||
catch (e: Throwable) {
|
catch (e: Throwable) {
|
||||||
val cause = e.getCause() ?: e
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user