Skip to content

Commit 29de03b

Browse files
author
zhourenjian
committed
Fixed bug on duplicate callbacks on nesting class loading. For example:
ClazzLoader.loadClass ("org.eclipse.swt.widgets.Display", function () { $wt.widgets.Display.getDefault(); ClazzLoader.packageClasspath ("iz", gtalkBase, true); ClazzLoader.loadClass ("net.izuz.gtalk.MainWindow", function () { var imType = parseIMType (); net.sf.j2s.ajax.SimplePipeRequest.switchToQueryMode (500); if (imType != null) { net.izuz.gtalk.MainWindow.main(["--" + imType]); } }); });
1 parent 26854e0 commit 29de03b

File tree

1 file changed

+41
-16
lines changed

1 file changed

+41
-16
lines changed

sources/net.sf.j2s.java.core/src/java/lang/ClassLoader.js

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,8 +1229,26 @@ ClazzLoader.tryToLoadNext = function (file) {
12291229
}
12301230
} else {
12311231
if (node.status < ClazzNode.STATUS_CONTENT_LOADED) {
1232-
node.status = ClazzNode.STATUS_CONTENT_LOADED;
1233-
ClazzLoader.updateNode (node);
1232+
var stillLoading = false;
1233+
var ss = document.getElementsByTagName ("SCRIPT");
1234+
for (var i = 0; i < ss.length; i++) {
1235+
if (ClazzLoader.isIE) {
1236+
if (ss[i].onreadystatechange != null && ss[i].onreadystatechange.path == node.path
1237+
&& ss[i].readyState == "interactive") {
1238+
stillLoading = true;
1239+
break;
1240+
}
1241+
} else {
1242+
if (ss[i].onload != null && ss[i].onload.path == node.path) {
1243+
stillLoading = true;
1244+
break;
1245+
}
1246+
}
1247+
}
1248+
if (!stillLoading) {
1249+
node.status = ClazzNode.STATUS_CONTENT_LOADED;
1250+
ClazzLoader.updateNode (node);
1251+
}
12341252
}
12351253
}
12361254
/*
@@ -1354,9 +1372,10 @@ ClazzLoader.tryToLoadNext = function (file) {
13541372
ClazzLoader.updateNode (dList[i]);
13551373
}
13561374
for (var i = 0; i < dList.length; i++) {
1357-
if (dList[i].optionalsLoaded != null) {
1358-
dList[i].optionalsLoaded ();
1375+
var optLoaded = dList[i].optionalsLoaded;
1376+
if (optLoaded != null) {
13591377
dList[i].optionalsLoaded = null;
1378+
optLoaded ();
13601379
}
13611380
}
13621381

@@ -1397,10 +1416,11 @@ ClazzLoader.checkOptionalCycle = function (node) {
13971416
ClazzLoader.updateNode (ts[i].parents[k]);
13981417
}
13991418
ts[i].parents = new Array ();
1400-
if (ts[i].optionalsLoaded != null) {
1401-
//window.setTimeout (ts[i].optionalsLoaded, 25);
1402-
ts[i].optionalsLoaded ();
1419+
var optLoaded = ts[i].optionalsLoaded;
1420+
if (optLoaded != null) {
14031421
ts[i].optionalsLoaded = null;
1422+
//window.setTimeout (optLoaded, 25);
1423+
optLoaded ();
14041424
}
14051425
}
14061426
ts.length = 0;
@@ -1504,10 +1524,12 @@ $_L(["$wt.widgets.Widget","$wt.graphics.Drawable"],"$wt.widgets.Control",
15041524
nns[nns.length] = n;
15051525
}
15061526
for (var j = 0; j < nns.length; j++) {
1507-
if (nns[j].optionalsLoaded != null) {
1508-
//window.setTimeout (nns[j].optionalsLoaded, 25);
1509-
nns[j].optionalsLoaded ();
1527+
var optLoaded = nns[j].optionalsLoaded;
1528+
if (optLoaded != null) {
15101529
nns[j].optionalsLoaded = null;
1530+
//window.setTimeout (optLoaded, 25);
1531+
alert (1);
1532+
optLoaded ();
15111533
}
15121534
}
15131535
} else { // why not break? -Zhou Renjian @ Nov 28, 2006
@@ -1607,10 +1629,11 @@ $_L(["$wt.widgets.Widget","$wt.graphics.Drawable"],"$wt.widgets.Control",
16071629
level = ClazzNode.STATUS_OPTIONALS_LOADED;
16081630
node.status = level;
16091631
ClazzLoader.scriptCompleted (node.path);
1610-
if (node.optionalsLoaded != null) {
1611-
//window.setTimeout (node.optionalsLoaded, 25);
1612-
node.optionalsLoaded ();
1632+
var optLoaded = node.optionalsLoaded;
1633+
if (optLoaded != null) {
16131634
node.optionalsLoaded = null;
1635+
//window.setTimeout (optLoaded, 25);
1636+
optLoaded ();
16141637
if (!ClazzLoader.keepOnLoading) {
16151638
return false;
16161639
}
@@ -1628,10 +1651,11 @@ $_L(["$wt.widgets.Widget","$wt.graphics.Drawable"],"$wt.widgets.Control",
16281651
nn.status = level;
16291652
nn.declaration = null;
16301653
ClazzLoader.scriptCompleted (nn.path);
1631-
if (nn.optionalsLoaded != null) {
1632-
//window.setTimeout (nn.optionalsLoaded, 25);
1633-
nn.optionalsLoaded ();
1654+
var optLoaded = nn.optionalsLoaded;
1655+
if (optLoaded != null) {
16341656
nn.optionalsLoaded = null;
1657+
//window.setTimeout (optLoaded, 25);
1658+
optLoaded ();
16351659
if (!ClazzLoader.keepOnLoading) {
16361660
return false;
16371661
}
@@ -2338,6 +2362,7 @@ ClazzLoader.runtimeLoaded = function () {
23382362
for (var i = 0; i < qbs.length; i++) {
23392363
ClazzLoader.loadClass (qbs[i][0], qbs[i][1]);
23402364
}
2365+
ClazzLoader.queueBe4KeyClazz = [];
23412366
/*
23422367
* Should not set to empty function! Some later package may need this
23432368
* runtimeLoaded function. For example, lazily loading SWT package may

0 commit comments

Comments
 (0)