Long (and probably also double) parameters need to increase the load index by two
1.1 --- a/boot/src/main/java/org/apidesign/html/boot/impl/JsClassLoader.java Thu Jul 11 21:26:28 2013 +0200
1.2 +++ b/boot/src/main/java/org/apidesign/html/boot/impl/JsClassLoader.java Fri Jul 12 09:43:02 2013 +0200
1.3 @@ -252,6 +252,7 @@
1.4 private boolean nowReturn;
1.5 private Type returnType;
1.6 private int index;
1.7 + private int loadIndex = offset;
1.8
1.9 public SV() {
1.10 super(Opcodes.ASM4);
1.11 @@ -265,15 +266,15 @@
1.12 return;
1.13 }
1.14 FindInMethod.super.visitInsn(Opcodes.DUP);
1.15 - FindInMethod.super.visitIntInsn(Opcodes.SIPUSH, index);
1.16 - FindInMethod.super.visitVarInsn(t.getOpcode(Opcodes.ILOAD), index + offset);
1.17 + FindInMethod.super.visitIntInsn(Opcodes.SIPUSH, index++);
1.18 + FindInMethod.super.visitVarInsn(t.getOpcode(Opcodes.ILOAD), loadIndex++);
1.19 String factory;
1.20 switch (descriptor) {
1.21 case 'I': factory = "java/lang/Integer"; break;
1.22 - case 'J': factory = "java/lang/Long"; break;
1.23 + case 'J': factory = "java/lang/Long"; loadIndex++; break;
1.24 case 'S': factory = "java/lang/Short"; break;
1.25 case 'F': factory = "java/lang/Float"; break;
1.26 - case 'D': factory = "java/lang/Double"; break;
1.27 + case 'D': factory = "java/lang/Double"; loadIndex++; break;
1.28 case 'Z': factory = "java/lang/Boolean"; break;
1.29 case 'C': factory = "java/lang/Character"; break;
1.30 case 'B': factory = "java/lang/Byte"; break;
1.31 @@ -283,7 +284,6 @@
1.32 factory, "valueOf", "(" + descriptor + ")L" + factory + ";"
1.33 );
1.34 FindInMethod.super.visitInsn(Opcodes.AASTORE);
1.35 - index++;
1.36 }
1.37
1.38 @Override
1.39 @@ -312,10 +312,9 @@
1.40
1.41 private void loadObject() {
1.42 FindInMethod.super.visitInsn(Opcodes.DUP);
1.43 - FindInMethod.super.visitIntInsn(Opcodes.SIPUSH, index);
1.44 - FindInMethod.super.visitVarInsn(Opcodes.ALOAD, index + offset);
1.45 + FindInMethod.super.visitIntInsn(Opcodes.SIPUSH, index++);
1.46 + FindInMethod.super.visitVarInsn(Opcodes.ALOAD, loadIndex++);
1.47 FindInMethod.super.visitInsn(Opcodes.AASTORE);
1.48 - index++;
1.49 }
1.50
1.51 }
2.1 --- a/boot/src/test/java/org/apidesign/html/boot/impl/JsClassLoaderBase.java Thu Jul 11 21:26:28 2013 +0200
2.2 +++ b/boot/src/test/java/org/apidesign/html/boot/impl/JsClassLoaderBase.java Fri Jul 12 09:43:02 2013 +0200
2.3 @@ -156,4 +156,19 @@
2.4 Method st = methodClass.getMethod("parseInt", String.class);
2.5 assertEquals(st.invoke(null, "42"), 42, "Meaning of JavaScript?");
2.6 }
2.7 +
2.8 + @Test public void firstLong() throws Throwable {
2.9 + Method st = methodClass.getMethod("chooseLong", boolean.class, boolean.class, long.class, long.class);
2.10 + assertEquals(st.invoke(null, true, false, 10, 20), 10L, "Take first value");
2.11 + }
2.12 +
2.13 + @Test public void secondLong() throws Throwable {
2.14 + Method st = methodClass.getMethod("chooseLong", boolean.class, boolean.class, long.class, long.class);
2.15 + assertEquals(st.invoke(null, false, true, 10, 20), 20L, "Take 2nd value");
2.16 + }
2.17 +
2.18 + @Test public void bothLong() throws Throwable {
2.19 + Method st = methodClass.getMethod("chooseLong", boolean.class, boolean.class, long.class, long.class);
2.20 + assertEquals(st.invoke(null, true, true, 10, 20), 30L, "Take both values");
2.21 + }
2.22 }
2.23 \ No newline at end of file
3.1 --- a/boot/src/test/java/org/apidesign/html/boot/impl/JsMethods.java Thu Jul 11 21:26:28 2013 +0200
3.2 +++ b/boot/src/test/java/org/apidesign/html/boot/impl/JsMethods.java Fri Jul 12 09:43:02 2013 +0200
3.3 @@ -81,4 +81,11 @@
3.4
3.5 @JavaScriptBody(args = { "v" }, javacall = true, body = "return @java.lang.Integer::parseInt(Ljava/lang/String;)(v);")
3.6 public static native int parseInt(String v);
3.7 +
3.8 + @JavaScriptBody(args = { "useA", "useB", "a", "b" }, body = "var l = 0;"
3.9 + + "if (useA) l += a;\n"
3.10 + + "if (useB) l += b;\n"
3.11 + + "return l;\n"
3.12 + )
3.13 + public static native long chooseLong(boolean useA, boolean useB, long a, long b);
3.14 }