mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-30 19:47:17 +02:00
LibJS+LibWeb: Implement resizable ArrayBuffer support for TypedArray
This is (part of) a normative change in the ECMA-262 spec. See: https://github.com/tc39/ecma262/commit/a9ae96e
This commit is contained in:
committed by
Andreas Kling
parent
c7fec9424c
commit
9258d7b98a
Notes:
sideshowbarker
2024-07-17 06:51:48 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/9258d7b98a Pull-request: https://github.com/SerenityOS/serenity/pull/22424 Reviewed-by: https://github.com/shannonbooth ✅
@@ -2041,14 +2041,17 @@ WebIDL::ExceptionOr<void> readable_byte_stream_controller_enqueue(ReadableByteSt
|
||||
// 4. Let byteOffset be chunk.[[ByteOffset]].
|
||||
auto byte_offset = typed_array->byte_offset();
|
||||
|
||||
// 5. Let byteLength be chunk.[[ByteLength]].
|
||||
auto byte_length = typed_array->byte_length();
|
||||
|
||||
// 6. If ! IsDetachedBuffer(buffer) is true, throw a TypeError exception.
|
||||
if (buffer->is_detached()) {
|
||||
auto error = JS::TypeError::create(realm, "Buffer is detached"sv);
|
||||
return JS::throw_completion(error);
|
||||
}
|
||||
// FIXME: The streams spec has not been updated for resizable ArrayBuffer objects. We must perform step 6 before
|
||||
// invoking TypedArrayByteLength in step 5. We also must check if the array is out-of-bounds, rather than
|
||||
// just detached.
|
||||
auto typed_array_record = JS::make_typed_array_with_buffer_witness_record(*typed_array, JS::ArrayBuffer::Order::SeqCst);
|
||||
|
||||
if (JS::is_typed_array_out_of_bounds(typed_array_record))
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::BufferOutOfBounds, "TypedArray"sv);
|
||||
|
||||
// 5. Let byteLength be chunk.[[ByteLength]].
|
||||
auto byte_length = JS::typed_array_byte_length(typed_array_record);
|
||||
|
||||
// 7. Let transferredBuffer be ? TransferArrayBuffer(buffer).
|
||||
auto transferred_buffer = TRY(transfer_array_buffer(realm, *buffer));
|
||||
|
||||
Reference in New Issue
Block a user