JSObject.makeTypedArray constructor

JSObject.makeTypedArray(
  1. JSContext context, {
  2. required JSTypedArrayType arrayType,
  3. required int length,
  4. bool autoDispose = true,
})

Creates a JavaScript Typed Array object with the given number of elements. arrayType A value JSTypedArrayType identifying the type of array to create. If arrayType is kJSTypedArrayTypeNone or kJSTypedArrayTypeArrayBuffer then NULL will be returned. length (size_t) The number of elements to be in the new Typed Array. 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.makeTypedArray(
  this.context, {
  required JSTypedArrayType arrayType,
  required int length,
  bool autoDispose = true,
}) {
  final JSException exception = JSException.create(context);
  _ref = JSObjectMakeTypedArray(
    context.ref,
    JSTypedArrayType.values.indexOf(arrayType),
    length,
    exception.ref,
  );
  if (exception.shouldThrow) throw exception.error;
  attach(calloc.nativeFree, _ref.cast(), autoDispose: autoDispose);
}