From 732957cd84908b034c36f0eddee159f3c1c97204 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Thu, 15 Oct 2015 16:03:11 +0300 Subject: [PATCH] Fix bugs --- .../src/main/java/org/teavm/javascript/Renderer.java | 3 +++ .../java/org/teavm/model/emit/ProgramEmitter.java | 4 ++++ .../java/org/teavm/html4j/testing/KOTestRunner.java | 1 + .../html4j/test/JavaScriptBodyConversionTest.java | 6 +++--- .../java/org/teavm/html4j/test/KnockoutFXTest.java | 2 +- .../org/teavm/tooling/testing/TestEntryPoint.java | 2 ++ .../tooling/testing/TestEntryPointTransformer.java | 12 +++++++++++- 7 files changed, 25 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/org/teavm/javascript/Renderer.java b/core/src/main/java/org/teavm/javascript/Renderer.java index e9ffad9af..5e9c69ea2 100644 --- a/core/src/main/java/org/teavm/javascript/Renderer.java +++ b/core/src/main/java/org/teavm/javascript/Renderer.java @@ -2165,6 +2165,9 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext } private void visitStatements(List statements) { + if (statements.isEmpty()) { + return; + } boolean oldEnd = end; for (int i = 0; i < statements.size() - 1; ++i) { end = false; diff --git a/core/src/main/java/org/teavm/model/emit/ProgramEmitter.java b/core/src/main/java/org/teavm/model/emit/ProgramEmitter.java index 0765b8a4d..b34bfb353 100644 --- a/core/src/main/java/org/teavm/model/emit/ProgramEmitter.java +++ b/core/src/main/java/org/teavm/model/emit/ProgramEmitter.java @@ -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)) { diff --git a/html4j/src/main/java/org/teavm/html4j/testing/KOTestRunner.java b/html4j/src/main/java/org/teavm/html4j/testing/KOTestRunner.java index 2892bd811..365c39ffe 100644 --- a/html4j/src/main/java/org/teavm/html4j/testing/KOTestRunner.java +++ b/html4j/src/main/java/org/teavm/html4j/testing/KOTestRunner.java @@ -34,6 +34,7 @@ public class KOTestRunner implements TestRunner { if (++repeatCount == 10) { throw e; } + Thread.sleep(50); } catch (Throwable e) { throw e; } diff --git a/html4j/src/test/java/org/teavm/html4j/test/JavaScriptBodyConversionTest.java b/html4j/src/test/java/org/teavm/html4j/test/JavaScriptBodyConversionTest.java index cf5122edc..f115b318f 100644 --- a/html4j/src/test/java/org/teavm/html4j/test/JavaScriptBodyConversionTest.java +++ b/html4j/src/test/java/org/teavm/html4j/test/JavaScriptBodyConversionTest.java @@ -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;") diff --git a/html4j/src/test/java/org/teavm/html4j/test/KnockoutFXTest.java b/html4j/src/test/java/org/teavm/html4j/test/KnockoutFXTest.java index a03433314..48ba91a42 100644 --- a/html4j/src/test/java/org/teavm/html4j/test/KnockoutFXTest.java +++ b/html4j/src/test/java/org/teavm/html4j/test/KnockoutFXTest.java @@ -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;" + diff --git a/tools/core/src/main/java/org/teavm/tooling/testing/TestEntryPoint.java b/tools/core/src/main/java/org/teavm/tooling/testing/TestEntryPoint.java index e67e8974b..5208d78ab 100644 --- a/tools/core/src/main/java/org/teavm/tooling/testing/TestEntryPoint.java +++ b/tools/core/src/main/java/org/teavm/tooling/testing/TestEntryPoint.java @@ -22,6 +22,8 @@ import org.teavm.testing.TestRunner; * @author Alexey Andreev */ final class TestEntryPoint { + private static Object testCase; + private TestEntryPoint() { } diff --git a/tools/core/src/main/java/org/teavm/tooling/testing/TestEntryPointTransformer.java b/tools/core/src/main/java/org/teavm/tooling/testing/TestEntryPointTransformer.java index dd631020f..017456bd6 100644 --- a/tools/core/src/main/java/org/teavm/tooling/testing/TestEntryPointTransformer.java +++ b/tools/core/src/main/java/org/teavm/tooling/testing/TestEntryPointTransformer.java @@ -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(); }