Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b3db746

Browse files
authored
Merge pull request #230 from BobHanson/master
omnibus pull from bobhanson/java2Script
2 parents df0959d + 76dc748 commit b3db746

35 files changed

+597
-364
lines changed
Binary file not shown.
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20240114215407
1+
20240225103130
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20240114215407
1+
20240225103130

sources/net.sf.j2s.core/src/j2s/swingjs/Java2ScriptVisitor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
// TODO: superclass inheritance for JAXB XmlAccessorType
3232
// TODO: Transpiler bug allows static String name, but JavaScript function().name is read-only and will be "clazz"
3333

34+
//BH 2024.02.22 -- 3.3.1-v7 fixes long extension issue causing MutableBitInteger to miscalculate subtraction(no change in version #)
3435
//BH 2023.03.29 -- 3.3.1-v7 fixes outer static method call from within lambda expression.
3536
//BH 2023.02.09 -- 3.3.1.v6 fixes j2s.excluded.paths needing /src/xxxx
3637
//BH 2022.06.27 -- 3.3.1-v5 fixes missing method annotations
@@ -4313,11 +4314,10 @@ && boxType(exp) == NO_BOX) {
43134314
private void addExtendedOperands(List<?> extendedOperands, String op, char pre, char post, boolean isToString,
43144315
boolean isLongCall) {
43154316
buffer.append(' ');
4317+
if (isLongCall)
4318+
op = ",";
43164319
for (Iterator<?> iter = extendedOperands.iterator(); iter.hasNext();) {
43174320
Expression exp = (Expression) iter.next();
4318-
// op may be int for a while, but after that it changes to long
4319-
if (isLongCall && exp.resolveTypeBinding().getName().equals("long"))
4320-
op = ",";
43214321
buffer.append(op);
43224322
buffer.append(pre);
43234323
addOperand(exp, isToString);
Binary file not shown.
Binary file not shown.

sources/net.sf.j2s.java.core/site-resources/test-raf.txt

Lines changed: 0 additions & 2 deletions
This file was deleted.

sources/net.sf.j2s.java.core/site-resources_4.2/jsmol/js/j2sjmol.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,7 @@ Clazz.defineMethod = function (clazzThis, funName, funBody, funParams) {
894894
if (!f$.stacks || f$.claxxReference !== clazzThis) {
895895
//Generate a new delegating method for the class
896896
var id = ++SAEMid;
897-
console.log("SAEM " + clazzThis.__CLASS_NAME__ + "." + funName);
897+
//console.log("SAEM " + clazzThis.__CLASS_NAME__ + "." + funName);
898898
var delegate = function () {
899899
return searchAndExecuteMethod(id, this, arguments.callee.claxxReference, arguments.callee.methodName, arguments);
900900
};

sources/net.sf.j2s.java.core/src/java/math/MutableBigInteger.java

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
/*
2+
* 2024.02.21 BH modified for SwingJS with a few (more!) (x + 0x80000000)|0 adjustments
3+
*
24
* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
35
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
46
*
@@ -25,7 +27,7 @@
2527

2628
package java.math;
2729

28-
/**
30+
/**
2931
* A class used to represent multiprecision integers that makes efficient
3032
* use of allocated space by allowing a number to occupy only part of
3133
* an array so that the arrays do not have to be reallocated as often.
@@ -294,8 +296,8 @@ private int compareShifted(MutableBigInteger b, int ints) {
294296
// comparison.
295297
int[] bval = b.value;
296298
for (int i = offset, j = b.offset; i < alen + offset; i++, j++) {
297-
int b1 = value[i] + 0x80000000;
298-
int b2 = bval[j] + 0x80000000;
299+
int b1 = (value[i] + 0x80000000)| 0;
300+
int b2 = (bval[j] + 0x80000000)| 0;
299301
if (b1 < b2)
300302
return -1;
301303
if (b1 > b2)
@@ -339,7 +341,7 @@ final int compareHalf(MutableBigInteger b) {
339341
long v = val[i++] & LONG_MASK;
340342
if (v != hb)
341343
return v < hb ? -1 : 1;
342-
carry = (bv & 1) << 31; // carray will be either 0x80000000 or 0
344+
carry = ((bv & 1) << 31)|0; // carray will be either 0x80000000 or 0
343345
}
344346
return carry == 0 ? 0 : -1;
345347
}
@@ -1131,7 +1133,6 @@ int divideOneWord(int divisor, MutableBigInteger quotient) {
11311133
quotient.value[intLen - xlen] = q;
11321134
remLong = rem & LONG_MASK;
11331135
}
1134-
11351136
quotient.normalize();
11361137
// Unnormalize
11371138
if (shift > 0)
@@ -1362,8 +1363,7 @@ private MutableBigInteger divide3n2n(MutableBigInteger b, MutableBigInteger quot
13621363
if (compareShifted(b, n) < 0) {
13631364
// step 3a: if a1<b1, let quotient=a12/b1 and r=a12%b1
13641365
r = a12.divide2n1n(b1, quotient);
1365-
1366-
// step 4: d=quotient*b2
1366+
// step 4: d=quotient*b2
13671367
d = new MutableBigInteger(quotient.toBigInteger().multiply(b2));
13681368
} else {
13691369
// step 3b: if a1>=b1, let quotient=beta^n-1 and r=a12-b1*2^n+b1
@@ -1378,7 +1378,7 @@ private MutableBigInteger divide3n2n(MutableBigInteger b, MutableBigInteger quot
13781378
d.leftShift(32 * n);
13791379
d.subtract(new MutableBigInteger(b2));
13801380
}
1381-
1381+
13821382
// step 5: r = r*beta^n + a3 - d (paper says a4)
13831383
// However, don't subtract d until after the while loop so r doesn't become negative
13841384
r.leftShift(32 * n);
@@ -1548,13 +1548,13 @@ private MutableBigInteger divideMagnitude(MutableBigInteger div,
15481548
int qrem = 0;
15491549
boolean skipCorrection = false;
15501550
int nh = rem.value[j+rem.offset];
1551-
int nh2 = nh + 0x80000000;
1551+
int nh2 = (nh + 0x80000000)| 0;
15521552
int nm = rem.value[j+1+rem.offset];
15531553

15541554
if (nh == dh) {
15551555
qhat = ~0;
15561556
qrem = nh + nm;
1557-
skipCorrection = qrem + 0x80000000 < nh2;
1557+
skipCorrection = ((qrem + 0x80000000)| 0) < nh2;
15581558
} else {
15591559
long nChunk = (((long)nh) << 32) | (nm & LONG_MASK);
15601560
if (nChunk >= 0) {
@@ -1607,13 +1607,13 @@ private MutableBigInteger divideMagnitude(MutableBigInteger div,
16071607
int qrem = 0;
16081608
boolean skipCorrection = false;
16091609
int nh = rem.value[limit - 1 + rem.offset];
1610-
int nh2 = nh + 0x80000000;
1610+
int nh2 = (nh + 0x80000000)|0;
16111611
int nm = rem.value[limit + rem.offset];
16121612

16131613
if (nh == dh) {
16141614
qhat = ~0;
16151615
qrem = nh + nm;
1616-
skipCorrection = qrem + 0x80000000 < nh2;
1616+
skipCorrection = ((qrem + 0x80000000)|0) < nh2;
16171617
} else {
16181618
long nChunk = (((long) nh) << 32) | (nm & LONG_MASK);
16191619
if (nChunk >= 0) {
@@ -1653,7 +1653,7 @@ private MutableBigInteger divideMagnitude(MutableBigInteger div,
16531653
borrow = mulsubBorrow(rem.value, divisor, qhat, dlen, limit - 1 + rem.offset);
16541654

16551655
// D5 Test remainder
1656-
if (borrow + 0x80000000 > nh2) {
1656+
if (((borrow + 0x80000000)|0) > nh2) {
16571657
// D6 Add back
16581658
if(needRemainder)
16591659
divadd(divisor, rem.value, limit - 1 + 1 + rem.offset);
@@ -1723,13 +1723,13 @@ private MutableBigInteger divideLongMagnitude(long ldivisor, MutableBigInteger q
17231723
int qrem = 0;
17241724
boolean skipCorrection = false;
17251725
int nh = rem.value[j + rem.offset];
1726-
int nh2 = nh + 0x80000000;
1726+
int nh2 = (nh + 0x80000000)|0;
17271727
int nm = rem.value[j + 1 + rem.offset];
17281728

17291729
if (nh == dh) {
17301730
qhat = ~0;
17311731
qrem = nh + nm;
1732-
skipCorrection = qrem + 0x80000000 < nh2;
1732+
skipCorrection = ((qrem + 0x80000000)|0) < nh2;
17331733
} else {
17341734
long nChunk = (((long) nh) << 32) | (nm & LONG_MASK);
17351735
if (nChunk >= 0) {
@@ -1767,7 +1767,7 @@ private MutableBigInteger divideLongMagnitude(long ldivisor, MutableBigInteger q
17671767
int borrow = mulsubLong(rem.value, dh, dl, qhat, j + rem.offset);
17681768

17691769
// D5 Test remainder
1770-
if (borrow + 0x80000000 > nh2) {
1770+
if (((borrow + 0x80000000)|0) > nh2) {
17711771
// D6 Add back
17721772
divaddLong(dh,dl, rem.value, j + 1 + rem.offset);
17731773
qhat--;
@@ -1963,7 +1963,7 @@ static int binaryGcd(int a, int b) {
19631963
int t = (aZeros < bZeros ? aZeros : bZeros);
19641964

19651965
while (a != b) {
1966-
if ((a+0x80000000) > (b+0x80000000)) { // a > b as unsigned
1966+
if (((a + 0x80000000)|0) > ((b + 0x80000000)|0)) { // a > b as unsigned
19671967
a -= b;
19681968
a >>>= Integer.numberOfTrailingZeros(a);
19691969
} else {
@@ -2246,4 +2246,20 @@ MutableBigInteger euclidModInverse(int k) {
22462246
mod.subtract(t1);
22472247
return mod;
22482248
}
2249+
2250+
// static {
2251+
// int a = 100;
2252+
// int b = a + 0x80000000;
2253+
// System.out.println(b);
2254+
// System.out.println((a + 0x80000000) | 0);
2255+
// System.out.println(a + 0x80000000L); // NOT in Java
2256+
// System.out.println((int) (a + 0x80000000L));
2257+
// a = -100;
2258+
// b = a + 0x80000000;
2259+
// System.out.println("?");
2260+
// System.out.println(b); //NOT in JS
2261+
// System.out.println((a + 0x80000000) | 0);
2262+
// System.out.println(a + 0x80000000L);
2263+
// System.out.println((int) (a + 0x80000000L));
2264+
// }
22492265
}

sources/net.sf.j2s.java.core/src/java/util/Hashtable.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1893,7 +1893,10 @@ public T nextElement() {
18931893

18941894
@Override
18951895
public V setValue(V value) {
1896-
return Hashtable.this.put(getKey(), value);
1896+
int m = modCount;
1897+
V v = put(getKey(), value);
1898+
modCount = m;
1899+
return v;
18971900
}
18981901
};
18991902
}

sources/net.sf.j2s.java.core/src/javajs/util/A4d.java

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,26 +35,7 @@ conforming to the Java(TM) 3D API specification by Sun Microsystems.
3535
* for unique constructor and method names
3636
* for the optimization of compiled JavaScript using Java2Script
3737
*/
38-
public class A4d implements JSONEncodable, Serializable {
39-
40-
/*
41-
* I assumed that the length of the axis vector is not significant.
42-
*/
43-
44-
/**
45-
* The x coordinate.
46-
*/
47-
public double x;
48-
49-
/**
50-
* The y coordinate.
51-
*/
52-
public double y;
53-
54-
/**
55-
* The z coordinate.
56-
*/
57-
public double z;
38+
public class A4d extends P3d {
5839

5940
/**
6041
* The angle.

sources/net.sf.j2s.java.core/src/javajs/util/MessagePackReader.java

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,9 @@ public Object getNext(Object array, int pt) throws Exception {
181181
if (array == null) {
182182
switch (b) {
183183
case FLOAT32:
184-
return Float.valueOf(doc.readFloat());
184+
return Double.valueOf(doc.readFloat());
185185
case FLOAT64:
186-
return Float.valueOf((float) doc.readDouble());
186+
return Double.valueOf(doc.readDouble());
187187
case UINT8:
188188
return Integer.valueOf(doc.readUInt8());
189189
case UINT16:
@@ -203,17 +203,17 @@ public Object getNext(Object array, int pt) throws Exception {
203203
case STR8:
204204
return doc.readString(doc.readUInt8());
205205
case STR16:
206-
return doc.readString(doc.readShort());
206+
return doc.readString(doc.readUnsignedShort());
207207
case STR32:
208208
return doc.readString(doc.readInt());
209209
}
210210
} else {
211211
switch (b) {
212212
case FLOAT32:
213-
((float[]) array)[pt] = doc.readFloat();
213+
((double[]) array)[pt] = doc.readFloat();
214214
break;
215215
case FLOAT64:
216-
((float[]) array)[pt] = (float) doc.readDouble();
216+
((double[]) array)[pt] = doc.readDouble();
217217
break;
218218
case UINT8:
219219
((int[]) array)[pt] = doc.readUInt8();
@@ -243,10 +243,10 @@ public Object getNext(Object array, int pt) throws Exception {
243243
((String[]) array)[pt] = doc.readString(doc.readUInt8());
244244
break;
245245
case STR16:
246-
((String[]) array)[pt] = doc.readString(doc.readShort());
246+
((String[]) array)[pt] = doc.readString(doc.readUnsignedShort());
247247
break;
248248
case STR32:
249-
((String[]) array)[pt] = doc.readString(doc.readInt());
249+
((String[]) array)[pt] = doc.readString(doc.readInt()); // technically shoild be unsigned int
250250
break;
251251
}
252252
}
@@ -267,9 +267,9 @@ private Object getArray(int n) throws Exception {
267267
int[] a = new int[n];
268268
a[0] = ((Integer) v).intValue();
269269
v = a;
270-
} else if (v instanceof Float) {
271-
float[] a = new float[n];
272-
a[0] = ((Float) v).floatValue();
270+
} else if (v instanceof Number) {
271+
double[] a = new double[n];
272+
a[0] = ((Number) v).doubleValue();
273273
v = a;
274274
} else if (v instanceof String) {
275275
String[] a = new String[n];
@@ -296,8 +296,6 @@ private Object getMap(int n) throws Exception {
296296
Map<String, Object> map = new Hashtable<String, Object>();
297297
for (int i = 0; i < n; i++) {
298298
String key = getNext(null, 0).toString();
299-
//Logger.info(key);
300-
301299
Object value = getNext(null, 0);
302300
if (value == null) {
303301
//Logger.info("null value for " + key);
@@ -366,10 +364,10 @@ public static Object decode(byte[] b) {
366364
* @param divisor
367365
* @return array of floats
368366
*/
369-
public static float[] getFloats(byte[] b, int n, float divisor) {
367+
public static double[] getFloats(byte[] b, int n, float divisor) {
370368
if (b == null)
371369
return null;
372-
float[] a = new float[n];
370+
double[] a = new double[n];
373371
try {
374372
switch ((b.length - 12) / n) {
375373
case 2:
@@ -522,10 +520,10 @@ public static int[] rldecode32Delta(byte[] b, int n) {
522520
* @param divisor
523521
* @return array of floats
524522
*/
525-
public static float[] rldecodef(byte[] b, int n, float divisor) {
523+
public static double[] rldecodef(byte[] b, int n, float divisor) {
526524
if (b == null)
527525
return null;
528-
float[] ret = new float[n];
526+
double[] ret = new double[n];
529527
for (int i = 0, pt = 3; i < n;) {
530528
int val = BC.bytesToInt(b, (pt++) << 2, true);
531529
for (int j = BC.bytesToInt(b, (pt++) << 2, true); --j >= 0;)
@@ -545,10 +543,10 @@ public static float[] rldecodef(byte[] b, int n, float divisor) {
545543
* @param divisor
546544
* @return array of floats
547545
*/
548-
public static float[] unpack16Deltaf(byte[] b, int n, float divisor) {
546+
public static double[] unpack16Deltaf(byte[] b, int n, float divisor) {
549547
if (b == null)
550548
return null;
551-
float[] ret = new float[n];
549+
double[] ret = new double[n];
552550
for (int i = 0, pt = 6, val = 0, buf = 0; i < n;) {
553551
int diff = BC.bytesToShort(b, (pt++) << 1, true);
554552
if (diff == Short.MAX_VALUE || diff == Short.MIN_VALUE) {
@@ -575,10 +573,10 @@ public static float[] unpack16Deltaf(byte[] b, int n, float divisor) {
575573
* @param divisor
576574
* @return array of floats
577575
*/
578-
public static float[] unpackf(byte[] b, int nBytes, int n, float divisor) {
576+
public static double[] unpackf(byte[] b, int nBytes, int n, float divisor) {
579577
if (b == null)
580578
return null;
581-
float[] ret = new float[n];
579+
double[] ret = new double[n];
582580
switch (nBytes) {
583581
case 1:
584582
for (int i = 0, pt = 12, offset = 0; i < n;) {

0 commit comments

Comments
 (0)