1313
1414// TODO: Check String.contentEquals -- CharSequence? StringBuffer.shareValue??
1515
16+ // BH 9/7/2017 10:53:30 AM adds Clazz.assert; deprecates all Clazz.floatToInt, floatToByte, etc.
1617// BH 8/30/2017 6:40:11 PM adds $newClass()
1718// BH 8/26/2017 9:45:55 AM fix for URL.getContent()
1819// BH 8/24/2017 1:54:01 AM fix for static Character.toUpperCase, .toLowerCase
@@ -162,8 +163,31 @@ Clazz.makeConstructor = function(){debugger}
162163
163164Clazz . defineMethod = function ( ) { debugger }
164165
165- Clazz . popup = Clazz . assert = Clazz . log = Clazz . error = window . alert ;
166+ Clazz . popup = Clazz . log = Clazz . error = window . alert ;
166167
168+ Clazz . _assertEnabled = true ;
169+ Clazz . _assertFunction = null ;
170+ Clazz . assert = function ( clazz , tf , msg ) {
171+ if ( ! Clazz . _assertEnabled ) return ;
172+ var ok = true ;
173+ try {
174+ ok = tf . apply ( clazz )
175+ if ( ! ok )
176+ msg = msg . apply ( clazz ) ;
177+ } catch ( e ) {
178+ ok = false ;
179+ }
180+ if ( ! ok ) {
181+ if ( Clazz . _assertFunction ) {
182+ return Clazz . _assertFunction ( msg || Clazz . getStackTrace ( ) ) ;
183+ }
184+ Clazz . loadClass ( "java.lang.AssertionError" ) ;
185+ if ( msg == null )
186+ throw new AssertionError ( ) ;
187+ else
188+ throw Clazz . $new ( AssertionError . construct$S , [ msg ] ) ;
189+ }
190+ }
167191//J2S._debugCode = false;
168192
169193Clazz . $new = function ( c , args , cl ) {
@@ -185,6 +209,7 @@ Clazz.$new = function(c, args, cl) {
185209 return f ;
186210}
187211
212+
188213Clazz . $newClass = function ( cl ) {
189214 // $Class$ is the java.lang.Class object wrapper
190215 // $clazz$ is the unwrapped JavaScript object
@@ -1552,51 +1577,14 @@ java.lang.ClassLoader = {
15521577 __CLASS_NAME__ : "ClassLoader"
15531578} ;
15541579
1555- /******************************************************************************
1556- * Copyright (c) 2007 java2script.org and others.
1557- * All rights reserved. This program and the accompanying materials
1558- * are made available under the terms of the Eclipse Public License v1.0
1559- * which accompanies this distribution, and is available at
1560- * http://www.eclipse.org/legal/epl-v10.html
1561- *
1562- * Contributors:
1563- * Zhou Renjian - initial API and implementation
1564- *****************************************************************************/
1565- /*******
1566- * @author zhou renjian
1567- * @create March 10, 2006
1568- *******/
1569-
1570- /**
1571- * Once ClassExt.js is part of Class.js.
1572- * In order to make the Class.js as small as possible, part of its content
1573- * is moved into this ClassExt.js.
1574- *
1575- * See also http://j2s.sourceforge.net/j2sclazz/
1576- */
1577-
1578- /**
1579- * Clazz.MethodNotFoundException is used to notify the developer about calling
1580- * methods with incorrect parameters.
1581- */
1582-
15831580//////// (int) conversions //////////
15841581
1585- Clazz . floatToInt = function ( x ) {
1582+ // deprecated
1583+ Clazz . doubleToInt = Clazz . floatToInt = function ( x ) {
15861584 // asm.js-style conversion
15871585 return x | 0 ;
15881586} ;
15891587
1590- Clazz . floatToByte = Clazz . floatToShort = Clazz . floatToLong = Clazz . floatToInt ;
1591- Clazz . doubleToByte = Clazz . doubleToShort = Clazz . doubleToLong = Clazz . doubleToInt = Clazz . floatToInt ;
1592-
1593- Clazz . floatToChar = function ( x ) {
1594- return String . fromCharCode ( isNaN ( x ) ? 0 : x < 0 ? Math . ceil ( x ) : Math . floor ( x ) ) ;
1595- } ;
1596-
1597- Clazz . doubleToChar = Clazz . floatToChar ;
1598-
1599-
16001588
16011589///////////////////////////////// Array additions //////////////////////////////
16021590//
@@ -4080,18 +4068,19 @@ Number.compare = function(a,b) { return (a < b ? -1 : a == b ? 0 : 1) };
40804068m$ ( Number , "shortValue" ,
40814069function ( ) {
40824070var x = Math . round ( this ) & 0xffff ;
4083- return ( this < 0 && x > 0 ? x - 0x10000 : x ) ;
4071+ return ( this < 0 && x > 0 || x == 0xffff ? x - 0x10000 : x ) ;
40844072} ) ;
40854073
40864074m$ ( Number , "byteValue" ,
40874075function ( ) {
40884076var x = Math . round ( this ) & 0xff ;
4089- return ( this < 0 && x > 0 ? x - 0x100 : x ) ;
4077+ return ( this < 0 && x > 0 || x == 0xff ? x - 0x100 : x ) ;
40904078} ) ;
40914079
40924080m$ ( Number , "intValue" ,
40934081function ( ) {
4094- return Math . round ( this ) & 0xffffffff ;
4082+ var x = Math . round ( this ) & 0xffffffff ;
4083+ return ( this < 0 && x > 0 || x == 0xffffffff ? x - 0x100000000 : x ) ;
40954084} ) ;
40964085
40974086m$ ( Number , "longValue" ,
@@ -4155,6 +4144,7 @@ m$(Integer, "construct", function(v){
41554144 v == null && ( v = 0 ) ;
41564145 if ( typeof v != "number" )
41574146 v = Integer . parseIntRadix ( v , 10 ) ;
4147+ v = v . intValue ( ) ;
41584148 this . valueOf = function ( ) { return v ; } ;
41594149} , 1 ) ;
41604150
@@ -4450,9 +4440,8 @@ m$(Byte, "construct", function(v){
44504440 if ( typeof v != "number" )
44514441 v = Integer . parseIntRadix ( v , 10 ) ;
44524442 v = v . byteValue ( ) ;
4453- this . valueOf = function ( ) {
4454- return v ;
4455- } ;
4443+ this . valueOf = function ( ) { return v ; } ;
4444+ this . byteValue = function ( ) { return v } ;
44564445} , 1 ) ;
44574446
44584447Byte . toString = Byte . prototype . toString = function ( ) {
@@ -5465,6 +5454,11 @@ if (typeof arguments[0] != "object")this.construct(arguments[0]);
54655454Clazz . _setDeclared ( "java.lang.Character" , java . lang . Character ) ;
54665455setJ2STypeclass ( Character , "char" , "C" ) ;
54675456
5457+ m$ ( c$ , "getName" ,
5458+ function ( ) {
5459+ return "?" ;
5460+ } , 1 ) ;
5461+
54685462m$ ( c$ , "construct" ,
54695463function ( value ) {
54705464this . value = value ;
@@ -5474,6 +5468,7 @@ m$(c$,"charValue",
54745468function ( ) {
54755469return this . value ;
54765470} ) ;
5471+
54775472m$ ( c$ , "hashCode" ,
54785473function ( ) {
54795474return ( this . value ) . charCodeAt ( 0 ) ;
@@ -5929,7 +5924,6 @@ declareType(java.lang,"LinkageError",Error);
59295924declareType ( java . lang , "VirtualMachineError" , Error ) ;
59305925declareType ( java . lang , "IncompatibleClassChangeError" , LinkageError ) ;
59315926
5932-
59335927declareType ( java . lang , "AbstractMethodError" , IncompatibleClassChangeError ) ;
59345928declareType ( java . lang , "ArithmeticException" , RuntimeException ) ;
59355929declareType ( java . lang , "ArrayStoreException" , RuntimeException ) ;
@@ -5964,12 +5958,6 @@ declareType(java.lang,"UnsupportedClassVersionError",ClassFormatError);
59645958declareType ( java . lang , "UnsupportedOperationException" , RuntimeException ) ;
59655959declareType ( java . lang , "VerifyError" , LinkageError ) ;
59665960
5967-
5968- var c$ = declareType ( java . lang , "ArrayIndexOutOfBoundsException" , IndexOutOfBoundsException ) ;
5969- m$ ( c$ , "construct$I" , function ( ) {
5970- c$ . superClazz . construct$S . apply ( this , [ "Array index out of range: " + index ] ) ;
5971- } , 1 ) ;
5972-
59735961declareType ( java . lang , "ClassCastException" , RuntimeException ) ;
59745962c$ = Clazz . decorateAsClass ( java . lang , "ClassNotFoundException" , function ( ) { this . ex = null ; } , Exception ) ;
59755963m$ ( c$ , "construct$S$Throwable" , function ( detailMessage , exception ) {
0 commit comments