1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 12:57:35 +00:00

LibJS: Expose TypedArray.prototype.byteOffset

This commit is contained in:
Luke 2021-05-21 21:45:47 +01:00 committed by Linus Groh
parent 58afd71ad2
commit 4d34802f74
4 changed files with 43 additions and 4 deletions

View file

@ -0,0 +1,28 @@
// Update when more typed arrays get added
const TYPED_ARRAYS = [
Uint8Array,
Uint16Array,
Uint32Array,
Int8Array,
Int16Array,
Int32Array,
Float32Array,
Float64Array,
];
test("basic functionality", () => {
TYPED_ARRAYS.forEach(T => {
const typedArray = new T([1, 2, 3]);
expect(Object.hasOwn(typedArray, "byteOffset")).toBeFalse();
expect(typedArray.byteOffset).toBe(0);
expect(typedArray.length).toBe(3);
const buffer = typedArray.buffer;
const arrayFromOffset = new T(buffer, T.BYTES_PER_ELEMENT);
expect(arrayFromOffset.byteOffset).toBe(T.BYTES_PER_ELEMENT);
expect(arrayFromOffset.length).toBe(2);
expect(arrayFromOffset[0]).toBe(2);
expect(arrayFromOffset[1]).toBe(3);
});
});