From 7f333cc73e77bd0395d140810d8dac53668101bf Mon Sep 17 00:00:00 2001 From: Bernd Busse Date: Mon, 31 Jul 2023 20:16:14 +0200 Subject: [PATCH] JSO: make global objects available in WebWorker contexts (no hardcoded window) --- jso/apis/src/main/java/org/teavm/jso/browser/Window.java | 4 ++-- jso/apis/src/main/java/org/teavm/jso/crypto/Crypto.java | 4 ++-- .../src/main/java/org/teavm/jso/indexeddb/IDBFactory.java | 3 +-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/jso/apis/src/main/java/org/teavm/jso/browser/Window.java b/jso/apis/src/main/java/org/teavm/jso/browser/Window.java index 4f0dc7372..479f3df4a 100644 --- a/jso/apis/src/main/java/org/teavm/jso/browser/Window.java +++ b/jso/apis/src/main/java/org/teavm/jso/browser/Window.java @@ -190,9 +190,9 @@ public abstract class Window implements JSObject, WindowEventTarget, StorageProv @JSProperty public abstract double getDevicePixelRatio(); - @JSBody(params = "s", script = "return window.atob(s);") + @JSBody(params = "s", script = "return atob(s);") public static native String atob(String s); - @JSBody(params = "s", script = "return window.btoa(s);") + @JSBody(params = "s", script = "return btoa(s);") public static native String btoa(String s); } diff --git a/jso/apis/src/main/java/org/teavm/jso/crypto/Crypto.java b/jso/apis/src/main/java/org/teavm/jso/crypto/Crypto.java index d32cadfbd..b435c01ab 100644 --- a/jso/apis/src/main/java/org/teavm/jso/crypto/Crypto.java +++ b/jso/apis/src/main/java/org/teavm/jso/crypto/Crypto.java @@ -25,10 +25,10 @@ import org.teavm.jso.typedarrays.Uint8Array; import org.teavm.jso.typedarrays.Uint8ClampedArray; public abstract class Crypto implements JSObject { - @JSBody(script = "return window.crypto != null;") + @JSBody(script = "return crypto != null;") public static native boolean isSupported(); - @JSBody(script = "return window.crypto;") + @JSBody(script = "return crypto;") public static native Crypto current(); public abstract String randomUUID(); diff --git a/jso/apis/src/main/java/org/teavm/jso/indexeddb/IDBFactory.java b/jso/apis/src/main/java/org/teavm/jso/indexeddb/IDBFactory.java index 4af07a6c3..04e039763 100644 --- a/jso/apis/src/main/java/org/teavm/jso/indexeddb/IDBFactory.java +++ b/jso/apis/src/main/java/org/teavm/jso/indexeddb/IDBFactory.java @@ -34,8 +34,7 @@ public abstract class IDBFactory implements JSObject { return factory; } - @JSBody(script = "return window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || " - + "window.msIndexedDB;") + @JSBody(script = "return indexedDB || mozIndexedDB || webkitIndexedDB || msIndexedDB;") static native IDBFactory getInstanceImpl(); public abstract IDBOpenDBRequest open(String name, int version);