Skip to content

Commit ebfe5ce

Browse files
author
zhourenjian
committed
1. Fix a bug that super#toString which is Object#toString may causes incorrect calling exceptions.
2. Fix bug that the lastMethod caches inside delegating methods blocks Java2Script Hotspot to work correctly. 3. Other bug-fix
1 parent fa7eb94 commit ebfe5ce

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,8 @@ Clazz.superCall = function (objThis, clazzThis, funName, funParams) {
497497
// This is a single method, call directly!
498498
fx = clazzFun;
499499
}
500+
} else if (clazzFun.stacks == null) { // super.toString
501+
fx = clazzFun;
500502
} else { // normal wrapped method
501503
var stacks = clazzFun.stacks;
502504
var length = stacks.length;

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,18 @@ Clazz.forName = function (clazzName) {
813813

814814
/* For hotspot and unloading */
815815

816+
/* private */
817+
Clazz.cleanDelegateMethod = function (m) {
818+
if (m == null) return;
819+
if (typeof m == "function" && m.lastMethod != null
820+
&& m.lastParams != null && m.lastClaxxRef != null) {
821+
m.lastMethod = null;
822+
m.lastParams = null;
823+
m.lastClaxxRef = null;
824+
}
825+
};
826+
827+
/* public */
816828
Clazz.unloadClass = function (qClazzName) {
817829
var cc = Clazz.evalType (qClazzName);
818830
if (cc != null) {
@@ -855,6 +867,13 @@ Clazz.unloadClass = function (qClazzName) {
855867
}
856868
}
857869
}
870+
871+
for (var m in cc) {
872+
Clazz.cleanDelegateMethod (cc[m]);
873+
}
874+
for (var m in cc.prototype) {
875+
Clazz.cleanDelegateMethod (cc.prototype[m]);
876+
}
858877

859878
if (window["ClazzLoader"] != null) {
860879
ClazzLoader.unloadClassExt (qClazzName);

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@
114114
# xxxoptionals -> so
115115
# declaration -> dcl
116116
# optionalsLoaded -> oled
117+
# qClazzName ->Nq
117118
#-*/
118119

119120
/**
@@ -2515,7 +2516,7 @@ ClazzLoader.updateHotspot = function () {
25152516
return function () {
25162517
// succeeded!
25172518
if (window["ClassLoaderProgressMonitor"] != null) {
2518-
ClassLoaderProgressMonitor.showStatus ("Class " + qClazzName + " is reloaded.", true);
2519+
ClassLoaderProgressMonitor.showStatus ("Class " + clazz + " is reloaded.", true);
25192520
}
25202521
Clazz.unloadedClasses[clazz] = null;
25212522
};
@@ -2569,15 +2570,19 @@ ClazzLoader.hotspotMonitoring = function () {
25692570
script.src = hotspotURL;
25702571
if (typeof (script.onreadystatechange) == "undefined") { // W3C
25712572
script.onload = script.onerror = function () {
2572-
ClazzLoader.lastHotspotScriptLoaded = true;
2573-
ClazzLoader.removeHotspotScriptNode (this);
2573+
try {
2574+
ClazzLoader.lastHotspotScriptLoaded = true;
2575+
ClazzLoader.removeHotspotScriptNode (this);
2576+
} catch (e) {}; // refreshing browser may cause exceptions
25742577
};
25752578
} else {
25762579
script.onreadystatechange = function () {
25772580
var state = "" + this.readyState;
25782581
if (state == "loaded" || state == "complete") {
2579-
ClazzLoader.lastHotspotScriptLoaded = true;
2580-
ClazzLoader.removeHotspotScriptNode (this);
2582+
try {
2583+
ClazzLoader.lastHotspotScriptLoaded = true;
2584+
ClazzLoader.removeHotspotScriptNode (this);
2585+
} catch (e) {}; // refreshing browser may cause exceptions
25812586
}
25822587
};
25832588
}

0 commit comments

Comments
 (0)