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 5d747f5e4..ae6eb87ef 100644 --- a/teavm-html4j/src/main/java/org/teavm/html4j/JavaScriptBodyDependency.java +++ b/teavm-html4j/src/main/java/org/teavm/html4j/JavaScriptBodyDependency.java @@ -112,7 +112,7 @@ public class JavaScriptBodyDependency implements DependencyListener { this.dependencyChecker = dependencyChecker; } @Override protected CharSequence callMethod(String ident, String fqn, String method, String params) { - MethodDescriptor desc = MethodDescriptor.parse(method + "V"); + MethodDescriptor desc = MethodDescriptor.parse(method + params + "V"); MethodReader reader = findMethod(classSource, fqn, desc); if (reader != null) { if (reader.hasModifier(ElementModifier.STATIC) || reader.hasModifier(ElementModifier.FINAL)) { @@ -142,7 +142,7 @@ public class JavaScriptBodyDependency implements DependencyListener { MethodReader reader = findMethod(classSource, type, desc); if (reader != null) { MethodGraph graph = dependencyChecker.attachMethodGraph(reader.getReference()); - for (int i = 0; i <= graph.getParameterCount(); ++i) { + for (int i = 0; i < graph.getParameterCount(); ++i) { allClassesNode.connect(graph.getVariable(i)); } } 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 6def41382..d56bd9f2d 100644 --- a/teavm-html4j/src/main/java/org/teavm/html4j/JavaScriptBodyGenerator.java +++ b/teavm-html4j/src/main/java/org/teavm/html4j/JavaScriptBodyGenerator.java @@ -66,20 +66,10 @@ public class JavaScriptBodyGenerator implements Generator { this.naming = naming; } @Override protected CharSequence callMethod(String ident, String fqn, String method, String params) { - MethodDescriptor desc = MethodDescriptor.parse(method + "V"); + MethodDescriptor desc = MethodDescriptor.parse(method + params + "V"); MethodReader reader = findMethod(fqn, desc); - StringBuilder sb = new StringBuilder(); - String name = naming.getNameFor(naming.getNameFor(reader.getReference())); - if (ident != null) { - if (reader.hasModifier(ElementModifier.FINAL)) { - sb.append(name).append("(").append(ident).append(",").append(params.substring(1)); - } else { - sb.append(ident).append('.').append(name).append(params); - } - } else { - sb.append("(").append(ident).append(",").append(params.substring(1)); - } - return sb.toString(); + return ident == null ? naming.getFullNameFor(reader.getReference()) + "(" : + ident + "." + naming.getNameFor(reader.getReference()) + "("; } private MethodReader findMethod(String clsName, MethodDescriptor desc) { while (clsName != null) { diff --git a/teavm-html4j/src/test/java/org/teavm/html4j/test/A.java b/teavm-html4j/src/test/java/org/teavm/html4j/test/A.java new file mode 100644 index 000000000..df6aaf128 --- /dev/null +++ b/teavm-html4j/src/test/java/org/teavm/html4j/test/A.java @@ -0,0 +1,24 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.html4j.test; + +/** + * + * @author Alexey Andreev + */ +interface A { + int foo(); +} diff --git a/teavm-html4j/src/test/java/org/teavm/html4j/test/B.java b/teavm-html4j/src/test/java/org/teavm/html4j/test/B.java new file mode 100644 index 000000000..b162ddd51 --- /dev/null +++ b/teavm-html4j/src/test/java/org/teavm/html4j/test/B.java @@ -0,0 +1,24 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.html4j.test; + +/** + * + * @author Alexey Andreev + */ +interface B { + int bar(A foo); +} diff --git a/teavm-html4j/src/test/java/org/teavm/html4j/test/JavaScriptBodyTests.java b/teavm-html4j/src/test/java/org/teavm/html4j/test/JavaScriptBodyTests.java index f3b4ae335..b0a4b44d0 100644 --- a/teavm-html4j/src/test/java/org/teavm/html4j/test/JavaScriptBodyTests.java +++ b/teavm-html4j/src/test/java/org/teavm/html4j/test/JavaScriptBodyTests.java @@ -58,9 +58,12 @@ public class JavaScriptBodyTests { assertEquals(23, first[0].foo()); } - private static interface A { - public int foo(); + @Test + public void valuePropagatedToCallback() { + A a = new AImpl(); + assertEquals(23, invokeCallback(a)); } + private static class AImpl implements A { @Override public int foo() { return 23; @@ -78,4 +81,13 @@ public class JavaScriptBodyTests { @JavaScriptBody(args = {}, body = "return window._global_;") private native Object retrieveObject(); + + @JavaScriptBody(args = { "callback" }, body = "return callback." + + "@org.teavm.html4j.test.A::foo()()", javacall = true) + private native int invokeCallback(A callback); + + @JavaScriptBody(args = { "callback" }, body = "return callback." + + "@org.teavm.html4j.test.B::bar(" + + "Lorg/teavm/html4j/test/A;)(_global_)", javacall = true) + private native int invokeCallback(B callback); }