1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 08:08:12 +00:00

LibWeb+Meta: Add wrapper for the BufferSource/ArrayBufferView IDL types

These wrappers will make it much easier to do various operations on the
different ArrayBuffer-related classes in LibWeb compared to the current
solution, which is to just accept a Handle<Object> everywhere (and use
"any" in the *.idl files).

Co-Authored-By: Matthew Olsson <mattco@serenityos.org>
This commit is contained in:
Shannon Booth 2023-11-23 20:07:25 +13:00 committed by Andreas Kling
parent 54d0aafff0
commit 04c094343f
27 changed files with 286 additions and 71 deletions

View file

@ -19,6 +19,7 @@
#include <LibWeb/Streams/AbstractOperations.h>
#include <LibWeb/Streams/ReadableStreamDefaultReader.h>
#include <LibWeb/WebIDL/AbstractOperations.h>
#include <LibWeb/WebIDL/Buffers.h>
namespace Web::FileAPI {
@ -99,8 +100,8 @@ ErrorOr<ByteBuffer> process_blob_parts(Vector<BlobPart> const& blob_parts, Optio
return bytes.try_append(s.bytes());
},
// 2. If element is a BufferSource, get a copy of the bytes held by the buffer source, and append those bytes to bytes.
[&](JS::Handle<JS::Object> const& buffer_source) -> ErrorOr<void> {
auto data_buffer = TRY(WebIDL::get_buffer_source_copy(*buffer_source.cell()));
[&](JS::Handle<WebIDL::BufferSource> const& buffer_source) -> ErrorOr<void> {
auto data_buffer = TRY(WebIDL::get_buffer_source_copy(*buffer_source->raw_object()));
return bytes.try_append(data_buffer.bytes());
},
// 3. If element is a Blob, append the bytes it represents to bytes.