Alexey Andreev 2014-12-09 18:08:58 +04:00
parent 11f270e3ef
commit 71da76ee06
4 changed files with 43 additions and 1 deletions

View File

@ -101,6 +101,9 @@
<debugInformationGenerated>true</debugInformationGenerated>
<sourceMapsGenerated>true</sourceMapsGenerated>
<sourceFilesCopied>true</sourceFilesCopied>
<additionalScripts>
</additionalScripts>
</configuration>
</execution>
</executions>

View File

@ -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);

View File

@ -0,0 +1,11 @@
package org.teavm.html4j.test;
import java.util.Calendar;
/**
*
* @author Alexey Andreev
*/
public interface Callback {
void exec(Calendar input);
}

View File

@ -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);
}