From 4d2c075c07b2453577ff1c3fcaf3748a24ad6a50 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Sun, 28 Oct 2018 00:15:36 +0300 Subject: [PATCH] Always embed runtime into generated file. Remove 'runtime' build property --- core/pom.xml | 4 + .../backend/javascript/JavaScriptTarget.java | 4 +- .../javascript/rendering}/AstWriter.java | 5 +- .../javascript/rendering}/JSParser.java | 4 +- .../javascript/rendering}/NameEmitter.java | 6 +- .../javascript/rendering/Renderer.java | 100 ----------- .../javascript/rendering/RuntimeRenderer.java | 163 ++++++++++++++++++ .../rendering/StringConstantElimination.java | 49 ++++++ .../javascript/rendering}/AstWriterTest.java | 10 +- jso/impl/pom.xml | 5 - .../org/teavm/jso/impl/JSBodyAstEmitter.java | 3 +- .../org/teavm/jso/impl/JSClassProcessor.java | 1 + pom.xml | 6 + samples/async/pom.xml | 1 - samples/async/src/main/webapp/index.html | 1 - samples/benchmark/pom.xml | 1 - samples/benchmark/src/main/webapp/teavm.html | 1 - samples/hello/pom.xml | 1 - samples/hello/src/main/webapp/index.html | 1 - samples/kotlin/pom.xml | 1 - samples/kotlin/src/main/webapp/index.html | 1 - samples/scala/pom.xml | 1 - samples/scala/src/main/webapp/index.html | 1 - samples/storage/src/main/webapp/index.html | 1 - samples/video/pom.xml | 1 - samples/video/src/main/webapp/index.html | 1 - tests/src/test/js/src/run-tests.js | 3 +- .../main/java/org/teavm/cli/TeaVMRunner.java | 17 -- .../teavm/tooling/RuntimeCopyOperation.java | 22 --- .../java/org/teavm/tooling/TeaVMTool.java | 52 +----- .../eclipse/m2e/TeaVMProjectConfigurator.java | 20 +-- .../PreferencesBasedTeaVMProjectSettings.java | 14 -- .../java/org/teavm/eclipse/TeaVMProfile.java | 4 - .../teavm/eclipse/TeaVMProjectBuilder.java | 13 -- .../org/teavm/eclipse/TeaVMRuntimeMode.java | 22 --- .../teavm/eclipse/ui/TeaVMProfileDialog.java | 18 -- .../org/teavm/junit/HtmlUnitRunStrategy.java | 1 - .../java/org/teavm/junit/TeaVMTestRunner.java | 1 - .../src/main/resources/teavm-run-test.html | 1 - .../org/teavm/maven/TeaVMCompileMojo.java | 5 - 40 files changed, 245 insertions(+), 321 deletions(-) rename {jso/impl/src/main/java/org/teavm/jso/impl => core/src/main/java/org/teavm/backend/javascript/rendering}/AstWriter.java (99%) rename {jso/impl/src/main/java/org/teavm/jso/impl => core/src/main/java/org/teavm/backend/javascript/rendering}/JSParser.java (93%) rename {jso/impl/src/main/java/org/teavm/jso/impl => core/src/main/java/org/teavm/backend/javascript/rendering}/NameEmitter.java (85%) create mode 100644 core/src/main/java/org/teavm/backend/javascript/rendering/RuntimeRenderer.java create mode 100644 core/src/main/java/org/teavm/backend/javascript/rendering/StringConstantElimination.java rename {jso/impl/src/test/java/org/teavm/jso/plugin => core/src/test/java/org/teavm/backend/javascript/rendering}/AstWriterTest.java (97%) delete mode 100644 tools/core/src/main/java/org/teavm/tooling/RuntimeCopyOperation.java delete mode 100644 tools/eclipse/plugin/src/main/java/org/teavm/eclipse/TeaVMRuntimeMode.java diff --git a/core/pom.xml b/core/pom.xml index c88c77e11..55ef9818f 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -67,6 +67,10 @@ jackson-annotations true + + org.mozilla + rhino + diff --git a/core/src/main/java/org/teavm/backend/javascript/JavaScriptTarget.java b/core/src/main/java/org/teavm/backend/javascript/JavaScriptTarget.java index 4b85dde2b..ad7f29d1c 100644 --- a/core/src/main/java/org/teavm/backend/javascript/JavaScriptTarget.java +++ b/core/src/main/java/org/teavm/backend/javascript/JavaScriptTarget.java @@ -45,6 +45,7 @@ import org.teavm.backend.javascript.codegen.SourceWriter; import org.teavm.backend.javascript.codegen.SourceWriterBuilder; import org.teavm.backend.javascript.rendering.Renderer; import org.teavm.backend.javascript.rendering.RenderingContext; +import org.teavm.backend.javascript.rendering.RuntimeRenderer; import org.teavm.backend.javascript.spi.GeneratedBy; import org.teavm.backend.javascript.spi.Generator; import org.teavm.backend.javascript.spi.InjectedBy; @@ -292,6 +293,7 @@ public class JavaScriptTarget implements TeaVMTarget, TeaVMJavaScriptHost { renderingContext.setMinifying(minifying); Renderer renderer = new Renderer(sourceWriter, asyncMethods, asyncFamilyMethods, controller.getDiagnostics(), renderingContext); + RuntimeRenderer runtimeRenderer = new RuntimeRenderer(naming, sourceWriter); renderer.setProperties(controller.getProperties()); renderer.setMinifying(minifying); if (debugEmitter != null) { @@ -319,7 +321,7 @@ public class JavaScriptTarget implements TeaVMTarget, TeaVMJavaScriptHost { int start = sourceWriter.getOffset(); sourceWriter.append("\"use strict\";").newLine(); renderer.prepare(clsNodes); - renderer.renderRuntime(); + runtimeRenderer.renderRuntime(); renderer.render(clsNodes); renderer.renderStringPool(); renderer.renderStringConstants(); diff --git a/jso/impl/src/main/java/org/teavm/jso/impl/AstWriter.java b/core/src/main/java/org/teavm/backend/javascript/rendering/AstWriter.java similarity index 99% rename from jso/impl/src/main/java/org/teavm/jso/impl/AstWriter.java rename to core/src/main/java/org/teavm/backend/javascript/rendering/AstWriter.java index 17d0ebe6d..6351181b4 100644 --- a/jso/impl/src/main/java/org/teavm/jso/impl/AstWriter.java +++ b/core/src/main/java/org/teavm/backend/javascript/rendering/AstWriter.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Alexey Andreev. + * Copyright 2018 Alexey Andreev. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.jso.impl; +package org.teavm.backend.javascript.rendering; import java.io.IOException; import java.util.Collections; @@ -276,6 +276,7 @@ public class AstWriter { private void print(AstRoot node) throws IOException { for (Node child : node) { print((AstNode) child); + writer.softNewLine(); } } diff --git a/jso/impl/src/main/java/org/teavm/jso/impl/JSParser.java b/core/src/main/java/org/teavm/backend/javascript/rendering/JSParser.java similarity index 93% rename from jso/impl/src/main/java/org/teavm/jso/impl/JSParser.java rename to core/src/main/java/org/teavm/backend/javascript/rendering/JSParser.java index 05950c698..05b75bff3 100644 --- a/jso/impl/src/main/java/org/teavm/jso/impl/JSParser.java +++ b/core/src/main/java/org/teavm/backend/javascript/rendering/JSParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Alexey Andreev. + * Copyright 2018 Alexey Andreev. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.jso.impl; +package org.teavm.backend.javascript.rendering; import org.mozilla.javascript.CompilerEnvirons; import org.mozilla.javascript.ErrorReporter; diff --git a/jso/impl/src/main/java/org/teavm/jso/impl/NameEmitter.java b/core/src/main/java/org/teavm/backend/javascript/rendering/NameEmitter.java similarity index 85% rename from jso/impl/src/main/java/org/teavm/jso/impl/NameEmitter.java rename to core/src/main/java/org/teavm/backend/javascript/rendering/NameEmitter.java index ef9d67eb0..4b811b7be 100644 --- a/jso/impl/src/main/java/org/teavm/jso/impl/NameEmitter.java +++ b/core/src/main/java/org/teavm/backend/javascript/rendering/NameEmitter.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Alexey Andreev. + * Copyright 2018 Alexey Andreev. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,10 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.jso.impl; +package org.teavm.backend.javascript.rendering; import java.io.IOException; -interface NameEmitter { +public interface NameEmitter { void emit(int precedence) throws IOException; } diff --git a/core/src/main/java/org/teavm/backend/javascript/rendering/Renderer.java b/core/src/main/java/org/teavm/backend/javascript/rendering/Renderer.java index 8dff9c424..64d57e28a 100644 --- a/core/src/main/java/org/teavm/backend/javascript/rendering/Renderer.java +++ b/core/src/main/java/org/teavm/backend/javascript/rendering/Renderer.java @@ -193,106 +193,6 @@ public class Renderer implements RenderingManager { sizeByClass.put(className, sizeByClass.getOrDefault(className, 0) + sz); } - public void renderRuntime() throws RenderingException { - try { - renderSetCloneMethod(); - renderRuntimeCls(); - renderRuntimeString(); - renderRuntimeUnwrapString(); - renderRuntimeObjcls(); - renderRuntimeNullCheck(); - renderRuntimeIntern(); - renderRuntimeThreads(); - } catch (NamingException e) { - throw new RenderingException("Error rendering runtime methods. See a cause for details", e); - } catch (IOException e) { - throw new RenderingException("IO error", e); - } - } - - private void renderSetCloneMethod() throws IOException { - writer.append("function $rt_setCloneMethod(target, f)").ws().append("{").softNewLine().indent(); - writer.append("target.").appendMethod("clone", Object.class).ws().append('=').ws().append("f;"). - softNewLine(); - writer.outdent().append("}").newLine(); - } - - private void renderRuntimeCls() throws IOException { - writer.append("function $rt_cls(cls)").ws().append("{").softNewLine().indent(); - writer.append("return ").appendMethodBody("java.lang.Class", "getClass", - ValueType.object("org.teavm.platform.PlatformClass"), - ValueType.object("java.lang.Class")).append("(cls);") - .softNewLine(); - writer.outdent().append("}").newLine(); - } - - private void renderRuntimeString() throws IOException { - MethodReference stringCons = new MethodReference(String.class, "", char[].class, void.class); - writer.append("function $rt_str(str) {").indent().softNewLine(); - writer.append("if (str === null) {").indent().softNewLine(); - writer.append("return null;").softNewLine(); - writer.outdent().append("}").softNewLine(); - writer.append("var characters = $rt_createCharArray(str.length);").softNewLine(); - writer.append("var charsBuffer = characters.data;").softNewLine(); - writer.append("for (var i = 0; i < str.length; i = (i + 1) | 0) {").indent().softNewLine(); - writer.append("charsBuffer[i] = str.charCodeAt(i) & 0xFFFF;").softNewLine(); - writer.outdent().append("}").softNewLine(); - writer.append("return ").append(naming.getNameForInit(stringCons)).append("(characters);").softNewLine(); - writer.outdent().append("}").newLine(); - } - - private void renderRuntimeUnwrapString() throws IOException { - MethodReference stringLen = new MethodReference(String.class, "length", int.class); - MethodReference getChars = new MethodReference(String.class, "getChars", int.class, int.class, - char[].class, int.class, void.class); - writer.append("function $rt_ustr(str) {").indent().softNewLine(); - writer.append("if (str === null) {").indent().softNewLine(); - writer.append("return null;").softNewLine(); - writer.outdent().append("}").softNewLine(); - writer.append("var result = \"\";").softNewLine(); - writer.append("var sz = ").appendMethodBody(stringLen).append("(str);").softNewLine(); - writer.append("var array = $rt_createCharArray(sz);").softNewLine(); - writer.appendMethodBody(getChars).append("(str, 0, sz, array, 0);").softNewLine(); - writer.append("for (var i = 0; i < sz; i = (i + 1) | 0) {").indent().softNewLine(); - writer.append("result += String.fromCharCode(array.data[i]);").softNewLine(); - writer.outdent().append("}").softNewLine(); - writer.append("return result;").softNewLine(); - writer.outdent().append("}").newLine(); - } - - private void renderRuntimeNullCheck() throws IOException { - writer.append("function $rt_nullCheck(val) {").indent().softNewLine(); - writer.append("if (val === null) {").indent().softNewLine(); - writer.append("$rt_throw(").append(naming.getNameForInit(new MethodReference(NullPointerException.class, - "", void.class))).append("());").softNewLine(); - writer.outdent().append("}").softNewLine(); - writer.append("return val;").softNewLine(); - writer.outdent().append("}").newLine(); - } - - private void renderRuntimeIntern() throws IOException { - writer.append("function $rt_intern(str) {").indent().softNewLine(); - writer.append("return ").appendMethodBody(new MethodReference(String.class, "intern", String.class)) - .append("(str);").softNewLine(); - writer.outdent().append("}").newLine(); - } - - private void renderRuntimeObjcls() throws IOException { - writer.append("function $rt_objcls() { return ").appendClass("java.lang.Object").append("; }").newLine(); - } - - private void renderRuntimeThreads() throws IOException { - writer.append("function $rt_getThread()").ws().append("{").indent().softNewLine(); - writer.append("return ").appendMethodBody(Thread.class, "currentThread", Thread.class).append("();") - .softNewLine(); - writer.outdent().append("}").newLine(); - - writer.append("function $rt_setThread(t)").ws().append("{").indent().softNewLine(); - writer.append("return ").appendMethodBody(Thread.class, "setCurrentThread", Thread.class, void.class) - .append("(t);").softNewLine(); - writer.outdent().append("}").newLine(); - } - private void renderRuntimeAliases() throws IOException { String[] names = { "$rt_throw", "$rt_compare", "$rt_nullCheck", "$rt_cls", "$rt_createArray", "$rt_isInstance", "$rt_nativeThread", "$rt_suspending", "$rt_resuming", "$rt_invalidPointer", diff --git a/core/src/main/java/org/teavm/backend/javascript/rendering/RuntimeRenderer.java b/core/src/main/java/org/teavm/backend/javascript/rendering/RuntimeRenderer.java new file mode 100644 index 000000000..0fcefa0d9 --- /dev/null +++ b/core/src/main/java/org/teavm/backend/javascript/rendering/RuntimeRenderer.java @@ -0,0 +1,163 @@ +/* + * Copyright 2018 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.backend.javascript.rendering; + +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.nio.charset.StandardCharsets; +import org.mozilla.javascript.CompilerEnvirons; +import org.mozilla.javascript.Context; +import org.mozilla.javascript.ast.AstRoot; +import org.teavm.backend.javascript.codegen.NamingException; +import org.teavm.backend.javascript.codegen.NamingStrategy; +import org.teavm.backend.javascript.codegen.SourceWriter; +import org.teavm.model.MethodReference; +import org.teavm.model.ValueType; +import org.teavm.vm.RenderingException; + +public class RuntimeRenderer { + private final NamingStrategy naming; + private final SourceWriter writer; + + public RuntimeRenderer(NamingStrategy naming, SourceWriter writer) { + this.naming = naming; + this.writer = writer; + } + + public void renderRuntime() throws RenderingException { + try { + renderHandWrittenRuntime(); + renderSetCloneMethod(); + renderRuntimeCls(); + renderRuntimeString(); + renderRuntimeUnwrapString(); + renderRuntimeObjcls(); + renderRuntimeNullCheck(); + renderRuntimeIntern(); + renderRuntimeThreads(); + } catch (NamingException e) { + throw new RenderingException("Error rendering runtime methods. See a cause for details", e); + } catch (IOException e) { + throw new RenderingException("IO error", e); + } + } + + private void renderHandWrittenRuntime() throws IOException { + AstRoot ast = parseRuntime(); + ast.visit(new StringConstantElimination()); + AstWriter astWriter = new AstWriter(writer); + astWriter.hoist(ast); + astWriter.print(ast); + } + + private AstRoot parseRuntime() throws IOException { + CompilerEnvirons env = new CompilerEnvirons(); + env.setRecoverFromErrors(true); + env.setLanguageVersion(Context.VERSION_1_8); + JSParser factory = new JSParser(env); + + ClassLoader loader = RuntimeRenderer.class.getClassLoader(); + try (InputStream input = loader.getResourceAsStream("org/teavm/backend/javascript/runtime.js"); + Reader reader = new InputStreamReader(input, StandardCharsets.UTF_8)) { + return factory.parse(reader, null, 0); + } + } + + private void renderSetCloneMethod() throws IOException { + writer.append("function $rt_setCloneMethod(target, f)").ws().append("{").softNewLine().indent(); + writer.append("target.").appendMethod("clone", Object.class).ws().append('=').ws().append("f;"). + softNewLine(); + writer.outdent().append("}").newLine(); + } + + private void renderRuntimeCls() throws IOException { + writer.append("function $rt_cls(cls)").ws().append("{").softNewLine().indent(); + writer.append("return ").appendMethodBody("java.lang.Class", "getClass", + ValueType.object("org.teavm.platform.PlatformClass"), + ValueType.object("java.lang.Class")).append("(cls);") + .softNewLine(); + writer.outdent().append("}").newLine(); + } + + private void renderRuntimeString() throws IOException { + MethodReference stringCons = new MethodReference(String.class, "", char[].class, void.class); + writer.append("function $rt_str(str) {").indent().softNewLine(); + writer.append("if (str === null) {").indent().softNewLine(); + writer.append("return null;").softNewLine(); + writer.outdent().append("}").softNewLine(); + writer.append("var characters = $rt_createCharArray(str.length);").softNewLine(); + writer.append("var charsBuffer = characters.data;").softNewLine(); + writer.append("for (var i = 0; i < str.length; i = (i + 1) | 0) {").indent().softNewLine(); + writer.append("charsBuffer[i] = str.charCodeAt(i) & 0xFFFF;").softNewLine(); + writer.outdent().append("}").softNewLine(); + writer.append("return ").append(naming.getNameForInit(stringCons)).append("(characters);").softNewLine(); + writer.outdent().append("}").newLine(); + } + + private void renderRuntimeUnwrapString() throws IOException { + MethodReference stringLen = new MethodReference(String.class, "length", int.class); + MethodReference getChars = new MethodReference(String.class, "getChars", int.class, int.class, + char[].class, int.class, void.class); + writer.append("function $rt_ustr(str) {").indent().softNewLine(); + writer.append("if (str === null) {").indent().softNewLine(); + writer.append("return null;").softNewLine(); + writer.outdent().append("}").softNewLine(); + writer.append("var result = \"\";").softNewLine(); + writer.append("var sz = ").appendMethodBody(stringLen).append("(str);").softNewLine(); + writer.append("var array = $rt_createCharArray(sz);").softNewLine(); + writer.appendMethodBody(getChars).append("(str, 0, sz, array, 0);").softNewLine(); + writer.append("for (var i = 0; i < sz; i = (i + 1) | 0) {").indent().softNewLine(); + writer.append("result += String.fromCharCode(array.data[i]);").softNewLine(); + writer.outdent().append("}").softNewLine(); + writer.append("return result;").softNewLine(); + writer.outdent().append("}").newLine(); + } + + private void renderRuntimeNullCheck() throws IOException { + writer.append("function $rt_nullCheck(val) {").indent().softNewLine(); + writer.append("if (val === null) {").indent().softNewLine(); + writer.append("$rt_throw(").append(naming.getNameForInit(new MethodReference(NullPointerException.class, + "", void.class))).append("());").softNewLine(); + writer.outdent().append("}").softNewLine(); + writer.append("return val;").softNewLine(); + writer.outdent().append("}").newLine(); + } + + private void renderRuntimeIntern() throws IOException { + writer.append("function $rt_intern(str) {").indent().softNewLine(); + writer.append("return ").appendMethodBody(new MethodReference(String.class, "intern", String.class)) + .append("(str);").softNewLine(); + writer.outdent().append("}").newLine(); + } + + private void renderRuntimeObjcls() throws IOException { + writer.append("function $rt_objcls() { return ").appendClass("java.lang.Object").append("; }").newLine(); + } + + private void renderRuntimeThreads() throws IOException { + writer.append("function $rt_getThread()").ws().append("{").indent().softNewLine(); + writer.append("return ").appendMethodBody(Thread.class, "currentThread", Thread.class).append("();") + .softNewLine(); + writer.outdent().append("}").newLine(); + + writer.append("function $rt_setThread(t)").ws().append("{").indent().softNewLine(); + writer.append("return ").appendMethodBody(Thread.class, "setCurrentThread", Thread.class, void.class) + .append("(t);").softNewLine(); + writer.outdent().append("}").newLine(); + } +} diff --git a/core/src/main/java/org/teavm/backend/javascript/rendering/StringConstantElimination.java b/core/src/main/java/org/teavm/backend/javascript/rendering/StringConstantElimination.java new file mode 100644 index 000000000..3e556b245 --- /dev/null +++ b/core/src/main/java/org/teavm/backend/javascript/rendering/StringConstantElimination.java @@ -0,0 +1,49 @@ +/* + * Copyright 2018 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.backend.javascript.rendering; + +import org.mozilla.javascript.Node; +import org.mozilla.javascript.ast.AstNode; +import org.mozilla.javascript.ast.AstRoot; +import org.mozilla.javascript.ast.Block; +import org.mozilla.javascript.ast.ExpressionStatement; +import org.mozilla.javascript.ast.NodeVisitor; +import org.mozilla.javascript.ast.Scope; +import org.mozilla.javascript.ast.StringLiteral; + +public class StringConstantElimination implements NodeVisitor { + @Override + public boolean visit(AstNode astNode) { + if (astNode instanceof Block || astNode instanceof Scope || astNode instanceof AstRoot) { + handle(astNode); + } + return true; + } + + private void handle(AstNode block) { + Node child = block.getFirstChild(); + while (child != null) { + Node next = child.getNext(); + if (child instanceof ExpressionStatement) { + ExpressionStatement statement = (ExpressionStatement) child; + if (statement.getExpression() instanceof StringLiteral) { + block.removeChild(child); + } + } + child = next; + } + } +} diff --git a/jso/impl/src/test/java/org/teavm/jso/plugin/AstWriterTest.java b/core/src/test/java/org/teavm/backend/javascript/rendering/AstWriterTest.java similarity index 97% rename from jso/impl/src/test/java/org/teavm/jso/plugin/AstWriterTest.java rename to core/src/test/java/org/teavm/backend/javascript/rendering/AstWriterTest.java index 4035b5aaf..78b397a08 100644 --- a/jso/impl/src/test/java/org/teavm/jso/plugin/AstWriterTest.java +++ b/core/src/test/java/org/teavm/backend/javascript/rendering/AstWriterTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Alexey Andreev. + * Copyright 2018 Alexey Andreev. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,10 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.jso.plugin; +package org.teavm.backend.javascript.rendering; -import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; import java.io.IOException; import java.io.StringReader; import org.junit.Test; @@ -25,8 +25,6 @@ import org.mozilla.javascript.Context; import org.mozilla.javascript.ast.AstRoot; import org.teavm.backend.javascript.codegen.SourceWriter; import org.teavm.backend.javascript.codegen.SourceWriterBuilder; -import org.teavm.jso.impl.AstWriter; -import org.teavm.jso.impl.JSParser; public class AstWriterTest { private StringBuilder sb = new StringBuilder(); diff --git a/jso/impl/pom.xml b/jso/impl/pom.xml index 87afd8d83..7d076f6b5 100644 --- a/jso/impl/pom.xml +++ b/jso/impl/pom.xml @@ -39,11 +39,6 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xs teavm-jso-apis ${project.version} - - org.mozilla - rhino - 1.7.7 - junit junit diff --git a/jso/impl/src/main/java/org/teavm/jso/impl/JSBodyAstEmitter.java b/jso/impl/src/main/java/org/teavm/jso/impl/JSBodyAstEmitter.java index 86edc4fe8..b75c176ad 100644 --- a/jso/impl/src/main/java/org/teavm/jso/impl/JSBodyAstEmitter.java +++ b/jso/impl/src/main/java/org/teavm/jso/impl/JSBodyAstEmitter.java @@ -20,6 +20,7 @@ import org.mozilla.javascript.Node; import org.mozilla.javascript.ast.AstNode; import org.mozilla.javascript.ast.Block; import org.teavm.backend.javascript.codegen.SourceWriter; +import org.teavm.backend.javascript.rendering.AstWriter; import org.teavm.backend.javascript.rendering.Precedence; import org.teavm.backend.javascript.spi.GeneratorContext; import org.teavm.backend.javascript.spi.InjectorContext; @@ -30,7 +31,7 @@ class JSBodyAstEmitter implements JSBodyEmitter { private AstNode ast; private String[] parameterNames; - public JSBodyAstEmitter(boolean isStatic, AstNode ast, String[] parameterNames) { + JSBodyAstEmitter(boolean isStatic, AstNode ast, String[] parameterNames) { this.isStatic = isStatic; this.ast = ast; this.parameterNames = parameterNames; diff --git a/jso/impl/src/main/java/org/teavm/jso/impl/JSClassProcessor.java b/jso/impl/src/main/java/org/teavm/jso/impl/JSClassProcessor.java index e9b4b7c00..113b2743e 100644 --- a/jso/impl/src/main/java/org/teavm/jso/impl/JSClassProcessor.java +++ b/jso/impl/src/main/java/org/teavm/jso/impl/JSClassProcessor.java @@ -30,6 +30,7 @@ import org.mozilla.javascript.Context; import org.mozilla.javascript.ast.AstNode; import org.mozilla.javascript.ast.AstRoot; import org.mozilla.javascript.ast.FunctionNode; +import org.teavm.backend.javascript.rendering.JSParser; import org.teavm.cache.NoCache; import org.teavm.diagnostics.Diagnostics; import org.teavm.interop.Sync; diff --git a/pom.xml b/pom.xml index 0003d6a33..14684f3e8 100644 --- a/pom.xml +++ b/pom.xml @@ -72,6 +72,7 @@ 2.6.2 2017.3.5 6.1.1 + 1.7.7 false 1 @@ -201,6 +202,11 @@ jackson-databind ${jackson.version} + + org.mozilla + rhino + ${rhino.version} + diff --git a/samples/async/pom.xml b/samples/async/pom.xml index bb55b7c93..83ad2b65c 100644 --- a/samples/async/pom.xml +++ b/samples/async/pom.xml @@ -63,7 +63,6 @@ ${project.build.directory}/generated/js/teavm org.teavm.samples.async.AsyncProgram - SEPARATE false true true diff --git a/samples/async/src/main/webapp/index.html b/samples/async/src/main/webapp/index.html index cf0f1bb3f..4ac1aeefd 100644 --- a/samples/async/src/main/webapp/index.html +++ b/samples/async/src/main/webapp/index.html @@ -18,7 +18,6 @@ Continuation-passing style demo - diff --git a/samples/benchmark/pom.xml b/samples/benchmark/pom.xml index 83d47bbed..e8b570e7b 100644 --- a/samples/benchmark/pom.xml +++ b/samples/benchmark/pom.xml @@ -149,7 +149,6 @@ ${project.build.directory}/generated/js/teavm org.teavm.samples.benchmark.teavm.BenchmarkStarter - SEPARATE true true FULL diff --git a/samples/benchmark/src/main/webapp/teavm.html b/samples/benchmark/src/main/webapp/teavm.html index 0ee75d29b..acb9c0513 100644 --- a/samples/benchmark/src/main/webapp/teavm.html +++ b/samples/benchmark/src/main/webapp/teavm.html @@ -18,7 +18,6 @@ TeaVM jbox2d benchmark - diff --git a/samples/hello/pom.xml b/samples/hello/pom.xml index bba3bb496..85b579ad0 100644 --- a/samples/hello/pom.xml +++ b/samples/hello/pom.xml @@ -76,7 +76,6 @@ ${project.build.directory}/generated/js/teavm org.teavm.samples.hello.Client - SEPARATE false true true diff --git a/samples/hello/src/main/webapp/index.html b/samples/hello/src/main/webapp/index.html index dc0c2a474..b5a1aab2a 100644 --- a/samples/hello/src/main/webapp/index.html +++ b/samples/hello/src/main/webapp/index.html @@ -18,7 +18,6 @@ Hello web application - diff --git a/samples/kotlin/pom.xml b/samples/kotlin/pom.xml index 26cf7e99a..8fec3847d 100644 --- a/samples/kotlin/pom.xml +++ b/samples/kotlin/pom.xml @@ -97,7 +97,6 @@ ${project.build.directory}/generated/js/teavm org.teavm.samples.kotlin.HelloKt - SEPARATE false true true diff --git a/samples/kotlin/src/main/webapp/index.html b/samples/kotlin/src/main/webapp/index.html index b1f851d52..bff0f30bc 100644 --- a/samples/kotlin/src/main/webapp/index.html +++ b/samples/kotlin/src/main/webapp/index.html @@ -3,7 +3,6 @@ Hello kotlin - diff --git a/samples/scala/pom.xml b/samples/scala/pom.xml index f6f95706e..a160151c9 100644 --- a/samples/scala/pom.xml +++ b/samples/scala/pom.xml @@ -71,7 +71,6 @@ ${project.build.directory}/generated/js/teavm org.teavm.samples.scala.Client - SEPARATE false true true diff --git a/samples/scala/src/main/webapp/index.html b/samples/scala/src/main/webapp/index.html index c18b19349..344147872 100644 --- a/samples/scala/src/main/webapp/index.html +++ b/samples/scala/src/main/webapp/index.html @@ -3,7 +3,6 @@ Hello Scala - diff --git a/samples/storage/src/main/webapp/index.html b/samples/storage/src/main/webapp/index.html index a961da445..4cbf27347 100644 --- a/samples/storage/src/main/webapp/index.html +++ b/samples/storage/src/main/webapp/index.html @@ -18,7 +18,6 @@ Web Storage web application - diff --git a/samples/video/pom.xml b/samples/video/pom.xml index b0331837b..6c6ba111f 100644 --- a/samples/video/pom.xml +++ b/samples/video/pom.xml @@ -76,7 +76,6 @@ ${project.build.directory}/generated/js/teavm org.teavm.samples.video.Player - SEPARATE false true true diff --git a/samples/video/src/main/webapp/index.html b/samples/video/src/main/webapp/index.html index e9740a3fe..1e78c566d 100644 --- a/samples/video/src/main/webapp/index.html +++ b/samples/video/src/main/webapp/index.html @@ -18,7 +18,6 @@ HTML5 Video web application - diff --git a/tests/src/test/js/src/run-tests.js b/tests/src/test/js/src/run-tests.js index bdbc2f26a..1173a7b7d 100644 --- a/tests/src/test/js/src/run-tests.js +++ b/tests/src/test/js/src/run-tests.js @@ -20,7 +20,6 @@ import * as http from "http"; import {server as WebSocketServer} from "websocket"; const TEST_FILE_NAME = "test.js"; -const RUNTIME_FILE_NAME = "runtime.js"; const WASM_RUNTIME_FILE_NAME = "test.wasm-runtime.js"; const TEST_FILES = [ { file: TEST_FILE_NAME, name: "simple", type: "js" }, @@ -122,7 +121,7 @@ async function serveFile(path, response) { async function walkDir(path, name, suite) { const files = await fs.readdir(rootDir + "/" + path); - if (files.includes(WASM_RUNTIME_FILE_NAME) || files.includes(RUNTIME_FILE_NAME)) { + if (files.includes(WASM_RUNTIME_FILE_NAME) || files.includes("test.js")) { for (const { file: fileName, name: profileName, type: type } of TEST_FILES) { if (files.includes(fileName)) { switch (type) { diff --git a/tools/cli/src/main/java/org/teavm/cli/TeaVMRunner.java b/tools/cli/src/main/java/org/teavm/cli/TeaVMRunner.java index 3780452c6..94492c705 100644 --- a/tools/cli/src/main/java/org/teavm/cli/TeaVMRunner.java +++ b/tools/cli/src/main/java/org/teavm/cli/TeaVMRunner.java @@ -46,7 +46,6 @@ import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; import org.apache.commons.cli.PosixParser; import org.teavm.backend.wasm.render.WasmBinaryVersion; -import org.teavm.tooling.RuntimeCopyOperation; import org.teavm.tooling.TeaVMTargetType; import org.teavm.tooling.TeaVMTool; import org.teavm.tooling.TeaVMToolException; @@ -231,22 +230,6 @@ public final class TeaVMRunner { } else { tool.setMinifying(false); } - if (commandLine.hasOption("r")) { - switch (commandLine.getOptionValue("r")) { - case "separate": - tool.setRuntime(RuntimeCopyOperation.SEPARATE); - break; - case "merge": - tool.setRuntime(RuntimeCopyOperation.MERGED); - break; - case "none": - tool.setRuntime(RuntimeCopyOperation.NONE); - break; - default: - System.err.println("Wrong parameter for -r option specified"); - printUsage(); - } - } } private void parseDebugOptions() { diff --git a/tools/core/src/main/java/org/teavm/tooling/RuntimeCopyOperation.java b/tools/core/src/main/java/org/teavm/tooling/RuntimeCopyOperation.java deleted file mode 100644 index 9d037fdec..000000000 --- a/tools/core/src/main/java/org/teavm/tooling/RuntimeCopyOperation.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * 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.tooling; - -public enum RuntimeCopyOperation { - SEPARATE, - MERGED, - NONE -} diff --git a/tools/core/src/main/java/org/teavm/tooling/TeaVMTool.java b/tools/core/src/main/java/org/teavm/tooling/TeaVMTool.java index e6e6f3b29..deadc4392 100644 --- a/tools/core/src/main/java/org/teavm/tooling/TeaVMTool.java +++ b/tools/core/src/main/java/org/teavm/tooling/TeaVMTool.java @@ -15,16 +15,14 @@ */ package org.teavm.tooling; -import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; -import java.io.InputStream; import java.io.OutputStream; import java.io.OutputStreamWriter; -import java.io.StringWriter; import java.io.Writer; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -32,10 +30,8 @@ import java.util.HashSet; import java.util.List; import java.util.Properties; import java.util.Set; -import org.apache.commons.io.IOUtils; import org.teavm.backend.c.CTarget; import org.teavm.backend.javascript.JavaScriptTarget; -import org.teavm.backend.javascript.rendering.RenderingManager; import org.teavm.backend.wasm.WasmTarget; import org.teavm.backend.wasm.render.WasmBinaryVersion; import org.teavm.cache.DiskCachedClassHolderSource; @@ -65,7 +61,6 @@ import org.teavm.vm.TeaVMBuilder; import org.teavm.vm.TeaVMOptimizationLevel; import org.teavm.vm.TeaVMProgressListener; import org.teavm.vm.TeaVMTarget; -import org.teavm.vm.spi.AbstractRendererListener; public class TeaVMTool implements BaseTeaVMTool { private File targetDirectory = new File("."); @@ -73,7 +68,6 @@ public class TeaVMTool implements BaseTeaVMTool { private String targetFileName = ""; private boolean minifying = true; private String mainClass; - private RuntimeCopyOperation runtime = RuntimeCopyOperation.SEPARATE; private Properties properties = new Properties(); private boolean debugInformationGenerated; private boolean sourceMapsFileGenerated; @@ -145,14 +139,6 @@ public class TeaVMTool implements BaseTeaVMTool { this.mainClass = mainClass; } - public RuntimeCopyOperation getRuntime() { - return runtime; - } - - public void setRuntime(RuntimeCopyOperation runtime) { - this.runtime = runtime; - } - public boolean isDebugInformationGenerated() { return debugInformationGenerated; } @@ -407,9 +393,6 @@ public class TeaVMTool implements BaseTeaVMTool { } targetDirectory.mkdirs(); - if (runtime == RuntimeCopyOperation.MERGED) { - javaScriptTarget.add(runtimeInjector); - } BuildTarget buildTarget = new DirectoryBuildTarget(targetDirectory); String outputName = getResolvedTargetFileName(); vm.build(buildTarget, outputName); @@ -495,7 +478,8 @@ public class TeaVMTool implements BaseTeaVMTool { String sourceMapsFileName = getResolvedTargetFileName() + ".map"; writer.append("\n//# sourceMappingURL=").append(sourceMapsFileName); File sourceMapsFile = new File(targetDirectory, sourceMapsFileName); - try (Writer sourceMapsOut = new OutputStreamWriter(new FileOutputStream(sourceMapsFile), "UTF-8")) { + try (Writer sourceMapsOut = new OutputStreamWriter(new FileOutputStream(sourceMapsFile), + StandardCharsets.UTF_8)) { debugInfo.writeAsSourceMaps(sourceMapsOut, "src", getResolvedTargetFileName()); } generatedFiles.add(sourceMapsFile); @@ -505,10 +489,6 @@ public class TeaVMTool implements BaseTeaVMTool { copySourceFiles(); log.info("Source files successfully written"); } - - if (runtime == RuntimeCopyOperation.SEPARATE) { - resourceToFile("org/teavm/backend/javascript/runtime.js", "runtime.js"); - } } private void printStats() { @@ -536,30 +516,4 @@ public class TeaVMTool implements BaseTeaVMTool { copier.setLog(log); copier.copy(new File(targetDirectory, "src")); } - - private AbstractRendererListener runtimeInjector = new AbstractRendererListener() { - @Override - public void begin(RenderingManager manager, BuildTarget buildTarget) throws IOException { - StringWriter writer = new StringWriter(); - resourceToWriter("org/teavm/backend/javascript/runtime.js", writer); - writer.close(); - manager.getWriter().append(writer.toString()).newLine(); - } - }; - - private void resourceToFile(String resource, String fileName) throws IOException { - try (InputStream input = TeaVMTool.class.getClassLoader().getResourceAsStream(resource)) { - File outputFile = new File(targetDirectory, fileName); - try (OutputStream output = new BufferedOutputStream(new FileOutputStream(outputFile))) { - IOUtils.copy(new BufferedInputStream(input), output); - } - generatedFiles.add(outputFile); - } - } - - private void resourceToWriter(String resource, Writer writer) throws IOException { - try (InputStream input = TeaVMTool.class.getClassLoader().getResourceAsStream(resource)) { - IOUtils.copy(new BufferedInputStream(input), writer, "UTF-8"); - } - } } diff --git a/tools/eclipse/m2e-plugin/src/main/java/org/teavm/eclipse/m2e/TeaVMProjectConfigurator.java b/tools/eclipse/m2e-plugin/src/main/java/org/teavm/eclipse/m2e/TeaVMProjectConfigurator.java index d1f258ea9..c80024e7b 100644 --- a/tools/eclipse/m2e-plugin/src/main/java/org/teavm/eclipse/m2e/TeaVMProjectConfigurator.java +++ b/tools/eclipse/m2e-plugin/src/main/java/org/teavm/eclipse/m2e/TeaVMProjectConfigurator.java @@ -23,7 +23,6 @@ import org.eclipse.m2e.core.project.configurator.ProjectConfigurationRequest; import org.teavm.eclipse.TeaVMEclipsePlugin; import org.teavm.eclipse.TeaVMProfile; import org.teavm.eclipse.TeaVMProjectSettings; -import org.teavm.eclipse.TeaVMRuntimeMode; public class TeaVMProjectConfigurator extends AbstractProjectConfigurator { private static final String TOOL_ID = "teavm-eclipse-m2e-plugin.tool"; @@ -88,7 +87,7 @@ public class TeaVMProjectConfigurator extends AbstractProjectConfigurator { private void configureProfile(MojoExecution execution, TeaVMProfile profile, IProgressMonitor monitor) throws CoreException { - monitor.beginTask("Configuring profile " + profile.getName(), 110); + monitor.beginTask("Configuring profile " + profile.getName(), 100); String buildDir = getProjectBuildDirectory(); String mainClass = maven.getMojoParameterValue(mavenSession, execution, "mainClass", String.class); @@ -104,10 +103,6 @@ public class TeaVMProjectConfigurator extends AbstractProjectConfigurator { profile.setTargetFileName(targetFileName != null ? targetFileName : "classes.js"); monitor.worked(10); - String runtime = maven.getMojoParameterValue(mavenSession, execution, "runtime", String.class); - profile.setRuntimeMode(runtime != null ? getRuntimeMode(runtime) : TeaVMRuntimeMode.SEPARATE); - monitor.worked(10); - Properties properties = maven.getMojoParameterValue(mavenSession, execution, "properties", Properties.class); profile.setProperties(properties != null ? properties : new Properties()); monitor.worked(10); @@ -184,19 +179,6 @@ public class TeaVMProjectConfigurator extends AbstractProjectConfigurator { return varManager.generateVariableExpression("workspace_loc", path) + suffix; } - private TeaVMRuntimeMode getRuntimeMode(String name) { - switch (name) { - case "SEPARATE": - return TeaVMRuntimeMode.SEPARATE; - case "MERGED": - return TeaVMRuntimeMode.MERGE; - case "NONE": - return TeaVMRuntimeMode.NONE; - default: - return TeaVMRuntimeMode.NONE; - } - } - private String getIdForProfile(MojoExecution pluginExecution) { String executionId = pluginExecution.getExecutionId(); if (executionId != null && usedExecutionIds.add(executionId)) { diff --git a/tools/eclipse/plugin/src/main/java/org/teavm/eclipse/PreferencesBasedTeaVMProjectSettings.java b/tools/eclipse/plugin/src/main/java/org/teavm/eclipse/PreferencesBasedTeaVMProjectSettings.java index 0066dbc90..9c1480603 100644 --- a/tools/eclipse/plugin/src/main/java/org/teavm/eclipse/PreferencesBasedTeaVMProjectSettings.java +++ b/tools/eclipse/plugin/src/main/java/org/teavm/eclipse/PreferencesBasedTeaVMProjectSettings.java @@ -32,7 +32,6 @@ public class PreferencesBasedTeaVMProjectSettings implements TeaVMProjectSetting public static final String MAIN_CLASS = "mainClass"; public static final String TARGET_DIRECTORY = "targetDirectory"; public static final String TARGET_FILE_NAME = "targetFileName"; - public static final String RUNTIME = "runtime"; public static final String MINIFYING = "minifying"; public static final String INCREMENTAL = "incremental"; public static final String CACHE_DIRECTORY = "cacheDirectory"; @@ -155,7 +154,6 @@ public class PreferencesBasedTeaVMProjectSettings implements TeaVMProjectSetting private String mainClass; private String targetDirectory; private String targetFileName; - private TeaVMRuntimeMode runtimeMode = TeaVMRuntimeMode.SEPARATE; private boolean incremental; private String cacheDirectory; private boolean sourceMapsGenerated; @@ -222,16 +220,6 @@ public class PreferencesBasedTeaVMProjectSettings implements TeaVMProjectSetting this.targetFileName = targetFileName; } - @Override - public TeaVMRuntimeMode getRuntimeMode() { - return runtimeMode; - } - - @Override - public void setRuntimeMode(TeaVMRuntimeMode runtimeMode) { - this.runtimeMode = runtimeMode; - } - @Override public boolean isIncremental() { return incremental; @@ -332,7 +320,6 @@ public class PreferencesBasedTeaVMProjectSettings implements TeaVMProjectSetting mainClass = preferences.get(MAIN_CLASS, ""); targetDirectory = preferences.get(TARGET_DIRECTORY, ""); targetFileName = preferences.get(TARGET_FILE_NAME, ""); - runtimeMode = TeaVMRuntimeMode.valueOf(preferences.get(RUNTIME, TeaVMRuntimeMode.SEPARATE.name())); incremental = preferences.getBoolean(INCREMENTAL, false); cacheDirectory = preferences.get(CACHE_DIRECTORY, ""); sourceMapsGenerated = preferences.getBoolean(SOURCE_MAPS, true); @@ -357,7 +344,6 @@ public class PreferencesBasedTeaVMProjectSettings implements TeaVMProjectSetting preferences.put(MAIN_CLASS, mainClass); preferences.put(TARGET_DIRECTORY, targetDirectory); preferences.put(TARGET_FILE_NAME, targetFileName); - preferences.put(RUNTIME, runtimeMode.name()); preferences.putBoolean(INCREMENTAL, incremental); preferences.put(CACHE_DIRECTORY, cacheDirectory); preferences.putBoolean(SOURCE_MAPS, sourceMapsGenerated); diff --git a/tools/eclipse/plugin/src/main/java/org/teavm/eclipse/TeaVMProfile.java b/tools/eclipse/plugin/src/main/java/org/teavm/eclipse/TeaVMProfile.java index ab9e8c429..07f679136 100644 --- a/tools/eclipse/plugin/src/main/java/org/teavm/eclipse/TeaVMProfile.java +++ b/tools/eclipse/plugin/src/main/java/org/teavm/eclipse/TeaVMProfile.java @@ -39,10 +39,6 @@ public interface TeaVMProfile { void setTargetFileName(String targetFileName); - TeaVMRuntimeMode getRuntimeMode(); - - void setRuntimeMode(TeaVMRuntimeMode runtimeMode); - boolean isIncremental(); void setIncremental(boolean incremental); diff --git a/tools/eclipse/plugin/src/main/java/org/teavm/eclipse/TeaVMProjectBuilder.java b/tools/eclipse/plugin/src/main/java/org/teavm/eclipse/TeaVMProjectBuilder.java index 341f0f489..0e87ee95f 100644 --- a/tools/eclipse/plugin/src/main/java/org/teavm/eclipse/TeaVMProjectBuilder.java +++ b/tools/eclipse/plugin/src/main/java/org/teavm/eclipse/TeaVMProjectBuilder.java @@ -70,7 +70,6 @@ import org.teavm.model.FieldReference; import org.teavm.model.MethodReference; import org.teavm.model.TextLocation; import org.teavm.model.ValueType; -import org.teavm.tooling.RuntimeCopyOperation; import org.teavm.tooling.TeaVMTool; import org.teavm.tooling.TeaVMToolException; import org.teavm.tooling.sources.DirectorySourceFileProvider; @@ -152,7 +151,6 @@ public class TeaVMProjectBuilder extends IncrementalProjectBuilder { tool.setTargetDirectory(new File(varManager.performStringSubstitution(targetDir, false))); tool.setTargetFileName(profile.getTargetFileName()); tool.setMinifying(false); - tool.setRuntime(mapRuntime(profile.getRuntimeMode())); tool.setMainClass(profile.getMainClass()); tool.getProperties().putAll(profile.getProperties()); tool.setIncremental(profile.isIncremental()); @@ -209,17 +207,6 @@ public class TeaVMProjectBuilder extends IncrementalProjectBuilder { } } - private RuntimeCopyOperation mapRuntime(TeaVMRuntimeMode runtimeMode) { - switch (runtimeMode) { - case MERGE: - return RuntimeCopyOperation.MERGED; - case SEPARATE: - return RuntimeCopyOperation.SEPARATE; - default: - return RuntimeCopyOperation.NONE; - } - } - private void classesToResources(ProfileData profileData, TeaVMTool tool) { Set resourcePaths = new HashSet<>(); for (String className : tool.getClasses()) { diff --git a/tools/eclipse/plugin/src/main/java/org/teavm/eclipse/TeaVMRuntimeMode.java b/tools/eclipse/plugin/src/main/java/org/teavm/eclipse/TeaVMRuntimeMode.java deleted file mode 100644 index 25a245f15..000000000 --- a/tools/eclipse/plugin/src/main/java/org/teavm/eclipse/TeaVMRuntimeMode.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * 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.eclipse; - -public enum TeaVMRuntimeMode { - SEPARATE, - MERGE, - NONE -} diff --git a/tools/eclipse/plugin/src/main/java/org/teavm/eclipse/ui/TeaVMProfileDialog.java b/tools/eclipse/plugin/src/main/java/org/teavm/eclipse/ui/TeaVMProfileDialog.java index 0904711d2..9ea7b8da7 100644 --- a/tools/eclipse/plugin/src/main/java/org/teavm/eclipse/ui/TeaVMProfileDialog.java +++ b/tools/eclipse/plugin/src/main/java/org/teavm/eclipse/ui/TeaVMProfileDialog.java @@ -66,11 +66,8 @@ import org.eclipse.ui.model.WorkbenchLabelProvider; import org.eclipse.ui.views.navigator.ResourceComparator; import org.teavm.eclipse.TeaVMProfile; import org.teavm.eclipse.TeaVMProjectSettings; -import org.teavm.eclipse.TeaVMRuntimeMode; public class TeaVMProfileDialog extends Dialog { - private static List runtimeModes = Arrays.asList(TeaVMRuntimeMode.SEPARATE, - TeaVMRuntimeMode.MERGE, TeaVMRuntimeMode.NONE); private TabFolder tabFolder; private Text nameField; private Text mainClassField; @@ -79,7 +76,6 @@ public class TeaVMProfileDialog extends Dialog { private Button targetDirectoryWorkspaceButton; private Button targetDirectoryFileSystemButton; private Text targetFileNameField; - private Combo runtimeField; private Button incrementalButton; private Text cacheDirectoryField; private Button cacheDirectoryWorkspaceButton; @@ -176,7 +172,6 @@ public class TeaVMProfileDialog extends Dialog { Group group = createGroup(parent, "Output settings", 4, false); createTargetDirectoryField(group); createTargetFileNameField(group); - createRuntimeField(group); } private void createIncrementalGroup(Composite parent) { @@ -425,17 +420,6 @@ public class TeaVMProfileDialog extends Dialog { targetFileNameField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1)); } - private void createRuntimeField(Composite container) { - Label label = new Label(container, SWT.NONE); - label.setText("Attach &runtime:"); - - runtimeField = new Combo(container, SWT.DROP_DOWN | SWT.READ_ONLY); - runtimeField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 3, 1)); - runtimeField.add("as a separate file (runtime.js)"); - runtimeField.add("merge into output file"); - runtimeField.add("don't attach"); - } - private void createIncrementalField(Composite container) { incrementalButton = new Button(container, SWT.CHECK); incrementalButton.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 4, 1)); @@ -626,7 +610,6 @@ public class TeaVMProfileDialog extends Dialog { mainClassField.setText(profile.getMainClass() != null ? profile.getMainClass() : ""); targetDirectoryField.setText(profile.getTargetDirectory()); targetFileNameField.setText(profile.getTargetFileName()); - runtimeField.select(runtimeModes.indexOf(profile.getRuntimeMode())); incrementalButton.setSelection(profile.isIncremental()); cacheDirectoryField.setText(profile.getCacheDirectory()); debugInformationButton.setSelection(profile.isDebugInformationGenerated()); @@ -663,7 +646,6 @@ public class TeaVMProfileDialog extends Dialog { profile.setMainClass(!mainClass.isEmpty() ? mainClass : null); profile.setTargetDirectory(targetDirectoryField.getText()); profile.setTargetFileName(targetFileNameField.getText().trim()); - profile.setRuntimeMode(runtimeModes.get(runtimeField.getSelectionIndex())); profile.setIncremental(incrementalButton.getSelection()); profile.setCacheDirectory(cacheDirectoryField.getText()); profile.setDebugInformationGenerated(debugInformationButton.getSelection()); diff --git a/tools/junit/src/main/java/org/teavm/junit/HtmlUnitRunStrategy.java b/tools/junit/src/main/java/org/teavm/junit/HtmlUnitRunStrategy.java index 4d2946540..8bc80f155 100644 --- a/tools/junit/src/main/java/org/teavm/junit/HtmlUnitRunStrategy.java +++ b/tools/junit/src/main/java/org/teavm/junit/HtmlUnitRunStrategy.java @@ -58,7 +58,6 @@ class HtmlUnitRunStrategy implements TestRunStrategy { } catch (IOException e) { throw new RuntimeException(e); } - page.get().executeJavaScript(readFile(new File(run.getBaseDirectory(), "runtime.js"))); page.get().executeJavaScript(readFile(new File(run.getBaseDirectory(), run.getFileName()))); AsyncResult asyncResult = new AsyncResult(); diff --git a/tools/junit/src/main/java/org/teavm/junit/TeaVMTestRunner.java b/tools/junit/src/main/java/org/teavm/junit/TeaVMTestRunner.java index 91397a094..707566800 100644 --- a/tools/junit/src/main/java/org/teavm/junit/TeaVMTestRunner.java +++ b/tools/junit/src/main/java/org/teavm/junit/TeaVMTestRunner.java @@ -424,7 +424,6 @@ public class TeaVMTestRunner extends Runner implements Filterable { } private void copyJsFilesTo(File path) throws IOException { - resourceToFile("org/teavm/backend/javascript/runtime.js", new File(path, "runtime.js")); resourceToFile("org/teavm/backend/wasm/wasm-runtime.js", new File(path, "test.wasm-runtime.js")); resourceToFile("teavm-run-test.html", new File(path, "run-test.html")); resourceToFile("teavm-run-test-wasm.html", new File(path, "run-test-wasm.html")); diff --git a/tools/junit/src/main/resources/teavm-run-test.html b/tools/junit/src/main/resources/teavm-run-test.html index 659e14466..2acb8b862 100644 --- a/tools/junit/src/main/resources/teavm-run-test.html +++ b/tools/junit/src/main/resources/teavm-run-test.html @@ -5,7 +5,6 @@ -