Skip to content

Commit d6d20ab

Browse files
author
jossonsmith
committed
Fixed bugs according to Apache Harmony's testcases
1 parent 7386823 commit d6d20ab

4 files changed

Lines changed: 36 additions & 7 deletions

File tree

sources/net.sf.j2s.java.core/j2score/Double.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,21 @@ this.valueOf = function () {
2828
}, "String");
2929

3030
Double.serialVersionUID = Double.prototype.serialVersionUID = -9172774392245257468;
31-
Double.MIN_VALUE = Double.prototype.MIN_VALUE = 3.4028235e+38;
32-
Double.MAX_VALUE = Double.prototype.MAX_VALUE = 1.4e-45;
31+
Double.MIN_VALUE = Double.prototype.MIN_VALUE = 4.9e-324;
32+
Double.MAX_VALUE = Double.prototype.MAX_VALUE = 1.7976931348623157e+308;
3333
Double.NEGATIVE_INFINITY = Number.NEGATIVE_INFINITY;
3434
Double.POSITIVE_INFINITY = Number.POSITIVE_INFINITY;
3535
Double.NaN = Number.NaN;
36+
Clazz.defineMethod (Double, "isNaN",
37+
function (num) {
38+
return isNaN (num);
39+
}, "Number");
40+
Double.isNaN = Double.prototype.isNaN;
41+
Clazz.defineMethod (Double, "isInfinite",
42+
function (num) {
43+
return !isFinite (num);
44+
}, "Number");
45+
Double.isInfinite = Double.prototype.isInfinite;
3646

3747
Clazz.defineMethod (Double, "parseDouble",
3848
function (s) {

sources/net.sf.j2s.java.core/j2score/Encoding.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ Encoding.readUTF8 = function (str) {
2727
var charCode = str.charCodeAt(i);
2828
if (charCode < 0x80) {
2929
arrs[arrs.length] = str.charAt(i);
30-
} else if (charCode > 0xc0 && charCode <= 0xe0) {
30+
} else if (charCode > 0xc0 && charCode < 0xe0) {
3131
var c1 = charCode & 0x1f;
3232
i++;
3333
var c2 = str.charCodeAt(i) & 0x3f;
3434
var c = (c1 << 6) + c2;
3535
arrs[arrs.length] = String.fromCharCode(c);
36-
} else if (charCode > 0xe0) {
36+
} else if (charCode >= 0xe0) {
3737
var c1 = charCode & 0x0f;
3838
i++;
3939
var c2 = str.charCodeAt(i) & 0x3f;
@@ -66,7 +66,7 @@ Encoding.convert2UTF8 = function (str) {
6666
var charCode = str.charCodeAt(i);
6767
if (charCode < 0x80) {
6868
arrs[offset + i - startIdx] = str.charAt(i);
69-
} else if (charCode < 0x07ff) { //(charCode > 0xc0 && charCode < 0xe0) {
69+
} else if (charCode <= 0x07ff) { //(charCode > 0xc0 && charCode < 0xe0) {
7070
var c1 = 0xc0 + ((charCode & 0x07c0) >> 6);
7171
var c2 = 0x80 + (charCode & 0x003f);
7272
arrs[offset + i - startIdx] = String.fromCharCode(c1) + String.fromCharCode(c2);

sources/net.sf.j2s.java.core/j2score/Float.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ this.valueOf = function () {
2121
}, "Number");
2222
Clazz.makeConstructor (Float,
2323
function (s) {
24-
var value = Float.parseFloat (s, 10);
24+
var value = null;
25+
if (s != null) {
26+
value = Float.parseFloat (s, 10);
27+
} else {
28+
value = 0;
29+
}
2530
this.valueOf = function () {
2631
return value;
2732
};
@@ -46,6 +51,11 @@ function (num) {
4651
return isNaN (num);
4752
}, "Number");
4853
Float.isNaN = Float.prototype.isNaN;
54+
Clazz.defineMethod (Float, "isInfinite",
55+
function (num) {
56+
return !isFinite (num);
57+
}, "Number");
58+
Float.isInfinite = Float.prototype.isInfinite;
4959

5060
Clazz.defineMethod (Float, "equals",
5161
function (s) {

sources/net.sf.j2s.java.core/j2score/Integer.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,14 @@ if(s == null || ! Clazz.instanceOf(s, Integer) ){
5555
return false;
5656
}
5757
return s.valueOf() == this.valueOf();
58-
}, "Object");
58+
}, "Object");
59+
Integer.toHexString = Integer.prototype.toHexString = function (i) {
60+
return i.toString (16);
61+
};
62+
Integer.toOctalString = Integer.prototype.toOctalString = function (i) {
63+
return i.toString (8);
64+
};
65+
Integer.toBinaryString = Integer.prototype.toBinaryString = function (i) {
66+
return i.toString (2);
67+
};
5968
});

0 commit comments

Comments
 (0)