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:
parent
f3fb005653
commit
ce2b88e7cc
Notes:
sideshowbarker
2024-07-17 01:55:29 +09:00
Author: https://github.com/kennethmyhra Commit: https://github.com/SerenityOS/serenity/commit/ce2b88e7cc Pull-request: https://github.com/SerenityOS/serenity/pull/19467 Reviewed-by: https://github.com/trflynn89 ✅
2 changed files with 6 additions and 4 deletions
Userland/Libraries/LibJS/Runtime
|
@ -176,8 +176,7 @@ ThrowCompletionOr<ArrayBuffer*> clone_array_buffer(VM& vm, ArrayBuffer& source_b
|
|||
auto& target_block = target_buffer->buffer();
|
||||
|
||||
// 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
|
||||
target_block.overwrite(0, source_block.offset_pointer(source_byte_offset), source_length);
|
||||
copy_data_block_bytes(target_block, 0, source_block, source_byte_offset, source_length);
|
||||
|
||||
// 6. Return targetBuffer.
|
||||
return target_buffer;
|
||||
|
|
|
@ -115,10 +115,13 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayBufferPrototype::slice)
|
|||
return vm.throw_completion<TypeError>(ErrorType::DetachedArrayBuffer);
|
||||
|
||||
// 24. Let fromBuf be O.[[ArrayBufferData]].
|
||||
auto& from_buf = array_buffer_object->buffer();
|
||||
|
||||
// 25. Let toBuf be new.[[ArrayBufferData]].
|
||||
auto& to_buf = new_array_buffer_object->buffer();
|
||||
|
||||
// 26. Perform CopyDataBlockBytes(toBuf, 0, fromBuf, first, newLen).
|
||||
// FIXME: Implement this to specification
|
||||
array_buffer_object->buffer().span().slice(first, new_length).copy_to(new_array_buffer_object->buffer().span());
|
||||
copy_data_block_bytes(to_buf, 0, from_buf, first, new_length);
|
||||
|
||||
// 27. Return new.
|
||||
return new_array_buffer_object;
|
||||
|
|
Loading…
Add table
Reference in a new issue