This commit is contained in:
Alexey Andreev 2015-10-15 16:03:11 +03:00
parent cf92616a6a
commit 732957cd84
7 changed files with 25 additions and 5 deletions

View File

@ -2165,6 +2165,9 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext
}
private void visitStatements(List<Statement> statements) {
if (statements.isEmpty()) {
return;
}
boolean oldEnd = end;
for (int i = 0; i < statements.size() - 1; ++i) {
end = false;

View File

@ -211,6 +211,10 @@ public final class ProgramEmitter {
return setField(new FieldReference(className, fieldName), value);
}
public ProgramEmitter setField(Class<?> cls, String fieldName, ValueEmitter value) {
return setField(new FieldReference(cls.getName(), fieldName), value);
}
public ValueEmitter invoke(MethodReference method, ValueEmitter... arguments) {
for (int i = 0; i < method.parameterCount(); ++i) {
if (!classSource.isSuperType(method.parameterType(i), arguments[i].getType()).orElse(true)) {

View File

@ -34,6 +34,7 @@ public class KOTestRunner implements TestRunner {
if (++repeatCount == 10) {
throw e;
}
Thread.sleep(50);
} catch (Throwable e) {
throw e;
}

View File

@ -93,13 +93,13 @@ public class JavaScriptBodyConversionTest {
@JavaScriptBody(args = { "value" }, body = "return value + 1;")
private native int addOne(int value);
@JavaScriptBody(args = { "value" }, body = "return value;")
@JavaScriptBody(args = { "array" }, body = "return array;")
private native Object returnAsObject(Object array);
@JavaScriptBody(args = { "value" }, body = "return value;")
@JavaScriptBody(args = { "array" }, body = "return array;")
private native int[] returnAsIntArray(Object array);
@JavaScriptBody(args = { "value" }, body = "return value;")
@JavaScriptBody(args = { "array" }, body = "return array;")
private native Integer[] returnAsIntegerArray(Object array);
@JavaScriptBody(args = { "value" }, body = "value[0] = 1; return value;")

View File

@ -97,7 +97,7 @@ public final class KnockoutFXTest extends KnockoutTCK implements Transfer {
"var f = new Function(s); " +
"return f.apply(null, args);"
)
public native Object executeScript(String script, Object[] arguments);
public native Object executeScript(String s, Object[] args);
@JavaScriptBody(args = { }, body =
"var h;" +

View File

@ -22,6 +22,8 @@ import org.teavm.testing.TestRunner;
* @author Alexey Andreev
*/
final class TestEntryPoint {
private static Object testCase;
private TestEntryPoint() {
}

View File

@ -23,7 +23,9 @@ import org.teavm.model.ElementModifier;
import org.teavm.model.MethodHolder;
import org.teavm.model.MethodReference;
import org.teavm.model.Program;
import org.teavm.model.ValueType;
import org.teavm.model.emit.ProgramEmitter;
import org.teavm.model.emit.ValueEmitter;
import org.teavm.vm.spi.TeaVMHost;
import org.teavm.vm.spi.TeaVMPlugin;
@ -70,7 +72,15 @@ class TestEntryPointTransformer implements ClassHolderTransformer, TeaVMPlugin {
private Program generateLaunchProgram(MethodHolder method, ClassReaderSource innerSource) {
ProgramEmitter pe = ProgramEmitter.create(method, innerSource);
pe.construct(testMethod.getClassName()).invokeSpecial(testMethod);
ValueEmitter testCaseVar = pe.getField(TestEntryPoint.class, "testCase", Object.class);
pe.when(testCaseVar.isNull())
.thenDo(() -> {
pe.setField(TestEntryPoint.class, "testCase",
pe.construct(testMethod.getClassName()).cast(Object.class));
});
pe.getField(TestEntryPoint.class, "testCase", Object.class)
.cast(ValueType.object(testMethod.getClassName()))
.invokeSpecial(testMethod);
pe.exit();
return pe.getProgram();
}