Invoke instance method supported

This commit is contained in:
Andrey Breslav
2013-10-06 22:59:44 +04:00
parent 47fd67a9b0
commit e8ac8cd7fa
2 changed files with 24 additions and 11 deletions
+18 -10
View File
@@ -98,7 +98,7 @@ class TestData {
}
}
static int testSimpleFinally() {
static int simpleFinally() {
int i = 5;
try {
return i;
@@ -108,7 +108,7 @@ class TestData {
}
}
static int testSimpleFinallyWithReturn() {
static int simpleFinallyWithReturn() {
int i = 5;
try {
return i;
@@ -118,7 +118,7 @@ class TestData {
}
}
static int testSimpleFinallyWithContinueInLoop() {
static int simpleFinallyWithContinueInLoop() {
int i = 5;
while (true) {
try {
@@ -131,7 +131,7 @@ class TestData {
}
}
static int testSimpleFinallyWithBreakInLoop() {
static int simpleFinallyWithBreakInLoop() {
int i = 5;
while (true) {
try {
@@ -144,21 +144,21 @@ class TestData {
return i;
}
static Object testCall() {
static Object call() {
return Integer.valueOf(1);
}
static Object testCallWithObject() {
static Object callWithObject() {
return String.valueOf("str");
}
static Object testGetStaticField() {
static Object getStaticField() {
return String.CASE_INSENSITIVE_ORDER;
}
static int FIELD = 0;
static int testPutStaticField() {
static int putStaticField() {
FIELD = 5;
int f1 = FIELD;
FIELD = 6;
@@ -169,16 +169,20 @@ class TestData {
static class C {
int y = 15;
int getY() {
return y;
}
static C newC() {
return new C();
}
}
static int testGetInstanceField() {
static int getInstanceField() {
return C.newC().y;
}
static int testPutInstanceField() {
static int putInstanceField() {
C c = C.newC();
c.y = 5;
int f1 = c.y;
@@ -187,4 +191,8 @@ class TestData {
return f1 + f2;
}
static int instanceMethod() {
return C.newC().getY();
}
}
+6 -1
View File
@@ -185,7 +185,12 @@ object REFLECTION_EVAL : Eval {
}
override fun invokeMethod(instance: Value, methodDesc: MethodDescription, arguments: List<Value>, invokespecial: Boolean): Value {
throw UnsupportedOperationException()
// TODO: INVOKESPECIAL
val obj = instance.obj
val method = obj.javaClass.findMethod(methodDesc)
assertNotNull("Method not found: $methodDesc", method)
val result = method!!.invoke(obj, *arguments.map { v -> v.obj }.copyToArray())
return objectToValue(result, methodDesc.returnType)
}
}