Skip to content

Commit 1c7654a

Browse files
author
jossonsmith
committed
Support loading JavaScript dynamically:
Implementing ClassLoader, and wrapping class Console and others
1 parent ae5e2ea commit 1c7654a

23 files changed

+2247
-523
lines changed

sources/net.sf.j2s.java.core/.j2s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#Java2Script Configuration
2-
#Thu Jun 15 00:01:08 CST 2006
2+
#Thu Jul 13 21:43:16 CST 2006
33
j2s.compiler.visitor=SWTScriptVisitor
44
j2s.abandoned.resources.list=bin/net/sf/j2s/java/core/CorePlugin.js,bin/net/sf/j2s/java/core/RegExCompress.js,bin/net/sf/j2s/java/core/Bundle2StringUtil.js
55
j2s.compiler.abbreviation=true

sources/net.sf.j2s.java.core/j2score/Class.js

Lines changed: 90 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,24 @@
1515
* @author josson smith
1616
* @create Nov 5, 2005
1717
*******/
18-
18+
19+
/*-#
20+
# _x_CLASS_NAME__ -> C$N
21+
# _x_PKG_NAME__ -> P$N
22+
#
23+
# clazzThis -> Tz
24+
# objThis -> To
25+
# clazzHost -> Hz
26+
# hostThis -> Th
27+
# hostSuper -> Sh
28+
# clazzFun -> Fc
29+
# clazzName -> Nc
30+
# funName -> Nf
31+
# funBody -> Bf
32+
# objType -> oT
33+
#
34+
# qClazzName ->Nq
35+
#-*/
1936
/**
2037
* Class Clazz. All the methods are static in this class.
2138
*/
@@ -52,6 +69,7 @@ Clazz.getClassName = function (clazzHost) {
5269
/* user defined class name */
5370
return clazz.__CLASS_NAME__;
5471
}
72+
/*-# clazzStr -> Sc #-*/
5573
var clazzStr = clazz.toString ();
5674
var idx0 = clazzStr.indexOf ("function");
5775
if (idx0 == -1) {
@@ -166,6 +184,7 @@ Clazz.getClass = function (clazzHost) {
166184
* Be used to copy members of class
167185
*/
168186
/* protected */
187+
/*-# extendsProperties -> eP #-*/
169188
Clazz.extendsProperties = function (hostThis, hostSuper) {
170189
for (var o in hostSuper) {
171190
if (o != "prototype" && o != "superClazz"
@@ -177,6 +196,7 @@ Clazz.extendsProperties = function (hostThis, hostSuper) {
177196
};
178197

179198
/* private */
199+
/*-# checkInnerFunction -> cIF #-*/
180200
Clazz.checkInnerFunction = function (hostSuper, funName) {
181201
for (var k = 0; k < Clazz.innerFunctionNames.length; k++) {
182202
if (funName == Clazz.innerFunctionNames[k] &&
@@ -191,6 +211,7 @@ Clazz.checkInnerFunction = function (hostSuper, funName) {
191211
* Be used to copy members of interface
192212
*/
193213
/* protected */
214+
/*-# implementsProperties -> ip #-*/
194215
Clazz.implementsProperties = function (hostThis, hostSuper) {
195216
for (var o in hostSuper) {
196217
if (o != "prototype" && o != "superClazz"
@@ -222,6 +243,7 @@ Clazz.implementsProperties = function (hostThis, hostSuper) {
222243
*/
223244
};
224245

246+
/*-# args4InheritClass -> aIC #-*/
225247
Clazz.args4InheritClass = function () {
226248
};
227249
Clazz.inheritArgs = new Clazz.args4InheritClass ();
@@ -235,7 +257,12 @@ Clazz.inheritArgs = new Clazz.args4InheritClass ();
235257
* @param clazzSuper super class which is inherited from
236258
* @param objSuper super class instance
237259
*/
238-
/* public */
260+
/* protected */
261+
/*-#
262+
# inheritClass -> xic
263+
#
264+
# objSuper -> oSp
265+
#-*/
239266
Clazz.inheritClass = function (clazzThis, clazzSuper, objSuper) {
240267
//var thisClassName = Clazz.getClassName (clazzThis);
241268
Clazz.extendsProperties (clazzThis, clazzSuper);
@@ -302,6 +329,11 @@ Clazz.implementOf = function (clazzThis, interfacez) {
302329
Clazz.extendInterface = Clazz.implementOf;
303330

304331
/* protected */
332+
/*-#
333+
# equalsOrExtendsLevel -> eOE
334+
#
335+
# clazzAncestor -> anc
336+
#-*/
305337
Clazz.equalsOrExtendsLevel = function (clazzThis, clazzAncestor) {
306338
if (clazzThis == clazzAncestor) {
307339
return 0;
@@ -336,6 +368,12 @@ Clazz.getClassNameEvalStr = function (clazzVarName, clazzName) {
336368
*/
337369

338370
/* protected */
371+
/*-#
372+
# getInheritedLevel -> gIL
373+
#
374+
# clazzBase -> bs
375+
# clazzTarget -> tg
376+
#-*/
339377
Clazz.getInheritedLevel = function (clazzTarget, clazzBase) {
340378
if (clazzTarget == clazzBase) {
341379
return 0;
@@ -501,6 +539,7 @@ Clazz.superCall = function (objThis, clazzThis, funName, funParams) {
501539
ss[0].con$truct.apply (objThis, []);
502540
}
503541
}
542+
/*# {$no.debug.support} >>x #*/
504543
if (Clazz.tracingCalling) {
505544
var caller = arguments.callee.caller;
506545
if (caller == Clazz.superConstructor) {
@@ -511,6 +550,7 @@ Clazz.superCall = function (objThis, clazzThis, funName, funParams) {
511550
Clazz.p0pCalling ();
512551
return ret;
513552
}
553+
/*# x<< #*/
514554
return fx.apply (objThis, (funParams == null) ? [] : funParams);
515555
} else if (funName == "construct") {
516556
/* there are members which are initialized out of the constructor */
@@ -608,6 +648,7 @@ Clazz.MethodNotFoundException = function () {
608648
};
609649

610650
/* private */
651+
/*-# getParamsType -> gPT #-*/
611652
Clazz.getParamsType = function (funParams) {
612653
var params = new Array ();
613654
params.hasCastedNull = false;
@@ -640,6 +681,7 @@ Clazz.getParamsType = function (funParams) {
640681
* @throws Clazz.MethodNotFoundException if no matched method is found
641682
*/
642683
/* protected */
684+
/*-# searchAndExecuteMethod -> saem #-*/
643685
Clazz.searchAndExecuteMethod = function (objThis, claxxRef, fxName, funParams) {
644686
var params = Clazz.getParamsType (funParams);
645687
var fx = objThis[fxName];
@@ -733,8 +775,6 @@ Clazz.searchAndExecuteMethod = function (objThis, claxxRef, fxName, funParams) {
733775
fxName, params.typeString);
734776
};
735777

736-
var fNullCount = 0;
737-
738778
/*
739779
* Internet Explorer will result the following expression as 1, while the
740780
* other browser will have result of 2.
@@ -744,9 +784,12 @@ var fNullCount = 0;
744784
/* private */
745785
Clazz.ie$plit = "\\2".split (/\\/).length == 1;
746786

787+
/*# {$no.debug.support} >>x #*/
747788
Clazz.tracingCalling = false;
789+
/*# x<< #*/
748790

749791
/* private */
792+
/*-# tryToSearchAndExecute -> tsae #-*/
750793
Clazz.tryToSearchAndExecute = function (objThis, clazzFun, params, funParams/*,
751794
isSuper, clazzThis*/, fx) {
752795
var methods = new Array ();
@@ -829,6 +872,7 @@ Clazz.tryToSearchAndExecute = function (objThis, clazzFun, params, funParams/*,
829872
} else {
830873
methodParams = funParams;
831874
}
875+
/*# {$no.debug.support} >>x #*/
832876
if (Clazz.tracingCalling) {
833877
var caller = arguments.callee.caller; // SAEM
834878
caller = caller.arguments.callee.caller; // Delegating
@@ -878,6 +922,7 @@ Clazz.tryToSearchAndExecute = function (objThis, clazzFun, params, funParams/*,
878922
}
879923
return ret;
880924
}
925+
/*# x<< #*/
881926
fx.lastMethod = f;
882927
return f.apply (objThis, methodParams);
883928
//}
@@ -886,7 +931,9 @@ Clazz.tryToSearchAndExecute = function (objThis, clazzFun, params, funParams/*,
886931
return new Clazz.MethodException ();
887932
};
888933

934+
/*# {$no.debug.support} >>x #*/
889935
Clazz.initializingException = false;
936+
/*# x<< #*/
890937

891938
/**
892939
* Search the existed polynomial methods to get the matched method with
@@ -897,6 +944,12 @@ Clazz.initializingException = false;
897944
* @return string of method parameters seperated by "\\"
898945
*/
899946
/* private */
947+
/*-#
948+
# searchMethod -> sM
949+
#
950+
# roundOne -> rO
951+
# paramTypes -> pts
952+
#-*/
900953
Clazz.searchMethod = function (roundOne, paramTypes) {
901954
/*
902955
var roundOne = new Array ();
@@ -915,8 +968,10 @@ Clazz.searchMethod = function (roundOne, paramTypes) {
915968
/*
916969
* Filter out all the fitted methods for the given parameters
917970
*/
971+
/*-# roundTwo -> rT #-*/
918972
var roundTwo = new Array ();
919973
for (var i = 0; i < roundOne.length; i++) {
974+
/*-# fittedLevel -> fL #-*/
920975
var fittedLevel = new Array ();
921976
var isFitted = true;
922977
for (var j = 0; j < roundOne[i].length; j++) {
@@ -938,9 +993,11 @@ Clazz.searchMethod = function (roundOne, paramTypes) {
938993
/*
939994
* Find out the best method according to the inheritance.
940995
*/
996+
/*-# resultTwo -> rtT #-*/
941997
var resultTwo = roundTwo;
942998
var min = resultTwo[0];
943999
for (var i = 1; i < resultTwo.length; i++) {
1000+
/*-# isVectorLesser -> vl #-*/
9441001
var isVectorLesser = true;
9451002
for (var j = 0; j < paramTypes.length; j++) {
9461003
if (min[j] < resultTwo[i][j]) {
@@ -980,6 +1037,7 @@ Clazz.searchMethod = function (roundOne, paramTypes) {
9801037
* from the given class by the parameters
9811038
*/
9821039
/* private */
1040+
/*-# generateDelegatingMethod -> gDM #-*/
9831041
Clazz.generateDelegatingMethod = function (claxxRef, funName) {
9841042
/*
9851043
* Delegating method.
@@ -1003,28 +1061,13 @@ SAEM = Clazz.searchAndExecuteMethod;
10031061
*/
10041062
/* protected */
10051063
Clazz.formatParameters = function (funParams) {
1006-
if (funParams != null && funParams.length != 0) {
1064+
if (funParams == null || funParams.length == 0) {
1065+
return "\\void";
1066+
} else {
10071067
/*
10081068
* If funParams is Array, funParams.toString() will
10091069
* also return "*,*,..." string.
10101070
*/
1011-
/*
1012-
var paramStr = funParams.toString ().replace (/\s/g, "");
1013-
if (paramStr.length != 0) {
1014-
//var params = paramStr.split (/,/);
1015-
//fpName += "\\" + params.join ('\\');
1016-
fpName = "\\" + paramStr.replace (/,/g, "\\");
1017-
} else {
1018-
fpName += "\\void";
1019-
}
1020-
*/
1021-
/*
1022-
if (typeof funParams == "string") {
1023-
fpName = "\\" + funParams.replace (/\s*,\s+/g, "\\");
1024-
} else {
1025-
fpName = "\\" + funParams.join ("\\");
1026-
}
1027-
*/
10281071
var s = funParams.toString ();
10291072
s = s.replace (/~([NABSO])/g, function ($0, $1) {
10301073
if ($1 == 'N') {
@@ -1040,11 +1083,11 @@ Clazz.formatParameters = function (funParams) {
10401083
}
10411084
return "Unknown";
10421085
});
1043-
return "\\" + s.replace (/\s+/g, "").replace (/,/g, "\\");
1044-
} else {
1045-
return "\\void";
1086+
return s.replace (/\s+/g, "").replace (/^|,/g, "\\")
1087+
.replace (/\$/g, "org.eclipse.s");
10461088
}
10471089
};
1090+
10481091
/*
10491092
* Override the existed methods which are in the same name.
10501093
* Overriding methods is provided for the purpose that the JavaScript
@@ -1278,6 +1321,7 @@ Clazz.declarePackage = function (pkgName) {
12781321
};
12791322

12801323
/* protected */
1324+
/*-# evalType -> eT #-*/
12811325
Clazz.evalType = function (typeStr, isQualified) {
12821326
//*
12831327
var idx = typeStr.lastIndexOf (".");
@@ -1348,10 +1392,12 @@ Clazz.defineType = function (qClazzName, clazzFun, clazzParent, interfacez) {
13481392
window[qClazzName] = clazzFun;
13491393
}
13501394
Clazz.decorateAsType (clazzFun, qClazzName, clazzParent, interfacez);
1395+
/*# {$no.javascript.support} >>x #*/
13511396
var iFun = Clazz.innerFunctions;
13521397
clazzFun.defineMethod = iFun.defineMethod;
13531398
clazzFun.defineStaticMethod = iFun.defineStaticMethod;
13541399
clazzFun.makeConstructor = iFun.makeConstructor;
1400+
/*# x<< #*/
13551401
return clazzFun;
13561402
};
13571403

@@ -1411,14 +1457,16 @@ Clazz.instantialize = function (objThis, args) {
14111457
* be function.
14121458
*/
14131459
/* protected */
1460+
/*-# innerFunctionNames -> iFN #-*/
14141461
Clazz.innerFunctionNames = [
1415-
"equals", "getName", "defineMethod", "defineStaticMethod",
1416-
"makeConstructor"
1462+
"equals", "getName" /*# {$no.javascript.support} >>x #*/, "defineMethod", "defineStaticMethod",
1463+
"makeConstructor" /*# x<< #*/
14171464
];
14181465

14191466
/*
14201467
* Static methods
14211468
*/
1469+
/*x-# innerFunctions -> inF #-x*/
14221470
Clazz.innerFunctions = {
14231471
/*
14241472
* Similar to Object#equals
@@ -1475,7 +1523,8 @@ Clazz.innerFunctions = {
14751523
}
14761524
}
14771525
return is;
1478-
},
1526+
}/*# {$no.javascript.support} >>x #*/,
1527+
14791528
/*
14801529
* For JavaScript programmers
14811530
*/
@@ -1497,9 +1546,11 @@ Clazz.innerFunctions = {
14971546
makeConstructor : function (funBody, paramTypes) {
14981547
Clazz.makeConstructor (this, funBody, paramTypes);
14991548
}
1549+
/*# x<< #*/
15001550
};
15011551

15021552
/* private */
1553+
/*-# decorateFunction -> dF #-*/
15031554
Clazz.decorateFunction = function (clazzFun, prefix, name) {
15041555
var qName = null;
15051556
if (prefix == null) {
@@ -1539,12 +1590,16 @@ Clazz.declareInterface = function (prefix, name, interfacez) {
15391590
};
15401591

15411592
/* protected */
1593+
/*-#
1594+
# parentClazzInstance -> pi
1595+
# clazzParent -> pc
1596+
#-*/
15421597
Clazz.decorateAsClass = function (clazzFun, prefix, name, clazzParent,
1543-
interfacez, clazzParentInstance) {
1598+
interfacez, parentClazzInstance) {
15441599
var qName = null;
15451600
Clazz.decorateFunction (clazzFun, prefix, name);
1546-
if (clazzParentInstance != null) {
1547-
Clazz.inheritClass (clazzFun, clazzParent, clazzParentInstance);
1601+
if (parentClazzInstance != null) {
1602+
Clazz.inheritClass (clazzFun, clazzParent, parentClazzInstance);
15481603
} else if (clazzParent != null) {
15491604
Clazz.inheritClass (clazzFun, clazzParent);
15501605
}
@@ -1556,7 +1611,7 @@ Clazz.decorateAsClass = function (clazzFun, prefix, name, clazzParent,
15561611

15571612
/* protected */
15581613
Clazz.decorateAsType = function (clazzFun, qClazzName, clazzParent,
1559-
interfacez, clazzParentInstance) {
1614+
interfacez, parentClazzInstance) {
15601615
clazzFun.__CLASS_NAME__ = qClazzName;
15611616
//if (qClazzName != "String" && qClazzName != "Object"
15621617
// && qClazzName != "Number" && qClazzName != "Date") {
@@ -1570,8 +1625,8 @@ Clazz.decorateAsType = function (clazzFun, qClazzName, clazzParent,
15701625
clazzFun[methodName] = Clazz.innerFunctions[methodName];
15711626
}
15721627
*/
1573-
if (clazzParentInstance != null) {
1574-
Clazz.inheritClass (clazzFun, clazzParent, clazzParentInstance);
1628+
if (parentClazzInstance != null) {
1629+
Clazz.inheritClass (clazzFun, clazzParent, parentClazzInstance);
15751630
} else if (clazzParent != null) {
15761631
Clazz.inheritClass (clazzFun, clazzParent);
15771632
}
@@ -1582,8 +1637,4 @@ Clazz.decorateAsType = function (clazzFun, qClazzName, clazzParent,
15821637
};
15831638

15841639
Clazz.declarePackage ("java.lang");
1585-
Clazz.declarePackage ("java.lang.ref");
1586-
Clazz.declarePackage ("java.lang.ref.reflect");
1587-
Clazz.declarePackage ("java.lang.reflect");
1588-
Clazz.declarePackage ("java.io");
1589-
Clazz.declarePackage ("java.util");
1640+

0 commit comments

Comments
 (0)