mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 16:14:10 -08:00
Add test to check async virtual call resolution. Fix bug in async unit
tests support
This commit is contained in:
parent
1f8ef1092c
commit
ce2c625f53
|
@ -16,6 +16,8 @@
|
|||
package org.teavm.classlib.java.lang;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
|
@ -28,7 +30,7 @@ public class ThreadTest {
|
|||
long start = System.currentTimeMillis();
|
||||
Thread.sleep(100);
|
||||
long duration = System.currentTimeMillis() - start;
|
||||
assertTrue("Thread.sleed did not wait enogh", duration < 100);
|
||||
assertTrue("Thread.sleed did not wait enogh", duration >= 100);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -41,8 +43,34 @@ public class ThreadTest {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
private void throwException() {
|
||||
Thread.yield();
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void asyncVirtualCallsSupported() {
|
||||
List<A> alist = new ArrayList<>();
|
||||
alist.add(new A() {
|
||||
@Override int foo() {
|
||||
return 3;
|
||||
}
|
||||
});
|
||||
alist.add(new A() {
|
||||
@Override int foo() {
|
||||
Thread.yield();
|
||||
return 5;
|
||||
}
|
||||
});
|
||||
int sum = 0;
|
||||
for (A a : alist) {
|
||||
sum += a.foo();
|
||||
}
|
||||
assertEquals(8, sum);
|
||||
}
|
||||
|
||||
abstract class A {
|
||||
abstract int foo();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -923,7 +923,9 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext
|
|||
writer.append(" $return($rt_asyncResult(");
|
||||
}
|
||||
if (statement.getResult() != null) {
|
||||
writer.append(' ');
|
||||
if (!async) {
|
||||
writer.append(' ');
|
||||
}
|
||||
prevCallSite = debugEmitter.emitCallSite();
|
||||
statement.getResult().acceptVisitor(this);
|
||||
debugEmitter.emitCallSite();
|
||||
|
|
|
@ -537,7 +537,7 @@ public class TeaVM implements TeaVMHost, ServiceRepository {
|
|||
private List<ClassNode> modelToAst(ListableClassHolderSource classes) {
|
||||
AsyncMethodFinder asyncFinder = new AsyncMethodFinder(dependencyChecker.getCallGraph(), diagnostics);
|
||||
asyncFinder.find(classes);
|
||||
asyncMethods.addAll(asyncMethods);
|
||||
asyncMethods.addAll(asyncFinder.getAsyncMethods());
|
||||
|
||||
progressListener.phaseStarted(TeaVMPhase.DECOMPILATION, classes.getClassNames().size());
|
||||
Decompiler decompiler = new Decompiler(classes, classLoader, asyncFinder.getAsyncMethods());
|
||||
|
|
Loading…
Reference in New Issue
Block a user