mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 08:14:09 -08:00
Support of html4j version 1.0. Better support of JavaScriptBody
callbacks.
This commit is contained in:
parent
3de49d6d54
commit
a24652a576
2
pom.xml
2
pom.xml
|
@ -66,7 +66,7 @@
|
|||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<sonatypeOssDistMgmtSnapshotsUrl>https://oss.sonatype.org/content/repositories/snapshots/</sonatypeOssDistMgmtSnapshotsUrl>
|
||||
<html4j.version>0.9</html4j.version>
|
||||
<html4j.version>1.0</html4j.version>
|
||||
<jetty.version>9.2.1.v20140609</jetty.version>
|
||||
<slf4j.version>1.7.7</slf4j.version>
|
||||
</properties>
|
||||
|
|
|
@ -138,7 +138,7 @@ public class JavaScriptBodyDependency implements DependencyListener {
|
|||
if (!methodDep.isMissing()) {
|
||||
if (reader.hasModifier(ElementModifier.STATIC) || reader.hasModifier(ElementModifier.FINAL)) {
|
||||
methodDep.use();
|
||||
for (int i = 0; i <= methodDep.getParameterCount(); ++i) {
|
||||
for (int i = 0; i < methodDep.getParameterCount(); ++i) {
|
||||
allClassesNode.connect(methodDep.getVariable(i));
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -85,9 +85,15 @@ public class JavaScriptBodyGenerator implements Generator {
|
|||
MethodDescriptor desc = MethodDescriptor.parse(method + params + "V");
|
||||
MethodReader reader = findMethod(fqn, desc);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("(function($this");
|
||||
sb.append("(function(");
|
||||
if (ident != null) {
|
||||
sb.append("$this");
|
||||
}
|
||||
for (int i = 0; i < reader.parameterCount(); ++i) {
|
||||
sb.append(", ").append("p").append(i);
|
||||
if (ident != null || i > 0) {
|
||||
sb.append(", ");
|
||||
}
|
||||
sb.append("p").append(i);
|
||||
}
|
||||
sb.append(") { return ").append(naming.getFullNameFor(JavaScriptConvGenerator.toJsMethod)).append("(");
|
||||
if (ident == null) {
|
||||
|
@ -105,7 +111,9 @@ public class JavaScriptBodyGenerator implements Generator {
|
|||
.append(Renderer.typeToClsString(naming, reader.parameterType(i))).append(")");
|
||||
}
|
||||
sb.append(")); })(");
|
||||
sb.append(ident == null ? "null" : ident);
|
||||
if (ident != null) {
|
||||
sb.append(ident);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
private MethodReader findMethod(String clsName, MethodDescriptor desc) {
|
||||
|
|
|
@ -26,28 +26,22 @@ import org.teavm.model.*;
|
|||
* @author Alexey Andreev <konsoletyper@gmail.com>
|
||||
*/
|
||||
public class JavaScriptConvGenerator implements Generator {
|
||||
private static final String convCls = JavaScriptConv.class.getName();
|
||||
static final MethodReference intValueMethod = new MethodReference("java.lang.Integer",
|
||||
new MethodDescriptor("intValue", ValueType.INTEGER));
|
||||
static final MethodReference booleanValueMethod = new MethodReference("java.lang.Boolean",
|
||||
new MethodDescriptor("booleanValue", ValueType.BOOLEAN));
|
||||
static final MethodReference doubleValueMethod = new MethodReference("java.lang.Double",
|
||||
new MethodDescriptor("doubleValue", ValueType.DOUBLE));
|
||||
static final MethodReference charValueMethod = new MethodReference("java.lang.Character",
|
||||
new MethodDescriptor("charValue", ValueType.CHARACTER));
|
||||
static final MethodReference valueOfIntMethod = new MethodReference("java.lang.Integer",
|
||||
new MethodDescriptor("valueOf", ValueType.INTEGER, ValueType.object("java.lang.Integer")));
|
||||
static final MethodReference valueOfBooleanMethod = new MethodReference("java.lang.Boolean",
|
||||
new MethodDescriptor("valueOf", ValueType.BOOLEAN, ValueType.object("java.lang.Boolean")));
|
||||
static final MethodReference valueOfDoubleMethod = new MethodReference("java.lang.Double",
|
||||
new MethodDescriptor("valueOf", ValueType.DOUBLE, ValueType.object("java.lang.Double")));
|
||||
static final MethodReference valueOfCharMethod = new MethodReference("java.lang.Character",
|
||||
new MethodDescriptor("valueOf", ValueType.CHARACTER, ValueType.object("java.lang.Character")));
|
||||
private static final ValueType objType = ValueType.object("java.lang.Object");
|
||||
static final MethodReference toJsMethod = new MethodReference(convCls, new MethodDescriptor(
|
||||
"toJavaScript", objType, objType));
|
||||
static final MethodReference fromJsMethod = new MethodReference(convCls, new MethodDescriptor(
|
||||
"fromJavaScript", objType, objType, objType));
|
||||
static final MethodReference intValueMethod = new MethodReference(Integer.class, "intValue", int.class);
|
||||
static final MethodReference booleanValueMethod = new MethodReference(Boolean.class, "booleanValue", boolean.class);
|
||||
static final MethodReference doubleValueMethod = new MethodReference(Double.class, "doubleValue", double.class);
|
||||
static final MethodReference charValueMethod = new MethodReference(Character.class, "charValue", char.class);
|
||||
static final MethodReference valueOfIntMethod = new MethodReference(Integer.class, "valueOf",
|
||||
int.class, Integer.class);
|
||||
static final MethodReference valueOfBooleanMethod = new MethodReference(Boolean.class, "valueOf",
|
||||
boolean.class, Boolean.class);
|
||||
static final MethodReference valueOfDoubleMethod = new MethodReference(Double.class, "valueOf",
|
||||
double.class, Double.class);
|
||||
static final MethodReference valueOfCharMethod = new MethodReference(Character.class, "valueOf",
|
||||
char.class, Character.class);
|
||||
static final MethodReference toJsMethod = new MethodReference(JavaScriptConv.class, "toJavaScript",
|
||||
Object.class, Object.class);
|
||||
static final MethodReference fromJsMethod = new MethodReference(JavaScriptConv.class, "fromJavaScript",
|
||||
Object.class, Object.class, Object.class);
|
||||
|
||||
@Override
|
||||
public void generate(GeneratorContext context, SourceWriter writer, MethodReference methodRef) throws IOException {
|
||||
|
|
|
@ -107,7 +107,7 @@ abstract class JsCallback {
|
|||
}
|
||||
|
||||
sb.append(callMethod(refId, fqn, method, params));
|
||||
if (body.charAt(paramBeg + 1) != (')')) {
|
||||
if (body.charAt(paramBeg + 1) != ')') {
|
||||
sb.append(",");
|
||||
}
|
||||
pos = paramBeg + 1;
|
||||
|
|
|
@ -18,7 +18,7 @@ package org.teavm.html4j.testing;
|
|||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Collections;
|
||||
import org.apidesign.html.json.tck.KOTest;
|
||||
import org.netbeans.html.json.tck.KOTest;
|
||||
import org.teavm.model.MethodReader;
|
||||
import org.teavm.testing.TestAdapter;
|
||||
|
||||
|
|
|
@ -51,12 +51,12 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
import net.java.html.BrwsrCtx;
|
||||
import net.java.html.js.JavaScriptBody;
|
||||
import org.apidesign.html.boot.spi.Fn;
|
||||
import org.apidesign.html.context.spi.Contexts;
|
||||
import org.apidesign.html.json.spi.JSONCall;
|
||||
import org.apidesign.html.json.spi.Technology;
|
||||
import org.apidesign.html.json.spi.Transfer;
|
||||
import org.apidesign.html.json.tck.KnockoutTCK;
|
||||
import org.netbeans.html.boot.spi.Fn;
|
||||
import org.netbeans.html.context.spi.Contexts;
|
||||
import org.netbeans.html.json.spi.JSONCall;
|
||||
import org.netbeans.html.json.spi.Technology;
|
||||
import org.netbeans.html.json.spi.Transfer;
|
||||
import org.netbeans.html.json.tck.KnockoutTCK;
|
||||
import org.netbeans.html.ko4j.KO4J;
|
||||
import org.testng.Assert;
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user