Skip to content

Commit 09a4cb7

Browse files
author
jossonsmith
committed
Support asynchronous Class.forName with net.sf.j2s.ajax.AClass.load (clazzName, ...).
See ControlExamples
1 parent 0913c47 commit 09a4cb7

3 files changed

Lines changed: 14 additions & 3 deletions

File tree

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,11 @@ Clazz.searchAndExecuteMethod = function (objThis, claxxRef, fxName, funParams) {
716716
} else {
717717
methodParams = funParams;
718718
}
719-
return fx.lastMethod.apply (objThis, methodParams);
719+
if (fx.lastMethod != null) {
720+
return fx.lastMethod.apply (objThis, methodParams);
721+
} else { // missed default constructor ?
722+
return ;
723+
}
720724
}
721725
fx.lastParams = params.typeString;
722726
fx.lastClaxxRef = claxxRef;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,9 @@ Clazz.innerFunctions.newInstance = function () {
736736
}
737737

738738
Clazz.forName = function (clazzName) {
739+
if (Clazz.isClassDefined (clazzName)) {
740+
return Clazz.evalType (clazzName);
741+
}
739742
if (window["ClazzLoader"] != null) {
740743
ClazzLoader.setLoadingMode ("xhr.sync");
741744
ClazzLoader.loadClass (clazzName);

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,7 +1318,7 @@ ClazzLoader.queueBe4KeyClazz = new Array ();
13181318
* Load the given class ant its related classes.
13191319
*/
13201320
/* public */
1321-
ClazzLoader.loadClass = function (name, optionalsLoaded, forced) {
1321+
ClazzLoader.loadClass = function (name, optionalsLoaded, forced, async) {
13221322
if (typeof optionalsLoaded == "boolean") {
13231323
return Clazz.evalType (name);
13241324
}
@@ -1367,7 +1367,11 @@ ClazzLoader.loadClass = function (name, optionalsLoaded, forced) {
13671367
}
13681368
}
13691369
} else if (optionalsLoaded != null && ClazzLoader.isClassDefined (name)) {
1370-
optionalsLoaded ();
1370+
if (async) {
1371+
window.setTimeout (optionalsLoaded, 25);
1372+
} else {
1373+
optionalsLoaded ();
1374+
}
13711375
}
13721376

13731377
};

0 commit comments

Comments
 (0)