Skip to content

Commit 4676a92

Browse files
author
zhourenjian
committed
Fixing bug that ClassLoader may add multiple SCRIPT elements with the same SRC attribute into DOM tree.
Fixing bug that ClassLoader's cyclic dependencies is not totally correct
1 parent f2e3c97 commit 4676a92

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

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

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,7 +1393,11 @@ ClazzLoader.tryToLoadNext = function (file) {
13931393
ClazzLoader.updateNode (n);
13941394
lastNode = n;
13951395
}
1396-
while (ClazzLoader.checkOptionalCycle (ClazzLoader.clazzTreeRoot)) {
1396+
while (true) {
1397+
ClazzLoader.tracks = new Array ();
1398+
if (!ClazzLoader.checkOptionalCycle (ClazzLoader.clazzTreeRoot)) {
1399+
break;
1400+
}
13971401
}
13981402
lastNode = null;
13991403
while ((n = ClazzLoader.findNextMustClass (ClazzLoader.clazzTreeRoot, ClazzNode.STATUS_DECLARED)) != null) {
@@ -1423,6 +1427,7 @@ ClazzLoader.tryToLoadNext = function (file) {
14231427
var optLoaded = dList[i].optionalsLoaded;
14241428
if (optLoaded != null) {
14251429
dList[i].optionalsLoaded = null;
1430+
//window.setTimeout (optLoaded, 25);
14261431
optLoaded ();
14271432
}
14281433
}
@@ -1456,6 +1461,12 @@ ClazzLoader.checkOptionalCycle = function (node) {
14561461
}
14571462
ts[ts.length] = node;
14581463
if (cycleFound != -1) {
1464+
/*
1465+
for (var i = cycleFound; i < ts.length; i++) {
1466+
alert (ts[i].name + ":::" + ts[i].status);
1467+
}
1468+
alert ("===");
1469+
*/
14591470
for (var i = cycleFound; i < ts.length; i++) {
14601471
ts[i].status = ClazzNode.STATUS_OPTIONALS_LOADED;
14611472
ClazzLoader.updateNode (ts[i]);
@@ -1467,6 +1478,7 @@ ClazzLoader.checkOptionalCycle = function (node) {
14671478
var optLoaded = ts[i].optionalsLoaded;
14681479
if (optLoaded != null) {
14691480
ts[i].optionalsLoaded = null;
1481+
//alert ("check cycle.");
14701482
//window.setTimeout (optLoaded, 25);
14711483
optLoaded ();
14721484
}
@@ -1576,7 +1588,6 @@ $_L(["$wt.widgets.Widget","$wt.graphics.Drawable"],"$wt.widgets.Control",
15761588
if (optLoaded != null) {
15771589
nns[j].optionalsLoaded = null;
15781590
//window.setTimeout (optLoaded, 25);
1579-
alert (1);
15801591
optLoaded ();
15811592
}
15821593
}
@@ -2269,7 +2280,16 @@ ClazzLoader.loadClass = function (name, optionalsLoaded, forced, async) {
22692280
if (!ClazzLoader.isClassDefined (name)
22702281
&& !ClazzLoader.isClassExcluded (name)) {
22712282
var path = ClazzLoader.getClasspathFor (name/*, true*/);
2272-
if (!ClazzLoader.loadedScripts[path]) {
2283+
var existed = ClazzLoader.loadedScripts[path];
2284+
var qq = ClazzLoader.classQueue;
2285+
if (!existed) {
2286+
for (var i = qq.length - 1; i >= 0; i--) {
2287+
if (qq[i].path == path || qq[i].name == name) {
2288+
existed = true;
2289+
}
2290+
}
2291+
}
2292+
if (!existed) {
22732293
var n = null;
22742294
if (Clazz.unloadedClasses[name] != null) {
22752295
n = ClazzLoader.findClass (name);
@@ -2284,7 +2304,6 @@ ClazzLoader.loadClass = function (name, optionalsLoaded, forced, async) {
22842304
n.status = ClazzNode.STATUS_KNOWN;
22852305
/*-# needBeingQueued -> nQ #-*/
22862306
var needBeingQueued = false;
2287-
var qq = ClazzLoader.classQueue;
22882307
//error (qq.length + ":" + qq);
22892308
//error (path);
22902309
for (var i = qq.length - 1; i >= 0; i--) {
@@ -2366,8 +2385,14 @@ $w$ = ClazzLoader.loadJ2SApp = function (clazz, args, loaded) {
23662385
}
23672386
var idx = -1;
23682387
if ((idx = clazzStr.indexOf ("@")) != -1) {
2369-
ClazzLoader.setPrimaryFolder (clazzStr.substring (idx + 1));
2388+
var path = clazzStr.substring (idx + 1);
2389+
ClazzLoader.setPrimaryFolder (path); // TODO: No primary folder?
23702390
clazzStr = clazzStr.substring (0, idx);
2391+
idx = clazzStr.lastIndexOf (".");
2392+
if (idx != -1) {
2393+
var pkgName = clazzStr.substring (0, idx);
2394+
ClazzLoader.packageClasspath (pkgName, path);
2395+
}
23712396
}
23722397
var agmts = args;
23732398
if (agmts == null || !(agmts instanceof Array)) {

0 commit comments

Comments
 (0)