Skip to content

Commit d81be5b

Browse files
author
zhourenjian
committed
Fixed bug#1843521 Stack overflow on evaluating instanceof operator
https://sourceforge.net/tracker/index.php?func=detail&aid=1843521&group_id=155436&atid=795800 Finally it turns out that it is a bug of misusing "==" results in unnecessary "#toString" invocation. "==" should be "===" and "!=" should be "!==" for class or object comparisons.
1 parent eb94cbf commit d81be5b

File tree

10 files changed

+57
-57
lines changed

10 files changed

+57
-57
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ Byte.prototype.valueOf = function () { return 0; };
77
Byte.toString = Byte.prototype.toString = function () {
88
if (arguments.length != 0) {
99
return "" + arguments[0];
10-
} else if (this == Byte) {
11-
return "[Byte]"; // Byte.toString
10+
} else if (this === Byte) {
11+
return "class java.lang.Byte"; // Byte.class.toString
1212
}
1313
return "" + this.valueOf ();
1414
};

sources/net.sf.j2s.java.core/src/java/lang/Character.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,8 @@ public String toString() {
357357
public static String toString(char c) {
358358
/**
359359
* @j2sNative
360-
* if (this == Charater) {
361-
* return "[Charater]";
360+
* if (this === Charater) {
361+
* return "class java.lang.Charater"; // Charater.class.toString
362362
* }
363363
*/ {}
364364
return String.valueOf(c);

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

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ Clazz.extendsProperties = function (hostThis, hostSuper) {
210210
Clazz.checkInnerFunction = function (hostSuper, funName) {
211211
for (var k = 0; k < Clazz.innerFunctionNames.length; k++) {
212212
if (funName == Clazz.innerFunctionNames[k] &&
213-
Clazz.innerFunctions[funName] == hostSuper[funName]) {
213+
Clazz.innerFunctions[funName] === hostSuper[funName]) {
214214
return true;
215215
}
216216
}
@@ -285,7 +285,7 @@ Clazz.inheritClass = function (clazzThis, clazzSuper, objSuper) {
285285
// which is not referenced elsewhere.
286286
// March 13, 2006
287287
clazzThis.prototype = objSuper;
288-
} else if (clazzSuper != Number) {
288+
} else if (clazzSuper !== Number) {
289289
clazzThis.prototype = new clazzSuper (Clazz.inheritArgs);
290290
} else { // Number
291291
clazzThis.prototype = new Number ();
@@ -347,7 +347,7 @@ Clazz.extendInterface = Clazz.implementOf;
347347
# clazzAncestor -> anc
348348
#-*/
349349
Clazz.equalsOrExtendsLevel = function (clazzThis, clazzAncestor) {
350-
if (clazzThis == clazzAncestor) {
350+
if (clazzThis === clazzAncestor) {
351351
return 0;
352352
}
353353
if (clazzThis.implementz != null) {
@@ -370,7 +370,7 @@ Clazz.equalsOrExtendsLevel = function (clazzThis, clazzAncestor) {
370370
# clazzTarget -> tg
371371
#-*/
372372
Clazz.getInheritedLevel = function (clazzTarget, clazzBase) {
373-
if (clazzTarget == clazzBase) {
373+
if (clazzTarget === clazzBase) {
374374
return 0;
375375
}
376376
var isTgtStr = (typeof clazzTarget == "string");
@@ -385,9 +385,9 @@ Clazz.getInheritedLevel = function (clazzTarget, clazzBase) {
385385
* March 10, 2006
386386
*/
387387
if ((isTgtStr && "NullObject" == clazzTarget)
388-
|| NullObject == clazzTarget) {
389-
if (clazzBase != Number && clazzBase != Boolean
390-
&& clazzBase != NullObject) {
388+
|| NullObject === clazzTarget) {
389+
if (clazzBase !== Number && clazzBase !== Boolean
390+
&& clazzBase !== NullObject) {
391391
return 0;
392392
}
393393
}
@@ -402,7 +402,7 @@ Clazz.getInheritedLevel = function (clazzTarget, clazzBase) {
402402
}
403403
var level = 0;
404404
var zzalc = clazzTarget; // zzalc <--> clazz
405-
while (zzalc != clazzBase && level < 10) {
405+
while (zzalc !== clazzBase && level < 10) {
406406
/* maybe clazzBase is interface */
407407
if (zzalc.implementz != null) {
408408
var impls = zzalc.implementz;
@@ -417,7 +417,7 @@ Clazz.getInheritedLevel = function (clazzTarget, clazzBase) {
417417

418418
zzalc = zzalc.superClazz;
419419
if (zzalc == null) {
420-
if (clazzBase == Object) {
420+
if (clazzBase === Object) {
421421
/*
422422
* getInheritedLevel(String, CharSequence) == 1
423423
* getInheritedLevel(String, Object) == 1.5
@@ -493,7 +493,7 @@ Clazz.superCall = function (objThis, clazzThis, funName, funParams) {
493493
if (clazzFun != null) {
494494
if (clazzFun.claxxOwner != null) {
495495
// claxxOwner is a mark for methods that is single.
496-
if (clazzFun.claxxOwner != clazzThis) {
496+
if (clazzFun.claxxOwner !== clazzThis) {
497497
// This is a single method, call directly!
498498
fx = clazzFun;
499499
}
@@ -509,7 +509,7 @@ Clazz.superCall = function (objThis, clazzThis, funName, funParams) {
509509
* comparision
510510
*/
511511
//var level = Clazz.getInheritedLevel (clazzThis, stacks[i]);
512-
if (clazzThis == stacks[i]) { // level == 0
512+
if (clazzThis === stacks[i]) { // level == 0
513513
if (i > 0) {
514514
i--;
515515
fx = stacks[i].prototype[funName];
@@ -549,7 +549,7 @@ Clazz.superCall = function (objThis, clazzThis, funName, funParams) {
549549
/*# {$no.debug.support} >>x #*/
550550
if (Clazz.tracingCalling) {
551551
var caller = arguments.callee.caller;
552-
if (caller == Clazz.superConstructor) {
552+
if (caller === Clazz.superConstructor) {
553553
caller = caller.arguments.callee.caller;
554554
}
555555
Clazz.pu$hCalling (new Clazz.callingStack (caller, clazzThis));
@@ -695,7 +695,7 @@ Clazz.searchAndExecuteMethod = function (objThis, claxxRef, fxName, funParams) {
695695
/*
696696
* Cache last matched method
697697
*/
698-
if (fx.lastParams == params.typeString && fx.lastClaxxRef == claxxRef) {
698+
if (fx.lastParams == params.typeString && fx.lastClaxxRef === claxxRef) {
699699
var methodParams = null;
700700
if (params.hasCastedNull) {
701701
methodParams = new Array ();
@@ -736,10 +736,10 @@ Clazz.searchAndExecuteMethod = function (objThis, claxxRef, fxName, funParams) {
736736
* right claxxRef in the stacks, and the inherited level of stacks
737737
* are in order.
738738
*/
739-
if (began || stacks[i] == claxxRef) {
739+
if (began || stacks[i] === claxxRef) {
740740
/*
741741
* First try to search method within the same class scope
742-
* with stacks[i] == claxxRef
742+
* with stacks[i] === claxxRef
743743
*/
744744
var clazzFun = stacks[i].prototype[fxName];
745745

@@ -752,7 +752,7 @@ Clazz.searchAndExecuteMethod = function (objThis, claxxRef, fxName, funParams) {
752752
* As there are no such methods in current class, Clazz will try
753753
* to search its super class stacks. Here variable began indicates
754754
* that super searchi is began, and there is no need checking
755-
* <code>stacks[i] == claxxRef</code>
755+
* <code>stacks[i] === claxxRef</code>
756756
*/
757757
began = true;
758758
} // end of if
@@ -894,8 +894,8 @@ Clazz.tryToSearchAndExecute = function (objThis, clazzFun, params, funParams/*,
894894
Clazz.pu$hCalling (new Clazz.callingStack (xcaller, owner));
895895
}
896896

897-
var noInnerWrapper = caller != Clazz.instantialize
898-
&& caller != Clazz.superCall;
897+
var noInnerWrapper = caller !== Clazz.instantialize
898+
&& caller !== Clazz.superCall;
899899
if (noInnerWrapper) {
900900
var fun = caller.arguments.callee;
901901
var owner = fun.claxxReference;
@@ -1120,7 +1120,7 @@ Clazz.defineMethod = function (clazzThis, funName, funBody, funParams) {
11201120
* wrapping into deep hierarchies!
11211121
*/
11221122
var f$ = clazzThis.prototype[funName];
1123-
if (f$ == null || (f$.claxxOwner == clazzThis
1123+
if (f$ == null || (f$.claxxOwner === clazzThis
11241124
&& f$.funParams == fpName)) {
11251125
// property "funParams" will be used as a mark of only-one method
11261126
funBody.funParams = fpName;
@@ -1154,7 +1154,7 @@ Clazz.defineMethod = function (clazzThis, funName, funBody, funParams) {
11541154
*/
11551155
//oldStacks[0] = oldFun.claxxOwner;
11561156
/*
1157-
if (oldFun.claxxOwner != clazzThis) {
1157+
if (oldFun.claxxOwner !== clazzThis) {
11581158
if ("releaseChild" == funName) {
11591159
error (" in here ");
11601160
}
@@ -1182,7 +1182,7 @@ Clazz.defineMethod = function (clazzThis, funName, funBody, funParams) {
11821182
/* method is defined in super class */
11831183
if (/*f$ == null
11841184
|| */f$.stacks == null
1185-
|| f$.claxxReference != clazzThis) {
1185+
|| f$.claxxReference !== clazzThis) {
11861186
/*
11871187
* Generate a new delegating method for the class
11881188
*/
@@ -1199,12 +1199,12 @@ Clazz.defineMethod = function (clazzThis, funName, funBody, funParams) {
11991199
}
12001200
var ss = f$.stacks;
12011201

1202-
if (ss.length == 0/* || ss[ss.length - 1] != clazzThis*/) {
1202+
if (ss.length == 0/* || ss[ss.length - 1] !== clazzThis*/) {
12031203
ss[ss.length] = clazzThis;
12041204
} else {
12051205
var existed = false;
12061206
for (var i = ss.length - 1; i >= 0; i--) {
1207-
if (ss[i] == clazzThis) {
1207+
if (ss[i] === clazzThis) {
12081208
existed = true;
12091209
break;
12101210
}
@@ -1215,7 +1215,7 @@ Clazz.defineMethod = function (clazzThis, funName, funBody, funParams) {
12151215
}
12161216

12171217
if (oldFun != null) {
1218-
if (oldFun.claxxOwner == clazzThis) {
1218+
if (oldFun.claxxOwner === clazzThis) {
12191219
f$[oldFun.funParams] = oldFun;
12201220
oldFun.claxxOwner = null;
12211221
// property "funParams" will be used as a mark of only-one method
@@ -1417,7 +1417,7 @@ Clazz.instantialize = function (objThis, args) {
14171417
objThis.con$truct.apply (objThis, []);
14181418
c.apply (objThis, args);
14191419
} else if ((c.claxxOwner != null
1420-
&& c.claxxOwner == objThis.getClass ())
1420+
&& c.claxxOwner === objThis.getClass ())
14211421
|| (c.stacks != null
14221422
&& c.stacks[c.stacks.length - 1] == objThis.getClass ())) {
14231423
/*
@@ -1466,7 +1466,7 @@ Clazz.innerFunctions = {
14661466
* Similar to Object#equals
14671467
*/
14681468
equals : function (aFun) {
1469-
return this == aFun;
1469+
return this === aFun;
14701470
},
14711471

14721472
/*
@@ -1579,7 +1579,7 @@ Clazz.decorateFunction = function (clazzFun, prefix, name) {
15791579
// org.eclipse.ui.IPlugin);
15801580
qName = prefix.__PKG_NAME__ + "." + name;
15811581
prefix[name] = clazzFun;
1582-
if (prefix == java.lang) {
1582+
if (prefix === java.lang) {
15831583
window[name] = clazzFun;
15841584
}
15851585
} else {

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ Clazz.MethodNotFoundException = function (obj, clazz, method, params) {
6060
Clazz.prepareCallback = function (objThis, args) {
6161
var classThisObj = args[0];
6262
var cbName = "b$"; // "callbacks";
63-
if (objThis != null && classThisObj != null && classThisObj != window) {
63+
if (objThis != null && classThisObj != null && classThisObj !== window) {
6464
var obs = new Array ();
6565
if (objThis[cbName] == null) {
6666
objThis[cbName] = obs;
@@ -126,7 +126,7 @@ Clazz.innerTypeInstance = function (clazzInner, objThis, finalVars) {
126126
obj = new clazzInner (objThis);
127127
} else if (arguments.length == 4) {
128128
if (objThis.__CLASS_NAME__ == clazzInner.__CLASS_NAME__
129-
&& arguments[3] == Clazz.inheritArgs) {
129+
&& arguments[3] === Clazz.inheritArgs) {
130130
obj = objThis;
131131
} else {
132132
obj = new clazzInner (objThis, arguments[3]);
@@ -434,13 +434,13 @@ Clazz.getMixedCallerMethod = function (args) {
434434
var o = new Object ();
435435
var argc = args.callee.caller; // Clazz.tryToSearchAndExecute
436436
if (argc == null) return null;
437-
if (argc != Clazz.tryToSearchAndExecute) { // inherited method's apply
437+
if (argc !== Clazz.tryToSearchAndExecute) { // inherited method's apply
438438
argc = argc.arguments.callee.caller;
439439
if (argc == null) return null;
440440
}
441-
if (argc != Clazz.tryToSearchAndExecute) return null;
441+
if (argc !== Clazz.tryToSearchAndExecute) return null;
442442
argc = argc.arguments.callee.caller; // Clazz.searchAndExecuteMethod
443-
if (argc == null || argc != Clazz.searchAndExecuteMethod) return null;
443+
if (argc == null || argc !== Clazz.searchAndExecuteMethod) return null;
444444
o.claxxRef = argc.arguments[1];
445445
o.fxName = argc.arguments[2];
446446
o.paramTypes = Clazz.getParamsType (argc.arguments[3]);
@@ -483,11 +483,11 @@ Clazz.checkPrivateMethod = function (args) {
483483
var stacks = callerFx.stacks;
484484
for (var i = stacks.length - 1; i >= 0; i--) {
485485
var fx = stacks[i].prototype[m.caller.exName];
486-
if (fx == m.caller) {
486+
if (fx === m.caller) {
487487
ppFun = stacks[i].prototype[m.fxName];
488488
} else if (fx != null) {
489489
for (var fn in fx) {
490-
if (fn.indexOf ('\\') == 0 && fx[fn] == m.caller) {
490+
if (fn.indexOf ('\\') == 0 && fx[fn] === m.caller) {
491491
ppFun = stacks[i].prototype[m.fxName];
492492
break;
493493
}
@@ -501,7 +501,7 @@ Clazz.checkPrivateMethod = function (args) {
501501
if (ppFun != null && ppFun.claxxOwner == null) {
502502
ppFun = ppFun["\\" + m.paramTypes];
503503
}
504-
if (ppFun != null && ppFun.isPrivate && ppFun != args.callee) {
504+
if (ppFun != null && ppFun.isPrivate && ppFun !== args.callee) {
505505
return ppFun;
506506
}
507507
return null;
@@ -711,7 +711,7 @@ System = {
711711
System.props.setProperty (key, val);
712712
},
713713
arraycopy : function (src, srcPos, dest, destPos, length) {
714-
if (src != dest) {
714+
if (src !== dest) {
715715
for (var i = 0; i < length; i++) {
716716
dest[destPos + i] = src[srcPos + i];
717717
}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,7 +1320,7 @@ ClazzLoader.tryToLoadNext = function (file) {
13201320
}
13211321
var lastNode = null;
13221322
while ((n = ClazzLoader.findNextOptionalClass (ClazzNode.STATUS_CONTENT_LOADED)) != null) {
1323-
if (lastNode == n) { // Already existed cycle ?
1323+
if (lastNode === n) { // Already existed cycle ?
13241324
n.status = ClazzNode.STATUS_OPTIONALS_LOADED;
13251325
}
13261326
ClazzLoader.updateNode (n);
@@ -1330,13 +1330,13 @@ ClazzLoader.tryToLoadNext = function (file) {
13301330
}
13311331
lastNode = null;
13321332
while ((n = ClazzLoader.findNextMustClass (ClazzLoader.clazzTreeRoot, ClazzNode.STATUS_DECLARED)) != null) {
1333-
if (lastNode == n) break;
1333+
if (lastNode === n) break;
13341334
ClazzLoader.updateNode (n);
13351335
lastNode = n;
13361336
}
13371337
lastNode = null;
13381338
while ((n = ClazzLoader.findNextOptionalClass (ClazzNode.STATUS_DECLARED)) != null) {
1339-
if (lastNode == n) break;
1339+
if (lastNode === n) break;
13401340
ClazzLoader.updateNode (n);
13411341
lastNode = n;
13421342
}
@@ -1380,7 +1380,7 @@ ClazzLoader.checkOptionalCycle = function (node) {
13801380
var length = ts.length;
13811381
var cycleFound = -1;
13821382
for (var i = 0; i < ts.length; i++) {
1383-
if (ts[i] == node && ts[i].status >= ClazzNode.STATUS_DECLARED) {
1383+
if (ts[i] === node && ts[i].status >= ClazzNode.STATUS_DECLARED) {
13841384
// Cycle is found;
13851385
cycleFound = i;
13861386
break;
@@ -1488,7 +1488,7 @@ $_L(["$wt.widgets.Widget","$wt.graphics.Drawable"],"$wt.widgets.Control",
14881488
for (var j = 0; j < list.length; j++) {
14891489
var nn = ClazzLoader.findClass (list[j]);
14901490
if (nn.status != ClazzNode.STATUS_OPTIONALS_LOADED
1491-
&& nn != n) {
1491+
&& nn !== n) {
14921492
nn.status = n.status;
14931493
nn.declaration = null;
14941494
ClazzLoader.updateNode (nn);
@@ -1566,7 +1566,7 @@ $_L(["$wt.widgets.Widget","$wt.graphics.Drawable"],"$wt.widgets.Control",
15661566
for (var j = 0; j < list.length; j++) {
15671567
var nn = ClazzLoader.findClass (list[j]);
15681568
if (nn.status != ClazzNode.STATUS_DECLARED
1569-
&& nn != node) {
1569+
&& nn !== node) {
15701570
nn.status = ClazzNode.STATUS_DECLARED;
15711571
if (ClazzLoader.definedClasses != null) {
15721572
ClazzLoader.definedClasses[nn.name] = true;
@@ -1623,7 +1623,7 @@ $_L(["$wt.widgets.Widget","$wt.graphics.Drawable"],"$wt.widgets.Control",
16231623
var list = node.declaration.clazzList;
16241624
for (var j = 0; j < list.length; j++) {
16251625
var nn = ClazzLoader.findClass (list[j]);
1626-
if (nn.status != level && nn != node) {
1626+
if (nn.status != level && nn !== node) {
16271627
nn.status = level;
16281628
nn.declaration = null;
16291629
ClazzLoader.scriptCompleted (nn.path);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ Double.prototype.valueOf = function () { return 0; };
77
Double.toString = Double.prototype.toString = function () {
88
if (arguments.length != 0) {
99
return "" + arguments[0];
10-
} else if (this == Double) {
11-
return "[Double]"; // Double.toString
10+
} else if (this === Double) {
11+
return "class java.lang.Double"; // Double.class.toString
1212
}
1313
return "" + this.valueOf ();
1414
};

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ Float.prototype.valueOf = function () { return 0; };
77
Float.toString = Float.prototype.toString = function () {
88
if (arguments.length != 0) {
99
return "" + arguments[0];
10-
} else if (this == Float) {
11-
return "[Float]"; // Float.toString
10+
} else if (this === Float) {
11+
return "class java.lang.Float"; // Float.class.toString
1212
}
1313
return "" + this.valueOf ();
1414
};

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ Integer.prototype.valueOf = function () { return 0; };
77
Integer.toString = Integer.prototype.toString = function () {
88
if (arguments.length != 0) {
99
return "" + arguments[0];
10-
} else if (this == Integer) {
11-
return "[Integer]"; // Integer.toString
10+
} else if (this === Integer) {
11+
return "class java.lang.Integer"; // Integer.class.toString
1212
}
1313
return "" + this.valueOf ();
1414
};

0 commit comments

Comments
 (0)