From 5c90d786a094dd43f131019e365005e775c9e394 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Fri, 8 Feb 2019 12:45:39 +0300 Subject: [PATCH] Fixes and improvements to JS APIs --- .../main/java/org/teavm/jso/core/JSON.java | 30 ------------------- .../java/org/teavm/jso/core/JSObjects.java | 8 ++++- .../org/teavm/jso/dom/html/HTMLDocument.java | 2 ++ .../org/teavm/jso/dom/html/HTMLElement.java | 2 -- .../teavm/jso/dom/html/HTMLImageElement.java | 6 ++++ 5 files changed, 15 insertions(+), 33 deletions(-) delete mode 100644 jso/apis/src/main/java/org/teavm/jso/core/JSON.java diff --git a/jso/apis/src/main/java/org/teavm/jso/core/JSON.java b/jso/apis/src/main/java/org/teavm/jso/core/JSON.java deleted file mode 100644 index 7bcebaecc..000000000 --- a/jso/apis/src/main/java/org/teavm/jso/core/JSON.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2019 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.jso.core; - -import org.teavm.jso.JSBody; -import org.teavm.jso.JSObject; - -public final class JSON { - private JSON() { - } - - @JSBody(params = "s", script = "return JSON.parse(s);") - public static native T parse(String s); - - @JSBody(params = "o", script = "JSON.stringify(o);") - public static native String stringify(JSObject o); -} diff --git a/jso/apis/src/main/java/org/teavm/jso/core/JSObjects.java b/jso/apis/src/main/java/org/teavm/jso/core/JSObjects.java index 1cd8ff844..da4b3e875 100644 --- a/jso/apis/src/main/java/org/teavm/jso/core/JSObjects.java +++ b/jso/apis/src/main/java/org/teavm/jso/core/JSObjects.java @@ -25,12 +25,18 @@ public final class JSObjects { @JSBody(params = "object", script = "return Object.getOwnPropertyNames(object);") public static native String[] getOwnPropertyNames(JSObject object); - @JSBody(script = "return Object.create(null);") + @JSBody(script = "return {};") public static native T create(); + @JSBody(script = "return Object.create(null);") + public static native T createWithoutProto(); + @JSBody(params = "object", script = "return typeof object === 'undefined';") public static native boolean isUndefined(JSObject object); + @JSBody(script = "return void 0;") + public static native JSObject undefined(); + @JSBody(params = "object", script = "return typeof object;") public static native String typeOf(JSObject object); diff --git a/jso/apis/src/main/java/org/teavm/jso/dom/html/HTMLDocument.java b/jso/apis/src/main/java/org/teavm/jso/dom/html/HTMLDocument.java index a08a850f3..6505a1866 100644 --- a/jso/apis/src/main/java/org/teavm/jso/dom/html/HTMLDocument.java +++ b/jso/apis/src/main/java/org/teavm/jso/dom/html/HTMLDocument.java @@ -88,4 +88,6 @@ public interface HTMLDocument extends Document, EventTarget { @JSProperty HTMLElement getPointerLockElement(); + + void exitPointerLock(); } diff --git a/jso/apis/src/main/java/org/teavm/jso/dom/html/HTMLElement.java b/jso/apis/src/main/java/org/teavm/jso/dom/html/HTMLElement.java index 4669dc90a..3d5e1dd7e 100644 --- a/jso/apis/src/main/java/org/teavm/jso/dom/html/HTMLElement.java +++ b/jso/apis/src/main/java/org/teavm/jso/dom/html/HTMLElement.java @@ -188,6 +188,4 @@ public interface HTMLElement extends Element, ElementCSSInlineStyle, EventTarget NodeList querySelectorAll(String selectors); void requestPointerLock(); - - void exitPointerLock(); } diff --git a/jso/apis/src/main/java/org/teavm/jso/dom/html/HTMLImageElement.java b/jso/apis/src/main/java/org/teavm/jso/dom/html/HTMLImageElement.java index 308dc8c67..971443cb9 100644 --- a/jso/apis/src/main/java/org/teavm/jso/dom/html/HTMLImageElement.java +++ b/jso/apis/src/main/java/org/teavm/jso/dom/html/HTMLImageElement.java @@ -48,4 +48,10 @@ public interface HTMLImageElement extends HTMLElement, CanvasImageSource { @JSProperty void setSrc(String src); + + @JSProperty + String getCrossOrigin(); + + @JSProperty + void setCrossOrigin(String crossOrigin); }