JSObject.makeArrayBufferWithBytesNoCopy constructor

JSObject.makeArrayBufferWithBytesNoCopy(
  1. JSContext context, {
  2. required Bytes bytes,
  3. JSTypedArrayBytesDeallocator? bytesDeallocator,
  4. required Pointer<Void> deallocatorContext,
  5. bool autoDispose = true,
})

Creates a JavaScript Array Buffer object from an existing pointer. If an exception is thrown during this function the bytesDeallocator will always be called. bytes (void*) A pointer to the byte buffer to be used as the backing store of the Typed Array object. bytesDeallocator (JSTypedArrayBytesDeallocator) The allocator to use to deallocate the external buffer when the Typed Array data object is deallocated. deallocatorContext (void*) A pointer to pass back to the deallocator. 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

JSObject.makeArrayBufferWithBytesNoCopy(
  this.context, {
  required Bytes bytes,
  JSTypedArrayBytesDeallocator? bytesDeallocator,
  required Pointer<Void> deallocatorContext,
  bool autoDispose = true,
}) {
  _bytesDeallocatorNC =
      typedArrayBytesDeallocatorCallbackDartToNativeConverter(
        bytesDeallocator,
        bytes.length,
      );
  final JSException exception = JSException.create(context);
  _ref = JSObjectMakeArrayBufferWithBytesNoCopy(
    context.ref,
    bytes.pointer.toCAny(),
    bytes.length,
    _bytesDeallocatorNC?.nativeFunction ?? nullptr,
    deallocatorContext,
    exception.ref,
  );
  if (exception.shouldThrow) throw exception.error;
  attach(calloc.nativeFree, _ref.cast(), autoDispose: autoDispose);
}