Skip to content

Commit dd3fb0a

Browse files
author
zhourenjian
committed
Try to check updated classes inside another IFRAME element to avoid blocking other *.js loading.
1 parent 40c0663 commit dd3fb0a

File tree

1 file changed

+114
-27
lines changed

1 file changed

+114
-27
lines changed

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

Lines changed: 114 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2576,16 +2576,20 @@ ClazzLoader.updateHotspot = function () {
25762576
if (Clazz.assureInnerClass == null) {
25772577
Clazz.assureInnerClass = ClazzLoader.assureInnerClass;
25782578
}
2579-
var length = (arguments.length - 1) / 3;
2579+
var args = arguments[0];
2580+
//if (arguments.length != 1 || arguments[0] == null) {
2581+
// args = arguments;
2582+
//}
2583+
var length = (args.length - 1) / 3;
25802584
var lastID = 0;
25812585
/*-# lastUpdated -> lUd #-*/
25822586
var lastUpdated = 0;
25832587
/*-# toUpdateClasses -> tUs #-*/
25842588
var toUpdateClasses = new Array ();
25852589
for (var i = 0; i < length; i++) {
2586-
var time = arguments[i * 3];
2587-
var id = arguments[i * 3 + 1];
2588-
var clazz = arguments[i * 3 + 2];
2590+
var time = args[i * 3];
2591+
var id = args[i * 3 + 1];
2592+
var clazz = args[i * 3 + 2];
25892593
if ((time > ClazzLoader.lastHotspotUpdated)
25902594
|| (time == ClazzLoader.lastHotspotUpdated
25912595
&& id > ClazzLoader.lastHotspotSessionID)) {
@@ -2647,6 +2651,110 @@ ClazzLoader.hotspotJSTimeout = null;
26472651
/*-# lastHotspotJSFailed -> ltJF #-*/
26482652
ClazzLoader.lastHotspotJSFailed = false;
26492653

2654+
/* private */
2655+
ClazzLoader.loadHotspotScript = function (hotspotURL, iframeID) {
2656+
var script = document.createElement ("SCRIPT");
2657+
script.type = "text/javascript";
2658+
script.src = hotspotURL;
2659+
if (typeof (script.onreadystatechange) == "undefined") { // W3C
2660+
script.onload = script.onerror = function () {
2661+
try {
2662+
//if (iframeID != null) {
2663+
if (window.parent == null || window.parent["ClassLoader"] == null) return;
2664+
window.parent.ClassLoader.lastHotspotScriptLoaded = true;
2665+
var iframe = window.parent.document.getElementById (iframeID);
2666+
if (iframe != null) {
2667+
iframe.parentNode.removeChild (iframe);
2668+
if (window.parent.ClassLoader.hotspotMonitoringTimeout != null) {
2669+
window.parent.clearTimeout (window.parent.ClassLoader.hotspotMonitoringTimeout);
2670+
window.parent.ClassLoader.hotspotMonitoringTimeout = null;
2671+
}
2672+
}
2673+
// return;
2674+
//}
2675+
//ClazzLoader.lastHotspotScriptLoaded = true;
2676+
//ClazzLoader.removeHotspotScriptNode (this);
2677+
} catch (e) {}; // refreshing browser may cause exceptions
2678+
};
2679+
} else {
2680+
script.onreadystatechange = function () {
2681+
var state = "" + this.readyState;
2682+
if (state == "loaded" || state == "complete") {
2683+
try {
2684+
//if (iframeID != null) {
2685+
if (window.parent == null || window.parent["ClassLoader"] == null) return;
2686+
window.parent.ClassLoader.lastHotspotScriptLoaded = true;
2687+
var iframe = window.parent.document.getElementById (iframeID);
2688+
if (iframe != null) {
2689+
iframe.parentNode.removeChild (iframe);
2690+
if (window.parent.ClassLoader.hotspotMonitoringTimeout != null) {
2691+
window.parent.clearTimeout (window.parent.ClassLoader.hotspotMonitoringTimeout);
2692+
window.parent.ClassLoader.hotspotMonitoringTimeout = null;
2693+
}
2694+
}
2695+
// return;
2696+
//}
2697+
//ClazzLoader.lastHotspotScriptLoaded = true;
2698+
//ClazzLoader.removeHotspotScriptNode (this);
2699+
} catch (e) {}; // refreshing browser may cause exceptions
2700+
}
2701+
};
2702+
}
2703+
var head = document.getElementsByTagName ("HEAD")[0];
2704+
head.appendChild (script);
2705+
};
2706+
2707+
/* private */
2708+
ClazzLoader.iframeDocumentWrite = function (handle, html) {
2709+
if (handle.contentWindow != null) {
2710+
handle.contentWindow.location = "about:blank";
2711+
} else { // Opera
2712+
handle.src = "about:blank";
2713+
}
2714+
try {
2715+
handle.contentWindow.document.write (html);
2716+
handle.contentWindow.document.close ();
2717+
} catch (e) {
2718+
window.setTimeout ((function () {
2719+
return function () {
2720+
handle.contentWindow.document.write (html);
2721+
handle.contentWindow.document.close ();
2722+
};
2723+
}) (), 25);
2724+
}
2725+
};
2726+
2727+
/* private */
2728+
ClazzLoader.loadHostspotIFrame = function (hotspotURL) {
2729+
var iframe = document.createElement ("IFRAME");
2730+
iframe.style.display = "none";
2731+
var iframeID = null;
2732+
do {
2733+
iframeID = "hotspot-script-" + Math.round (10000000 * Math.random ());
2734+
} while (document.getElementById (iframeID) != null);
2735+
iframe.id = iframeID;
2736+
document.body.appendChild (iframe);
2737+
var html = "<html><head><title></title>";
2738+
html += "<script type=\"text/javascript\">\r\n";
2739+
html += "var Clazz" + "Loader = new Object ();\r\n";
2740+
html += "Clazz" + "Loader.updateHotspot = function () {\r\n";
2741+
html += " var args = new Array ();\r\n";
2742+
html += " for (var i = 0; i < arguments.length; i++) {\r\n";
2743+
html += " args[i] = arguments[i];\r\n";
2744+
html += " }\r\n";
2745+
html += " with (window.parent) {\r\n";
2746+
html += " ClassLoader.updateHotspot (args);\r\n";
2747+
html += " };\r\n";
2748+
html += "};\r\n";
2749+
html += "</scr" + "ipt></head><body><script type=\"text/javascript\">\r\n";
2750+
html += "(" + ClazzLoader.loadHotspotScript + ") (";
2751+
html += "\"" + hotspotURL.replace (/"/g, "\\\"") + "\", \"" + iframeID + "\"";
2752+
html += ");\r\n";
2753+
html += "</scr" + "ipt></body></html>";
2754+
ClazzLoader.iframeDocumentWrite (iframe, html);
2755+
return iframeID;
2756+
};
2757+
26502758
/* protected */
26512759
/*-# hotspotMonitoring -> htMr #-*/
26522760
ClazzLoader.hotspotMonitoring = function () {
@@ -2667,30 +2775,9 @@ ClazzLoader.hotspotMonitoring = function () {
26672775
ClazzLoader.lastHotspotJSFailed = true;
26682776
ClazzLoader.lastHotspotScriptLoaded = false;
26692777

2670-
var script = document.createElement ("SCRIPT");
2671-
script.type = "text/javascript";
2672-
script.src = hotspotURL;
2673-
if (typeof (script.onreadystatechange) == "undefined") { // W3C
2674-
script.onload = script.onerror = function () {
2675-
try {
2676-
ClazzLoader.lastHotspotScriptLoaded = true;
2677-
ClazzLoader.removeHotspotScriptNode (this);
2678-
} catch (e) {}; // refreshing browser may cause exceptions
2679-
};
2680-
} else {
2681-
script.onreadystatechange = function () {
2682-
var state = "" + this.readyState;
2683-
if (state == "loaded" || state == "complete") {
2684-
try {
2685-
ClazzLoader.lastHotspotScriptLoaded = true;
2686-
ClazzLoader.removeHotspotScriptNode (this);
2687-
} catch (e) {}; // refreshing browser may cause exceptions
2688-
}
2689-
};
2690-
}
2778+
//ClazzLoader.loadHotspotScript (hotspotURL);
2779+
ClazzLoader.loadHostspotIFrame (hotspotURL);
26912780

2692-
var head = document.getElementsByTagName ("HEAD")[0];
2693-
head.appendChild (script);
26942781
if (ClazzLoader.hotspotJSTimeout != null) {
26952782
window.clearTimeout (ClazzLoader.hotspotJSTimeout);
26962783
ClazzLoader.hotspotJSTimeout = null;

0 commit comments

Comments
 (0)