@@ -49,6 +49,7 @@ JavaObject = Object;
4949
5050/* protected */
5151Clazz . supportsNativeObject = window [ "j2s.object.native" ] ;
52+ Clazz . supportsNativeArray = window [ "j2s.array.native" ] ;
5253
5354if ( Clazz . supportsNativeObject ) {
5455 JavaObject = function ( ) { } ;
@@ -92,23 +93,28 @@ JavaObject.prototype.toString = function () {
9293 if ( this . __CLASS_NAME__ != null ) {
9394 return "[" + this . __CLASS_NAME__ + " object]" ;
9495 } else {
95- return this . to$tring . apply ( this , arguments ) ;
96+ return JavaObject . prototype . to$tring . apply ( this , arguments ) ;
9697 }
9798} ;
9899
99- if ( Clazz . supportsNativeObject ) {
100- /* protected */
101- Clazz . extendedObjectMethods = [
102- "equals" , "hashCode" , "getClass" , "clone" , "finalize" , "notify" , "notifyAll" , "wait" , "to$tring" , "toString"
103- ] ;
104-
105- for ( var i = 0 ; i < Clazz . extendedObjectMethods . length ; i ++ ) {
106- var p = Clazz . extendedObjectMethods [ i ] ;
107- Array . prototype [ p ] = JavaObject . prototype [ p ] ;
100+ ( function ( ) {
101+ if ( Clazz . supportsNativeObject ) {
102+ /* protected */
103+ Clazz . extendedObjectMethods = [
104+ "equals" , "hashCode" , "getClass" , "clone" , "finalize" , "notify" , "notifyAll" , "wait" , "to$tring" , "toString"
105+ ] ;
106+ if ( ! Clazz . supportsNativeArray ) {
107+ Array . prototype . to$tring = Array . prototype . toString ;
108+ for ( var i = 0 ; i < Clazz . extendedObjectMethods . length ; i ++ ) {
109+ var p = Clazz . extendedObjectMethods [ i ] ;
110+ if ( p == "toString" || p == "to$tring" ) continue ;
111+ Array . prototype [ p ] = JavaObject . prototype [ p ] ;
112+ }
113+ }
114+ JavaObject . __CLASS_NAME__ = "Object" ;
115+ JavaObject [ "getClass" ] = function ( ) { return JavaObject ; } ;
108116 }
109- JavaObject . __CLASS_NAME__ = "Object" ;
110- JavaObject [ "getClass" ] = function ( ) { return JavaObject ; } ;
111- }
117+ } ) ( ) ;
112118
113119/**
114120 * Try to fix bug on Safari
@@ -1518,15 +1524,17 @@ Clazz.defineType = function (qClazzName, clazzFun, clazzParent, interfacez) {
15181524
15191525Clazz . isSafari = ( navigator . userAgent . indexOf ( "Safari" ) != - 1 ) ;
15201526Clazz . isSafari4Plus = false ;
1521- if ( Clazz . isSafari ) {
1522- var ua = navigator . userAgent ;
1523- var verIdx = ua . indexOf ( "Version/" ) ;
1524- if ( verIdx != - 1 ) {
1525- var verStr = ua . substring ( verIdx + 8 ) ;
1526- var verNumber = parseFloat ( verStr ) ;
1527- Clazz . isSafari4Plus = verNumber >= 4.0 ;
1527+ ( function ( ) {
1528+ if ( Clazz . isSafari ) {
1529+ var ua = navigator . userAgent ;
1530+ var verIdx = ua . indexOf ( "Version/" ) ;
1531+ if ( verIdx != - 1 ) {
1532+ var verStr = ua . substring ( verIdx + 8 ) ;
1533+ var verNumber = parseFloat ( verStr ) ;
1534+ Clazz . isSafari4Plus = verNumber >= 4.0 ;
1535+ }
15281536 }
1529- }
1537+ } ) ( ) ;
15301538
15311539/* protected */
15321540Clazz . instantialize = function ( objThis , args ) {
@@ -1970,31 +1978,34 @@ Clazz._ex_reg=function (msg, spliterName, spliterRegex) {
19701978 regexp = new RegExp ( "^" + str + "$" ) ;
19711979 return regexp ;
19721980} ;
1973- // reproduce NullPointerException for knowing how to detect them, and create detector function Clazz._isNPEExceptionPredicate
1974- var $$o$$ = null ;
1975- try {
1976- $$o$$ . hello ( ) ;
1977- } catch ( e ) {
1978- if ( / O p e r a [ \/ \s ] ( \d + \. \d + ) / . test ( navigator . userAgent ) ) { // opera throws an exception with fixed messages like "Statement on line 23: Cannot convert undefined or null to Object Backtrace: Line....long text... "
1979- var idx1 = e . message . indexOf ( ":" ) , idx2 = e . message . indexOf ( ":" , idx1 + 2 ) ;
1980- Clazz . _NPEMsgFragment = e . message . substr ( idx1 + 1 , idx2 - idx1 - 20 ) ;
1981- Clazz . _isNPEExceptionPredicate = function ( e ) {
1982- return e . message . indexOf ( Clazz . _NPEMsgFragment ) != - 1 ;
1983- } ;
1984- }
1985- else if ( navigator . userAgent . toLowerCase ( ) . indexOf ( "webkit" ) != - 1 ) { //webkit, google chrome prints the property name accessed.
1986- Clazz . _exceptionNPERegExp = Clazz . _ex_reg ( e . message , "hello" ) ;
1987- Clazz . _isNPEExceptionPredicate = function ( e ) {
1988- return Clazz . _exceptionNPERegExp . test ( e . message ) ;
1989- } ;
1990- }
1991- else { // ie, firefox and others print the name of the object accessed:
1992- Clazz . _exceptionNPERegExp = Clazz . _ex_reg ( e . message , "$$o$$" ) ;
1993- Clazz . _isNPEExceptionPredicate = function ( e ) {
1994- return Clazz . _exceptionNPERegExp . test ( e . message ) ;
1995- } ;
1996- }
1997- } ;
1981+ ( function ( ) {
1982+ // reproduce NullPointerException for knowing how to detect them, and create detector function Clazz._isNPEExceptionPredicate
1983+ var $$o$$ = null ;
1984+ try {
1985+ $$o$$ . hello ( ) ;
1986+ } catch ( e ) {
1987+ if ( / O p e r a [ \/ \s ] ( \d + \. \d + ) / . test ( navigator . userAgent ) ) { // opera throws an exception with fixed messages like "Statement on line 23: Cannot convert undefined or null to Object Backtrace: Line....long text... "
1988+ var idx1 = e . message . indexOf ( ":" ) , idx2 = e . message . indexOf ( ":" , idx1 + 2 ) ;
1989+ Clazz . _NPEMsgFragment = e . message . substr ( idx1 + 1 , idx2 - idx1 - 20 ) ;
1990+ Clazz . _isNPEExceptionPredicate = function ( e ) {
1991+ return e . message . indexOf ( Clazz . _NPEMsgFragment ) != - 1 ;
1992+ } ;
1993+ }
1994+ else if ( navigator . userAgent . toLowerCase ( ) . indexOf ( "webkit" ) != - 1 ) { //webkit, google chrome prints the property name accessed.
1995+ Clazz . _exceptionNPERegExp = Clazz . _ex_reg ( e . message , "hello" ) ;
1996+ Clazz . _isNPEExceptionPredicate = function ( e ) {
1997+ return Clazz . _exceptionNPERegExp . test ( e . message ) ;
1998+ } ;
1999+ }
2000+ else { // ie, firefox and others print the name of the object accessed:
2001+ Clazz . _exceptionNPERegExp = Clazz . _ex_reg ( e . message , "$$o$$" ) ;
2002+ Clazz . _isNPEExceptionPredicate = function ( e ) {
2003+ return Clazz . _exceptionNPERegExp . test ( e . message ) ;
2004+ } ;
2005+ }
2006+ }
2007+ } ) ( ) ;
2008+
19982009/**sgurin
19992010 * Implements Java's keyword "instanceof" in JavaScript's way **for exception objects**.
20002011 *
0 commit comments