import { ALLOCATE, REGISTER, HEADER, HEADER_SIZE, MAX_BYTELENGTH } from "./runtime"; @sealed export class ArrayBuffer { static isView(value: T): bool { if (value) { if (value instanceof Int8Array) return true; if (value instanceof Uint8Array) return true; if (value instanceof Uint8ClampedArray) return true; if (value instanceof Int16Array) return true; if (value instanceof Uint16Array) return true; if (value instanceof Int32Array) return true; if (value instanceof Uint32Array) return true; if (value instanceof Int64Array) return true; if (value instanceof Uint64Array) return true; if (value instanceof Float32Array) return true; if (value instanceof Float64Array) return true; if (value instanceof DataView) return true; } return false; } constructor(length: i32) { if (length > MAX_BYTELENGTH) throw new RangeError("Invalid array buffer length"); var buffer = ALLOCATE(length); memory.fill(changetype(buffer), 0, length); return REGISTER(buffer); } get byteLength(): i32 { return changetype
(changetype(this) - HEADER_SIZE).payloadSize; } slice(begin: i32 = 0, end: i32 = MAX_BYTELENGTH): ArrayBuffer { var length = this.byteLength; begin = begin < 0 ? max(length + begin, 0) : min(begin, length); end = end < 0 ? max(length + end , 0) : min(end , length); var outSize = max(end - begin, 0); var out = ALLOCATE(outSize); memory.copy(out, changetype(this) + begin, outSize); return REGISTER(out); } toString(): string { return "[object ArrayBuffer]"; } }