This commit is contained in:
dcode
2019-03-12 02:14:30 +01:00
parent 146dfdbb4a
commit 8e9586783f
3 changed files with 69 additions and 49 deletions

View File

@ -5,45 +5,48 @@ import {
} from "./runtime";
import {
Uint8ClampedArray,
Uint8Array,
Int8Array,
Uint16Array,
Uint8Array,
Uint8ClampedArray,
Int16Array,
Uint32Array,
Uint16Array,
Int32Array,
Uint32Array,
Int64Array,
Uint64Array,
Int64Array
Float32Array,
Float64Array
} from "./typedarray";
import {
DataView
} from "./dataview";
@sealed
export class ArrayBuffer extends ArrayBufferBase {
@sealed export class ArrayBuffer extends ArrayBufferBase {
@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;
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;
}
slice(begin: i32 = 0, end: i32 = ArrayBuffer.MAX_BYTELENGTH): ArrayBuffer {
var len = this.byteLength;
begin = begin < 0 ? max(len + begin, 0) : min(begin, len);
end = end < 0 ? max(len + end, 0) : min(end, len);
len = max(end - begin, 0);
var outSize = <usize>len;
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 = <usize>max(end - begin, 0);
var out = ALLOC_RAW(outSize);
memory.copy(out, changetype<usize>(this) + <usize>begin, outSize);
return REGISTER<ArrayBuffer>(out);