src/jdk/nashorn/internal/objects/NativeArrayBuffer.java

Print this page
rev 755 : 8035948: Redesign property listeners for shared classes
Reviewed-by: sundar, lagergren
rev 759 : 8015958: DataView constructor is not defined
Reviewed-by: attila, hannesw, lagergren
rev 760 : 8037400: Remove getInitialMap getters and GlobalObject interface
Reviewed-by: lagergren, jlaskey, attila

*** 23,32 **** --- 23,33 ---- * questions. */ package jdk.nashorn.internal.objects; + import java.nio.ByteBuffer; import java.util.Arrays; import jdk.nashorn.internal.objects.annotations.Attribute; import jdk.nashorn.internal.objects.annotations.Constructor; import jdk.nashorn.internal.objects.annotations.Function; import jdk.nashorn.internal.objects.annotations.Getter;
*** 41,65 **** private final byte[] buffer; // initialized by nasgen private static PropertyMap $nasgenmap$; - static PropertyMap getInitialMap() { - return $nasgenmap$; - } - @Constructor(arity = 1) public static Object constructor(final boolean newObj, final Object self, final Object... args) { if (args.length == 0) { throw new RuntimeException("missing length argument"); } return new NativeArrayBuffer(JSType.toInt32(args[0])); } protected NativeArrayBuffer(final byte[] byteArray, final Global global) { ! super(global.getArrayBufferPrototype(), global.getArrayBufferMap()); this.buffer = byteArray; } protected NativeArrayBuffer(final byte[] byteArray) { this(byteArray, Global.instance()); --- 42,62 ---- private final byte[] buffer; // initialized by nasgen private static PropertyMap $nasgenmap$; @Constructor(arity = 1) public static Object constructor(final boolean newObj, final Object self, final Object... args) { if (args.length == 0) { throw new RuntimeException("missing length argument"); } return new NativeArrayBuffer(JSType.toInt32(args[0])); } protected NativeArrayBuffer(final byte[] byteArray, final Global global) { ! super(global.getArrayBufferPrototype(), $nasgenmap$); this.buffer = byteArray; } protected NativeArrayBuffer(final byte[] byteArray) { this(byteArray, Global.instance());
*** 126,131 **** --- 123,140 ---- } public int getByteLength() { return buffer.length; } + + ByteBuffer getBuffer() { + return ByteBuffer.wrap(buffer); + } + + ByteBuffer getBuffer(final int offset) { + return ByteBuffer.wrap(buffer, offset, buffer.length - offset); + } + + ByteBuffer getBuffer(final int offset, final int length) { + return ByteBuffer.wrap(buffer, offset, length); + } }