LibWeb/Bindings: Generate buffer typedefs as variants

Represent BufferSource and ArrayBufferView as ordinary IDL typedefs over
their underlying union types, instead of special casing in the IDL
generator. This allows the union conversion/return machinery handle
these types consistently with other typedefs, which removes buffer
specific paths from the IDL generator.

This necessitates changing the WebIDL::BufferSource and
WebIDL::ArrayBufferView classes as views over these variants. This
replaces the old GC backed BufferableObject wrapper structure and
provide convenience helpers to determine things such as the byte length,
byte offset, backing buffer, and typed-array APIs.
This commit is contained in:
Shannon Booth 2026-05-28 23:14:33 +02:00 committed by Shannon Booth
parent de4b665298
commit 97abc707c7
Notes: github-actions[bot] 2026-05-30 09:23:03 +00:00
55 changed files with 496 additions and 473 deletions

View file

@ -63,13 +63,13 @@ void TextDecoder::initialize(JS::Realm& realm)
}
// https://encoding.spec.whatwg.org/#dom-textdecoder-decode
WebIDL::ExceptionOr<String> TextDecoder::decode(GC::Ptr<WebIDL::BufferSource> input, Optional<Bindings::TextDecodeOptions> const&) const
WebIDL::ExceptionOr<String> TextDecoder::decode(Optional<WebIDL::BufferSourceVariant> input, Optional<Bindings::TextDecodeOptions> const&) const
{
if (!input)
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->raw_object());
auto data_buffer_or_error = WebIDL::get_buffer_source_copy(*input);
if (data_buffer_or_error.is_error())
return WebIDL::OperationError::create(realm(), "Failed to copy bytes from ArrayBuffer"_utf16);
auto& data_buffer = data_buffer_or_error.value();