Skip to content

Commit 013c55c

Browse files
committed
Swingjs transpiler and runtime upgrade
- fix bug in synchronized() - fix bug in new int[]{'a',1,2,3}
1 parent f363aa8 commit 013c55c

File tree

6 files changed

+22
-23
lines changed

6 files changed

+22
-23
lines changed
-11 Bytes
Binary file not shown.
-11 Bytes
Binary file not shown.

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

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -911,30 +911,27 @@ public boolean visit(SwitchCase node) {
911911
}
912912

913913
public boolean visit(SynchronizedStatement node) {
914-
// we could wrap this with a simple if() statement,
914+
// we could wrap this with a simple if() statement,
915915
// checking that it is not null, but that seems to me
916916
// to be unnecessary. When would one ever intentionally
917917
// produce a null pointer exception from synchronized(...)?
918-
918+
919919
Expression e = node.getExpression();
920-
if (e instanceof Name
921-
|| e instanceof TypeLiteral
922-
|| e instanceof ThisExpression)
923-
return false;
924-
buffer.append("/*sync " + e.getClass().getName() + "*/");
925-
// get actual JavaScript code
926-
int pt = buffer.length();
927-
e.accept(this);
928-
String expr = buffer.substring(pt, buffer.length());
929-
buffer.setLength(pt);
930-
// ignore (treeLock())
931-
if (e instanceof MethodInvocation && expr.indexOf(".getTreeLock()") >= 0){
932-
MethodInvocation m = (MethodInvocation) e;
933-
m.getExpression().getName();
934-
return false;
920+
if (!(e instanceof Name || e instanceof TypeLiteral || e instanceof ThisExpression)) {
921+
buffer.append("/*sync " + e.getClass().getName() + "*/");
922+
// get actual JavaScript code
923+
int pt = buffer.length();
924+
e.accept(this);
925+
String expr = buffer.substring(pt, buffer.length());
926+
buffer.setLength(pt);
927+
// ignore (treeLock())
928+
if (e instanceof MethodInvocation && expr.indexOf(".getTreeLock()") >= 0) {
929+
return false;
930+
}
931+
buffer.append("(");
932+
buffer.append(expr);
933+
buffer.append(");\n");
935934
}
936-
buffer.append(expr);
937-
buffer.append(";");
938935
node.getBody().accept(this);
939936
return false;
940937
}
-17.6 KB
Binary file not shown.

sources/net.sf.j2s.java.core/srcjs/js/j2sClazz.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
// Google closure compiler cannot handle Clazz.new or Clazz.super
99

10+
// BH 6/25/2018 10:23:24 AM really fixing new int[] {'a'} using .$c() see Test_Byte.java
1011
// BH 6/21/2018 1:08:58 PM missing mysterious Integer.objectValue()
1112
// BH 6/20/2018 6:00:23 AM missing printStackTrace(PrintStream)
1213
// BH 6/19/2018 8:49:57 AM fix for checkDeclared
@@ -862,7 +863,7 @@ var newTypedA = function(baseClass, args, nBits, ndims) {
862863
} else if (nBits > 0 && dim < 0) {
863864
// make sure this is not a character
864865
for (var i = val.length; --i >= 0;)
865-
val[i].charAt && (val[i] = val[i].charAt(0));
866+
val[i].charAt && (val[i] = val[i].$c());
866867
dim = val; // because we can initialize an array using new Int32Array([...])
867868
}
868869
if (nBits > 0)
@@ -2429,7 +2430,7 @@ Con.consoleOutput = function (s, color) {
24292430
switch (s.charAt(s.length - 1)) {
24302431
case '\n':
24312432
case '\r':
2432-
s = (s.length > 1 ? s.substring (0, s.length - (s.charAt (s.length - 2) == '\r' ? 2 : 1)) : "");
2433+
s = (s.length > 1 ? s.substring (0, s.length - (s.charAt(s.length - 2) == '\r' ? 2 : 1)) : "");
24332434
willMeetLineBreak = true;
24342435
break;
24352436
}

sources/net.sf.j2s.java.core/srcjs/swingjs2.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13094,6 +13094,7 @@ J2S._getResourcePath = function(path, isJavaPath) {
1309413094

1309513095
// Google closure compiler cannot handle Clazz.new or Clazz.super
1309613096

13097+
// BH 6/25/2018 10:23:24 AM really fixing new int[] {'a'} using .$c() see Test_Byte.java
1309713098
// BH 6/21/2018 1:08:58 PM missing mysterious Integer.objectValue()
1309813099
// BH 6/20/2018 6:00:23 AM missing printStackTrace(PrintStream)
1309913100
// BH 6/19/2018 8:49:57 AM fix for checkDeclared
@@ -13949,7 +13950,7 @@ var newTypedA = function(baseClass, args, nBits, ndims) {
1394913950
} else if (nBits > 0 && dim < 0) {
1395013951
// make sure this is not a character
1395113952
for (var i = val.length; --i >= 0;)
13952-
val[i].charAt && (val[i] = val[i].charAt(0));
13953+
val[i].charAt && (val[i] = val[i].$c());
1395313954
dim = val; // because we can initialize an array using new Int32Array([...])
1395413955
}
1395513956
if (nBits > 0)
@@ -15516,7 +15517,7 @@ Con.consoleOutput = function (s, color) {
1551615517
switch (s.charAt(s.length - 1)) {
1551715518
case '\n':
1551815519
case '\r':
15519-
s = (s.length > 1 ? s.substring (0, s.length - (s.charAt (s.length - 2) == '\r' ? 2 : 1)) : "");
15520+
s = (s.length > 1 ? s.substring (0, s.length - (s.charAt(s.length - 2) == '\r' ? 2 : 1)) : "");
1552015521
willMeetLineBreak = true;
1552115522
break;
1552215523
}

0 commit comments

Comments
 (0)