From 4aaf2f26db34d79556028116759f137adb3b6aaf Mon Sep 17 00:00:00 2001 From: TopchetoEU <36534413+TopchetoEU@users.noreply.github.com> Date: Sun, 24 Sep 2023 20:50:53 +0300 Subject: [PATCH] feat: add some standard functions to Number --- .../jscript/polyfills/NumberPolyfill.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/me/topchetoeu/jscript/polyfills/NumberPolyfill.java b/src/me/topchetoeu/jscript/polyfills/NumberPolyfill.java index c0c7e6a..a3859eb 100644 --- a/src/me/topchetoeu/jscript/polyfills/NumberPolyfill.java +++ b/src/me/topchetoeu/jscript/polyfills/NumberPolyfill.java @@ -19,6 +19,20 @@ public class NumberPolyfill { public final double value; + @Native public static boolean isFinite(Context ctx, double val) { return Double.isFinite(val); } + @Native public static boolean isInfinite(Context ctx, double val) { return Double.isInfinite(val); } + @Native public static boolean isNaN(Context ctx, double val) { return Double.isNaN(val); } + @Native public static boolean isSafeInteger(Context ctx, double val) { + return val > MIN_SAFE_INTEGER && val < MAX_SAFE_INTEGER; + } + + @Native public static double parseFloat(Context ctx, String val) throws InterruptedException { + return Values.toNumber(ctx, val); + } + @Native public static double parseInt(Context ctx, String val) throws InterruptedException { + return (long)Values.toNumber(ctx, val); + } + @NativeConstructor(thisArg = true) public static Object constructor(Context ctx, Object thisArg, Object val) throws InterruptedException { val = Values.toNumber(ctx, val); if (thisArg instanceof ObjectValue) return new NumberPolyfill((double)val);