From 530fe1d277bca3b55da0c722744f54e150eeb405 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Sat, 15 Apr 2017 13:40:54 +0300 Subject: [PATCH] JS: remove references to window. See #269 --- .../resources/org/teavm/backend/javascript/runtime.js | 1 + .../src/main/java/org/teavm/platform/Platform.java | 10 ++++++---- .../main/java/org/teavm/platform/PlatformConsole.java | 4 ---- 3 files changed, 7 insertions(+), 8 deletions(-) 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 0fef3e723..bce7d151c 100644 --- a/core/src/main/resources/org/teavm/backend/javascript/runtime.js +++ b/core/src/main/resources/org/teavm/backend/javascript/runtime.js @@ -14,6 +14,7 @@ * limitations under the License. */ "use strict"; +var $rt_global = this; var $rt_lastObjectId = 1; function $rt_nextId() { var current = $rt_lastObjectId; diff --git a/platform/src/main/java/org/teavm/platform/Platform.java b/platform/src/main/java/org/teavm/platform/Platform.java index 91a6e3b37..177bb50dc 100644 --- a/platform/src/main/java/org/teavm/platform/Platform.java +++ b/platform/src/main/java/org/teavm/platform/Platform.java @@ -24,7 +24,6 @@ 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.platform.metadata.ClassResource; import org.teavm.platform.metadata.StaticFieldResource; import org.teavm.platform.plugin.PlatformGenerator; @@ -84,7 +83,7 @@ public final class Platform { public static native Class asJavaClass(PlatformObject obj); public static PlatformConsole getConsole() { - return (PlatformConsole) Window.current(); + return (PlatformConsole) getGlobal(); } @JSBody(script = "return $rt_nextId();") @@ -182,14 +181,14 @@ public final class Platform { public static native int schedule(PlatformRunnable runnable, int timeout); public static void killSchedule(int id) { - ((PlatformHelper) Window.current()).killSchedule(id); + ((PlatformHelper) getGlobal()).killSchedule(id); } @JSBody(script = "return [];") public static native PlatformQueue createQueue(); public static PlatformString stringFromCharCode(int charCode) { - return ((PlatformHelper) Window.current()).getStringClass().fromCharCode(charCode); + return ((PlatformHelper) getGlobal()).getStringClass().fromCharCode(charCode); } @DelegateTo("isPrimitiveLowLevel") @@ -227,4 +226,7 @@ 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 index 376724ff4..f0b8873d1 100644 --- a/platform/src/main/java/org/teavm/platform/PlatformConsole.java +++ b/platform/src/main/java/org/teavm/platform/PlatformConsole.java @@ -18,10 +18,6 @@ package org.teavm.platform; import org.teavm.jso.JSMethod; import org.teavm.jso.JSObject; -/** - * - * @author Alexey Andreev - */ public interface PlatformConsole extends JSObject { @JSMethod("$rt_putStdout") void output(int b);