Thu, 13 Mar 2014 15:58:24 +0530
8015958: DataView constructor is not defined
Reviewed-by: attila, hannesw, lagergren
1.1 --- a/src/jdk/nashorn/internal/objects/Global.java Wed Mar 12 11:26:00 2014 +0100 1.2 +++ b/src/jdk/nashorn/internal/objects/Global.java Thu Mar 13 15:58:24 2014 +0530 1.3 @@ -226,6 +226,10 @@ 1.4 @Property(name = "ArrayBuffer", attributes = Attribute.NOT_ENUMERABLE) 1.5 public volatile Object arrayBuffer; 1.6 1.7 + /** DataView object */ 1.8 + @Property(name = "DataView", attributes = Attribute.NOT_ENUMERABLE) 1.9 + public volatile Object dataView; 1.10 + 1.11 /** TypedArray (int8) */ 1.12 @Property(name = "Int8Array", attributes = Attribute.NOT_ENUMERABLE) 1.13 public volatile Object int8Array; 1.14 @@ -352,6 +356,7 @@ 1.15 private ScriptObject builtinJavaImporter; 1.16 private ScriptObject builtinJavaApi; 1.17 private ScriptObject builtinArrayBuffer; 1.18 + private ScriptObject builtinDataView; 1.19 private ScriptObject builtinInt8Array; 1.20 private ScriptObject builtinUint8Array; 1.21 private ScriptObject builtinUint8ClampedArray; 1.22 @@ -866,6 +871,10 @@ 1.23 return ScriptFunction.getPrototype(builtinArrayBuffer); 1.24 } 1.25 1.26 + ScriptObject getDataViewPrototype() { 1.27 + return ScriptFunction.getPrototype(builtinDataView); 1.28 + } 1.29 + 1.30 ScriptObject getInt8ArrayPrototype() { 1.31 return ScriptFunction.getPrototype(builtinInt8Array); 1.32 } 1.33 @@ -1634,6 +1643,7 @@ 1.34 1.35 private void initTypedArray() { 1.36 this.builtinArrayBuffer = initConstructor("ArrayBuffer"); 1.37 + this.builtinDataView = initConstructor("DataView"); 1.38 this.builtinInt8Array = initConstructor("Int8Array"); 1.39 this.builtinUint8Array = initConstructor("Uint8Array"); 1.40 this.builtinUint8ClampedArray = initConstructor("Uint8ClampedArray"); 1.41 @@ -1674,6 +1684,7 @@ 1.42 this.typeError = this.builtinTypeError; 1.43 this.uriError = this.builtinURIError; 1.44 this.arrayBuffer = this.builtinArrayBuffer; 1.45 + this.dataView = this.builtinDataView; 1.46 this.int8Array = this.builtinInt8Array; 1.47 this.uint8Array = this.builtinUint8Array; 1.48 this.uint8ClampedArray = this.builtinUint8ClampedArray;
2.1 --- a/src/jdk/nashorn/internal/objects/NativeArrayBuffer.java Wed Mar 12 11:26:00 2014 +0100 2.2 +++ b/src/jdk/nashorn/internal/objects/NativeArrayBuffer.java Thu Mar 13 15:58:24 2014 +0530 2.3 @@ -25,6 +25,7 @@ 2.4 2.5 package jdk.nashorn.internal.objects; 2.6 2.7 +import java.nio.ByteBuffer; 2.8 import java.util.Arrays; 2.9 import jdk.nashorn.internal.objects.annotations.Attribute; 2.10 import jdk.nashorn.internal.objects.annotations.Constructor; 2.11 @@ -128,4 +129,16 @@ 2.12 public int getByteLength() { 2.13 return buffer.length; 2.14 } 2.15 + 2.16 + ByteBuffer getBuffer() { 2.17 + return ByteBuffer.wrap(buffer); 2.18 + } 2.19 + 2.20 + ByteBuffer getBuffer(final int offset) { 2.21 + return ByteBuffer.wrap(buffer, offset, buffer.length - offset); 2.22 + } 2.23 + 2.24 + ByteBuffer getBuffer(final int offset, final int length) { 2.25 + return ByteBuffer.wrap(buffer, offset, length); 2.26 + } 2.27 }
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/src/jdk/nashorn/internal/objects/NativeDataView.java Thu Mar 13 15:58:24 2014 +0530 3.3 @@ -0,0 +1,1015 @@ 3.4 +/* 3.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 3.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3.7 + * 3.8 + * This code is free software; you can redistribute it and/or modify it 3.9 + * under the terms of the GNU General Public License version 2 only, as 3.10 + * published by the Free Software Foundation. Oracle designates this 3.11 + * particular file as subject to the "Classpath" exception as provided 3.12 + * by Oracle in the LICENSE file that accompanied this code. 3.13 + * 3.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 3.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 3.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 3.17 + * version 2 for more details (a copy is included in the LICENSE file that 3.18 + * accompanied this code). 3.19 + * 3.20 + * You should have received a copy of the GNU General Public License version 3.21 + * 2 along with this work; if not, write to the Free Software Foundation, 3.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 3.23 + * 3.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 3.25 + * or visit www.oracle.com if you need additional information or have any 3.26 + * questions. 3.27 + */ 3.28 +package jdk.nashorn.internal.objects; 3.29 + 3.30 +import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED; 3.31 +import static jdk.nashorn.internal.runtime.ECMAErrors.rangeError; 3.32 +import static jdk.nashorn.internal.runtime.ECMAErrors.typeError; 3.33 + 3.34 +import java.nio.ByteBuffer; 3.35 +import java.nio.ByteOrder; 3.36 +import jdk.nashorn.internal.objects.annotations.Attribute; 3.37 +import jdk.nashorn.internal.objects.annotations.Constructor; 3.38 +import jdk.nashorn.internal.objects.annotations.Function; 3.39 +import jdk.nashorn.internal.objects.annotations.Property; 3.40 +import jdk.nashorn.internal.objects.annotations.ScriptClass; 3.41 +import jdk.nashorn.internal.objects.annotations.SpecializedConstructor; 3.42 +import jdk.nashorn.internal.objects.annotations.SpecializedFunction; 3.43 +import jdk.nashorn.internal.runtime.JSType; 3.44 +import jdk.nashorn.internal.runtime.PropertyMap; 3.45 +import jdk.nashorn.internal.runtime.ScriptObject; 3.46 +import jdk.nashorn.internal.runtime.ScriptRuntime; 3.47 + 3.48 +/** 3.49 + * <p> 3.50 + * DataView builtin constructor. Based on the specification here: 3.51 + * http://www.khronos.org/registry/typedarray/specs/latest/#8 3.52 + * </p> 3.53 + * <p> 3.54 + * An ArrayBuffer is a useful object for representing an arbitrary chunk of data. 3.55 + * In many cases, such data will be read from disk or from the network, and will 3.56 + * not follow the alignment restrictions that are imposed on the typed array views 3.57 + * described earlier. In addition, the data will often be heterogeneous in nature 3.58 + * and have a defined byte order. The DataView view provides a low-level interface 3.59 + * for reading such data from and writing it to an ArrayBuffer. 3.60 + * </p> 3.61 + * <p> 3.62 + * Regardless of the host computer's endianness, DataView reads or writes values 3.63 + * to or from main memory with a specified endianness: big or little. 3.64 + * </p> 3.65 + */ 3.66 +@ScriptClass("DataView") 3.67 +public class NativeDataView extends ScriptObject { 3.68 + // initialized by nasgen 3.69 + private static PropertyMap $nasgenmap$; 3.70 + 3.71 + // inherited ArrayBufferView properties 3.72 + 3.73 + /** 3.74 + * Underlying ArrayBuffer storage object 3.75 + */ 3.76 + @Property(attributes = Attribute.NON_ENUMERABLE_CONSTANT) 3.77 + public final Object buffer; 3.78 + 3.79 + /** 3.80 + * The offset in bytes from the start of the ArrayBuffer 3.81 + */ 3.82 + @Property(attributes = Attribute.NON_ENUMERABLE_CONSTANT) 3.83 + public final int byteOffset; 3.84 + 3.85 + /** 3.86 + * The number of bytes from the offset that this DataView will reference 3.87 + */ 3.88 + @Property(attributes = Attribute.NON_ENUMERABLE_CONSTANT) 3.89 + public final int byteLength; 3.90 + 3.91 + // underlying ByteBuffer 3.92 + private final ByteBuffer buf; 3.93 + 3.94 + private NativeDataView(NativeArrayBuffer arrBuf) { 3.95 + this(arrBuf, arrBuf.getBuffer(), 0); 3.96 + } 3.97 + 3.98 + private NativeDataView(NativeArrayBuffer arrBuf, int offset) { 3.99 + this(arrBuf, bufferFrom(arrBuf, offset), offset); 3.100 + } 3.101 + 3.102 + private NativeDataView(NativeArrayBuffer arrBuf, int offset, int length) { 3.103 + this(arrBuf, bufferFrom(arrBuf, offset, length), offset, length); 3.104 + } 3.105 + 3.106 + private NativeDataView(final NativeArrayBuffer arrBuf, final ByteBuffer buf, final int offset) { 3.107 + this(arrBuf, buf, offset, buf.capacity() - offset); 3.108 + } 3.109 + 3.110 + private NativeDataView(final NativeArrayBuffer arrBuf, final ByteBuffer buf, final int offset, final int length) { 3.111 + super(Global.instance().getDataViewPrototype(), $nasgenmap$); 3.112 + this.buffer = arrBuf; 3.113 + this.byteOffset = offset; 3.114 + this.byteLength = length; 3.115 + this.buf = buf; 3.116 + } 3.117 + 3.118 + /** 3.119 + * Create a new DataView object using the passed ArrayBuffer for its 3.120 + * storage. Optional byteOffset and byteLength can be used to limit the 3.121 + * section of the buffer referenced. The byteOffset indicates the offset in 3.122 + * bytes from the start of the ArrayBuffer, and the byteLength is the number 3.123 + * of bytes from the offset that this DataView will reference. If both 3.124 + * byteOffset and byteLength are omitted, the DataView spans the entire 3.125 + * ArrayBuffer range. If the byteLength is omitted, the DataView extends from 3.126 + * the given byteOffset until the end of the ArrayBuffer. 3.127 + * 3.128 + * If the given byteOffset and byteLength references an area beyond the end 3.129 + * of the ArrayBuffer an exception is raised. 3.130 + 3.131 + * @param newObj if this constructor was invoked with 'new' or not 3.132 + * @param self constructor function object 3.133 + * @param args arguments to the constructor 3.134 + * @return newly constructed DataView object 3.135 + */ 3.136 + @Constructor(arity = 1) 3.137 + public static Object constructor(final boolean newObj, final Object self, final Object... args) { 3.138 + if (args.length == 0 || !(args[0] instanceof NativeArrayBuffer)) { 3.139 + throw typeError("not.an.arraybuffer.in.dataview"); 3.140 + } 3.141 + 3.142 + final NativeArrayBuffer arrBuf = (NativeArrayBuffer) args[0]; 3.143 + switch (args.length) { 3.144 + case 1: 3.145 + return new NativeDataView(arrBuf); 3.146 + case 2: 3.147 + return new NativeDataView(arrBuf, JSType.toInt32(args[1])); 3.148 + default: 3.149 + return new NativeDataView(arrBuf, JSType.toInt32(args[1]), JSType.toInt32(args[2])); 3.150 + } 3.151 + } 3.152 + 3.153 + /** 3.154 + * Specialized version of DataView constructor 3.155 + * 3.156 + * @param newObj if this constructor was invoked with 'new' or not 3.157 + * @param self constructor function object 3.158 + * @param arrBuf underlying ArrayBuffer storage object 3.159 + * @param offset offset in bytes from the start of the ArrayBuffer 3.160 + * @return newly constructed DataView object 3.161 + */ 3.162 + @SpecializedConstructor 3.163 + public static Object constructor(final boolean newObj, final Object self, final Object arrBuf, final int offset) { 3.164 + if (!(arrBuf instanceof NativeArrayBuffer)) { 3.165 + throw typeError("not.an.arraybuffer.in.dataview"); 3.166 + } 3.167 + return new NativeDataView((NativeArrayBuffer) arrBuf, offset); 3.168 + } 3.169 + 3.170 + /** 3.171 + * Specialized version of DataView constructor 3.172 + * 3.173 + * @param newObj if this constructor was invoked with 'new' or not 3.174 + * @param self constructor function object 3.175 + * @param arrBuf underlying ArrayBuffer storage object 3.176 + * @param offset in bytes from the start of the ArrayBuffer 3.177 + * @param length is the number of bytes from the offset that this DataView will reference 3.178 + * @return newly constructed DataView object 3.179 + */ 3.180 + @SpecializedConstructor 3.181 + public static Object constructor(final boolean newObj, final Object self, final Object arrBuf, final int offset, final int length) { 3.182 + if (!(arrBuf instanceof NativeArrayBuffer)) { 3.183 + throw typeError("not.an.arraybuffer.in.dataview"); 3.184 + } 3.185 + return new NativeDataView((NativeArrayBuffer) arrBuf, offset, length); 3.186 + } 3.187 + 3.188 + // Gets the value of the given type at the specified byte offset 3.189 + // from the start of the view. There is no alignment constraint; 3.190 + // multi-byte values may be fetched from any offset. 3.191 + // 3.192 + // For multi-byte values, the optional littleEndian argument 3.193 + // indicates whether a big-endian or little-endian value should be 3.194 + // read. If false or undefined, a big-endian value is read. 3.195 + // 3.196 + // These methods raise an exception if they would read 3.197 + // beyond the end of the view. 3.198 + 3.199 + /** 3.200 + * Get 8-bit signed int from given byteOffset 3.201 + * 3.202 + * @param self DataView object 3.203 + * @param byteOffset byte offset to read from 3.204 + * @return 8-bit signed int value at the byteOffset 3.205 + */ 3.206 + @Function(attributes = Attribute.NOT_ENUMERABLE) 3.207 + public static int getInt8(final Object self, final Object byteOffset) { 3.208 + try { 3.209 + return getBuffer(self).get(JSType.toInt32(byteOffset)); 3.210 + } catch (final IndexOutOfBoundsException ioe) { 3.211 + throw rangeError(ioe, "dataview.offset"); 3.212 + } 3.213 + } 3.214 + 3.215 + /** 3.216 + * Get 8-bit signed int from given byteOffset 3.217 + * 3.218 + * @param self DataView object 3.219 + * @param byteOffset byte offset to read from 3.220 + * @return 8-bit signed int value at the byteOffset 3.221 + */ 3.222 + @SpecializedFunction 3.223 + public static int getInt8(final Object self, final int byteOffset) { 3.224 + try { 3.225 + return getBuffer(self).get(byteOffset); 3.226 + } catch (final IndexOutOfBoundsException ioe) { 3.227 + throw rangeError(ioe, "dataview.offset"); 3.228 + } 3.229 + } 3.230 + 3.231 + /** 3.232 + * Get 8-bit unsigned int from given byteOffset 3.233 + * 3.234 + * @param self DataView object 3.235 + * @param byteOffset byte offset to read from 3.236 + * @return 8-bit unsigned int value at the byteOffset 3.237 + */ 3.238 + @Function(attributes = Attribute.NOT_ENUMERABLE) 3.239 + public static int getUint8(final Object self, final Object byteOffset) { 3.240 + try { 3.241 + return (0xFF & getBuffer(self).get(JSType.toInt32(byteOffset))); 3.242 + } catch (final IndexOutOfBoundsException ioe) { 3.243 + throw rangeError(ioe, "dataview.offset"); 3.244 + } 3.245 + } 3.246 + 3.247 + /** 3.248 + * Get 8-bit unsigned int from given byteOffset 3.249 + * 3.250 + * @param self DataView object 3.251 + * @param byteOffset byte offset to read from 3.252 + * @return 8-bit unsigned int value at the byteOffset 3.253 + */ 3.254 + @SpecializedFunction 3.255 + public static int getUint8(final Object self, final int byteOffset) { 3.256 + try { 3.257 + return (0xFF & getBuffer(self).get(byteOffset)); 3.258 + } catch (final IndexOutOfBoundsException ioe) { 3.259 + throw rangeError(ioe, "dataview.offset"); 3.260 + } 3.261 + } 3.262 + 3.263 + /** 3.264 + * Get 16-bit signed int from given byteOffset 3.265 + * 3.266 + * @param self DataView object 3.267 + * @param byteOffset byte offset to read from 3.268 + * @param littleEndian (optional) flag indicating whether to read in little endian order 3.269 + * @return 16-bit signed int value at the byteOffset 3.270 + */ 3.271 + @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1) 3.272 + public static int getInt16(final Object self, final Object byteOffset, final Object littleEndian) { 3.273 + try { 3.274 + return getBuffer(self, littleEndian).getShort(JSType.toInt32(byteOffset)); 3.275 + } catch (final IndexOutOfBoundsException ioe) { 3.276 + throw rangeError(ioe, "dataview.offset"); 3.277 + } 3.278 + } 3.279 + 3.280 + /** 3.281 + * Get 16-bit signed int from given byteOffset 3.282 + * 3.283 + * @param self DataView object 3.284 + * @param byteOffset byte offset to read from 3.285 + * @return 16-bit signed int value at the byteOffset 3.286 + */ 3.287 + @SpecializedFunction 3.288 + public static int getInt16(final Object self, final int byteOffset) { 3.289 + try { 3.290 + return getBuffer(self, false).getShort(byteOffset); 3.291 + } catch (final IndexOutOfBoundsException ioe) { 3.292 + throw rangeError(ioe, "dataview.offset"); 3.293 + } 3.294 + } 3.295 + 3.296 + /** 3.297 + * Get 16-bit signed int from given byteOffset 3.298 + * 3.299 + * @param self DataView object 3.300 + * @param byteOffset byte offset to read from 3.301 + * @param littleEndian (optional) flag indicating whether to read in little endian order 3.302 + * @return 16-bit signed int value at the byteOffset 3.303 + */ 3.304 + @SpecializedFunction 3.305 + public static int getInt16(final Object self, final int byteOffset, final boolean littleEndian) { 3.306 + try { 3.307 + return getBuffer(self, littleEndian).getShort(byteOffset); 3.308 + } catch (final IndexOutOfBoundsException ioe) { 3.309 + throw rangeError(ioe, "dataview.offset"); 3.310 + } 3.311 + } 3.312 + 3.313 + /** 3.314 + * Get 16-bit unsigned int from given byteOffset 3.315 + * 3.316 + * @param self DataView object 3.317 + * @param byteOffset byte offset to read from 3.318 + * @param littleEndian (optional) flag indicating whether to read in little endian order 3.319 + * @return 16-bit unsigned int value at the byteOffset 3.320 + */ 3.321 + @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1) 3.322 + public static int getUint16(final Object self, final Object byteOffset, final Object littleEndian) { 3.323 + try { 3.324 + return (int) (0xFFFF & getBuffer(self, littleEndian).getShort(JSType.toInt32(byteOffset))); 3.325 + } catch (final IndexOutOfBoundsException ioe) { 3.326 + throw rangeError(ioe, "dataview.offset"); 3.327 + } 3.328 + } 3.329 + 3.330 + /** 3.331 + * Get 16-bit unsigned int from given byteOffset 3.332 + * 3.333 + * @param self DataView object 3.334 + * @param byteOffset byte offset to read from 3.335 + * @return 16-bit unsigned int value at the byteOffset 3.336 + */ 3.337 + @SpecializedFunction 3.338 + public static int getUint16(final Object self, final int byteOffset) { 3.339 + try { 3.340 + return (int) (0xFFFF & getBuffer(self, false).getShort(byteOffset)); 3.341 + } catch (final IndexOutOfBoundsException ioe) { 3.342 + throw rangeError(ioe, "dataview.offset"); 3.343 + } 3.344 + } 3.345 + 3.346 + /** 3.347 + * Get 16-bit unsigned int from given byteOffset 3.348 + * 3.349 + * @param self DataView object 3.350 + * @param byteOffset byte offset to read from 3.351 + * @param littleEndian (optional) flag indicating whether to read in little endian order 3.352 + * @return 16-bit unsigned int value at the byteOffset 3.353 + */ 3.354 + @SpecializedFunction 3.355 + public static int getUint16(final Object self, final int byteOffset, final boolean littleEndian) { 3.356 + try { 3.357 + return (int) (0xFFFF & getBuffer(self, littleEndian).getShort(byteOffset)); 3.358 + } catch (final IndexOutOfBoundsException ioe) { 3.359 + throw rangeError(ioe, "dataview.offset"); 3.360 + } 3.361 + } 3.362 + 3.363 + /** 3.364 + * Get 32-bit signed int from given byteOffset 3.365 + * 3.366 + * @param self DataView object 3.367 + * @param byteOffset byte offset to read from 3.368 + * @param littleEndian (optional) flag indicating whether to read in little endian order 3.369 + * @return 32-bit signed int value at the byteOffset 3.370 + */ 3.371 + @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1) 3.372 + public static int getInt32(final Object self, final Object byteOffset, final Object littleEndian) { 3.373 + try { 3.374 + return getBuffer(self, littleEndian).getInt(JSType.toInt32(byteOffset)); 3.375 + } catch (final IndexOutOfBoundsException ioe) { 3.376 + throw rangeError(ioe, "dataview.offset"); 3.377 + } 3.378 + } 3.379 + 3.380 + /** 3.381 + * Get 32-bit signed int from given byteOffset 3.382 + * 3.383 + * @param self DataView object 3.384 + * @param byteOffset byte offset to read from 3.385 + * @return 32-bit signed int value at the byteOffset 3.386 + */ 3.387 + @SpecializedFunction 3.388 + public static int getInt32(final Object self, final int byteOffset) { 3.389 + try { 3.390 + return getBuffer(self, false).getInt(byteOffset); 3.391 + } catch (final IndexOutOfBoundsException ioe) { 3.392 + throw rangeError(ioe, "dataview.offset"); 3.393 + } 3.394 + } 3.395 + 3.396 + /** 3.397 + * Get 32-bit signed int from given byteOffset 3.398 + * 3.399 + * @param self DataView object 3.400 + * @param byteOffset byte offset to read from 3.401 + * @param littleEndian (optional) flag indicating whether to read in little endian order 3.402 + * @return 32-bit signed int value at the byteOffset 3.403 + */ 3.404 + @SpecializedFunction 3.405 + public static int getInt32(final Object self, final int byteOffset, final boolean littleEndian) { 3.406 + try { 3.407 + return getBuffer(self, littleEndian).getInt(byteOffset); 3.408 + } catch (final IndexOutOfBoundsException ioe) { 3.409 + throw rangeError(ioe, "dataview.offset"); 3.410 + } 3.411 + } 3.412 + 3.413 + /** 3.414 + * Get 32-bit unsigned int from given byteOffset 3.415 + * 3.416 + * @param self DataView object 3.417 + * @param byteOffset byte offset to read from 3.418 + * @param littleEndian (optional) flag indicating whether to read in little endian order 3.419 + * @return 32-bit unsigned int value at the byteOffset 3.420 + */ 3.421 + @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1) 3.422 + public static long getUint32(final Object self, final Object byteOffset, final Object littleEndian) { 3.423 + try { 3.424 + return (long) (0xFFFFFFFFL & getBuffer(self, littleEndian).getInt(JSType.toInt32(byteOffset))); 3.425 + } catch (final IndexOutOfBoundsException ioe) { 3.426 + throw rangeError(ioe, "dataview.offset"); 3.427 + } 3.428 + } 3.429 + 3.430 + /** 3.431 + * Get 32-bit unsigned int from given byteOffset 3.432 + * 3.433 + * @param self DataView object 3.434 + * @param byteOffset byte offset to read from 3.435 + * @return 32-bit unsigned int value at the byteOffset 3.436 + */ 3.437 + @SpecializedFunction 3.438 + public static long getUint32(final Object self, final int byteOffset) { 3.439 + try { 3.440 + return (long) (0xFFFFFFFFL & getBuffer(self, false).getInt(JSType.toInt32(byteOffset))); 3.441 + } catch (final IndexOutOfBoundsException ioe) { 3.442 + throw rangeError(ioe, "dataview.offset"); 3.443 + } 3.444 + } 3.445 + 3.446 + /** 3.447 + * Get 32-bit unsigned int from given byteOffset 3.448 + * 3.449 + * @param self DataView object 3.450 + * @param byteOffset byte offset to read from 3.451 + * @param littleEndian (optional) flag indicating whether to read in little endian order 3.452 + * @return 32-bit unsigned int value at the byteOffset 3.453 + */ 3.454 + @SpecializedFunction 3.455 + public static long getUint32(final Object self, final int byteOffset, final boolean littleEndian) { 3.456 + try { 3.457 + return (long) (0xFFFFFFFFL & getBuffer(self, littleEndian).getInt(JSType.toInt32(byteOffset))); 3.458 + } catch (final IndexOutOfBoundsException ioe) { 3.459 + throw rangeError(ioe, "dataview.offset"); 3.460 + } 3.461 + } 3.462 + 3.463 + /** 3.464 + * Get 32-bit float value from given byteOffset 3.465 + * 3.466 + * @param self DataView object 3.467 + * @param byteOffset byte offset to read from 3.468 + * @param littleEndian (optional) flag indicating whether to read in little endian order 3.469 + * @return 32-bit float value at the byteOffset 3.470 + */ 3.471 + @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1) 3.472 + public static double getFloat32(final Object self, final Object byteOffset, final Object littleEndian) { 3.473 + try { 3.474 + return getBuffer(self, littleEndian).getFloat(JSType.toInt32(byteOffset)); 3.475 + } catch (final IndexOutOfBoundsException ioe) { 3.476 + throw rangeError(ioe, "dataview.offset"); 3.477 + } 3.478 + } 3.479 + 3.480 + /** 3.481 + * Get 32-bit float value from given byteOffset 3.482 + * 3.483 + * @param self DataView object 3.484 + * @param byteOffset byte offset to read from 3.485 + * @return 32-bit float value at the byteOffset 3.486 + */ 3.487 + @SpecializedFunction 3.488 + public static double getFloat32(final Object self, final int byteOffset) { 3.489 + try { 3.490 + return getBuffer(self, false).getFloat(byteOffset); 3.491 + } catch (final IndexOutOfBoundsException ioe) { 3.492 + throw rangeError(ioe, "dataview.offset"); 3.493 + } 3.494 + } 3.495 + 3.496 + /** 3.497 + * Get 32-bit float value from given byteOffset 3.498 + * 3.499 + * @param self DataView object 3.500 + * @param byteOffset byte offset to read from 3.501 + * @param littleEndian (optional) flag indicating whether to read in little endian order 3.502 + * @return 32-bit float value at the byteOffset 3.503 + */ 3.504 + @SpecializedFunction 3.505 + public static double getFloat32(final Object self, final int byteOffset, final boolean littleEndian) { 3.506 + try { 3.507 + return getBuffer(self, littleEndian).getFloat(byteOffset); 3.508 + } catch (final IndexOutOfBoundsException ioe) { 3.509 + throw rangeError(ioe, "dataview.offset"); 3.510 + } 3.511 + } 3.512 + 3.513 + /** 3.514 + * Get 64-bit float value from given byteOffset 3.515 + * 3.516 + * @param self DataView object 3.517 + * @param byteOffset byte offset to read from 3.518 + * @param littleEndian (optional) flag indicating whether to read in little endian order 3.519 + * @return 64-bit float value at the byteOffset 3.520 + */ 3.521 + @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1) 3.522 + public static double getFloat64(final Object self, final Object byteOffset, final Object littleEndian) { 3.523 + try { 3.524 + return getBuffer(self, littleEndian).getDouble(JSType.toInt32(byteOffset)); 3.525 + } catch (final IndexOutOfBoundsException ioe) { 3.526 + throw rangeError(ioe, "dataview.offset"); 3.527 + } 3.528 + } 3.529 + 3.530 + /** 3.531 + * Get 64-bit float value from given byteOffset 3.532 + * 3.533 + * @param self DataView object 3.534 + * @param byteOffset byte offset to read from 3.535 + * @return 64-bit float value at the byteOffset 3.536 + */ 3.537 + @SpecializedFunction 3.538 + public static double getFloat64(final Object self, final int byteOffset) { 3.539 + try { 3.540 + return getBuffer(self, false).getDouble(byteOffset); 3.541 + } catch (final IndexOutOfBoundsException ioe) { 3.542 + throw rangeError(ioe, "dataview.offset"); 3.543 + } 3.544 + } 3.545 + 3.546 + /** 3.547 + * Get 64-bit float value from given byteOffset 3.548 + * 3.549 + * @param self DataView object 3.550 + * @param byteOffset byte offset to read from 3.551 + * @param littleEndian (optional) flag indicating whether to read in little endian order 3.552 + * @return 64-bit float value at the byteOffset 3.553 + */ 3.554 + @SpecializedFunction 3.555 + public static double getFloat64(final Object self, final int byteOffset, final boolean littleEndian) { 3.556 + try { 3.557 + return getBuffer(self, littleEndian).getDouble(byteOffset); 3.558 + } catch (final IndexOutOfBoundsException ioe) { 3.559 + throw rangeError(ioe, "dataview.offset"); 3.560 + } 3.561 + } 3.562 + 3.563 + // Stores a value of the given type at the specified byte offset 3.564 + // from the start of the view. There is no alignment constraint; 3.565 + // multi-byte values may be stored at any offset. 3.566 + // 3.567 + // For multi-byte values, the optional littleEndian argument 3.568 + // indicates whether the value should be stored in big-endian or 3.569 + // little-endian byte order. If false or undefined, the value is 3.570 + // stored in big-endian byte order. 3.571 + // 3.572 + // These methods raise an exception if they would write 3.573 + // beyond the end of the view. 3.574 + 3.575 + /** 3.576 + * Set 8-bit signed int at the given byteOffset 3.577 + * 3.578 + * @param self DataView object 3.579 + * @param byteOffset byte offset to read from 3.580 + * @param value byte value to set 3.581 + * @return undefined 3.582 + */ 3.583 + @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 2) 3.584 + public static Object setInt8(final Object self, final Object byteOffset, final Object value) { 3.585 + try { 3.586 + getBuffer(self).put(JSType.toInt32(byteOffset), (byte)JSType.toInt32(value)); 3.587 + return UNDEFINED; 3.588 + } catch (final IndexOutOfBoundsException ioe) { 3.589 + throw rangeError(ioe, "dataview.offset"); 3.590 + } 3.591 + } 3.592 + 3.593 + /** 3.594 + * Set 8-bit signed int at the given byteOffset 3.595 + * 3.596 + * @param self DataView object 3.597 + * @param byteOffset byte offset to read from 3.598 + * @param value byte value to set 3.599 + * @return undefined 3.600 + */ 3.601 + @SpecializedFunction 3.602 + public static Object setInt8(final Object self, final int byteOffset, final int value) { 3.603 + try { 3.604 + getBuffer(self).put(byteOffset, (byte)value); 3.605 + return UNDEFINED; 3.606 + } catch (final IndexOutOfBoundsException ioe) { 3.607 + throw rangeError(ioe, "dataview.offset"); 3.608 + } 3.609 + } 3.610 + 3.611 + /** 3.612 + * Set 8-bit unsigned int at the given byteOffset 3.613 + * 3.614 + * @param self DataView object 3.615 + * @param byteOffset byte offset to write at 3.616 + * @param value byte value to set 3.617 + * @return undefined 3.618 + */ 3.619 + @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 2) 3.620 + public static Object setUint8(final Object self, final Object byteOffset, final Object value) { 3.621 + try { 3.622 + getBuffer(self).put(JSType.toInt32(byteOffset), (byte)JSType.toInt32(value)); 3.623 + return UNDEFINED; 3.624 + } catch (final IndexOutOfBoundsException ioe) { 3.625 + throw rangeError(ioe, "dataview.offset"); 3.626 + } 3.627 + } 3.628 + 3.629 + /** 3.630 + * Set 8-bit unsigned int at the given byteOffset 3.631 + * 3.632 + * @param self DataView object 3.633 + * @param byteOffset byte offset to write at 3.634 + * @param value byte value to set 3.635 + * @return undefined 3.636 + */ 3.637 + @SpecializedFunction 3.638 + public static Object setUint8(final Object self, final int byteOffset, final int value) { 3.639 + try { 3.640 + getBuffer(self).put(byteOffset, (byte)value); 3.641 + return UNDEFINED; 3.642 + } catch (final IndexOutOfBoundsException ioe) { 3.643 + throw rangeError(ioe, "dataview.offset"); 3.644 + } 3.645 + } 3.646 + 3.647 + /** 3.648 + * Set 16-bit signed int at the given byteOffset 3.649 + * 3.650 + * @param self DataView object 3.651 + * @param byteOffset byte offset to write at 3.652 + * @param value short value to set 3.653 + * @param littleEndian (optional) flag indicating whether to write in little endian order 3.654 + * @return undefined 3.655 + */ 3.656 + @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 2) 3.657 + public static Object setInt16(final Object self, final Object byteOffset, final Object value, final Object littleEndian) { 3.658 + try { 3.659 + getBuffer(self, littleEndian).putShort(JSType.toInt32(byteOffset), (short)JSType.toInt32(value)); 3.660 + return UNDEFINED; 3.661 + } catch (final IndexOutOfBoundsException ioe) { 3.662 + throw rangeError(ioe, "dataview.offset"); 3.663 + } 3.664 + } 3.665 + 3.666 + /** 3.667 + * Set 16-bit signed int at the given byteOffset 3.668 + * 3.669 + * @param self DataView object 3.670 + * @param byteOffset byte offset to write at 3.671 + * @param value short value to set 3.672 + * @return undefined 3.673 + */ 3.674 + @SpecializedFunction 3.675 + public static Object setInt16(final Object self, final int byteOffset, final int value) { 3.676 + try { 3.677 + getBuffer(self, false).putShort(byteOffset, (short)value); 3.678 + return UNDEFINED; 3.679 + } catch (final IndexOutOfBoundsException ioe) { 3.680 + throw rangeError(ioe, "dataview.offset"); 3.681 + } 3.682 + } 3.683 + 3.684 + /** 3.685 + * Set 16-bit signed int at the given byteOffset 3.686 + * 3.687 + * @param self DataView object 3.688 + * @param byteOffset byte offset to write at 3.689 + * @param value short value to set 3.690 + * @param littleEndian (optional) flag indicating whether to write in little endian order 3.691 + * @return undefined 3.692 + */ 3.693 + @SpecializedFunction 3.694 + public static Object setInt16(final Object self, final int byteOffset, final int value, final boolean littleEndian) { 3.695 + try { 3.696 + getBuffer(self, littleEndian).putShort(byteOffset, (short)value); 3.697 + return UNDEFINED; 3.698 + } catch (final IndexOutOfBoundsException ioe) { 3.699 + throw rangeError(ioe, "dataview.offset"); 3.700 + } 3.701 + } 3.702 + 3.703 + /** 3.704 + * Set 16-bit unsigned int at the given byteOffset 3.705 + * 3.706 + * @param self DataView object 3.707 + * @param byteOffset byte offset to write at 3.708 + * @param value short value to set 3.709 + * @param littleEndian (optional) flag indicating whether to write in little endian order 3.710 + * @return undefined 3.711 + */ 3.712 + @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 2) 3.713 + public static Object setUint16(final Object self, final Object byteOffset, final Object value, final Object littleEndian) { 3.714 + try { 3.715 + getBuffer(self, littleEndian).putShort(JSType.toInt32(byteOffset), (short)JSType.toInt32(value)); 3.716 + return UNDEFINED; 3.717 + } catch (final IndexOutOfBoundsException ioe) { 3.718 + throw rangeError(ioe, "dataview.offset"); 3.719 + } 3.720 + } 3.721 + 3.722 + /** 3.723 + * Set 16-bit unsigned int at the given byteOffset 3.724 + * 3.725 + * @param self DataView object 3.726 + * @param byteOffset byte offset to write at 3.727 + * @param value short value to set 3.728 + * @return undefined 3.729 + */ 3.730 + @SpecializedFunction 3.731 + public static Object setUint16(final Object self, final int byteOffset, final int value) { 3.732 + try { 3.733 + getBuffer(self, false).putShort(byteOffset, (short)value); 3.734 + return UNDEFINED; 3.735 + } catch (final IndexOutOfBoundsException ioe) { 3.736 + throw rangeError(ioe, "dataview.offset"); 3.737 + } 3.738 + } 3.739 + 3.740 + /** 3.741 + * Set 16-bit unsigned int at the given byteOffset 3.742 + * 3.743 + * @param self DataView object 3.744 + * @param byteOffset byte offset to write at 3.745 + * @param value short value to set 3.746 + * @param littleEndian (optional) flag indicating whether to write in little endian order 3.747 + * @return undefined 3.748 + */ 3.749 + @SpecializedFunction 3.750 + public static Object setUint16(final Object self, final int byteOffset, final int value, final boolean littleEndian) { 3.751 + try { 3.752 + getBuffer(self, littleEndian).putShort(byteOffset, (short)value); 3.753 + return UNDEFINED; 3.754 + } catch (final IndexOutOfBoundsException ioe) { 3.755 + throw rangeError(ioe, "dataview.offset"); 3.756 + } 3.757 + } 3.758 + 3.759 + /** 3.760 + * Set 32-bit signed int at the given byteOffset 3.761 + * 3.762 + * @param self DataView object 3.763 + * @param byteOffset byte offset to write at 3.764 + * @param value int value to set 3.765 + * @param littleEndian (optional) flag indicating whether to write in little endian order 3.766 + * @return undefined 3.767 + */ 3.768 + @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 2) 3.769 + public static Object setInt32(final Object self, final Object byteOffset, final Object value, final Object littleEndian) { 3.770 + try { 3.771 + getBuffer(self, littleEndian).putInt(JSType.toInt32(byteOffset), (int)JSType.toInt32(value)); 3.772 + return UNDEFINED; 3.773 + } catch (final IndexOutOfBoundsException ioe) { 3.774 + throw rangeError(ioe, "dataview.offset"); 3.775 + } 3.776 + } 3.777 + 3.778 + /** 3.779 + * Set 32-bit signed int at the given byteOffset 3.780 + * 3.781 + * @param self DataView object 3.782 + * @param byteOffset byte offset to write at 3.783 + * @param value int value to set 3.784 + * @return undefined 3.785 + */ 3.786 + @SpecializedFunction 3.787 + public static Object setInt32(final Object self, final int byteOffset, final int value) { 3.788 + try { 3.789 + getBuffer(self, false).putInt(byteOffset, value); 3.790 + return UNDEFINED; 3.791 + } catch (final IndexOutOfBoundsException ioe) { 3.792 + throw rangeError(ioe, "dataview.offset"); 3.793 + } 3.794 + } 3.795 + 3.796 + /** 3.797 + * Set 32-bit signed int at the given byteOffset 3.798 + * 3.799 + * @param self DataView object 3.800 + * @param byteOffset byte offset to write at 3.801 + * @param value int value to set 3.802 + * @param littleEndian (optional) flag indicating whether to write in little endian order 3.803 + * @return undefined 3.804 + */ 3.805 + @SpecializedFunction 3.806 + public static Object setInt32(final Object self, final int byteOffset, final int value, final boolean littleEndian) { 3.807 + try { 3.808 + getBuffer(self, littleEndian).putInt(byteOffset, value); 3.809 + return UNDEFINED; 3.810 + } catch (final IndexOutOfBoundsException ioe) { 3.811 + throw rangeError(ioe, "dataview.offset"); 3.812 + } 3.813 + } 3.814 + 3.815 + /** 3.816 + * Set 32-bit unsigned int at the given byteOffset 3.817 + * 3.818 + * @param self DataView object 3.819 + * @param byteOffset byte offset to write at 3.820 + * @param value int value to set 3.821 + * @param littleEndian (optional) flag indicating whether to write in little endian order 3.822 + * @return undefined 3.823 + */ 3.824 + @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 2) 3.825 + public static Object setUint32(final Object self, final Object byteOffset, final Object value, final Object littleEndian) { 3.826 + try { 3.827 + getBuffer(self, littleEndian).putInt(JSType.toInt32(byteOffset), (int)JSType.toUint32(value)); 3.828 + return UNDEFINED; 3.829 + } catch (final IndexOutOfBoundsException ioe) { 3.830 + throw rangeError(ioe, "dataview.offset"); 3.831 + } 3.832 + } 3.833 + 3.834 + /** 3.835 + * Set 32-bit unsigned int at the given byteOffset 3.836 + * 3.837 + * @param self DataView object 3.838 + * @param byteOffset byte offset to write at 3.839 + * @param value int value to set 3.840 + * @return undefined 3.841 + */ 3.842 + @SpecializedFunction 3.843 + public static Object setUint32(final Object self, final int byteOffset, final long value) { 3.844 + try { 3.845 + getBuffer(self, false).putInt(byteOffset, (int)value); 3.846 + return UNDEFINED; 3.847 + } catch (final IndexOutOfBoundsException ioe) { 3.848 + throw rangeError(ioe, "dataview.offset"); 3.849 + } 3.850 + } 3.851 + 3.852 + /** 3.853 + * Set 32-bit unsigned int at the given byteOffset 3.854 + * 3.855 + * @param self DataView object 3.856 + * @param byteOffset byte offset to write at 3.857 + * @param value int value to set 3.858 + * @param littleEndian (optional) flag indicating whether to write in little endian order 3.859 + * @return undefined 3.860 + */ 3.861 + @SpecializedFunction 3.862 + public static Object setUint32(final Object self, final int byteOffset, final long value, final boolean littleEndian) { 3.863 + try { 3.864 + getBuffer(self, littleEndian).putInt(byteOffset, (int)value); 3.865 + return UNDEFINED; 3.866 + } catch (final IndexOutOfBoundsException ioe) { 3.867 + throw rangeError(ioe, "dataview.offset"); 3.868 + } 3.869 + } 3.870 + 3.871 + /** 3.872 + * Set 32-bit float at the given byteOffset 3.873 + * 3.874 + * @param self DataView object 3.875 + * @param byteOffset byte offset to write at 3.876 + * @param value float value to set 3.877 + * @param littleEndian (optional) flag indicating whether to write in little endian order 3.878 + * @return undefined 3.879 + */ 3.880 + @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 2) 3.881 + public static Object setFloat32(final Object self, final Object byteOffset, final Object value, final Object littleEndian) { 3.882 + try { 3.883 + getBuffer(self, littleEndian).putFloat((int)JSType.toUint32(byteOffset), (float)JSType.toNumber(value)); 3.884 + return UNDEFINED; 3.885 + } catch (final IndexOutOfBoundsException ioe) { 3.886 + throw rangeError(ioe, "dataview.offset"); 3.887 + } 3.888 + } 3.889 + 3.890 + /** 3.891 + * Set 32-bit float at the given byteOffset 3.892 + * 3.893 + * @param self DataView object 3.894 + * @param byteOffset byte offset to write at 3.895 + * @param value float value to set 3.896 + * @return undefined 3.897 + */ 3.898 + @SpecializedFunction 3.899 + public static Object setFloat32(final Object self, final int byteOffset, final double value) { 3.900 + try { 3.901 + getBuffer(self, false).putFloat(byteOffset, (float)value); 3.902 + return UNDEFINED; 3.903 + } catch (final IndexOutOfBoundsException ioe) { 3.904 + throw rangeError(ioe, "dataview.offset"); 3.905 + } 3.906 + } 3.907 + 3.908 + /** 3.909 + * Set 32-bit float at the given byteOffset 3.910 + * 3.911 + * @param self DataView object 3.912 + * @param byteOffset byte offset to write at 3.913 + * @param value float value to set 3.914 + * @param littleEndian (optional) flag indicating whether to write in little endian order 3.915 + * @return undefined 3.916 + */ 3.917 + @SpecializedFunction 3.918 + public static Object setFloat32(final Object self, final int byteOffset, final double value, final boolean littleEndian) { 3.919 + try { 3.920 + getBuffer(self, littleEndian).putFloat(byteOffset, (float)value); 3.921 + return UNDEFINED; 3.922 + } catch (final IndexOutOfBoundsException ioe) { 3.923 + throw rangeError(ioe, "dataview.offset"); 3.924 + } 3.925 + } 3.926 + 3.927 + /** 3.928 + * Set 64-bit float at the given byteOffset 3.929 + * 3.930 + * @param self DataView object 3.931 + * @param byteOffset byte offset to write at 3.932 + * @param value double value to set 3.933 + * @param littleEndian (optional) flag indicating whether to write in little endian order 3.934 + * @return undefined 3.935 + */ 3.936 + @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 2) 3.937 + public static Object setFloat64(final Object self, final Object byteOffset, final Object value, final Object littleEndian) { 3.938 + try { 3.939 + getBuffer(self, littleEndian).putDouble((int)JSType.toUint32(byteOffset), JSType.toNumber(value)); 3.940 + return UNDEFINED; 3.941 + } catch (final IndexOutOfBoundsException ioe) { 3.942 + throw rangeError(ioe, "dataview.offset"); 3.943 + } 3.944 + } 3.945 + 3.946 + /** 3.947 + * Set 64-bit float at the given byteOffset 3.948 + * 3.949 + * @param self DataView object 3.950 + * @param byteOffset byte offset to write at 3.951 + * @param value double value to set 3.952 + * @return undefined 3.953 + */ 3.954 + @SpecializedFunction 3.955 + public static Object setFloat64(final Object self, final int byteOffset, final double value) { 3.956 + try { 3.957 + getBuffer(self, false).putDouble(byteOffset, value); 3.958 + return UNDEFINED; 3.959 + } catch (final IndexOutOfBoundsException ioe) { 3.960 + throw rangeError(ioe, "dataview.offset"); 3.961 + } 3.962 + } 3.963 + 3.964 + /** 3.965 + * Set 64-bit float at the given byteOffset 3.966 + * 3.967 + * @param self DataView object 3.968 + * @param byteOffset byte offset to write at 3.969 + * @param value double value to set 3.970 + * @param littleEndian (optional) flag indicating whether to write in little endian order 3.971 + * @return undefined 3.972 + */ 3.973 + @SpecializedFunction 3.974 + public static Object setFloat64(final Object self, final int byteOffset, final double value, final boolean littleEndian) { 3.975 + try { 3.976 + getBuffer(self, littleEndian).putDouble(byteOffset, value); 3.977 + return UNDEFINED; 3.978 + } catch (final IndexOutOfBoundsException ioe) { 3.979 + throw rangeError(ioe, "dataview.offset"); 3.980 + } 3.981 + } 3.982 + 3.983 + // internals only below this point 3.984 + private static ByteBuffer bufferFrom(final NativeArrayBuffer nab, final int offset) { 3.985 + try { 3.986 + return nab.getBuffer(offset); 3.987 + } catch (final IndexOutOfBoundsException ioe) { 3.988 + throw rangeError(ioe, "dataview.constructor.offset"); 3.989 + } 3.990 + } 3.991 + 3.992 + private static ByteBuffer bufferFrom(final NativeArrayBuffer nab, final int offset, final int length) { 3.993 + try { 3.994 + return nab.getBuffer(offset, length); 3.995 + } catch (final IndexOutOfBoundsException ioe) { 3.996 + throw rangeError(ioe, "dataview.constructor.offset"); 3.997 + } 3.998 + } 3.999 + 3.1000 + private static NativeDataView checkSelf(final Object self) { 3.1001 + if (!(self instanceof NativeDataView)) { 3.1002 + throw typeError("not.an.arraybuffer", ScriptRuntime.safeToString(self)); 3.1003 + } 3.1004 + return (NativeDataView)self; 3.1005 + } 3.1006 + 3.1007 + private static ByteBuffer getBuffer(final Object self) { 3.1008 + return checkSelf(self).buf; 3.1009 + } 3.1010 + 3.1011 + private static ByteBuffer getBuffer(final Object self, final Object littleEndian) { 3.1012 + return getBuffer(self, JSType.toBoolean(littleEndian)); 3.1013 + } 3.1014 + 3.1015 + private static ByteBuffer getBuffer(final Object self, final boolean littleEndian) { 3.1016 + return getBuffer(self).order(littleEndian? ByteOrder.LITTLE_ENDIAN : ByteOrder.BIG_ENDIAN); 3.1017 + } 3.1018 +}
4.1 --- a/src/jdk/nashorn/internal/runtime/Context.java Wed Mar 12 11:26:00 2014 +0100 4.2 +++ b/src/jdk/nashorn/internal/runtime/Context.java Thu Mar 13 15:58:24 2014 +0530 4.3 @@ -649,7 +649,7 @@ 4.4 * Checks that the given Class can be accessed from no permissions context. 4.5 * 4.6 * @param clazz Class object 4.7 - * @throw SecurityException if not accessible 4.8 + * @throws SecurityException if not accessible 4.9 */ 4.10 public static void checkPackageAccess(final Class<?> clazz) { 4.11 final SecurityManager sm = System.getSecurityManager(); 4.12 @@ -666,7 +666,7 @@ 4.13 * Checks that the given package name can be accessed from no permissions context. 4.14 * 4.15 * @param pkgName package name 4.16 - * @throw SecurityException if not accessible 4.17 + * @throws SecurityException if not accessible 4.18 */ 4.19 public static void checkPackageAccess(final String pkgName) { 4.20 final SecurityManager sm = System.getSecurityManager();
5.1 --- a/src/jdk/nashorn/internal/runtime/resources/Messages.properties Wed Mar 12 11:26:00 2014 +0100 5.2 +++ b/src/jdk/nashorn/internal/runtime/resources/Messages.properties Thu Mar 13 15:58:24 2014 +0530 5.3 @@ -79,6 +79,7 @@ 5.4 type.error.not.a.constructor={0} is not a constructor function 5.5 type.error.not.a.file={0} is not a File 5.6 type.error.not.a.bytebuffer={0} is not a java.nio.ByteBuffer 5.7 +type.error.not.an.arraybuffer.in.dataview=First arg to DataView constructor must be an ArrayBuffer 5.8 5.9 # operations not permitted on undefined 5.10 type.error.cant.call.undefined=Cannot call undefined 5.11 @@ -137,6 +138,9 @@ 5.12 type.error.method.not.constructor=Java method {0} can't be used as a constructor. 5.13 type.error.env.not.object=$ENV must be an Object. 5.14 type.error.unsupported.java.to.type=Unsupported Java.to target type {0}. 5.15 + 5.16 +range.error.dataview.constructor.offset=Wrong offset or length in DataView constructor 5.17 +range.error.dataview.offset=Offset is outside the bounds of the DataView 5.18 range.error.inappropriate.array.length=inappropriate array length: {0} 5.19 range.error.inappropriate.array.buffer.length=inappropriate array buffer length: {0} 5.20 range.error.invalid.fraction.digits=fractionDigits argument to {0} must be in [0, 20]
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 6.2 +++ b/test/script/basic/dataview_endian.js Thu Mar 13 15:58:24 2014 +0530 6.3 @@ -0,0 +1,70 @@ 6.4 +/* 6.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 6.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 6.7 + * 6.8 + * This code is free software; you can redistribute it and/or modify it 6.9 + * under the terms of the GNU General Public License version 2 only, as 6.10 + * published by the Free Software Foundation. 6.11 + * 6.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 6.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 6.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 6.15 + * version 2 for more details (a copy is included in the LICENSE file that 6.16 + * accompanied this code). 6.17 + * 6.18 + * You should have received a copy of the GNU General Public License version 6.19 + * 2 along with this work; if not, write to the Free Software Foundation, 6.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 6.21 + * 6.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 6.23 + * or visit www.oracle.com if you need additional information or have any 6.24 + * questions. 6.25 + */ 6.26 + 6.27 +/** 6.28 + * JDK-8015958: DataView constructor is not defined 6.29 + * 6.30 + * @test 6.31 + * @run 6.32 + */ 6.33 + 6.34 +// set/get endianess checks 6.35 + 6.36 +var buffer = new ArrayBuffer(4); 6.37 +var dv = new DataView(buffer); 6.38 + 6.39 +// write (default) big endian, read big/little endian 6.40 +dv.setUint16(0, 0xABCD); 6.41 +Assert.assertEquals(dv.getUint16(0), 0xABCD); 6.42 +Assert.assertEquals(dv.getUint16(0, false), 0xABCD); 6.43 +Assert.assertEquals(dv.getUint16(0, true), 0xCDAB); 6.44 + 6.45 +// write little endian, read big/little endian 6.46 +dv.setUint16(0, 0xABCD, true); 6.47 +Assert.assertEquals(dv.getUint16(0), 0xCDAB); 6.48 +Assert.assertEquals(dv.getUint16(0, false), 0xCDAB); 6.49 +Assert.assertEquals(dv.getUint16(0, true), 0xABCD); 6.50 + 6.51 +// write explicit big endian, read big/little endian 6.52 +dv.setUint16(0, 0xABCD, false); 6.53 +Assert.assertEquals(dv.getUint16(0), 0xABCD); 6.54 +Assert.assertEquals(dv.getUint16(0, false), 0xABCD); 6.55 +Assert.assertEquals(dv.getUint16(0, true), 0xCDAB); 6.56 + 6.57 +// write (default) big endian, read big/little endian 6.58 +dv.setUint32(0, 0xABCDEF89); 6.59 +Assert.assertEquals(dv.getUint32(0), 0xABCDEF89); 6.60 +Assert.assertEquals(dv.getUint32(0, false), 0xABCDEF89); 6.61 +Assert.assertEquals(dv.getUint32(0, true), 0x89EFCDAB); 6.62 + 6.63 +// write little endian, read big/little endian 6.64 +dv.setUint32(0, 0xABCDEF89, true); 6.65 +Assert.assertEquals(dv.getUint32(0), 0x89EFCDAB); 6.66 +Assert.assertEquals(dv.getUint32(0, false), 0x89EFCDAB); 6.67 +Assert.assertEquals(dv.getUint32(0, true), 0xABCDEF89); 6.68 + 6.69 +// write explicit big endian, read big/little endian 6.70 +dv.setUint32(0, 0xABCDEF89, false); 6.71 +Assert.assertEquals(dv.getUint32(0), 0xABCDEF89); 6.72 +Assert.assertEquals(dv.getUint32(0, false), 0xABCDEF89); 6.73 +Assert.assertEquals(dv.getUint32(0, true), 0x89EFCDAB);
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 7.2 +++ b/test/script/basic/dataview_getset.js Thu Mar 13 15:58:24 2014 +0530 7.3 @@ -0,0 +1,93 @@ 7.4 +/* 7.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 7.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 7.7 + * 7.8 + * This code is free software; you can redistribute it and/or modify it 7.9 + * under the terms of the GNU General Public License version 2 only, as 7.10 + * published by the Free Software Foundation. 7.11 + * 7.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 7.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 7.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 7.15 + * version 2 for more details (a copy is included in the LICENSE file that 7.16 + * accompanied this code). 7.17 + * 7.18 + * You should have received a copy of the GNU General Public License version 7.19 + * 2 along with this work; if not, write to the Free Software Foundation, 7.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 7.21 + * 7.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 7.23 + * or visit www.oracle.com if you need additional information or have any 7.24 + * questions. 7.25 + */ 7.26 + 7.27 +/** 7.28 + * JDK-8015958: DataView constructor is not defined 7.29 + * 7.30 + * @test 7.31 + * @run 7.32 + */ 7.33 + 7.34 +// checking get/set of values of various types 7.35 +// Also basic endianess check. 7.36 + 7.37 +var Float = Java.type("java.lang.Float"); 7.38 +var Double = Java.type("java.lang.Double"); 7.39 + 7.40 +var DOUBLE_MIN = Double.MIN_VALUE; 7.41 +var DOUBLE_MIN_NORMAL = Double.MIN_NORMAL; 7.42 +var FLOAT_MIN = Float.MIN_VALUE; 7.43 +var FLOAT_MIN_NORMAL = Float.MIN_NORMAL; 7.44 + 7.45 +var buffer = new ArrayBuffer(12); 7.46 +var dv = new DataView(buffer); 7.47 + 7.48 +dv.setInt8(1, 123); 7.49 +Assert.assertEquals(dv.getInt8(1), 123); 7.50 +dv.setInt8(1, 123, true); 7.51 +Assert.assertEquals(dv.getInt8(1, true), 123); 7.52 + 7.53 +dv.setUint8(1, 255); 7.54 +Assert.assertEquals(dv.getUint8(1), 255); 7.55 +dv.setUint8(1, 255, true); 7.56 +Assert.assertEquals(dv.getUint8(1, true), 255); 7.57 + 7.58 +dv.setInt16(1, 1234); 7.59 +Assert.assertEquals(dv.getInt16(1), 1234); 7.60 +dv.setInt16(1, 1234, true); 7.61 +Assert.assertEquals(dv.getInt16(1, true), 1234); 7.62 + 7.63 +dv.setUint16(1, 65535); 7.64 +Assert.assertEquals(dv.getUint16(1), 65535); 7.65 +dv.setUint16(1, 65535, true); 7.66 +Assert.assertEquals(dv.getUint16(1, true), 65535); 7.67 + 7.68 +dv.setInt32(1, 1234); 7.69 +Assert.assertEquals(dv.getInt32(1), 1234); 7.70 +dv.setInt32(1, 1234, true); 7.71 +Assert.assertEquals(dv.getInt32(1, true), 1234); 7.72 + 7.73 +dv.setUint32(1, 4294967295); 7.74 +Assert.assertEquals(dv.getUint32(1), 4294967295); 7.75 +dv.setUint32(1, 4294967295, true); 7.76 +Assert.assertEquals(dv.getUint32(1, true), 4294967295); 7.77 + 7.78 +dv.setFloat64(1, Math.PI); 7.79 +Assert.assertEquals(dv.getFloat64(1), Math.PI, DOUBLE_MIN); 7.80 +dv.setFloat64(1, Math.PI, true); 7.81 +Assert.assertEquals(dv.getFloat64(1, true), Math.PI, DOUBLE_MIN); 7.82 + 7.83 +dv.setFloat64(1, DOUBLE_MIN_NORMAL); 7.84 +Assert.assertEquals(dv.getFloat64(1), DOUBLE_MIN_NORMAL, DOUBLE_MIN); 7.85 +dv.setFloat64(1, DOUBLE_MIN_NORMAL, true); 7.86 +Assert.assertEquals(dv.getFloat64(1, true), DOUBLE_MIN_NORMAL, DOUBLE_MIN); 7.87 + 7.88 +dv.setFloat32(1, 1.414); 7.89 +Assert["assertEquals(float, float, float)"](dv.getFloat32(1), 1.414, FLOAT_MIN); 7.90 +dv.setFloat32(1, 1.414, true); 7.91 +Assert["assertEquals(float, float, float)"](dv.getFloat32(1, true), 1.414, FLOAT_MIN); 7.92 + 7.93 +dv.setFloat32(1, FLOAT_MIN_NORMAL); 7.94 +Assert["assertEquals(float, float, float)"](dv.getFloat32(1), FLOAT_MIN_NORMAL, FLOAT_MIN); 7.95 +dv.setFloat32(1, FLOAT_MIN_NORMAL, true); 7.96 +Assert["assertEquals(float, float, float)"](dv.getFloat32(1, true), FLOAT_MIN_NORMAL, FLOAT_MIN);
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 8.2 +++ b/test/script/basic/dataview_new.js Thu Mar 13 15:58:24 2014 +0530 8.3 @@ -0,0 +1,71 @@ 8.4 +/* 8.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 8.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 8.7 + * 8.8 + * This code is free software; you can redistribute it and/or modify it 8.9 + * under the terms of the GNU General Public License version 2 only, as 8.10 + * published by the Free Software Foundation. 8.11 + * 8.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 8.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 8.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 8.15 + * version 2 for more details (a copy is included in the LICENSE file that 8.16 + * accompanied this code). 8.17 + * 8.18 + * You should have received a copy of the GNU General Public License version 8.19 + * 2 along with this work; if not, write to the Free Software Foundation, 8.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 8.21 + * 8.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 8.23 + * or visit www.oracle.com if you need additional information or have any 8.24 + * questions. 8.25 + */ 8.26 + 8.27 +/** 8.28 + * JDK-8015958: DataView constructor is not defined 8.29 + * 8.30 + * @test 8.31 + * @run 8.32 + */ 8.33 + 8.34 +// basic DataView constructor checks. 8.35 + 8.36 +// check ArrayBufferView property values of DataView instance 8.37 +function check(dv, buf, offset, length) { 8.38 + if (dv.buffer !== buf) { 8.39 + fail("DataView.buffer is wrong"); 8.40 + } 8.41 + 8.42 + if (dv.byteOffset != offset) { 8.43 + fail("DataView.byteOffset = " + dv.byteOffset + ", expected " + offset); 8.44 + } 8.45 + 8.46 + if (dv.byteLength != length) { 8.47 + fail("DataView.byteLength = " + dv.byteLength + ", expected " + length); 8.48 + } 8.49 +} 8.50 + 8.51 +var buffer = new ArrayBuffer(12); 8.52 +check(new DataView(buffer), buffer, 0, 12); 8.53 +check(new DataView(buffer, 2), buffer, 2, 10); 8.54 +check(new DataView(buffer, 4, 8), buffer, 4, 8); 8.55 + 8.56 +// make sure expected error is thrown 8.57 +function checkError(callback, ErrorType) { 8.58 + try { 8.59 + callback(); 8.60 + fail("Should have thrown " + ErrorType.name); 8.61 + } catch (e) { 8.62 + if (! (e instanceof ErrorType)) { 8.63 + fail("Expected " + ErrorType.name + " got " + e); 8.64 + } 8.65 + } 8.66 +} 8.67 + 8.68 +// non ArrayBuffer as first arg 8.69 +checkError(function() { new DataView(344) }, TypeError); 8.70 + 8.71 +// illegal offset/length values 8.72 +checkError(function() { new DataView(buffer, -1) }, RangeError); 8.73 +checkError(function() { new DataView(buffer, 15) }, RangeError); 8.74 +checkError(function() { new DataView(buffer, 1, 32) }, RangeError);