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

LibJS: ArrayBuffer.prototype.slice

Implements the aforementioned native Javascript function, following the
specification's [1] implementation.

[1] https://tc39.es/ecma262/#sec-arraybuffer.prototype.slice
This commit is contained in:
Jamie Mansfield 2021-04-02 21:31:23 +01:00 committed by Andreas Kling
parent b50de19cd3
commit 01187e58f2
4 changed files with 82 additions and 1 deletions

View file

@ -0,0 +1,29 @@
test("single parameter", () => {
const buffer = new ArrayBuffer(16);
const fullView = new Int32Array(buffer);
// modify some value that we can check in the sliced buffer
fullView[3] = 7;
// slice the buffer and use a new int32 view to perform basic checks
const slicedBuffer = buffer.slice(12);
const slicedView = new Int32Array(slicedBuffer);
expect(slicedView).toHaveLength(1);
expect(slicedView[0]).toBe(7);
});
test("both parameters", () => {
const buffer = new ArrayBuffer(16);
const fullView = new Int32Array(buffer);
// modify some value that we can check in the sliced buffer
fullView[1] = 12;
// slice the buffer and use a new int32 view to perform basic checks
const slicedBuffer = buffer.slice(4, 8);
const slicedView = new Int32Array(slicedBuffer);
expect(slicedView).toHaveLength(1);
expect(slicedView[0]).toBe(12);
});