8012334: ToUint32, ToInt32, and ToUint16 don't conform to spec

Wed, 24 Apr 2013 13:28:25 +0200

author
hannesw
date
Wed, 24 Apr 2013 13:28:25 +0200
changeset 219
a6c53280343d
parent 218
32036918585d
child 220
3974ce844f17

8012334: ToUint32, ToInt32, and ToUint16 don't conform to spec
Reviewed-by: lagergren, attila

src/jdk/nashorn/internal/codegen/CodeGenerator.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/codegen/FoldConstants.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/NativeArray.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/NativeUint32Array.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/JSType.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/ScriptObject.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/arrays/SparseArrayData.java file | annotate | diff | comparison | revisions
test/examples/int-micro.js file | annotate | diff | comparison | revisions
test/script/basic/JDK-8012334.js file | annotate | diff | comparison | revisions
test/script/basic/JDK-8012334.js.EXPECTED file | annotate | diff | comparison | revisions
test/src/jdk/nashorn/internal/runtime/JSTypeTest.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/jdk/nashorn/internal/codegen/CodeGenerator.java	Tue Apr 23 16:48:57 2013 +0200
     1.2 +++ b/src/jdk/nashorn/internal/codegen/CodeGenerator.java	Wed Apr 24 13:28:25 2013 +0200
     1.3 @@ -117,6 +117,7 @@
     1.4  import jdk.nashorn.internal.runtime.Debug;
     1.5  import jdk.nashorn.internal.runtime.DebugLogger;
     1.6  import jdk.nashorn.internal.runtime.ECMAException;
     1.7 +import jdk.nashorn.internal.runtime.JSType;
     1.8  import jdk.nashorn.internal.runtime.Property;
     1.9  import jdk.nashorn.internal.runtime.PropertyMap;
    1.10  import jdk.nashorn.internal.runtime.RecompilableScriptFunctionData;
    1.11 @@ -2572,7 +2573,7 @@
    1.12              @Override
    1.13              protected void op() {
    1.14                  method.shr();
    1.15 -                method.convert(Type.LONG).load(0xffff_ffffL).and();
    1.16 +                method.convert(Type.LONG).load(JSType.MAX_UINT).and();
    1.17              }
    1.18          }.store();
    1.19  
    1.20 @@ -2807,7 +2808,7 @@
    1.21              @Override
    1.22              protected void op() {
    1.23                  method.shr();
    1.24 -                method.convert(Type.LONG).load(0xffff_ffffL).and();
    1.25 +                method.convert(Type.LONG).load(JSType.MAX_UINT).and();
    1.26              }
    1.27          }.evaluate(binaryNode);
    1.28  
     2.1 --- a/src/jdk/nashorn/internal/codegen/FoldConstants.java	Tue Apr 23 16:48:57 2013 +0200
     2.2 +++ b/src/jdk/nashorn/internal/codegen/FoldConstants.java	Wed Apr 24 13:28:25 2013 +0200
     2.3 @@ -247,7 +247,7 @@
     2.4                  value = lhs.getNumber() - rhs.getNumber();
     2.5                  break;
     2.6              case SHR:
     2.7 -                return LiteralNode.newInstance(source, token, finish, (lhs.getInt32() >>> rhs.getInt32()) & 0xffff_ffffL);
     2.8 +                return LiteralNode.newInstance(source, token, finish, (lhs.getInt32() >>> rhs.getInt32()) & JSType.MAX_UINT);
     2.9              case SAR:
    2.10                  return LiteralNode.newInstance(source, token, finish, lhs.getInt32() >> rhs.getInt32());
    2.11              case SHL:
     3.1 --- a/src/jdk/nashorn/internal/objects/NativeArray.java	Tue Apr 23 16:48:57 2013 +0200
     3.2 +++ b/src/jdk/nashorn/internal/objects/NativeArray.java	Wed Apr 24 13:28:25 2013 +0200
     3.3 @@ -418,7 +418,7 @@
     3.4                  long length;
     3.5                  if (len instanceof Integer || len instanceof Long) {
     3.6                      length = ((Number) len).longValue();
     3.7 -                    if (length >= 0 && length < 0xffff_ffffL) {
     3.8 +                    if (length >= 0 && length < JSType.MAX_UINT) {
     3.9                          return new NativeArray(length);
    3.10                      }
    3.11                  }
     4.1 --- a/src/jdk/nashorn/internal/objects/NativeUint32Array.java	Tue Apr 23 16:48:57 2013 +0200
     4.2 +++ b/src/jdk/nashorn/internal/objects/NativeUint32Array.java	Wed Apr 24 13:28:25 2013 +0200
     4.3 @@ -29,6 +29,7 @@
     4.4  import jdk.nashorn.internal.objects.annotations.Constructor;
     4.5  import jdk.nashorn.internal.objects.annotations.Function;
     4.6  import jdk.nashorn.internal.objects.annotations.ScriptClass;
     4.7 +import jdk.nashorn.internal.runtime.JSType;
     4.8  import jdk.nashorn.internal.runtime.ScriptObject;
     4.9  import jdk.nashorn.internal.runtime.arrays.ArrayData;
    4.10  
    4.11 @@ -71,17 +72,17 @@
    4.12  
    4.13          @Override
    4.14          protected long getLongImpl(final int key) {
    4.15 -            return getIntImpl(key) & 0xffff_ffffL;
    4.16 +            return getIntImpl(key) & JSType.MAX_UINT;
    4.17          }
    4.18  
    4.19          @Override
    4.20          protected double getDoubleImpl(final int key) {
    4.21 -            return getIntImpl(key) & 0xffff_ffffL;
    4.22 +            return getIntImpl(key) & JSType.MAX_UINT;
    4.23          }
    4.24  
    4.25          @Override
    4.26          protected Object getObjectImpl(final int key) {
    4.27 -            return getIntImpl(key) & 0xffff_ffffL;
    4.28 +            return getIntImpl(key) & JSType.MAX_UINT;
    4.29          }
    4.30  
    4.31          @Override
     5.1 --- a/src/jdk/nashorn/internal/runtime/JSType.java	Tue Apr 23 16:48:57 2013 +0200
     5.2 +++ b/src/jdk/nashorn/internal/runtime/JSType.java	Wed Apr 24 13:28:25 2013 +0200
     5.3 @@ -102,6 +102,8 @@
     5.4      /** JavaScript compliant conversion function from Object to primitive */
     5.5      public static final Call TO_PRIMITIVE = staticCall(JSType.class, "toPrimitive", Object.class,  Object.class);
     5.6  
     5.7 +    private static final double INT32_LIMIT = 4294967296.0;
     5.8 +
     5.9      /**
    5.10       * The external type name as returned by ECMAScript "typeof" operator
    5.11       *
    5.12 @@ -612,10 +614,7 @@
    5.13       * @return an int32
    5.14       */
    5.15      public static int toInt32(final double num) {
    5.16 -        if (Double.isInfinite(num)) {
    5.17 -            return 0;
    5.18 -        }
    5.19 -        return (int)(long)num;
    5.20 +        return (int)doubleToInt32(num);
    5.21      }
    5.22  
    5.23      /**
    5.24 @@ -658,10 +657,7 @@
    5.25       * @return a uint32
    5.26       */
    5.27      public static long toUint32(final double num) {
    5.28 -        if (Double.isInfinite(num)) {
    5.29 -            return 0L;
    5.30 -        }
    5.31 -        return ((long)num) & 0xffff_ffffL;
    5.32 +        return doubleToInt32(num) & MAX_UINT;
    5.33      }
    5.34  
    5.35      /**
    5.36 @@ -702,10 +698,22 @@
    5.37       * @return a uint16
    5.38       */
    5.39      public static int toUint16(final double num) {
    5.40 -        if (Double.isInfinite(num)) {
    5.41 +        return ((int)doubleToInt32(num)) & 0xffff;
    5.42 +    }
    5.43 +
    5.44 +    private static long doubleToInt32(final double num) {
    5.45 +        final int exponent = Math.getExponent(num);
    5.46 +        if (exponent < 31) {
    5.47 +            return (long) num;  // Fits into 32 bits
    5.48 +        }
    5.49 +        if (exponent >= 84) {
    5.50 +            // Either infinite or NaN or so large that shift / modulo will produce 0
    5.51 +            // (52 bit mantissa + 32 bit target width).
    5.52              return 0;
    5.53          }
    5.54 -        return ((int)(long)num) & 0xffff;
    5.55 +        // This is rather slow and could probably be sped up using bit-fiddling.
    5.56 +        final double d = (num >= 0) ? Math.floor(num) : Math.ceil(num);
    5.57 +        return (long)(d % INT32_LIMIT);
    5.58      }
    5.59  
    5.60      /**
     6.1 --- a/src/jdk/nashorn/internal/runtime/ScriptObject.java	Tue Apr 23 16:48:57 2013 +0200
     6.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptObject.java	Wed Apr 24 13:28:25 2013 +0200
     6.3 @@ -2425,7 +2425,7 @@
     6.4       */
     6.5      private void doesNotHave(final int index, final Object value, final boolean strict) {
     6.6          final long oldLength = getArray().length();
     6.7 -        final long longIndex = index & 0xffff_ffffL;
     6.8 +        final long longIndex = index & JSType.MAX_UINT;
     6.9  
    6.10          if (!getArray().has(index)) {
    6.11              final String key = convertKey(longIndex);
     7.1 --- a/src/jdk/nashorn/internal/runtime/arrays/SparseArrayData.java	Tue Apr 23 16:48:57 2013 +0200
     7.2 +++ b/src/jdk/nashorn/internal/runtime/arrays/SparseArrayData.java	Wed Apr 24 13:28:25 2013 +0200
     7.3 @@ -273,7 +273,7 @@
     7.4      }
     7.5  
     7.6      private static Long indexToKey(final int index) {
     7.7 -        return Long.valueOf(index & 0xffff_ffffL);
     7.8 +        return Long.valueOf(index & JSType.MAX_UINT);
     7.9      }
    7.10  
    7.11      @Override
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/test/examples/int-micro.js	Wed Apr 24 13:28:25 2013 +0200
     8.3 @@ -0,0 +1,107 @@
     8.4 +/*
     8.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
     8.6 + * 
     8.7 + * Redistribution and use in source and binary forms, with or without
     8.8 + * modification, are permitted provided that the following conditions
     8.9 + * are met:
    8.10 + * 
    8.11 + *   - Redistributions of source code must retain the above copyright
    8.12 + *     notice, this list of conditions and the following disclaimer.
    8.13 + * 
    8.14 + *   - Redistributions in binary form must reproduce the above copyright
    8.15 + *     notice, this list of conditions and the following disclaimer in the
    8.16 + *     documentation and/or other materials provided with the distribution.
    8.17 + * 
    8.18 + *   - Neither the name of Oracle nor the names of its
    8.19 + *     contributors may be used to endorse or promote products derived
    8.20 + *     from this software without specific prior written permission.
    8.21 + * 
    8.22 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
    8.23 + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
    8.24 + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
    8.25 + * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
    8.26 + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
    8.27 + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
    8.28 + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
    8.29 + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
    8.30 + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
    8.31 + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    8.32 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    8.33 + */
    8.34 +
    8.35 +
    8.36 +function bench(name, func) {
    8.37 +    var start = Date.now();
    8.38 +    for (var iter = 0; iter < 5000000; iter++) {
    8.39 +        func();
    8.40 +    }
    8.41 +    print(name + "\t" + (Date.now() - start));
    8.42 +}
    8.43 +
    8.44 +function uint32(value) {
    8.45 +    return function() {
    8.46 +        value >>> 0;
    8.47 +        value >>> 0;
    8.48 +        value >>> 0;
    8.49 +        value >>> 0;
    8.50 +        value >>> 0;
    8.51 +        value >>> 0;
    8.52 +        value >>> 0;
    8.53 +        value >>> 0;
    8.54 +        value >>> 0;
    8.55 +        value >>> 0;
    8.56 +        value >>> 0;
    8.57 +        value >>> 0;
    8.58 +        value >>> 0;
    8.59 +        value >>> 0;
    8.60 +        value >>> 0;
    8.61 +    };
    8.62 +}
    8.63 +
    8.64 +function int32(value) {
    8.65 +    return function() {
    8.66 +        value >> 0;
    8.67 +        value >> 0;
    8.68 +        value >> 0;
    8.69 +        value >> 0;
    8.70 +        value >> 0;
    8.71 +        value >> 0;
    8.72 +        value >> 0;
    8.73 +        value >> 0;
    8.74 +        value >> 0;
    8.75 +        value >> 0;
    8.76 +        value >> 0;
    8.77 +        value >> 0;
    8.78 +        value >> 0;
    8.79 +        value >> 0;
    8.80 +        value >> 0;
    8.81 +    };
    8.82 +}
    8.83 +
    8.84 +print("\nToUint32");
    8.85 +for (var i = 1; i < 3; i++) {
    8.86 +    bench("infinity      ", uint32(Infinity));
    8.87 +    bench("infinity neg  ", uint32(-Infinity));
    8.88 +    bench("nan           ", uint32(NaN));
    8.89 +    bench("small         ", uint32(1));
    8.90 +    bench("small neg     ", uint32(-1));
    8.91 +    bench("small frac    ", uint32(1.5));
    8.92 +    bench("small neg frac", uint32(-1.5));
    8.93 +    bench("large         ", uint32(9223372036854775807));
    8.94 +    bench("large neg     ", uint32(-9223372036854775808));
    8.95 +}
    8.96 +
    8.97 +print("\nToInt32");
    8.98 +for (var i = 1; i < 3; i++) {
    8.99 +    bench("infinity      ", int32(Infinity));
   8.100 +    bench("infinity neg  ", int32(-Infinity));
   8.101 +    bench("nan           ", int32(NaN));
   8.102 +    bench("small         ", int32(1));
   8.103 +    bench("small neg     ", int32(-1));
   8.104 +    bench("small frac    ", int32(1.5));
   8.105 +    bench("small neg frac", int32(-1.5));
   8.106 +    bench("large         ", int32(9223372036854775807));
   8.107 +    bench("large neg     ", int32(-9223372036854775808));
   8.108 +}
   8.109 +
   8.110 +
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/test/script/basic/JDK-8012334.js	Wed Apr 24 13:28:25 2013 +0200
     9.3 @@ -0,0 +1,80 @@
     9.4 +/*
     9.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
     9.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     9.7 + *
     9.8 + * This code is free software; you can redistribute it and/or modify it
     9.9 + * under the terms of the GNU General Public License version 2 only, as
    9.10 + * published by the Free Software Foundation.
    9.11 + *
    9.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    9.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    9.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    9.15 + * version 2 for more details (a copy is included in the LICENSE file that
    9.16 + * accompanied this code).
    9.17 + *
    9.18 + * You should have received a copy of the GNU General Public License version
    9.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    9.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    9.21 + *
    9.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    9.23 + * or visit www.oracle.com if you need additional information or have any
    9.24 + * questions.
    9.25 + */
    9.26 +
    9.27 +/**
    9.28 + * JDK-8012334: ToUint32, ToInt32, and ToUint16 don't conform to spec
    9.29 + *
    9.30 + * @test
    9.31 + * @run
    9.32 + */
    9.33 +
    9.34 +
    9.35 +function test(val) {
    9.36 +    print(val | 0);
    9.37 +    print(val >> 0);
    9.38 +    print(val >>> 0);
    9.39 +    print(1 >>> val);
    9.40 +    print(parseInt("10", val));
    9.41 +}
    9.42 +
    9.43 +test(0);
    9.44 +test(-0);
    9.45 +test('Infinity');
    9.46 +test('+Infinity');
    9.47 +test('-Infinity');
    9.48 +test(Number.POSITIVE_INFINITY);
    9.49 +test(Number.NEGATIVE_INFINITY);
    9.50 +test(Number.NaN);
    9.51 +test(Number.MIN_VALUE);
    9.52 +test(-Number.MIN_VALUE);
    9.53 +test(1);
    9.54 +test(-1);
    9.55 +test(0.1);
    9.56 +test(-0.1);
    9.57 +test(1.1);
    9.58 +test(-1.1);
    9.59 +test(9223372036854775807);
    9.60 +test(-9223372036854775808);
    9.61 +test('9223372036854775807');
    9.62 +test('-9223372036854775808');
    9.63 +test(2147483647);
    9.64 +test(2147483648);
    9.65 +test(2147483649);
    9.66 +test(-2147483647);
    9.67 +test(-2147483648);
    9.68 +test(-2147483649);
    9.69 +test(4294967295);
    9.70 +test(4294967296);
    9.71 +test(4294967297);
    9.72 +test(-4294967295);
    9.73 +test(-4294967296);
    9.74 +test(-4294967297);
    9.75 +test(1e23);
    9.76 +test(-1e23);
    9.77 +test(1e24);
    9.78 +test(-1e24);
    9.79 +test(1e25);
    9.80 +test(-1e25);
    9.81 +test(1e26);
    9.82 +test(-1e26);
    9.83 +
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/test/script/basic/JDK-8012334.js.EXPECTED	Wed Apr 24 13:28:25 2013 +0200
    10.3 @@ -0,0 +1,200 @@
    10.4 +0
    10.5 +0
    10.6 +0
    10.7 +1
    10.8 +10
    10.9 +0
   10.10 +0
   10.11 +0
   10.12 +1
   10.13 +10
   10.14 +0
   10.15 +0
   10.16 +0
   10.17 +1
   10.18 +10
   10.19 +0
   10.20 +0
   10.21 +0
   10.22 +1
   10.23 +10
   10.24 +0
   10.25 +0
   10.26 +0
   10.27 +1
   10.28 +10
   10.29 +0
   10.30 +0
   10.31 +0
   10.32 +1
   10.33 +10
   10.34 +0
   10.35 +0
   10.36 +0
   10.37 +1
   10.38 +10
   10.39 +0
   10.40 +0
   10.41 +0
   10.42 +1
   10.43 +10
   10.44 +0
   10.45 +0
   10.46 +0
   10.47 +1
   10.48 +10
   10.49 +0
   10.50 +0
   10.51 +0
   10.52 +1
   10.53 +10
   10.54 +1
   10.55 +1
   10.56 +1
   10.57 +0
   10.58 +NaN
   10.59 +-1
   10.60 +-1
   10.61 +4294967295
   10.62 +0
   10.63 +NaN
   10.64 +0
   10.65 +0
   10.66 +0
   10.67 +1
   10.68 +10
   10.69 +0
   10.70 +0
   10.71 +0
   10.72 +1
   10.73 +10
   10.74 +1
   10.75 +1
   10.76 +1
   10.77 +0
   10.78 +NaN
   10.79 +-1
   10.80 +-1
   10.81 +4294967295
   10.82 +0
   10.83 +NaN
   10.84 +0
   10.85 +0
   10.86 +0
   10.87 +1
   10.88 +10
   10.89 +0
   10.90 +0
   10.91 +0
   10.92 +1
   10.93 +10
   10.94 +0
   10.95 +0
   10.96 +0
   10.97 +1
   10.98 +10
   10.99 +0
  10.100 +0
  10.101 +0
  10.102 +1
  10.103 +10
  10.104 +2147483647
  10.105 +2147483647
  10.106 +2147483647
  10.107 +0
  10.108 +NaN
  10.109 +-2147483648
  10.110 +-2147483648
  10.111 +2147483648
  10.112 +1
  10.113 +NaN
  10.114 +-2147483647
  10.115 +-2147483647
  10.116 +2147483649
  10.117 +0
  10.118 +NaN
  10.119 +-2147483647
  10.120 +-2147483647
  10.121 +2147483649
  10.122 +0
  10.123 +NaN
  10.124 +-2147483648
  10.125 +-2147483648
  10.126 +2147483648
  10.127 +1
  10.128 +NaN
  10.129 +2147483647
  10.130 +2147483647
  10.131 +2147483647
  10.132 +0
  10.133 +NaN
  10.134 +-1
  10.135 +-1
  10.136 +4294967295
  10.137 +0
  10.138 +NaN
  10.139 +0
  10.140 +0
  10.141 +0
  10.142 +1
  10.143 +10
  10.144 +1
  10.145 +1
  10.146 +1
  10.147 +0
  10.148 +NaN
  10.149 +1
  10.150 +1
  10.151 +1
  10.152 +0
  10.153 +NaN
  10.154 +0
  10.155 +0
  10.156 +0
  10.157 +1
  10.158 +10
  10.159 +-1
  10.160 +-1
  10.161 +4294967295
  10.162 +0
  10.163 +NaN
  10.164 +-167772160
  10.165 +-167772160
  10.166 +4127195136
  10.167 +1
  10.168 +NaN
  10.169 +167772160
  10.170 +167772160
  10.171 +167772160
  10.172 +1
  10.173 +NaN
  10.174 +-1610612736
  10.175 +-1610612736
  10.176 +2684354560
  10.177 +1
  10.178 +NaN
  10.179 +1610612736
  10.180 +1610612736
  10.181 +1610612736
  10.182 +1
  10.183 +NaN
  10.184 +-2147483648
  10.185 +-2147483648
  10.186 +2147483648
  10.187 +1
  10.188 +NaN
  10.189 +-2147483648
  10.190 +-2147483648
  10.191 +2147483648
  10.192 +1
  10.193 +NaN
  10.194 +0
  10.195 +0
  10.196 +0
  10.197 +1
  10.198 +10
  10.199 +0
  10.200 +0
  10.201 +0
  10.202 +1
  10.203 +10
    11.1 --- a/test/src/jdk/nashorn/internal/runtime/JSTypeTest.java	Tue Apr 23 16:48:57 2013 +0200
    11.2 +++ b/test/src/jdk/nashorn/internal/runtime/JSTypeTest.java	Wed Apr 24 13:28:25 2013 +0200
    11.3 @@ -105,4 +105,89 @@
    11.4          // FIXME: add more number-to-string test cases
    11.5          // FIXME: add case for Object type (JSObject with getDefaultValue)
    11.6      }
    11.7 +
    11.8 +    /**
    11.9 +     * Test of JSType.toUint32(double)
   11.10 +     */
   11.11 +    @Test
   11.12 +    public void testToUint32() {
   11.13 +        assertEquals(JSType.toUint32(+0.0), 0);
   11.14 +        assertEquals(JSType.toUint32(-0.0), 0);
   11.15 +        assertEquals(JSType.toUint32(Double.NaN), 0);
   11.16 +        assertEquals(JSType.toUint32(Double.POSITIVE_INFINITY), 0);
   11.17 +        assertEquals(JSType.toUint32(Double.NEGATIVE_INFINITY), 0);
   11.18 +        assertEquals(JSType.toUint32(9223372036854775807.0d), 0);
   11.19 +        assertEquals(JSType.toUint32(-9223372036854775807.0d), 0);
   11.20 +        assertEquals(JSType.toUint32(1099511627776.0d), 0);
   11.21 +        assertEquals(JSType.toUint32(-1099511627776.0d), 0);
   11.22 +        assertEquals(JSType.toUint32(4294967295.0d), 4294967295l);
   11.23 +        assertEquals(JSType.toUint32(4294967296.0d), 0);
   11.24 +        assertEquals(JSType.toUint32(4294967297.0d), 1);
   11.25 +        assertEquals(JSType.toUint32(-4294967295.0d), 1);
   11.26 +        assertEquals(JSType.toUint32(-4294967296.0d), 0);
   11.27 +        assertEquals(JSType.toUint32(-4294967297.0d), 4294967295l);
   11.28 +        assertEquals(JSType.toUint32(4294967295.6d), 4294967295l);
   11.29 +        assertEquals(JSType.toUint32(4294967296.6d), 0);
   11.30 +        assertEquals(JSType.toUint32(4294967297.6d), 1);
   11.31 +        assertEquals(JSType.toUint32(-4294967295.6d), 1);
   11.32 +        assertEquals(JSType.toUint32(-4294967296.6d), 0);
   11.33 +        assertEquals(JSType.toUint32(-4294967297.6d), 4294967295l);
   11.34 +    }
   11.35 +
   11.36 +    /**
   11.37 +     * Test of JSType.toInt32(double)
   11.38 +     */
   11.39 +    @Test
   11.40 +    public void testToInt32() {
   11.41 +        assertEquals(JSType.toInt32(+0.0), 0);
   11.42 +        assertEquals(JSType.toInt32(-0.0), 0);
   11.43 +        assertEquals(JSType.toInt32(Double.NaN), 0);
   11.44 +        assertEquals(JSType.toInt32(Double.POSITIVE_INFINITY), 0);
   11.45 +        assertEquals(JSType.toInt32(Double.NEGATIVE_INFINITY), 0);
   11.46 +        assertEquals(JSType.toInt32(9223372036854775807.0d), 0);
   11.47 +        assertEquals(JSType.toInt32(-9223372036854775807.0d), 0);
   11.48 +        assertEquals(JSType.toInt32(1099511627776.0d), 0);
   11.49 +        assertEquals(JSType.toInt32(-1099511627776.0d), 0);
   11.50 +        assertEquals(JSType.toInt32(4294967295.0d), -1);
   11.51 +        assertEquals(JSType.toInt32(4294967296.0d), 0);
   11.52 +        assertEquals(JSType.toInt32(4294967297.0d), 1);
   11.53 +        assertEquals(JSType.toInt32(-4294967295.0d), 1);
   11.54 +        assertEquals(JSType.toInt32(-4294967296.0d), 0);
   11.55 +        assertEquals(JSType.toInt32(-4294967297.d), -1);
   11.56 +        assertEquals(JSType.toInt32(4294967295.6d), -1);
   11.57 +        assertEquals(JSType.toInt32(4294967296.6d), 0);
   11.58 +        assertEquals(JSType.toInt32(4294967297.6d), 1);
   11.59 +        assertEquals(JSType.toInt32(-4294967295.6d), 1);
   11.60 +        assertEquals(JSType.toInt32(-4294967296.6d), 0);
   11.61 +        assertEquals(JSType.toInt32(-4294967297.6d), -1);
   11.62 +    }
   11.63 +
   11.64 +    /**
   11.65 +     * Test of JSType.toUint16(double)
   11.66 +     */
   11.67 +    @Test
   11.68 +    public void testToUint16() {
   11.69 +        assertEquals(JSType.toUint16(+0.0), 0);
   11.70 +        assertEquals(JSType.toUint16(-0.0), 0);
   11.71 +        assertEquals(JSType.toUint16(Double.NaN), 0);
   11.72 +        assertEquals(JSType.toUint16(Double.POSITIVE_INFINITY), 0);
   11.73 +        assertEquals(JSType.toUint16(Double.NEGATIVE_INFINITY), 0);
   11.74 +        assertEquals(JSType.toUint16(9223372036854775807.0d), 0);
   11.75 +        assertEquals(JSType.toUint16(-9223372036854775807.0d), 0);
   11.76 +        assertEquals(JSType.toUint16(1099511627776.0d), 0);
   11.77 +        assertEquals(JSType.toUint16(-1099511627776.0d), 0);
   11.78 +        assertEquals(JSType.toUint16(4294967295.0d), 65535);
   11.79 +        assertEquals(JSType.toUint16(4294967296.0d), 0);
   11.80 +        assertEquals(JSType.toUint16(4294967297.0d), 1);
   11.81 +        assertEquals(JSType.toUint16(-4294967295.0d), 1);
   11.82 +        assertEquals(JSType.toUint16(-4294967296.0d), 0);
   11.83 +        assertEquals(JSType.toUint16(-4294967297.0d), 65535);
   11.84 +        assertEquals(JSType.toUint16(4294967295.6d), 65535);
   11.85 +        assertEquals(JSType.toUint16(4294967296.6d), 0);
   11.86 +        assertEquals(JSType.toUint16(4294967297.6d), 1);
   11.87 +        assertEquals(JSType.toUint16(-4294967295.6d), 1);
   11.88 +        assertEquals(JSType.toUint16(-4294967296.6d), 0);
   11.89 +        assertEquals(JSType.toUint16(-4294967297.6d), 65535);
   11.90 +    }
   11.91 +
   11.92  }

mercurial