arrayBufferBytes method

Bytes arrayBufferBytes()

Returns a pointer to the data buffer that serves as the backing store for a JavaScript Typed Array object. The pointer returned by this function is temporary and is not guaranteed to remain valid across JavaScriptCore API calls. exception (JSValueRef*) A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.

Implementation

Bytes arrayBufferBytes() {
  final JSException exception1 = JSException.create(context);
  final JSException exception2 = JSException.create(context);
  final Pointer<Void> bytes = JSObjectGetArrayBufferBytesPtr(
    context.ref,
    _ref,
    exception1.ref,
  );
  if (exception1.shouldThrow) throw exception1.error;
  final int length = JSObjectGetArrayBufferByteLength(
    context.ref,
    _ref,
    exception2.ref,
  );
  if (exception2.shouldThrow) throw exception2.error;
  return Bytes(bytes.toUint8List(length), length);
}