mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:37:35 +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:
parent
54d0aafff0
commit
04c094343f
27 changed files with 286 additions and 71 deletions
|
@ -9,6 +9,7 @@
|
|||
#include <LibWeb/Bindings/Intrinsics.h>
|
||||
#include <LibWeb/Encoding/TextDecoder.h>
|
||||
#include <LibWeb/WebIDL/AbstractOperations.h>
|
||||
#include <LibWeb/WebIDL/Buffers.h>
|
||||
|
||||
namespace Web::Encoding {
|
||||
|
||||
|
@ -44,14 +45,13 @@ void TextDecoder::initialize(JS::Realm& realm)
|
|||
}
|
||||
|
||||
// https://encoding.spec.whatwg.org/#dom-textdecoder-decode
|
||||
WebIDL::ExceptionOr<String> TextDecoder::decode(Optional<JS::Handle<JS::Object>> const& input, Optional<TextDecodeOptions> const&) const
|
||||
WebIDL::ExceptionOr<String> TextDecoder::decode(Optional<JS::Handle<WebIDL::BufferSource>> const& input, Optional<TextDecodeOptions> const&) const
|
||||
{
|
||||
if (!input.has_value())
|
||||
return TRY_OR_THROW_OOM(vm(), m_decoder.to_utf8({}));
|
||||
|
||||
// FIXME: Implement the streaming stuff.
|
||||
|
||||
auto data_buffer_or_error = WebIDL::get_buffer_source_copy(*input->cell());
|
||||
auto data_buffer_or_error = WebIDL::get_buffer_source_copy(*input.value()->raw_object());
|
||||
if (data_buffer_or_error.is_error())
|
||||
return WebIDL::OperationError::create(realm(), "Failed to copy bytes from ArrayBuffer"_fly_string);
|
||||
auto& data_buffer = data_buffer_or_error.value();
|
||||
|
|
|
@ -37,7 +37,7 @@ public:
|
|||
|
||||
virtual ~TextDecoder() override;
|
||||
|
||||
WebIDL::ExceptionOr<String> decode(Optional<JS::Handle<JS::Object>> const&, Optional<TextDecodeOptions> const& options = {}) const;
|
||||
WebIDL::ExceptionOr<String> decode(Optional<JS::Handle<WebIDL::BufferSource>> const&, Optional<TextDecodeOptions> const& options = {}) const;
|
||||
|
||||
FlyString const& encoding() const { return m_encoding; }
|
||||
bool fatal() const { return m_fatal; }
|
||||
|
|
|
@ -50,10 +50,9 @@ JS::NonnullGCPtr<JS::Uint8Array> TextEncoder::encode(String const& input) const
|
|||
}
|
||||
|
||||
// https://encoding.spec.whatwg.org/#dom-textencoder-encodeinto
|
||||
TextEncoderEncodeIntoResult TextEncoder::encode_into(String const& source, JS::Handle<JS::Object> const& destination) const
|
||||
TextEncoderEncodeIntoResult TextEncoder::encode_into(String const& source, JS::Handle<WebIDL::BufferSource> const& destination) const
|
||||
{
|
||||
auto& destination_array = static_cast<JS::Uint8Array&>(*destination);
|
||||
auto data = destination_array.data();
|
||||
auto& data = destination->viewed_array_buffer()->buffer();
|
||||
|
||||
// 1. Let read be 0.
|
||||
unsigned long long read = 0;
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include <LibJS/Forward.h>
|
||||
#include <LibWeb/Bindings/PlatformObject.h>
|
||||
#include <LibWeb/Forward.h>
|
||||
#include <LibWeb/WebIDL/Buffers.h>
|
||||
|
||||
namespace Web::Encoding {
|
||||
|
||||
|
@ -32,7 +33,7 @@ public:
|
|||
virtual ~TextEncoder() override;
|
||||
|
||||
JS::NonnullGCPtr<JS::Uint8Array> encode(String const& input) const;
|
||||
TextEncoderEncodeIntoResult encode_into(String const& source, JS::Handle<JS::Object> const& destination) const;
|
||||
TextEncoderEncodeIntoResult encode_into(String const& source, JS::Handle<WebIDL::BufferSource> const& destination) const;
|
||||
|
||||
static FlyString const& encoding();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue