Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,136 @@ public boolean equals(Object that) {
public int hashCode() {
return javaDouble().hashCode();
}

@JS.Coerce
@JS(value = "return isFinite(number);")
public native static boolean isFinite(JSNumber number);

@JS.Coerce
@JS(value = "return isFinite(number);")
public native static boolean isFinite(double number);

@JS.Coerce
@JS(value = "return Number.isInteger(number);")
public native static boolean isInteger(JSNumber number);

@JS.Coerce
@JS(value = "return Number.isInteger(number);")
public native static boolean isInteger(double number);

@JS.Coerce
@JS(value = "return isNaN(number);")
public native static boolean isNaN(JSValue number);

@JS.Coerce
@JS(value = "return isNaN(number);")
public native static boolean isNaN(double number);

@JS.Coerce
@JS(value = "return Number.isSafeInteger(number);")
public native static boolean isSafeInteger(JSValue number);

@JS.Coerce
@JS(value = "return Number.isSafeInteger(number);")
public native static boolean isSafeInteger(double number);

@JS.Coerce
@JS(value = "return parseFloat(number);")
public native static float parseFloat(double number);

@JS.Coerce
@JS(value = "return parseFloat(number);")
public native static float parseFloat(String number);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parseFloat returns JS number, so we should use double here.

Also, we should probably prefer Number.parseFloat (even though they're the same function) just for consistency.


@JS.Coerce
@JS(value = "return parseInt(number);")
public native static int parseInt(double number);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depending on the approach we take for the return value, this method may not be necessary


@JS.Coerce
@JS(value = "return parseInt(number);")
public native static int parseInt(String number);

@JS.Coerce
@JS(value = "return parseInt(number, radix);")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer Number.parseInt for consistency

public native static int parseInt(String number, int radix);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parseInt can return NaN and it can also return integer values that don't fit into a 32bit int.

I see two approaches here:

  • Return a long value and throw IllegalArgumentException when parseInt returns NaN
  • Just return JSNumber here

@axel22 What do you think?


@JS.Coerce
@JS(value = "return Number.EPSILON;")
public native static double EPSILON();

@JS.Coerce
@JS(value = "return Number.MAX_SAFE_INTEGER;")
public native static double MAX_SAFE_INTEGER();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we return a long here and for MIN_SAFE_INTEGER?


@JS.Coerce
@JS(value = "return Number.MAX_VALUE;")
public native static double MAX_VALUE();

@JS.Coerce
@JS(value = "return Number.MIN_SAFE_INTEGER;")
public native static double MIN_SAFE_INTEGER();

@JS.Coerce
@JS(value = "return Number.MIN_VALUE;")
public native static double MIN_VALUE();

@JS.Coerce
@JS(value = "return Number.NaN;")
public native static double NaN();

@JS.Coerce
@JS(value = "return Number.NEGATIVE_INFINITY;")
public native static double NEGATIVE_INFINITY();

@JS.Coerce
@JS(value = "return Number.POSITIVE_INFINITY;")
public native static double POSITIVE_INFINITY();

@JS.Coerce
@JS(value = "return this.toExponential();")
public native String toExponential();

@JS.Coerce
@JS(value = "return this.toExponential(fractionDigits);")
public native String toExponential(int fractionDigits);

@JS.Coerce
@JS(value = "return this.toFixed();")
public native String toFixed();

@JS.Coerce
@JS(value = "return this.toFixed(digits);")
public native String toFixed(int digits);

@JS.Coerce
@JS(value = "return this.toLocaleString();")
public native String toLocaleString();

@JS.Coerce
@JS(value = "return this.toLocaleString(locales);")
public native String toLocaleString(String locales);

@JS.Coerce
@JS(value = "return this.toLocaleString(locales, options);")
public native String toLocaleString(String locales, JSObject options);

@JS.Coerce
@JS(value = "return this.toPrecision();")
public native String toPrecision();

@JS.Coerce
@JS(value = "return this.toPrecision(precision);")
public native String toPrecision(int precision);

@JS.Coerce
@JS(value = "return this.toString(radix);")
private native String toJSString(int radix);

public String toString(int radix) {
return "JavaScript<" + typeof() + "; " + toJSString(radix) + ">";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should just return Number.toString(radix).

}

@JS.Coerce
@JS(value = "return this.valueOf();")
public native double valueOf();
}
Loading