mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 08:14:09 -08:00
Adds test on simple callback support
This commit is contained in:
parent
f085dbb607
commit
f8ea743c26
|
@ -112,7 +112,7 @@ public class JavaScriptBodyDependency implements DependencyListener {
|
||||||
this.dependencyChecker = dependencyChecker;
|
this.dependencyChecker = dependencyChecker;
|
||||||
}
|
}
|
||||||
@Override protected CharSequence callMethod(String ident, String fqn, String method, String params) {
|
@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);
|
MethodReader reader = findMethod(classSource, fqn, desc);
|
||||||
if (reader != null) {
|
if (reader != null) {
|
||||||
if (reader.hasModifier(ElementModifier.STATIC) || reader.hasModifier(ElementModifier.FINAL)) {
|
if (reader.hasModifier(ElementModifier.STATIC) || reader.hasModifier(ElementModifier.FINAL)) {
|
||||||
|
@ -142,7 +142,7 @@ public class JavaScriptBodyDependency implements DependencyListener {
|
||||||
MethodReader reader = findMethod(classSource, type, desc);
|
MethodReader reader = findMethod(classSource, type, desc);
|
||||||
if (reader != null) {
|
if (reader != null) {
|
||||||
MethodGraph graph = dependencyChecker.attachMethodGraph(reader.getReference());
|
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));
|
allClassesNode.connect(graph.getVariable(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,20 +66,10 @@ public class JavaScriptBodyGenerator implements Generator {
|
||||||
this.naming = naming;
|
this.naming = naming;
|
||||||
}
|
}
|
||||||
@Override protected CharSequence callMethod(String ident, String fqn, String method, String params) {
|
@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);
|
MethodReader reader = findMethod(fqn, desc);
|
||||||
StringBuilder sb = new StringBuilder();
|
return ident == null ? naming.getFullNameFor(reader.getReference()) + "(" :
|
||||||
String name = naming.getNameFor(naming.getNameFor(reader.getReference()));
|
ident + "." + 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();
|
|
||||||
}
|
}
|
||||||
private MethodReader findMethod(String clsName, MethodDescriptor desc) {
|
private MethodReader findMethod(String clsName, MethodDescriptor desc) {
|
||||||
while (clsName != null) {
|
while (clsName != null) {
|
||||||
|
|
24
teavm-html4j/src/test/java/org/teavm/html4j/test/A.java
Normal file
24
teavm-html4j/src/test/java/org/teavm/html4j/test/A.java
Normal file
|
@ -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();
|
||||||
|
}
|
24
teavm-html4j/src/test/java/org/teavm/html4j/test/B.java
Normal file
24
teavm-html4j/src/test/java/org/teavm/html4j/test/B.java
Normal file
|
@ -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);
|
||||||
|
}
|
|
@ -58,9 +58,12 @@ public class JavaScriptBodyTests {
|
||||||
assertEquals(23, first[0].foo());
|
assertEquals(23, first[0].foo());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static interface A {
|
@Test
|
||||||
public int foo();
|
public void valuePropagatedToCallback() {
|
||||||
|
A a = new AImpl();
|
||||||
|
assertEquals(23, invokeCallback(a));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class AImpl implements A {
|
private static class AImpl implements A {
|
||||||
@Override public int foo() {
|
@Override public int foo() {
|
||||||
return 23;
|
return 23;
|
||||||
|
@ -78,4 +81,13 @@ public class JavaScriptBodyTests {
|
||||||
|
|
||||||
@JavaScriptBody(args = {}, body = "return window._global_;")
|
@JavaScriptBody(args = {}, body = "return window._global_;")
|
||||||
private native Object retrieveObject();
|
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);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user