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:
parent
4dfdca74e2
commit
34e328e580
4 changed files with 39 additions and 79 deletions
|
@ -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 => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue