1.1 --- a/emul/compact/src/test/java/org/apidesign/bck2brwsr/compact/tck/JFXIssuesTest.java Sat Feb 16 11:02:15 2013 +0100
1.2 +++ b/emul/compact/src/test/java/org/apidesign/bck2brwsr/compact/tck/JFXIssuesTest.java Mon Feb 25 11:18:12 2013 +0100
1.3 @@ -39,7 +39,15 @@
1.4 @Compare public boolean isClassAssignable() {
1.5 return Application.class.isAssignableFrom(MyApplication.class);
1.6 }
1.7 -
1.8 +
1.9 + @Compare public boolean isNaN() {
1.10 + return Double.isNaN(Double.NaN);
1.11 + }
1.12 +
1.13 + @Compare public boolean isInfinite() {
1.14 + return Float.isInfinite(Float.NEGATIVE_INFINITY);
1.15 + }
1.16 +
1.17 @Factory public static Object[] create() {
1.18 return VMTest.create(JFXIssuesTest.class);
1.19 }
2.1 --- a/emul/mini/src/main/java/java/lang/Double.java Sat Feb 16 11:02:15 2013 +0100
2.2 +++ b/emul/mini/src/main/java/java/lang/Double.java Mon Feb 25 11:18:12 2013 +0100
2.3 @@ -191,7 +191,7 @@
2.4 * @return a string representation of the argument.
2.5 */
2.6 @JavaScriptBody(args="d", body="var r = d.toString();"
2.7 - + "if (r.indexOf('.') === -1) r = r + '.0';"
2.8 + + "if (isFinite(d) && (r.indexOf('.') === -1)) r = r + '.0';"
2.9 + "return r;")
2.10 public static String toString(double d) {
2.11 throw new UnsupportedOperationException();
3.1 --- a/emul/mini/src/main/java/java/lang/Float.java Sat Feb 16 11:02:15 2013 +0100
3.2 +++ b/emul/mini/src/main/java/java/lang/Float.java Mon Feb 25 11:18:12 2013 +0100
3.3 @@ -819,11 +819,15 @@
3.4 */
3.5 @JavaScriptBody(args = "bits",
3.6 body =
3.7 - "if (bits === 0x7f800000) return Number.POSITIVE_INFINITY;\n"
3.8 - + "if (bits === 0xff800000) return Number.NEGATIVE_INFINITY;\n"
3.9 - + "if (bits >= 0x7f800001 && bits <= 0xffffffff) return Number.NaN;\n"
3.10 - + "var s = ((bits >> 31) == 0) ? 1 : -1;\n"
3.11 + "var s = ((bits >> 31) == 0) ? 1 : -1;\n"
3.12 + "var e = ((bits >> 23) & 0xff);\n"
3.13 + + "if (e === 0xff) {\n"
3.14 + + " if ((bits & 0x7fffff) === 0) {\n"
3.15 + + " return (s > 0) ? Number.POSITIVE_INFINITY"
3.16 + + " : Number.NEGATIVE_INFINITY;\n"
3.17 + + " }\n"
3.18 + + " return Number.NaN;\n"
3.19 + + "}\n"
3.20 + "var m = (e == 0) ?\n"
3.21 + " (bits & 0x7fffff) << 1 :\n"
3.22 + " (bits & 0x7fffff) | 0x800000;\n"
4.1 --- a/emul/mini/src/main/resources/org/apidesign/vm4brwsr/emul/lang/java_lang_Number.js Sat Feb 16 11:02:15 2013 +0100
4.2 +++ b/emul/mini/src/main/resources/org/apidesign/vm4brwsr/emul/lang/java_lang_Number.js Mon Feb 25 11:18:12 2013 +0100
4.3 @@ -212,6 +212,14 @@
4.4 };
4.5
4.6 (function(numberPrototype) {
4.7 + function __handleDivByZero() {
4.8 + var exception = new vm.java_lang_ArithmeticException;
4.9 + vm.java_lang_ArithmeticException(false).constructor
4.10 + .cons__VLjava_lang_String_2.call(exception, "/ by zero");
4.11 +
4.12 + throw exception;
4.13 + }
4.14 +
4.15 function __Int64(hi32, lo32) {
4.16 this.hi32 = hi32 | 0;
4.17 this.lo32 = lo32 | 0;
4.18 @@ -438,11 +446,27 @@
4.19 r.setDigit(j + n, nrm, uj);
4.20 }
4.21 }
4.22 -
4.23 +
4.24 + numberPrototype.div32 = function(x) {
4.25 + if (x === 0) {
4.26 + __handleDivByZero();
4.27 + }
4.28 +
4.29 + return (this / x) | 0;
4.30 + }
4.31 +
4.32 + numberPrototype.mod32 = function(x) {
4.33 + if (x === 0) {
4.34 + __handleDivByZero();
4.35 + }
4.36 +
4.37 + return (this % x);
4.38 + }
4.39 +
4.40 numberPrototype.div64 = function(x) {
4.41 var negateResult = false;
4.42 var u, v;
4.43 -
4.44 +
4.45 if ((this.high32() & 0x80000000) != 0) {
4.46 u = this.neg64();
4.47 negateResult = !negateResult;
4.48 @@ -458,7 +482,7 @@
4.49 }
4.50
4.51 if ((v === 0) && (v.high32() === 0)) {
4.52 - // TODO: throw
4.53 + __handleDivByZero();
4.54 }
4.55
4.56 if (u.high32() === 0) {
4.57 @@ -499,7 +523,7 @@
4.58 }
4.59
4.60 if ((v === 0) && (v.high32() === 0)) {
4.61 - // TODO: throw
4.62 + __handleDivByZero();
4.63 }
4.64
4.65 if (u.high32() === 0) {
5.1 --- a/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Sat Feb 16 11:02:15 2013 +0100
5.2 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Mon Feb 25 11:18:12 2013 +0100
5.3 @@ -555,7 +555,7 @@
5.4 emit(out, "@1 *= @2;", smapper.getD(1), smapper.popD());
5.5 break;
5.6 case opc_idiv:
5.7 - emit(out, "@1 = Math.floor(@1 / @2);",
5.8 + emit(out, "@1 = @1.div32(@2);",
5.9 smapper.getI(1), smapper.popI());
5.10 break;
5.11 case opc_ldiv:
5.12 @@ -569,7 +569,8 @@
5.13 emit(out, "@1 /= @2;", smapper.getD(1), smapper.popD());
5.14 break;
5.15 case opc_irem:
5.16 - emit(out, "@1 %= @2;", smapper.getI(1), smapper.popI());
5.17 + emit(out, "@1 = @1.mod32(@2);",
5.18 + smapper.getI(1), smapper.popI());
5.19 break;
5.20 case opc_lrem:
5.21 emit(out, "@1 = @1.mod64(@2);",
6.1 --- a/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/IntegerArithmeticTest.java Sat Feb 16 11:02:15 2013 +0100
6.2 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/IntegerArithmeticTest.java Mon Feb 25 11:18:12 2013 +0100
6.3 @@ -94,7 +94,33 @@
6.4 @Compare public int divisionReminder() {
6.5 return mod(1, 2);
6.6 }
6.7 -
6.8 +
6.9 + @Compare public int negativeDivision() {
6.10 + return div(-7, 3);
6.11 + }
6.12 +
6.13 + @Compare public int negativeDivisionReminder() {
6.14 + return mod(-7, 3);
6.15 + }
6.16 +
6.17 + @Compare public boolean divByZeroThrowsArithmeticException() {
6.18 + try {
6.19 + div(1, 0);
6.20 + return false;
6.21 + } catch (final ArithmeticException e) {
6.22 + return true;
6.23 + }
6.24 + }
6.25 +
6.26 + @Compare public boolean modByZeroThrowsArithmeticException() {
6.27 + try {
6.28 + mod(1, 0);
6.29 + return false;
6.30 + } catch (final ArithmeticException e) {
6.31 + return true;
6.32 + }
6.33 + }
6.34 +
6.35 @Compare public int negate() {
6.36 return neg(123456);
6.37 }
7.1 --- a/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/LongArithmeticTest.java Sat Feb 16 11:02:15 2013 +0100
7.2 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/LongArithmeticTest.java Mon Feb 25 11:18:12 2013 +0100
7.3 @@ -250,7 +250,25 @@
7.4 @Compare public long moduloWithCorrection() {
7.5 return mod(0x7fff800000000000l, 0x800000000001l);
7.6 }
7.7 -
7.8 +
7.9 + @Compare public boolean divByZeroThrowsArithmeticException() {
7.10 + try {
7.11 + div(1, 0);
7.12 + return false;
7.13 + } catch (final ArithmeticException e) {
7.14 + return true;
7.15 + }
7.16 + }
7.17 +
7.18 + @Compare public boolean modByZeroThrowsArithmeticException() {
7.19 + try {
7.20 + mod(1, 0);
7.21 + return false;
7.22 + } catch (final ArithmeticException e) {
7.23 + return true;
7.24 + }
7.25 + }
7.26 +
7.27 @Compare public long shiftL1() {
7.28 return shl(0x00fa37d7763e0ca1l, 5);
7.29 }