Wed, 14 Jun 2017 10:07:07 +0200
8181191: getUint32 returning Long
Reviewed-by: attila, jlaskey
src/jdk/nashorn/internal/objects/NativeDataView.java | file | annotate | diff | comparison | revisions | |
test/script/basic/JDK-8181191.js | file | annotate | diff | comparison | revisions |
1.1 --- a/src/jdk/nashorn/internal/objects/NativeDataView.java Tue May 16 13:30:01 2017 -0700 1.2 +++ b/src/jdk/nashorn/internal/objects/NativeDataView.java Wed Jun 14 10:07:07 2017 +0200 1.3 @@ -416,7 +416,7 @@ 1.4 * @return 32-bit unsigned int value at the byteOffset 1.5 */ 1.6 @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1) 1.7 - public static long getUint32(final Object self, final Object byteOffset, final Object littleEndian) { 1.8 + public static double getUint32(final Object self, final Object byteOffset, final Object littleEndian) { 1.9 try { 1.10 return 0xFFFFFFFFL & getBuffer(self, littleEndian).getInt(JSType.toInt32(byteOffset)); 1.11 } catch (final IllegalArgumentException iae) { 1.12 @@ -432,7 +432,7 @@ 1.13 * @return 32-bit unsigned int value at the byteOffset 1.14 */ 1.15 @SpecializedFunction 1.16 - public static long getUint32(final Object self, final int byteOffset) { 1.17 + public static double getUint32(final Object self, final int byteOffset) { 1.18 try { 1.19 return JSType.toUint32(getBuffer(self, false).getInt(JSType.toInt32(byteOffset))); 1.20 } catch (final IllegalArgumentException iae) { 1.21 @@ -449,7 +449,7 @@ 1.22 * @return 32-bit unsigned int value at the byteOffset 1.23 */ 1.24 @SpecializedFunction 1.25 - public static long getUint32(final Object self, final int byteOffset, final boolean littleEndian) { 1.26 + public static double getUint32(final Object self, final int byteOffset, final boolean littleEndian) { 1.27 try { 1.28 return JSType.toUint32(getBuffer(self, littleEndian).getInt(JSType.toInt32(byteOffset))); 1.29 } catch (final IllegalArgumentException iae) { 1.30 @@ -837,9 +837,9 @@ 1.31 * @return undefined 1.32 */ 1.33 @SpecializedFunction 1.34 - public static Object setUint32(final Object self, final int byteOffset, final long value) { 1.35 + public static Object setUint32(final Object self, final int byteOffset, final double value) { 1.36 try { 1.37 - getBuffer(self, false).putInt(byteOffset, (int)value); 1.38 + getBuffer(self, false).putInt(byteOffset, (int) JSType.toUint32(value)); 1.39 return UNDEFINED; 1.40 } catch (final IllegalArgumentException iae) { 1.41 throw rangeError(iae, "dataview.offset"); 1.42 @@ -856,9 +856,9 @@ 1.43 * @return undefined 1.44 */ 1.45 @SpecializedFunction 1.46 - public static Object setUint32(final Object self, final int byteOffset, final long value, final boolean littleEndian) { 1.47 + public static Object setUint32(final Object self, final int byteOffset, final double value, final boolean littleEndian) { 1.48 try { 1.49 - getBuffer(self, littleEndian).putInt(byteOffset, (int)value); 1.50 + getBuffer(self, littleEndian).putInt(byteOffset, (int) JSType.toUint32(value)); 1.51 return UNDEFINED; 1.52 } catch (final IllegalArgumentException iae) { 1.53 throw rangeError(iae, "dataview.offset");
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/test/script/basic/JDK-8181191.js Wed Jun 14 10:07:07 2017 +0200 2.3 @@ -0,0 +1,52 @@ 2.4 +/* 2.5 + * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. 2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.7 + * 2.8 + * This code is free software; you can redistribute it and/or modify it 2.9 + * under the terms of the GNU General Public License version 2 only, as 2.10 + * published by the Free Software Foundation. 2.11 + * 2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 2.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 2.15 + * version 2 for more details (a copy is included in the LICENSE file that 2.16 + * accompanied this code). 2.17 + * 2.18 + * You should have received a copy of the GNU General Public License version 2.19 + * 2 along with this work; if not, write to the Free Software Foundation, 2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2.21 + * 2.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2.23 + * or visit www.oracle.com if you need additional information or have any 2.24 + * questions. 2.25 + */ 2.26 + 2.27 +/** 2.28 + * JDK-8181191: getUint32 returning Long 2.29 + * 2.30 + * @test 2.31 + * @run 2.32 + */ 2.33 + 2.34 + 2.35 +function uint32(x) { 2.36 + var buffer = new ArrayBuffer(16); 2.37 + var dataview = new DataView(buffer); 2.38 + dataview.setUint32(0, x); 2.39 + return dataview.getUint32(0); 2.40 +} 2.41 + 2.42 +Assert.assertTrue(typeof uint32(0x7f) === 'number'); 2.43 +Assert.assertTrue(typeof uint32(0x80) === 'number'); 2.44 +Assert.assertTrue(typeof uint32(0xffffffff) === 'number'); 2.45 +Assert.assertTrue(typeof uint32(0x100000000) === 'number'); 2.46 + 2.47 +Assert.assertTrue(uint32(0x7f) === 0x7f); 2.48 +Assert.assertTrue(uint32(0x80) === 0x80); 2.49 +Assert.assertTrue(uint32(0xffffffff) === 0xffffffff); 2.50 +Assert.assertTrue(uint32(0x100000000) === 0x0); 2.51 + 2.52 +Assert.assertTrue(uint32(0x7f) === uint32(0x7f)); 2.53 +Assert.assertTrue(uint32(0x80) === uint32(0x80)); 2.54 +Assert.assertTrue(uint32(0xffffffff) === uint32(0xffffffff)); 2.55 +Assert.assertTrue(uint32(0x100000000) === uint32(0x100000000));