Add ArrayBuffer.isView and rework Array.isArray (#431)

This commit is contained in:
Max Graey
2019-02-03 11:41:04 +02:00
committed by Daniel Wirtz
parent 1867416236
commit 4829f3a3e4
18 changed files with 3530 additions and 2567 deletions

View File

@ -4,13 +4,44 @@ import {
allocateUnsafe
} from "./internal/arraybuffer";
import {
Uint8ClampedArray,
Uint8Array,
Int8Array,
Uint16Array,
Int16Array,
Uint32Array,
Int32Array,
Uint64Array,
Int64Array
} from "./typedarray";
import {
DataView
} from "./dataview";
@sealed
export class ArrayBuffer {
readonly byteLength: i32; // capped to [0, MAX_LENGTH]
@inline static isView<T>(value: T): bool {
if (value === null) return false;
if (value instanceof Uint8ClampedArray) return true;
if (value instanceof Uint8Array) return true;
if (value instanceof Int8Array) return true;
if (value instanceof Uint16Array) return true;
if (value instanceof Int16Array) return true;
if (value instanceof Uint32Array) return true;
if (value instanceof Int32Array) return true;
if (value instanceof Uint64Array) return true;
if (value instanceof Int64Array) return true;
if (value instanceof DataView) return true;
return false;
}
// @unsafe
get data(): usize { return changetype<usize>(this) + HEADER_SIZE; }
@inline get data(): usize { return changetype<usize>(this) + HEADER_SIZE; }
constructor(length: i32, unsafe: bool = false) {
if (<u32>length > <u32>MAX_BLENGTH) throw new RangeError("Invalid array buffer length");