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

LibJS: Implement missing conditional when creating a TypedArray subarray

This commit is contained in:
Timothy Flynn 2023-12-27 14:18:06 -05:00 committed by Tim Flynn
parent 522302d5d6
commit f1e01a681e
2 changed files with 19 additions and 1 deletions

View file

@ -1846,7 +1846,7 @@ JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::subarray)
MarkedVector<Value> arguments(vm.heap()); MarkedVector<Value> arguments(vm.heap());
// 15. If O.[[ArrayLength]] is auto and end is undefined, then // 15. If O.[[ArrayLength]] is auto and end is undefined, then
if (typed_array->array_length().is_auto()) { if (typed_array->array_length().is_auto() && end.is_undefined()) {
// a. Let argumentsList be « buffer, 𝔽(beginByteOffset) ». // a. Let argumentsList be « buffer, 𝔽(beginByteOffset) ».
arguments.empend(buffer); arguments.empend(buffer);
arguments.empend(begin_byte_offset.value()); arguments.empend(begin_byte_offset.value());

View file

@ -57,3 +57,21 @@ test("resizable ArrayBuffer", () => {
expect(typedArray.subarray(0, 1).byteLength).toBe(0); expect(typedArray.subarray(0, 1).byteLength).toBe(0);
}); });
}); });
test("resizable ArrayBuffer resized during `start` parameter access", () => {
TYPED_ARRAYS.forEach(T => {
let arrayBuffer = new ArrayBuffer(T.BYTES_PER_ELEMENT * 2, {
maxByteLength: T.BYTES_PER_ELEMENT * 4,
});
let badAccessor = {
valueOf: () => {
arrayBuffer.resize(T.BYTES_PER_ELEMENT * 4);
return 0;
},
};
let typedArray = new T(arrayBuffer);
expect(typedArray.subarray(badAccessor, typedArray.length).length).toBe(2);
});
});