mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 16:14:10 -08:00
This commit is contained in:
parent
11f270e3ef
commit
71da76ee06
|
@ -101,6 +101,9 @@
|
||||||
<debugInformationGenerated>true</debugInformationGenerated>
|
<debugInformationGenerated>true</debugInformationGenerated>
|
||||||
<sourceMapsGenerated>true</sourceMapsGenerated>
|
<sourceMapsGenerated>true</sourceMapsGenerated>
|
||||||
<sourceFilesCopied>true</sourceFilesCopied>
|
<sourceFilesCopied>true</sourceFilesCopied>
|
||||||
|
<additionalScripts>
|
||||||
|
|
||||||
|
</additionalScripts>
|
||||||
</configuration>
|
</configuration>
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
|
|
|
@ -106,9 +106,10 @@ public class JavaScriptBodyGenerator implements Generator {
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
sb.append(", ");
|
sb.append(", ");
|
||||||
}
|
}
|
||||||
|
ValueType paramType = simplifyParamType(reader.parameterType(i));
|
||||||
sb.append(naming.getFullNameFor(JavaScriptConvGenerator.fromJsMethod)).append("(p").append(i)
|
sb.append(naming.getFullNameFor(JavaScriptConvGenerator.fromJsMethod)).append("(p").append(i)
|
||||||
.append(", ")
|
.append(", ")
|
||||||
.append(Renderer.typeToClsString(naming, reader.parameterType(i))).append(")");
|
.append(Renderer.typeToClsString(naming, paramType)).append(")");
|
||||||
}
|
}
|
||||||
sb.append(")); })(");
|
sb.append(")); })(");
|
||||||
if (ident != null) {
|
if (ident != null) {
|
||||||
|
@ -116,6 +117,16 @@ public class JavaScriptBodyGenerator implements Generator {
|
||||||
}
|
}
|
||||||
return sb.toString();
|
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) {
|
private MethodReader findMethod(String clsName, MethodDescriptor desc) {
|
||||||
while (clsName != null) {
|
while (clsName != null) {
|
||||||
ClassReader cls = classSource.get(clsName);
|
ClassReader cls = classSource.get(clsName);
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
package org.teavm.html4j.test;
|
||||||
|
|
||||||
|
import java.util.Calendar;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Alexey Andreev
|
||||||
|
*/
|
||||||
|
public interface Callback {
|
||||||
|
void exec(Calendar input);
|
||||||
|
}
|
|
@ -16,6 +16,7 @@
|
||||||
package org.teavm.html4j.test;
|
package org.teavm.html4j.test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import java.util.Calendar;
|
||||||
import net.java.html.js.JavaScriptBody;
|
import net.java.html.js.JavaScriptBody;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
@ -60,6 +61,18 @@ public class JavaScriptBodyTest {
|
||||||
assertEquals(23, invokeStaticCallback(new AImpl()));
|
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 {
|
private static class AImpl implements A {
|
||||||
@Override public int foo() {
|
@Override public int foo() {
|
||||||
return 23;
|
return 23;
|
||||||
|
@ -95,4 +108,8 @@ public class JavaScriptBodyTest {
|
||||||
"@org.teavm.html4j.test.JavaScriptBodyTest::staticCallback(" +
|
"@org.teavm.html4j.test.JavaScriptBodyTest::staticCallback(" +
|
||||||
"Lorg/teavm/html4j/test/A;)(a)", javacall = true)
|
"Lorg/teavm/html4j/test/A;)(a)", javacall = true)
|
||||||
private native int invokeStaticCallback(A a);
|
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);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user