readBytes method

Uint8List readBytes(
  1. int ptr,
  2. int len
)

Copies len bytes at ptr out of the module heap.

slice (a fresh JS snapshot), never subarray: on BOTH compilers .toDart is a view over the JS array, so a subarray view would alias the live heap and read freed memory later (dart2wasm returned garbage bytes in the typed-data suites). The remaining dart2wasm cost is per-element JS reads through the wrapped list — an SDK-level boundary property.

Implementation

Uint8List readBytes(int ptr, int len) {
  if (len == 0) return Uint8List(0);
  final heap = module.heapU8;
  return (heap.callMethod('slice'.toJS, ptr.toJS, (ptr + len).toJS) as JSUint8Array).toDart;
}