1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 08:57:47 +00:00

LibJS: Allow TypedArrays to become detached while sorting

This is a normative change in the Change Array by Copy proposal. See:
17d8b54
This commit is contained in:
Timothy Flynn 2022-11-25 10:04:36 -05:00 committed by Linus Groh
parent 4dfdca74e2
commit 34e328e580
4 changed files with 39 additions and 79 deletions

View file

@ -49,6 +49,28 @@ test("basic functionality", () => {
});
});
test("detached buffer", () => {
TYPED_ARRAYS.forEach(T => {
const typedArray = new T(3);
typedArray[0] = 3;
typedArray[1] = 1;
typedArray[2] = 2;
const sortedTypedArray = typedArray.toSorted((a, b) => {
detachArrayBuffer(typedArray.buffer);
return a - b;
});
expect(typedArray[0]).toBeUndefined();
expect(typedArray[1]).toBeUndefined();
expect(typedArray[2]).toBeUndefined();
expect(sortedTypedArray[0]).toBe(1);
expect(sortedTypedArray[1]).toBe(2);
expect(sortedTypedArray[2]).toBe(3);
});
});
describe("errors", () => {
test("null or undefined this value", () => {
TYPED_ARRAYS.forEach(T => {