LibWeb: Add AO CanCopyDataBlockBytes()

This commit is contained in:
Kenneth Myhra 2024-12-01 21:36:06 +01:00 committed by Tim Flynn
parent 4152870b85
commit 5a9f602fef
Notes: github-actions[bot] 2024-12-05 18:21:38 +00:00
2 changed files with 33 additions and 0 deletions

View file

@ -5353,6 +5353,38 @@ bool is_non_negative_number(JS::Value value)
return true;
}
// https://streams.spec.whatwg.org/#abstract-opdef-cancopydatablockbytes
bool can_copy_data_block_bytes_buffer(JS::ArrayBuffer const& to_buffer, u64 to_index, JS::ArrayBuffer const& from_buffer, u64 from_index, u64 count)
{
// 1. Assert: toBuffer is an Object.
// 2. Assert: toBuffer has an [[ArrayBufferData]] internal slot.
// 3. Assert: fromBuffer is an Object.
// 4. Assert: fromBuffer has an [[ArrayBufferData]] internal slot.
// 5. If toBuffer is fromBuffer, return false.
if (&to_buffer == &from_buffer)
return false;
// 6. If ! IsDetachedBuffer(toBuffer) is true, return false.
if (to_buffer.is_detached())
return false;
// 7. If ! IsDetachedBuffer(fromBuffer) is true, return false.
if (from_buffer.is_detached())
return false;
// 8. If toIndex + count > toBuffer.[[ArrayBufferByteLength]], return false.
if (to_index + count > to_buffer.byte_length())
return false;
// 9. If fromIndex + count > fromBuffer.[[ArrayBufferByteLength]], return false.
if (from_index + count > from_buffer.byte_length())
return false;
// 10. Return true.
return true;
}
// https://streams.spec.whatwg.org/#can-transfer-array-buffer
bool can_transfer_array_buffer(JS::ArrayBuffer const& array_buffer)
{

View file

@ -188,6 +188,7 @@ void transform_stream_set_up(TransformStream&, GC::Ref<TransformAlgorithm>, GC::
void transform_stream_unblock_write(TransformStream&);
bool is_non_negative_number(JS::Value);
bool can_copy_data_block_bytes_buffer(JS::ArrayBuffer const& to_buffer, u64 to_index, JS::ArrayBuffer const& from_buffer, u64 from_index, u64 count);
bool can_transfer_array_buffer(JS::ArrayBuffer const& array_buffer);
WebIDL::ExceptionOr<JS::Value> clone_as_uint8_array(JS::Realm&, WebIDL::ArrayBufferView&);
WebIDL::ExceptionOr<JS::Value> structured_clone(JS::Realm&, JS::Value value);