j2s/lib/src/stdlib/arrays/ArrayBuffer.ts
TopchetoEU ff44423a58
Some checks failed
tagged-release / Tagged Release (push) Has been cancelled
build: split up into multiple projects, use kotlin DLS
2025-01-10 04:05:17 +02:00

31 lines
670 B
TypeScript

import { buffer, type InternalBuffer, map, symbol } from "../primordials.ts";
export const abs = new map(true);
export const abKey: unique symbol = symbol.getSymbol("ArrayBuffer.impl") as any;
export class ArrayBuffer {
public [abKey]!: InternalBuffer;
public get byteLength() {
return this[abKey].length;
}
public get byteOffset() {
return 0;
}
public constructor(val: unknown) {
if (buffer.isBuff(val)) this[abKey] = val;
else this[abKey] = buffer.buff(Number(val));
}
}
export function getAB(buff: InternalBuffer): ArrayBuffer {
let res = abs.get(buff);
if (res == null) {
res = new ArrayBuffer(buff);
abs.set(buff, res);
}
return res;
}