Understands aconst_null. To achieve that we realized that invokeinterface bytecode is followed by four bytes, not just two.
1.1 --- a/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Fri Sep 28 12:58:20 2012 +0200
1.2 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Fri Sep 28 14:45:00 2012 +0200
1.3 @@ -355,6 +355,9 @@
1.4 case bc_i2s:
1.5 out.append("/* number conversion */");
1.6 break;
1.7 + case bc_aconst_null:
1.8 + out.append("stack.push(null);");
1.9 + break;
1.10 case bc_iconst_0:
1.11 case bc_dconst_0:
1.12 case bc_lconst_0:
1.13 @@ -485,7 +488,10 @@
1.14 i += 2;
1.15 break;
1.16 }
1.17 - case bc_invokeinterface:
1.18 + case bc_invokeinterface: {
1.19 + i = invokeVirtualMethod(byteCodes, i) + 2;
1.20 + break;
1.21 + }
1.22 case bc_invokevirtual:
1.23 i = invokeVirtualMethod(byteCodes, i);
1.24 break;
2.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/StaticMethod.java Fri Sep 28 12:58:20 2012 +0200
2.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/StaticMethod.java Fri Sep 28 14:45:00 2012 +0200
2.3 @@ -24,6 +24,18 @@
2.4 public class StaticMethod {
2.5 private static int cnt;
2.6
2.7 + public static Object none(int x, int y) {
2.8 + Object toRet = null;
2.9 + for (int i = x; i < y; i++) {
2.10 + if (i == 2) {
2.11 + toRet = null;
2.12 + } else {
2.13 + toRet = new Object();
2.14 + }
2.15 + }
2.16 + return toRet;
2.17 + }
2.18 +
2.19 public static int sum(int x, int y) {
2.20 return x + y;
2.21 }
3.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/StaticMethodTest.java Fri Sep 28 12:58:20 2012 +0200
3.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/StaticMethodTest.java Fri Sep 28 14:45:00 2012 +0200
3.3 @@ -110,6 +110,13 @@
3.4 3
3.5 );
3.6 }
3.7 + @Test public void nullCheck() throws Exception {
3.8 + assertExec(
3.9 + "Returns nothing",
3.10 + "org_apidesign_vm4brwsr_StaticMethod_noneLjava_lang_ObjectII",
3.11 + null, 1, 3
3.12 + );
3.13 + }
3.14 @Test public void and() throws Exception {
3.15 assertExec(
3.16 "And will be 3",
3.17 @@ -143,7 +150,7 @@
3.18 if (ret == null && expRes == null) {
3.19 return;
3.20 }
3.21 - if (expRes.equals(ret)) {
3.22 + if (expRes != null && expRes.equals(ret)) {
3.23 return;
3.24 }
3.25 assertEquals(ret, expRes, msg + "was: " + ret + "\n" + sb);