diff --git a/classlib/src/main/java/org/teavm/classlib/java/lang/TConsoleOutputStreamStderr.java b/classlib/src/main/java/org/teavm/classlib/java/lang/TConsoleOutputStreamStderr.java index 3e63f6fda..eb7f3b0ea 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/lang/TConsoleOutputStreamStderr.java +++ b/classlib/src/main/java/org/teavm/classlib/java/lang/TConsoleOutputStreamStderr.java @@ -19,15 +19,18 @@ import org.teavm.classlib.java.io.TIOException; import org.teavm.classlib.java.io.TOutputStream; import org.teavm.interop.DelegateTo; import org.teavm.interop.Import; -import org.teavm.platform.Platform; +import org.teavm.jso.JSBody; class TConsoleOutputStreamStderr extends TOutputStream { @Override @DelegateTo("writeLowLevel") public void write(int b) throws TIOException { - Platform.getConsole().error(b); + writeJs(b); } + @JSBody(params = "b", script = "$rt_putStderr(b);") + private static native void writeJs(int b); + private void writeLowLevel(int b) { writeImpl(b); } diff --git a/classlib/src/main/java/org/teavm/classlib/java/lang/TConsoleOutputStreamStdout.java b/classlib/src/main/java/org/teavm/classlib/java/lang/TConsoleOutputStreamStdout.java index 39250657d..de3503e20 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/lang/TConsoleOutputStreamStdout.java +++ b/classlib/src/main/java/org/teavm/classlib/java/lang/TConsoleOutputStreamStdout.java @@ -18,15 +18,18 @@ package org.teavm.classlib.java.lang; import org.teavm.classlib.java.io.TIOException; import org.teavm.classlib.java.io.TOutputStream; import org.teavm.interop.DelegateTo; -import org.teavm.platform.Platform; +import org.teavm.jso.JSBody; class TConsoleOutputStreamStdout extends TOutputStream { @Override @DelegateTo("writeLowLevel") public void write(int b) throws TIOException { - Platform.getConsole().output(b); + writeJs(b); } + @JSBody(params = "b", script = "$rt_putStdout(b);") + private static native void writeJs(int b); + private void writeLowLevel(int b) { TConsoleOutputStreamStderr.writeImpl(b); } diff --git a/core/src/main/resources/org/teavm/backend/javascript/runtime.js b/core/src/main/resources/org/teavm/backend/javascript/runtime.js index 80c188e6b..6dcf426a5 100644 --- a/core/src/main/resources/org/teavm/backend/javascript/runtime.js +++ b/core/src/main/resources/org/teavm/backend/javascript/runtime.js @@ -14,7 +14,6 @@ * limitations under the License. */ "use strict"; -var $rt_global = this; var $rt_seed = 2463534242; function $rt_nextId() { var x = $rt_seed; diff --git a/platform/src/main/java/org/teavm/platform/Platform.java b/platform/src/main/java/org/teavm/platform/Platform.java index a54016694..1c6781de9 100644 --- a/platform/src/main/java/org/teavm/platform/Platform.java +++ b/platform/src/main/java/org/teavm/platform/Platform.java @@ -24,6 +24,8 @@ import org.teavm.interop.DelegateTo; import org.teavm.interop.Unmanaged; import org.teavm.jso.JSBody; import org.teavm.jso.JSObject; +import org.teavm.jso.browser.Window; +import org.teavm.jso.core.JSString; import org.teavm.platform.metadata.ClassResource; import org.teavm.platform.metadata.StaticFieldResource; import org.teavm.platform.plugin.PlatformGenerator; @@ -84,10 +86,6 @@ public final class Platform { @Unmanaged public static native Class asJavaClass(PlatformObject obj); - public static PlatformConsole getConsole() { - return (PlatformConsole) getGlobal(); - } - @JSBody(script = "return $rt_nextId();") public static native int nextObjectId(); @@ -191,14 +189,14 @@ public final class Platform { public static native int schedule(PlatformRunnable runnable, int timeout); public static void killSchedule(int id) { - ((PlatformHelper) getGlobal()).killSchedule(id); + Window.clearTimeout(id); } @JSBody(script = "return [];") public static native PlatformQueue createQueue(); public static PlatformString stringFromCharCode(int charCode) { - return ((PlatformHelper) getGlobal()).getStringClass().fromCharCode(charCode); + return JSString.fromCharCode(charCode).cast(); } @DelegateTo("isPrimitiveLowLevel") @@ -231,7 +229,4 @@ public final class Platform { public static String getName(PlatformClass cls) { return cls.getMetadata().getName(); } - - @JSBody(script = "return $rt_global;") - private static native JSObject getGlobal(); } diff --git a/platform/src/main/java/org/teavm/platform/PlatformConsole.java b/platform/src/main/java/org/teavm/platform/PlatformConsole.java deleted file mode 100644 index f0b8873d1..000000000 --- a/platform/src/main/java/org/teavm/platform/PlatformConsole.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2015 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.platform; - -import org.teavm.jso.JSMethod; -import org.teavm.jso.JSObject; - -public interface PlatformConsole extends JSObject { - @JSMethod("$rt_putStdout") - void output(int b); - - @JSMethod("$rt_putStderr") - void error(int b); -} diff --git a/platform/src/main/java/org/teavm/platform/PlatformHelper.java b/platform/src/main/java/org/teavm/platform/PlatformHelper.java deleted file mode 100644 index f4329545b..000000000 --- a/platform/src/main/java/org/teavm/platform/PlatformHelper.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2015 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.platform; - -import org.teavm.jso.JSMethod; -import org.teavm.jso.JSObject; -import org.teavm.jso.JSProperty; - -interface PlatformHelper extends JSObject { - @JSMethod("$rt_nextId") - int nextId(); - - @JSProperty("String") - PlatformStringClass getStringClass(); - - @JSMethod("clearTimeout") - void killSchedule(int scheduleId); -}