Skip to content

Commit aa78687

Browse files
committed
[GR-70792] Extend wrapped JS function coverage in core runtime types
PullRequest: graal/22386
2 parents 20fe19f + 1bf4e9e commit aa78687

File tree

19 files changed

+2029
-54
lines changed

19 files changed

+2029
-54
lines changed

sdk/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JSNumber.java

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,140 @@ public boolean equals(Object that) {
119119
public int hashCode() {
120120
return javaDouble().hashCode();
121121
}
122+
123+
@JS.Coerce
124+
@JS(value = "return isFinite(number);")
125+
public static native boolean isFinite(JSNumber number);
126+
127+
@JS.Coerce
128+
@JS(value = "return isFinite(number);")
129+
public static native boolean isFinite(double number);
130+
131+
@JS.Coerce
132+
@JS(value = "return Number.isInteger(number);")
133+
public static native boolean isInteger(JSNumber number);
134+
135+
@JS.Coerce
136+
@JS(value = "return Number.isInteger(number);")
137+
public static native boolean isInteger(double number);
138+
139+
@JS.Coerce
140+
@JS(value = "return isNaN(number);")
141+
public static native boolean isNaN(JSNumber number);
142+
143+
@JS.Coerce
144+
@JS(value = "return isNaN(number);")
145+
public static native boolean isNaN(double number);
146+
147+
@JS.Coerce
148+
@JS(value = "return Number.isSafeInteger(number);")
149+
public static native boolean isSafeInteger(JSNumber number);
150+
151+
@JS.Coerce
152+
@JS(value = "return Number.isSafeInteger(number);")
153+
public static native boolean isSafeInteger(double number);
154+
155+
@JS.Coerce
156+
@JS(value = "return Number.parseFloat(number);")
157+
public static native double parseFloat(String number);
158+
159+
@JS.Coerce
160+
@JS(value = "return Number.parseInt(number);")
161+
private static native double parseIntRaw(String number);
162+
163+
@JS.Coerce
164+
@JS(value = "return Number.parseInt(number, radix);")
165+
private static native double parseIntRaw(String number, int radix);
166+
167+
public static long parseInt(String number) {
168+
double result = parseIntRaw(number);
169+
if (Double.isNaN(result)) {
170+
throw new IllegalArgumentException("Invalid integer: " + number);
171+
}
172+
return (long) result;
173+
}
174+
175+
public static long parseInt(String number, int radix) {
176+
double result = parseIntRaw(number, radix);
177+
if (Double.isNaN(result)) {
178+
throw new IllegalArgumentException("Invalid integer: " + number + " with radix " + radix);
179+
}
180+
return (long) result;
181+
}
182+
183+
@JS.Coerce
184+
@JS(value = "return Number.EPSILON;")
185+
public static native double epsilon();
186+
187+
@JS.Coerce
188+
@JS(value = "return Number.MAX_SAFE_INTEGER;")
189+
public static native long maxSafeInteger();
190+
191+
@JS.Coerce
192+
@JS(value = "return Number.MAX_VALUE;")
193+
public static native double maxValue();
194+
195+
@JS.Coerce
196+
@JS(value = "return Number.MIN_SAFE_INTEGER;")
197+
public static native long minSafeInteger();
198+
199+
@JS.Coerce
200+
@JS(value = "return Number.MIN_VALUE;")
201+
public static native double minValue();
202+
203+
@JS.Coerce
204+
@JS(value = "return Number.NaN;")
205+
public static native double nan();
206+
207+
@JS.Coerce
208+
@JS(value = "return Number.NEGATIVE_INFINITY;")
209+
public static native double negativeInfinity();
210+
211+
@JS.Coerce
212+
@JS(value = "return Number.POSITIVE_INFINITY;")
213+
public static native double positiveInfinity();
214+
215+
@JS.Coerce
216+
@JS(value = "return this.toExponential();")
217+
public native String toExponential();
218+
219+
@JS.Coerce
220+
@JS(value = "return this.toExponential(fractionDigits);")
221+
public native String toExponential(int fractionDigits);
222+
223+
@JS.Coerce
224+
@JS(value = "return this.toFixed();")
225+
public native String toFixed();
226+
227+
@JS.Coerce
228+
@JS(value = "return this.toFixed(digits);")
229+
public native String toFixed(int digits);
230+
231+
@JS.Coerce
232+
@JS(value = "return this.toLocaleString();")
233+
public native String toLocaleString();
234+
235+
@JS.Coerce
236+
@JS(value = "return this.toLocaleString(locales);")
237+
public native String toLocaleString(String locales);
238+
239+
@JS.Coerce
240+
@JS(value = "return this.toLocaleString(locales, options);")
241+
public native String toLocaleString(String locales, JSObject options);
242+
243+
@JS.Coerce
244+
@JS(value = "return this.toPrecision();")
245+
public native String toPrecision();
246+
247+
@JS.Coerce
248+
@JS(value = "return this.toPrecision(precision);")
249+
public native String toPrecision(int precision);
250+
251+
@JS.Coerce
252+
@JS(value = "return this.toString(radix);")
253+
public native String toString(int radix);
254+
255+
@JS.Coerce
256+
@JS(value = "return this.valueOf();")
257+
public native double valueOf();
122258
}

0 commit comments

Comments
 (0)