From 928a8631a890f98d21462df5c82a354ee56170cf Mon Sep 17 00:00:00 2001 From: Ivan Hetman Date: Tue, 11 Apr 2023 13:10:44 +0300 Subject: [PATCH] jso apis: add missing methods for Array and Object (#686) --- jso/apis/src/main/java/org/teavm/jso/core/JSArray.java | 4 ++++ jso/apis/src/main/java/org/teavm/jso/core/JSObjects.java | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/jso/apis/src/main/java/org/teavm/jso/core/JSArray.java b/jso/apis/src/main/java/org/teavm/jso/core/JSArray.java index b62178a51..206a36e90 100644 --- a/jso/apis/src/main/java/org/teavm/jso/core/JSArray.java +++ b/jso/apis/src/main/java/org/teavm/jso/core/JSArray.java @@ -91,6 +91,10 @@ public abstract class JSArray implements JSArrayReader { @NoSideEffects public static native JSArray create(int size); + @JSBody(params = "object", script = "return Array.isArray(object);") + @NoSideEffects + public static native boolean isArray(JSObject object); + @SafeVarargs public static JSArray of(S... items) { JSArray array = create(items.length); 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 0939c08b7..020fab64b 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 @@ -27,6 +27,14 @@ public final class JSObjects { @NoSideEffects public static native String[] getOwnPropertyNames(JSObject object); + @JSBody(params = "object", script = "return Object.keys(object);") + @NoSideEffects + public static native String[] keys(JSObject object); + + @JSBody(params = "object", script = "return Object.values(object);") + @NoSideEffects + public static native JSObject[] values(JSObject object); + @JSBody(script = "return {};") @NoSideEffects public static native T create();