X Tutup
Skip to content

Commit 56c837b

Browse files
committed
refactored run-time; fix for static initialization timing
1 parent 3da6320 commit 56c837b

File tree

8 files changed

+830
-858
lines changed

8 files changed

+830
-858
lines changed

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,8 +1284,6 @@ private boolean addClassOrInterface(ASTNode node, ITypeBinding binding, List<?>
12841284
trailingBuffer = new TrailingBuffer();
12851285
}
12861286

1287-
boolean hasSuperclass = hasSuperClass(binding);
1288-
12891287
for (Iterator<?> iter = bodyDeclarations.iterator(); iter.hasNext();) {
12901288
BodyDeclaration element = (BodyDeclaration) iter.next();
12911289
boolean isField = element instanceof FieldDeclaration;
@@ -1301,8 +1299,9 @@ private boolean addClassOrInterface(ASTNode node, ITypeBinding binding, List<?>
13011299
if (isField || element instanceof Initializer) {
13021300
if ((isInterface || isStatic(element)) && !checkj2sIgnore(element)) {
13031301
lstStatic.add(element);
1304-
if (isField && hasSuperclass)
1302+
if (isField)
13051303
addFieldDeclaration((FieldDeclaration) element, FIELD_DECL_STATIC_DEFAULTS);
1304+
13061305
}
13071306
} else if (!havePrivateMethods && element instanceof MethodDeclaration) {
13081307
if (Modifier.isPrivate(((MethodDeclaration) element).resolveBinding().getModifiers())) {
@@ -1313,18 +1312,17 @@ private boolean addClassOrInterface(ASTNode node, ITypeBinding binding, List<?>
13131312
}
13141313
if (lstStatic.size() > 0 || hasDependents) {
13151314
pt = buffer.length();
1316-
buffer.append("\r\nC$.$clinit$ = function() {Clazz.load(C$, 1);\r\n");
13171315
boolean haveDeclarations = false;
1316+
buffer.append("\r\nC$.$clinit$ = function() {Clazz.load(C$, 1);\r\n");
13181317
for (int i = lstStatic.size(); --i >= 0;) {
13191318
BodyDeclaration element = lstStatic.remove(0);
13201319
if (element instanceof Initializer) {
13211320
element.accept(this);
13221321
buffer.append(";\r\n");
13231322
haveDeclarations = true;
1324-
continue;
1325-
}
1326-
if (addFieldDeclaration((FieldDeclaration) element, FIELD_DECL_STATIC_NONDEFAULT))
1323+
} else if (addFieldDeclaration((FieldDeclaration) element, FIELD_DECL_STATIC_NONDEFAULT)) {
13271324
haveDeclarations = true;
1325+
}
13281326
}
13291327
if (haveDeclarations || hasDependents)
13301328
buffer.append("}\r\n");
@@ -1542,18 +1540,19 @@ private boolean addFieldDeclaration(FieldDeclaration field, int mode) {
15421540
for (Iterator<?> iter = fragments.iterator(); iter.hasNext();) {
15431541
VariableDeclarationFragment fragment = (VariableDeclarationFragment) iter.next();
15441542
Expression initializer = fragment.getInitializer();
1545-
if (isFinal && VariableAdapter.getConstantValue(initializer) != null)
1543+
if (isFinal ? VariableAdapter.getConstantValue(initializer) != null
1544+
: isStatic && initializer == null && !needDefault)
15461545
continue;
15471546
int len = buffer.length();
15481547
String prefix = (isStatic ? "C$." : "this.")
15491548
+ getCheckedFieldName(J2SMapAdapter.getJ2SName(fragment.getName()), classBinding, false);
15501549
buffer.append(prefix);
15511550
buffer.append(" = ");
15521551
int len1 = buffer.length();
1552+
15531553
if (initializer == null || needDefault) {
15541554
// Route default for this to the $init0$ buffer if nonstatic, or straight to the class if static
1555-
// if static and not initialized or nonstatic and there is a
1556-
// superclass
1555+
// if static and not initialized
15571556

15581557
buffer.append(code == null ? "null" : getPrimitiveDefault(code));
15591558
buffer.append(";\r\n");

sources/net.sf.j2s.core/test/dev/js/j2sApplet.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ J2S._getDefaultLanguage = function(isAll) { return (isAll ? J2S.featureDetection
781781
return data.getBytes();
782782
// ArrayBuffer assumed here
783783
data = new Uint8Array(data);
784-
var b = (Clazz.newArray$ ? Clazz.newArray$(Byte.TYPE, data.length) : Clazz.newByteArray(data.length, 0));
784+
var b = Clazz.array(Byte.TYPE, data.length);
785785
for (var i = data.length; --i >= 0;)
786786
b[i] = data[i];
787787
return b;
@@ -898,7 +898,7 @@ J2S._getDefaultLanguage = function(isAll) { return (isAll ? J2S.featureDetection
898898
return Clazz.load("javajs.util.Base64").decodeBase64$S(s.substring(8));
899899
}
900900
// not UTF-8
901-
var b = (Clazz.newArray$ ? Clazz.newArray$(Byte.TYPE, s.length) : Clazz.newByteArray(s.length, 0));
901+
var b = Clazz.array(Byte.TYPE, s.length);
902902
for (var i = s.length; --i >= 0;)
903903
b[i] = s.charCodeAt(i) & 0xFF;
904904
return b;
@@ -1995,7 +1995,7 @@ J2S.Cache.put = function(filename, data) {
19951995
// false is from Repaintmanager.requestRepaintAndWait()
19961996
// called from apiPlatform Display.repaint()
19971997

1998-
//alert("_repaint " + Clazz.getStackTrace())
1998+
//alert("_repaint " + Clazz._getStackTrace())
19991999
if (!applet || !applet._appletPanel)return;
20002000

20012001
// asNewThread = false;

0 commit comments

Comments
 (0)
X Tutup