Class NativeArrayBuffer

All Implemented Interfaces:
Serializable, ConstProperties<Scriptable>, DebuggableObject, PropHolder<Scriptable>, Scriptable, SymbolScriptable

public class NativeArrayBuffer extends ScriptableObject
A NativeArrayBuffer is the backing buffer for a typed array. Used inside JavaScript code, it implements the ArrayBuffer interface. Used directly from Java, it simply holds a byte array.
See Also:
  • Field Details

  • Constructor Details

    • NativeArrayBuffer

      public NativeArrayBuffer()
      Create an empty buffer.
    • NativeArrayBuffer

      public NativeArrayBuffer(double len)
      Create a buffer of the specified length in bytes.
  • Method Details

    • getClassName

      public String getClassName()
      Description copied from class: ScriptableObject
      Return the name of the class.

      This is typically the same name as the constructor. Classes extending ScriptableObject must implement this abstract method.

      Specified by:
      getClassName in interface Scriptable
      Specified by:
      getClassName in class ScriptableObject
    • init

      public static Object init(Context cx, VarScope scope, boolean sealed)
    • getLength

      public int getLength()
      Get the number of bytes in the buffer.
    • getBuffer

      @Deprecated public byte[] getBuffer()
      Deprecated.
      This method will return null for shared buffers and possibly other buffers in the future. Callers should use getByteBuffer() instead.
      Return the actual bytes that back the buffer. This is a reference to the real buffer, so changes to bytes here will be reflected in the actual object and all its views. In the future, for a shared array buffer this will return null -- callers should use getByteBuffer() instead.
    • getByteBuffer

      public ByteBuffer getByteBuffer()
      Return a buffer that points to the contents. The position will be zero and the limit will be the length of the buffer. The buffer is returned using Buffer.duplicate().
    • detach

      public void detach()
    • isDetached

      public boolean isDetached()
    • isResizable

      public boolean isResizable()
      Return true if this ArrayBuffer is resizable (ES2024).