diff --git a/teavm-html4j/pom.xml b/teavm-html4j/pom.xml index 64f1472d9..78f588056 100644 --- a/teavm-html4j/pom.xml +++ b/teavm-html4j/pom.xml @@ -101,6 +101,9 @@ true true true + + + diff --git a/teavm-html4j/src/main/java/org/teavm/html4j/JavaScriptBodyGenerator.java b/teavm-html4j/src/main/java/org/teavm/html4j/JavaScriptBodyGenerator.java index 50fb1e828..12e1222b0 100644 --- a/teavm-html4j/src/main/java/org/teavm/html4j/JavaScriptBodyGenerator.java +++ b/teavm-html4j/src/main/java/org/teavm/html4j/JavaScriptBodyGenerator.java @@ -106,9 +106,10 @@ public class JavaScriptBodyGenerator implements Generator { if (i > 0) { sb.append(", "); } + ValueType paramType = simplifyParamType(reader.parameterType(i)); sb.append(naming.getFullNameFor(JavaScriptConvGenerator.fromJsMethod)).append("(p").append(i) .append(", ") - .append(Renderer.typeToClsString(naming, reader.parameterType(i))).append(")"); + .append(Renderer.typeToClsString(naming, paramType)).append(")"); } sb.append(")); })("); if (ident != null) { @@ -116,6 +117,16 @@ public class JavaScriptBodyGenerator implements Generator { } return sb.toString(); } + private ValueType simplifyParamType(ValueType type) { + if (type instanceof ValueType.Object) { + return ValueType.object("java.lang.Object"); + } else if (type instanceof ValueType.Array) { + ValueType.Array array = (ValueType.Array)type; + return ValueType.arrayOf(simplifyParamType(array.getItemType())); + } else { + return type; + } + } private MethodReader findMethod(String clsName, MethodDescriptor desc) { while (clsName != null) { ClassReader cls = classSource.get(clsName); diff --git a/teavm-html4j/src/test/java/org/teavm/html4j/test/Callback.java b/teavm-html4j/src/test/java/org/teavm/html4j/test/Callback.java new file mode 100644 index 000000000..0b58916e2 --- /dev/null +++ b/teavm-html4j/src/test/java/org/teavm/html4j/test/Callback.java @@ -0,0 +1,11 @@ +package org.teavm.html4j.test; + +import java.util.Calendar; + +/** + * + * @author Alexey Andreev + */ +public interface Callback { + void exec(Calendar input); +} diff --git a/teavm-html4j/src/test/java/org/teavm/html4j/test/JavaScriptBodyTest.java b/teavm-html4j/src/test/java/org/teavm/html4j/test/JavaScriptBodyTest.java index a3dce3b5d..6374dd80f 100644 --- a/teavm-html4j/src/test/java/org/teavm/html4j/test/JavaScriptBodyTest.java +++ b/teavm-html4j/src/test/java/org/teavm/html4j/test/JavaScriptBodyTest.java @@ -16,6 +16,7 @@ package org.teavm.html4j.test; import static org.junit.Assert.assertEquals; +import java.util.Calendar; import net.java.html.js.JavaScriptBody; import org.junit.Test; @@ -60,6 +61,18 @@ public class JavaScriptBodyTest { assertEquals(23, invokeStaticCallback(new AImpl())); } + @Test + public void unusedArgumentIgnored() { + final int[] array = new int[1]; + invokeCallback(new Callback() { + @Override + public void exec(Calendar input) { + array[0] = 23; + } + }); + assertEquals(23, array[0]); + } + private static class AImpl implements A { @Override public int foo() { return 23; @@ -95,4 +108,8 @@ public class JavaScriptBodyTest { "@org.teavm.html4j.test.JavaScriptBodyTest::staticCallback(" + "Lorg/teavm/html4j/test/A;)(a)", javacall = true) private native int invokeStaticCallback(A a); + + @JavaScriptBody(args = "callback", body = "callback.@org.teavm.html4j.test.Callback::exec(" + + "Ljava/util/Calendar;)(null)", javacall = true) + private native void invokeCallback(Callback callback); }