1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 14:17:42 +00:00

LibJS: Use copy_data_block_bytes() instead of overwrite() and copy_to()

Replaces usage of ByteBuffer::overwrite() and combinations of
Span::slice() + Span::copy_to() with AO CopyDataBlockBytes.
This commit is contained in:
Kenneth Myhra 2023-06-17 21:09:18 +02:00 committed by Andreas Kling
parent f3fb005653
commit ce2b88e7cc
2 changed files with 6 additions and 4 deletions

View file

@ -176,8 +176,7 @@ ThrowCompletionOr<ArrayBuffer*> clone_array_buffer(VM& vm, ArrayBuffer& source_b
auto& target_block = target_buffer->buffer(); auto& target_block = target_buffer->buffer();
// 5. Perform CopyDataBlockBytes(targetBlock, 0, srcBlock, srcByteOffset, srcLength). // 5. Perform CopyDataBlockBytes(targetBlock, 0, srcBlock, srcByteOffset, srcLength).
// FIXME: This is only correct for ArrayBuffers, once SharedArrayBuffer is implemented, the AO has to be implemented copy_data_block_bytes(target_block, 0, source_block, source_byte_offset, source_length);
target_block.overwrite(0, source_block.offset_pointer(source_byte_offset), source_length);
// 6. Return targetBuffer. // 6. Return targetBuffer.
return target_buffer; return target_buffer;

View file

@ -115,10 +115,13 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayBufferPrototype::slice)
return vm.throw_completion<TypeError>(ErrorType::DetachedArrayBuffer); return vm.throw_completion<TypeError>(ErrorType::DetachedArrayBuffer);
// 24. Let fromBuf be O.[[ArrayBufferData]]. // 24. Let fromBuf be O.[[ArrayBufferData]].
auto& from_buf = array_buffer_object->buffer();
// 25. Let toBuf be new.[[ArrayBufferData]]. // 25. Let toBuf be new.[[ArrayBufferData]].
auto& to_buf = new_array_buffer_object->buffer();
// 26. Perform CopyDataBlockBytes(toBuf, 0, fromBuf, first, newLen). // 26. Perform CopyDataBlockBytes(toBuf, 0, fromBuf, first, newLen).
// FIXME: Implement this to specification copy_data_block_bytes(to_buf, 0, from_buf, first, new_length);
array_buffer_object->buffer().span().slice(first, new_length).copy_to(new_array_buffer_object->buffer().span());
// 27. Return new. // 27. Return new.
return new_array_buffer_object; return new_array_buffer_object;