Skip to content

Commit 6e245bf

Browse files
author
zhourenjian
committed
Fix bug that Java2Script OO is not correctly run in Apple Safari 4.0 beta
It is considered that WebKit engine over optimizes on function's arguments object. So we must make a clone copy of arguments before calling #apply
1 parent b84f46c commit 6e245bf

File tree

1 file changed

+19
-0
lines changed
  • sources/net.sf.j2s.java.core/src/java/lang

1 file changed

+19
-0
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,6 +1397,18 @@ Clazz.defineType = function (qClazzName, clazzFun, clazzParent, interfacez) {
13971397
return clazzFun;
13981398
};
13991399

1400+
Clazz.isSafari = (navigator.userAgent.indexOf ("Safari") != -1);
1401+
Clazz.isSafari4Plus = false;
1402+
if (Clazz.isSafari) {
1403+
var ua = navigator.userAgent;
1404+
var verIdx = ua.indexOf ("Version/");
1405+
if (verIdx != -1) {
1406+
var verStr = ua.substring (verIdx + 8);
1407+
var verNumber = parseFloat (verStr);
1408+
Clazz.isSafari4Plus = verNumber >= 4.0;
1409+
}
1410+
}
1411+
14001412
/* protected */
14011413
Clazz.instantialize = function (objThis, args) {
14021414
if (args != null && args.length == 1 && args[0] != null
@@ -1416,6 +1428,13 @@ Clazz.instantialize = function (objThis, args) {
14161428
return this;
14171429
};
14181430
}
1431+
if (Clazz.isSafari4Plus) { // Fix bug of Safari 4.0+'s over-optimization
1432+
var argsClone = new Array ();
1433+
for (var k = 0; k < args.length; k++) {
1434+
argsClone[k] = args[k];
1435+
}
1436+
args = argsClone;
1437+
}
14191438
var c = objThis.construct;
14201439
if (c != null) {
14211440
if (objThis.con$truct == null) { // no need to init fields

0 commit comments

Comments
 (0)