diff --git a/teavm-html4j/src/main/java/org/teavm/html4j/JavaScriptBodyDependency.java b/teavm-html4j/src/main/java/org/teavm/html4j/JavaScriptBodyDependency.java
index ded276f45..02bad2296 100644
--- a/teavm-html4j/src/main/java/org/teavm/html4j/JavaScriptBodyDependency.java
+++ b/teavm-html4j/src/main/java/org/teavm/html4j/JavaScriptBodyDependency.java
@@ -76,9 +76,10 @@ public class JavaScriptBodyDependency implements DependencyListener {
}
private void includeDefaultDependencies(DependencyChecker dependencyChecker) {
- dependencyChecker.attachMethodGraph(JavaScriptBodyConverterGenerator.fromJsMethod);
- dependencyChecker.attachMethodGraph(JavaScriptBodyConverterGenerator.toJsMethod);
- dependencyChecker.attachMethodGraph(JavaScriptBodyConverterGenerator.intValueMethod);
+ dependencyChecker.attachMethodGraph(JavaScriptConvGenerator.fromJsMethod);
+ dependencyChecker.attachMethodGraph(JavaScriptConvGenerator.toJsMethod);
+ dependencyChecker.attachMethodGraph(JavaScriptConvGenerator.intValueMethod);
+ dependencyChecker.attachMethodGraph(JavaScriptConvGenerator.valueOfIntMethod);
}
@Override
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 88c7677b2..f89c13033 100644
--- a/teavm-html4j/src/main/java/org/teavm/html4j/JavaScriptBodyGenerator.java
+++ b/teavm-html4j/src/main/java/org/teavm/html4j/JavaScriptBodyGenerator.java
@@ -63,7 +63,7 @@ public class JavaScriptBodyGenerator implements Generator {
private void wrapParameter(SourceWriter writer, ValueType type, String param) throws IOException {
if (type.isObject("java.lang.Object")) {
- writer.appendMethodBody(JavaScriptBodyConverterGenerator.toJsMethod);
+ writer.appendMethodBody(JavaScriptConvGenerator.toJsMethod);
writer.append("(").append(param).append(")");
} else {
writer.append(param);
@@ -72,7 +72,7 @@ public class JavaScriptBodyGenerator implements Generator {
private void unwrapValue(SourceWriter writer, ValueType type, String param) throws IOException {
if (type.isObject("java.lang.Object")) {
- writer.appendMethodBody(JavaScriptBodyConverterGenerator.fromJsMethod);
+ writer.appendMethodBody(JavaScriptConvGenerator.fromJsMethod);
writer.append("(").append(param).append(")");
} else {
writer.append(param);
diff --git a/teavm-html4j/src/main/java/org/teavm/html4j/JavaScriptBodyConverter.java b/teavm-html4j/src/main/java/org/teavm/html4j/JavaScriptConv.java
similarity index 81%
rename from teavm-html4j/src/main/java/org/teavm/html4j/JavaScriptBodyConverter.java
rename to teavm-html4j/src/main/java/org/teavm/html4j/JavaScriptConv.java
index 1dc0d0fdd..4139f076c 100644
--- a/teavm-html4j/src/main/java/org/teavm/html4j/JavaScriptBodyConverter.java
+++ b/teavm-html4j/src/main/java/org/teavm/html4j/JavaScriptConv.java
@@ -21,13 +21,13 @@ import org.teavm.javascript.ni.GeneratedBy;
*
* @author Alexey Andreev
*/
-public final class JavaScriptBodyConverter {
- private JavaScriptBodyConverter() {
+public final class JavaScriptConv {
+ private JavaScriptConv() {
}
- @GeneratedBy(JavaScriptBodyConverterGenerator.class)
+ @GeneratedBy(JavaScriptConvGenerator.class)
public static native Object toJavaScript(Object obj);
- @GeneratedBy(JavaScriptBodyConverterGenerator.class)
+ @GeneratedBy(JavaScriptConvGenerator.class)
public static native Object fromJavaScript(Object obj);
}
diff --git a/teavm-html4j/src/main/java/org/teavm/html4j/JavaScriptBodyConverterGenerator.java b/teavm-html4j/src/main/java/org/teavm/html4j/JavaScriptConvGenerator.java
similarity index 89%
rename from teavm-html4j/src/main/java/org/teavm/html4j/JavaScriptBodyConverterGenerator.java
rename to teavm-html4j/src/main/java/org/teavm/html4j/JavaScriptConvGenerator.java
index 930695608..e9ba59792 100644
--- a/teavm-html4j/src/main/java/org/teavm/html4j/JavaScriptBodyConverterGenerator.java
+++ b/teavm-html4j/src/main/java/org/teavm/html4j/JavaScriptConvGenerator.java
@@ -25,10 +25,12 @@ import org.teavm.model.*;
*
* @author Alexey Andreev
*/
-public class JavaScriptBodyConverterGenerator implements Generator {
- private static final String convCls = JavaScriptBodyConverter.class.getName();
+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 valueOfIntMethod = new MethodReference("java.lang.Integer",
+ new MethodDescriptor("valueOf", ValueType.INTEGER, ValueType.object("java.lang.Integer")));
private static final ValueType objType = ValueType.object("java.lang.Object");
static final MethodReference toJsMethod = new MethodReference(convCls, new MethodDescriptor(
"toJavaScript", objType, objType));
@@ -86,8 +88,9 @@ public class JavaScriptBodyConverterGenerator implements Generator {
writer.append(" else if (" + obj + ".constructor === ").appendClass("java.lang.String")
.append(") {").indent().softNewLine();
writer.append("return $rt_str(" + obj + ");").softNewLine();
- writer.outdent().append("}");
- writer.ws().append("else").ws().append("{").indent().softNewLine();
+ writer.outdent().append("} else if (" + obj + " | 0 === " + obj + ") {").indent().softNewLine();
+ writer.append("return ").appendMethodBody(valueOfIntMethod).append("(" + obj + ");").softNewLine();
+ writer.outdent().append("} else {").indent().softNewLine();
writer.append("return ").append(obj).append(";").softNewLine();
writer.outdent().append("}").softNewLine();
}
diff --git a/teavm-html4j/src/test/java/org/teavm/html4j/test/JavaScriptBodyConversionTests.java b/teavm-html4j/src/test/java/org/teavm/html4j/test/JavaScriptBodyConversionTests.java
index b64d34f37..96167b4c8 100644
--- a/teavm-html4j/src/test/java/org/teavm/html4j/test/JavaScriptBodyConversionTests.java
+++ b/teavm-html4j/src/test/java/org/teavm/html4j/test/JavaScriptBodyConversionTests.java
@@ -29,6 +29,14 @@ public class JavaScriptBodyConversionTests {
assertEquals(23, returnAsInt(23));
}
+ @Test
+ public void convertsIntegerResult() {
+ assertEquals(23, returnAsObject(23));
+ }
+
@JavaScriptBody(args = { "value" }, body = "return value;")
private native int returnAsInt(Object value);
+
+ @JavaScriptBody(args = { "value" }, body = "return value;")
+ private native Object returnAsObject(int value);
}