1.1 --- a/rt/emul/compacttest/src/test/java/org/apidesign/bck2brwsr/tck/IntegerArithmeticTest.java Thu Jun 25 08:45:40 2015 +0200
1.2 +++ b/rt/emul/compacttest/src/test/java/org/apidesign/bck2brwsr/tck/IntegerArithmeticTest.java Tue Jul 07 07:46:52 2015 +0200
1.3 @@ -148,6 +148,18 @@
1.4 @Compare public int negateMinInt() {
1.5 return neg(Integer.MIN_VALUE);
1.6 }
1.7 +
1.8 + @Compare public int parseNaN() {
1.9 + return Integer.parseInt("nothing");
1.10 + }
1.11 +
1.12 + @Compare public int parseAsIntNaN() {
1.13 + return Integer.parseInt("0.33");
1.14 + }
1.15 +
1.16 + @Compare public double parseDoubleNaN() {
1.17 + return Double.parseDouble("nothing");
1.18 + }
1.19
1.20 @Compare public int sumTwoDimensions() {
1.21 int[][] matrix = createMatrix(4, 3);
2.1 --- a/rt/emul/mini/src/main/java/java/lang/Double.java Thu Jun 25 08:45:40 2015 +0200
2.2 +++ b/rt/emul/mini/src/main/java/java/lang/Double.java Tue Jul 07 07:46:52 2015 +0200
2.3 @@ -538,10 +538,15 @@
2.4 * @see java.lang.Double#valueOf(String)
2.5 * @since 1.2
2.6 */
2.7 + public static double parseDouble(String s) throws NumberFormatException {
2.8 + double ret = parseDouble0(s);
2.9 + if (isNaN(ret)) {
2.10 + throw new NumberFormatException("For input string: \"" + s + '\"');
2.11 + }
2.12 + return ret;
2.13 + }
2.14 @JavaScriptBody(args="s", body="return parseFloat(s);")
2.15 - public static double parseDouble(String s) throws NumberFormatException {
2.16 - return 0;
2.17 - }
2.18 + private static native double parseDouble0(String s) throws NumberFormatException;
2.19
2.20 /**
2.21 * Returns {@code true} if the specified number is a
3.1 --- a/rt/emul/mini/src/main/java/java/lang/Integer.java Thu Jun 25 08:45:40 2015 +0200
3.2 +++ b/rt/emul/mini/src/main/java/java/lang/Integer.java Tue Jul 07 07:46:52 2015 +0200
3.3 @@ -442,71 +442,17 @@
3.4 * @exception NumberFormatException if the {@code String}
3.5 * does not contain a parsable {@code int}.
3.6 */
3.7 + public static int parseInt(String s, int radix)
3.8 + throws NumberFormatException {
3.9 + double val = parseInt0(s, radix);
3.10 + if (Double.isNaN(val) || s.contains(".")) {
3.11 + throw new NumberFormatException("For input string: \"" + s + '\"');
3.12 + }
3.13 + return (int)val;
3.14 + }
3.15 +
3.16 @JavaScriptBody(args={"s", "radix"}, body="return parseInt(s,radix);")
3.17 - public static int parseInt(String s, int radix)
3.18 - throws NumberFormatException
3.19 - {
3.20 - /*
3.21 - * WARNING: This method may be invoked early during VM initialization
3.22 - * before IntegerCache is initialized. Care must be taken to not use
3.23 - * the valueOf method.
3.24 - */
3.25 -
3.26 - if (s == null) {
3.27 - throw new NumberFormatException("null");
3.28 - }
3.29 -
3.30 - if (radix < Character.MIN_RADIX) {
3.31 - throw new NumberFormatException("radix " + radix +
3.32 - " less than Character.MIN_RADIX");
3.33 - }
3.34 -
3.35 - if (radix > Character.MAX_RADIX) {
3.36 - throw new NumberFormatException("radix " + radix +
3.37 - " greater than Character.MAX_RADIX");
3.38 - }
3.39 -
3.40 - int result = 0;
3.41 - boolean negative = false;
3.42 - int i = 0, len = s.length();
3.43 - int limit = -Integer.MAX_VALUE;
3.44 - int multmin;
3.45 - int digit;
3.46 -
3.47 - if (len > 0) {
3.48 - char firstChar = s.charAt(0);
3.49 - if (firstChar < '0') { // Possible leading "+" or "-"
3.50 - if (firstChar == '-') {
3.51 - negative = true;
3.52 - limit = Integer.MIN_VALUE;
3.53 - } else if (firstChar != '+')
3.54 - throw NumberFormatException.forInputString(s);
3.55 -
3.56 - if (len == 1) // Cannot have lone "+" or "-"
3.57 - throw NumberFormatException.forInputString(s);
3.58 - i++;
3.59 - }
3.60 - multmin = limit / radix;
3.61 - while (i < len) {
3.62 - // Accumulating negatively avoids surprises near MAX_VALUE
3.63 - digit = Character.digit(s.charAt(i++),radix);
3.64 - if (digit < 0) {
3.65 - throw NumberFormatException.forInputString(s);
3.66 - }
3.67 - if (result < multmin) {
3.68 - throw NumberFormatException.forInputString(s);
3.69 - }
3.70 - result *= radix;
3.71 - if (result < limit + digit) {
3.72 - throw NumberFormatException.forInputString(s);
3.73 - }
3.74 - result -= digit;
3.75 - }
3.76 - } else {
3.77 - throw NumberFormatException.forInputString(s);
3.78 - }
3.79 - return negative ? result : -result;
3.80 - }
3.81 + private static native double parseInt0(String s, int radix);
3.82
3.83 /**
3.84 * Parses the string argument as a signed decimal integer. The