Skip to content

Commit 8f0dc69

Browse files
author
zhourenjian
committed
Fixed a bug that IE does not load scripts in correct orders which result in failing to
load Java2Script application in the first time but successing in second time.
1 parent 8d5f3ea commit 8f0dc69

File tree

2 files changed

+43
-16
lines changed

2 files changed

+43
-16
lines changed

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

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,13 @@
9898
* HTTP connections timeout, but should not accur in local file system, or it
9999
* is a loading bug by using JavaScript timeout thread).
100100
*/
101-
101+
102+
/*
103+
* The following comments with "#" are special configurations for a much
104+
* smaller *.js file size.
105+
*
106+
* @see net.sf.j2s.lib/src/net/sf/j2s/lib/build/SmartJSCompressor.java
107+
*/
102108
/*-#
103109
# ClazzNode -> $CN$
104110
# ClazzLoader -> $CL$
@@ -186,13 +192,18 @@ ClazzLoader.inLoadingThreads = 0;
186192
/* protected */
187193
ClazzLoader.maxLoadingThreads = 6;
188194

195+
ClazzLoader.userAgent = navigator.userAgent.toLowerCase ();
196+
ClazzLoader.isOpera = (ClazzLoader.userAgent.indexOf ("opera") != -1);
197+
ClazzLoader.isIE = (ClazzLoader.userAgent.indexOf ("msie") != -1) && !ClazzLoader.isOpera;
198+
ClazzLoader.isGecko = (ClazzLoader.userAgent.indexOf ("gecko") != -1);
199+
189200
/*
190201
* Opera has different loading order which will result in performance degrade!
191202
* So just return to single thread loading in Opera!
192203
*
193204
* FIXME: This different loading order also causes bugs in single thread!
194205
*/
195-
if (navigator.userAgent.toLowerCase ().indexOf ("opera") != -1) {
206+
if (ClazzLoader.isOpera) {
196207
ClazzLoader.maxLoadingThreads = 1;
197208
}
198209

@@ -907,8 +918,7 @@ ClazzLoader.loadScript = function (file) {
907918
}
908919
this.onload = null;
909920
var path = arguments.callee.path;
910-
if (!ClazzLoader.innerLoadedScripts[this.src]
911-
&& navigator.userAgent.indexOf("Opera") >= 0) {
921+
if (!ClazzLoader.innerLoadedScripts[this.src] && ClazzLoader.isOpera) {
912922
// Opera will not take another try.
913923
var fss = ClazzLoader.failedScripts;
914924
if (fss[path] == null && ClazzLoader.takeAnotherTry) {
@@ -972,7 +982,7 @@ ClazzLoader.loadScript = function (file) {
972982
ClazzLoader.removeScriptNode (this);
973983
};
974984
script.onerror.path = file;
975-
if (navigator.userAgent.indexOf("Opera") >= 0) {
985+
if (ClazzLoader.isOpera) {
976986
ClazzLoader.needOnloadCheck = true;
977987
}
978988
} else { // IE
@@ -1152,7 +1162,7 @@ ClazzLoader.tryToLoadNext = function (file) {
11521162
*/
11531163
if (ClazzLoader.lockQueueBe4SWT && ClazzLoader.pkgRefCount != 0
11541164
&& file.lastIndexOf ("package.js") != file.length - 10
1155-
&& navigator.userAgent.toLowerCase ().indexOf ("gecko") != -1) {
1165+
&& (ClazzLoader.isGecko || ClazzLoader.isIE)) { // No Opera!
11561166
var qbs = ClazzLoader.queueBe4SWT;
11571167
qbs[qbs.length] = file;
11581168
return;
@@ -1245,12 +1255,13 @@ ClazzLoader.tryToLoadNext = function (file) {
12451255
if (cq.length != 0) {
12461256
/* queue must be loaded in order! */
12471257
n = cq[0]; // popup class from the queue
1258+
//alert ("load from queue");
1259+
//alert (cq.length + ":" + cq);
12481260
for (var i = 0; i < cq.length - 1; i++) {
12491261
cq[i] = cq[i + 1];
12501262
}
12511263
cq.length--;
1252-
1253-
//alert ("load from queue");
1264+
//log (cq.length + ":" + cq);
12541265
if (!ClazzLoader.loadedScripts[n.path] || cq.length != 0
12551266
|| !ClazzLoader.isLoadingEntryClass
12561267
|| (n.musts != null && n.musts.length != 0)
@@ -1779,7 +1790,7 @@ ClazzLoader.checkInteractive = function () {
17791790
&& ss[i].onreadystatechange != null) { // IE
17801791
ClazzLoader.interactiveScript = ss[i];
17811792
ClazzLoader.innerLoadedScripts[ss[i].src] = true;
1782-
} else if (navigator.userAgent.indexOf("Opera") >= 0) { // Opera
1793+
} else if (ClazzLoader.isOpera) { // Opera
17831794
if (ss[i].readyState == "loaded"
17841795
&& ss[i].src != null && ss[i].src.length != 0) {
17851796
ClazzLoader.innerLoadedScripts[ss[i].src] = true;
@@ -2053,6 +2064,13 @@ ClazzLoader.queueBe4KeyClazz = new Array ();
20532064
/* private */
20542065
/*-# getJ2SLibBase -> gLB #-*/
20552066
ClazzLoader.getJ2SLibBase = function () {
2067+
var o = window["j2s.lib"];
2068+
if (o != null) {
2069+
if (o.base == null) {
2070+
o.base = "http://archive.java2script.org/";
2071+
}
2072+
return o.base + (o.alias ? o.alias : (o.version ? o.version : "1.0.0")) + "/";
2073+
}
20562074
var ss = document.getElementsByTagName ("SCRIPT");
20572075
for (var i = 0; i < ss.length; i++) {
20582076
var src = ss[i].src;
@@ -2154,23 +2172,32 @@ ClazzLoader.loadClass = function (name, optionalsLoaded, forced, async) {
21542172
/*-# needBeingQueued -> nQ #-*/
21552173
var needBeingQueued = false;
21562174
var qq = ClazzLoader.classQueue;
2175+
//error (qq.length + ":" + qq);
2176+
//error (path);
21572177
for (var i = qq.length - 1; i >= 0; i--) {
21582178
if (qq[i].status != ClazzNode.STATUS_OPTIONALS_LOADED) {
21592179
needBeingQueued = true;
21602180
break;
21612181
}
21622182
}
2163-
/*
2164-
if (forced) {
2183+
if (path.lastIndexOf ("package.js") == path.length - 10) {//forced
21652184
// push class to queue
2185+
var inserted = false;
21662186
for (var i = qq.length - 1; i >= 0; i--) {
2187+
var name = qq[i].name;
2188+
if (name.lastIndexOf ("package.js") == name.length - 10) {
2189+
qq[i + 1] = n;
2190+
inserted = true;
2191+
break;
2192+
}
21672193
qq[i + 1] = qq[i];
21682194
}
2169-
qq[0] = n;
2195+
if (!inserted) {
2196+
qq[0] = n;
2197+
}
21702198
} else {
2171-
//*/
21722199
qq[qq.length] = n;
2173-
//}
2200+
}
21742201
if (!needBeingQueued) { // can be loaded directly
21752202
/*-# bakEntryClassLoading -> bkECL #-*/
21762203
var bakEntryClassLoading = false;

sources/net.sf.j2s.java.core/src/java/package.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ window["java.registered"] = false;
9494
"$.Method"
9595
]);
9696
base = base.substring (0, base.lastIndexOf ("java/"));
97-
ClazzLoader.jarClasspath (base + "/org/apache/harmony/luni/util/Msg.js",
97+
ClazzLoader.jarClasspath (base + "org/apache/harmony/luni/util/Msg.js",
9898
["org.apache.harmony.luni.util.Msg"]);
99-
ClazzLoader.jarClasspath (base + "/org/apache/harmony/luni/util/MsgHelp.js",
99+
ClazzLoader.jarClasspath (base + "org/apache/harmony/luni/util/MsgHelp.js",
100100
["org.apache.harmony.luni.util.MsgHelp"]);
101101
}) ();
102102

0 commit comments

Comments
 (0)