mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-11 17:37:33 +02:00
LibJS+LibWeb: Allow instantiating DataBlock with an external buffer
This requires the minimal API exposed by ByteBuffer, allowing external users to implement them as needed instead of being forced to use a ByteBuffer.
This commit is contained in:
committed by
Ali Mohammad Pur
parent
0a7bef349d
commit
0bb987e809
Notes:
github-actions[bot]
2026-05-10 14:43:40 +00:00
Author: https://github.com/alimpfard Commit: https://github.com/LadybirdBrowser/ladybird/commit/0bb987e809f Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/8866 Reviewed-by: https://github.com/ADKaster Reviewed-by: https://github.com/Hendiadyoin1 Reviewed-by: https://github.com/R-Goc Reviewed-by: https://github.com/gmta Reviewed-by: https://github.com/trflynn89
@@ -167,7 +167,10 @@ static WebIDL::ExceptionOr<void> serialize_array_buffer(JS::VM& vm, TransferData
|
||||
auto data_copy = TRY(JS::create_byte_data_block(vm, size));
|
||||
|
||||
// 4. Perform CopyDataBlockBytes(dataCopy, 0, value.[[ArrayBufferData]], 0, size).
|
||||
JS::copy_data_block_bytes(data_copy.buffer(), 0, array_buffer.buffer(), 0, size);
|
||||
if (array_buffer.is_external())
|
||||
data_copy.overwrite(0, array_buffer.data(), size);
|
||||
else
|
||||
JS::copy_data_block_bytes(data_copy.buffer(), 0, array_buffer.buffer(), 0, size);
|
||||
|
||||
// 5. If value has an [[ArrayBufferMaxByteLength]] internal slot, then set serialized to { [[Type]]: "ResizableArrayBuffer",
|
||||
// [[ArrayBufferData]]: dataCopy, [[ArrayBufferByteLength]]: size, [[ArrayBufferMaxByteLength]]: value.[[ArrayBufferMaxByteLength]] }.
|
||||
@@ -1040,13 +1043,17 @@ WebIDL::ExceptionOr<SerializedTransferRecord> structured_serialize_with_transfer
|
||||
// 4. If transferable has an [[ArrayBufferData]] internal slot, then:
|
||||
if (array_buffer) {
|
||||
// 1. If transferable has an [[ArrayBufferMaxByteLength]] internal slot, then:
|
||||
auto buffer_data = array_buffer->is_external()
|
||||
? MUST(ByteBuffer::copy(array_buffer->bytes()))
|
||||
: ByteBuffer(array_buffer->buffer());
|
||||
|
||||
if (!array_buffer->is_fixed_length()) {
|
||||
// 1. Set dataHolder.[[Type]] to "ResizableArrayBuffer".
|
||||
data_holder.encode(TransferType::ResizableArrayBuffer);
|
||||
|
||||
// 2. Set dataHolder.[[ArrayBufferData]] to transferable.[[ArrayBufferData]].
|
||||
// 3. Set dataHolder.[[ArrayBufferByteLength]] to transferable.[[ArrayBufferByteLength]].
|
||||
data_holder.encode(array_buffer->buffer());
|
||||
data_holder.encode(buffer_data);
|
||||
|
||||
// 4. Set dataHolder.[[ArrayBufferMaxByteLength]] to transferable.[[ArrayBufferMaxByteLength]].
|
||||
data_holder.encode(array_buffer->max_byte_length());
|
||||
@@ -1058,7 +1065,7 @@ WebIDL::ExceptionOr<SerializedTransferRecord> structured_serialize_with_transfer
|
||||
|
||||
// 2. Set dataHolder.[[ArrayBufferData]] to transferable.[[ArrayBufferData]].
|
||||
// 3. Set dataHolder.[[ArrayBufferByteLength]] to transferable.[[ArrayBufferByteLength]].
|
||||
data_holder.encode(array_buffer->buffer());
|
||||
data_holder.encode(buffer_data);
|
||||
}
|
||||
|
||||
// 3. Perform ? DetachArrayBuffer(transferable).
|
||||
|
||||
Reference in New Issue
Block a user