JS: remove references to window. See #269

This commit is contained in:
Alexey Andreev 2017-04-15 13:40:54 +03:00
parent 1993060824
commit 530fe1d277
3 changed files with 7 additions and 8 deletions

View File

@ -14,6 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
"use strict"; "use strict";
var $rt_global = this;
var $rt_lastObjectId = 1; var $rt_lastObjectId = 1;
function $rt_nextId() { function $rt_nextId() {
var current = $rt_lastObjectId; var current = $rt_lastObjectId;

View File

@ -24,7 +24,6 @@ import org.teavm.interop.DelegateTo;
import org.teavm.interop.Unmanaged; import org.teavm.interop.Unmanaged;
import org.teavm.jso.JSBody; import org.teavm.jso.JSBody;
import org.teavm.jso.JSObject; import org.teavm.jso.JSObject;
import org.teavm.jso.browser.Window;
import org.teavm.platform.metadata.ClassResource; import org.teavm.platform.metadata.ClassResource;
import org.teavm.platform.metadata.StaticFieldResource; import org.teavm.platform.metadata.StaticFieldResource;
import org.teavm.platform.plugin.PlatformGenerator; import org.teavm.platform.plugin.PlatformGenerator;
@ -84,7 +83,7 @@ public final class Platform {
public static native Class<?> asJavaClass(PlatformObject obj); public static native Class<?> asJavaClass(PlatformObject obj);
public static PlatformConsole getConsole() { public static PlatformConsole getConsole() {
return (PlatformConsole) Window.current(); return (PlatformConsole) getGlobal();
} }
@JSBody(script = "return $rt_nextId();") @JSBody(script = "return $rt_nextId();")
@ -182,14 +181,14 @@ public final class Platform {
public static native int schedule(PlatformRunnable runnable, int timeout); public static native int schedule(PlatformRunnable runnable, int timeout);
public static void killSchedule(int id) { public static void killSchedule(int id) {
((PlatformHelper) Window.current()).killSchedule(id); ((PlatformHelper) getGlobal()).killSchedule(id);
} }
@JSBody(script = "return [];") @JSBody(script = "return [];")
public static native <T> PlatformQueue<T> createQueue(); public static native <T> PlatformQueue<T> createQueue();
public static PlatformString stringFromCharCode(int charCode) { public static PlatformString stringFromCharCode(int charCode) {
return ((PlatformHelper) Window.current()).getStringClass().fromCharCode(charCode); return ((PlatformHelper) getGlobal()).getStringClass().fromCharCode(charCode);
} }
@DelegateTo("isPrimitiveLowLevel") @DelegateTo("isPrimitiveLowLevel")
@ -227,4 +226,7 @@ public final class Platform {
public static String getName(PlatformClass cls) { public static String getName(PlatformClass cls) {
return cls.getMetadata().getName(); return cls.getMetadata().getName();
} }
@JSBody(script = "return $rt_global;")
private static native JSObject getGlobal();
} }

View File

@ -18,10 +18,6 @@ package org.teavm.platform;
import org.teavm.jso.JSMethod; import org.teavm.jso.JSMethod;
import org.teavm.jso.JSObject; import org.teavm.jso.JSObject;
/**
*
* @author Alexey Andreev
*/
public interface PlatformConsole extends JSObject { public interface PlatformConsole extends JSObject {
@JSMethod("$rt_putStdout") @JSMethod("$rt_putStdout")
void output(int b); void output(int b);