///
import { OBJECT, BLOCK_MAXSIZE, TOTAL_OVERHEAD } from "./rt/common";
import { Runtime } from "shared/runtime";
import { idof } from "./builtins";
import { E_INVALIDLENGTH } from "./util/error";
export abstract class ArrayBufferView {
readonly buffer: ArrayBuffer;
@unsafe readonly dataStart: usize;
readonly byteLength: i32;
get byteOffset(): i32 {
return (this.dataStart - changetype(this.buffer));
}
protected constructor(length: i32, alignLog2: i32) {
if (length > BLOCK_MAXSIZE >>> alignLog2) throw new RangeError(E_INVALIDLENGTH);
let buffer = changetype(__new(length = length << alignLog2, idof()));
if (ASC_RUNTIME != Runtime.Incremental) {
memory.fill(changetype(buffer), 0, length);
}
this.buffer = buffer; // links
this.dataStart = changetype(buffer);
this.byteLength = length;
}
}
@final export class ArrayBuffer {
static isView(value: T): bool {
if (isNullable()) {
if (changetype(value) == 0) return false;
}
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 > BLOCK_MAXSIZE) throw new RangeError(E_INVALIDLENGTH);
let buffer = changetype(__new(length, idof()));
if (ASC_RUNTIME != Runtime.Incremental) {
memory.fill(changetype(buffer), 0, length);
}
return buffer;
}
get byteLength(): i32 {
return changetype