From c0da3e356aeced8a8167f10f1d9023f26053d331 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Fri, 15 Nov 2024 14:47:27 -0500 Subject: [PATCH] LibWeb: Add a couple ad-hoc BufferSource AOs These helpers will be used by CompressionStream/DecompressionStream. --- .../LibWeb/WebIDL/AbstractOperations.cpp | 21 +++++++++++++++++++ Libraries/LibWeb/WebIDL/AbstractOperations.h | 2 ++ 2 files changed, 23 insertions(+) diff --git a/Libraries/LibWeb/WebIDL/AbstractOperations.cpp b/Libraries/LibWeb/WebIDL/AbstractOperations.cpp index 405bc700f3..ca0cb380f9 100644 --- a/Libraries/LibWeb/WebIDL/AbstractOperations.cpp +++ b/Libraries/LibWeb/WebIDL/AbstractOperations.cpp @@ -23,6 +23,27 @@ namespace Web::WebIDL { +bool is_buffer_source_type(JS::Value value) +{ + if (!value.is_object()) + return false; + + auto const& object = value.as_object(); + return is(object) || is(object) || is(object); +} + +GC::Ptr underlying_buffer_source(JS::Object& buffer_source) +{ + if (is(buffer_source)) + return static_cast(buffer_source).viewed_array_buffer(); + if (is(buffer_source)) + return static_cast(buffer_source).viewed_array_buffer(); + if (is(buffer_source)) + return static_cast(buffer_source); + + VERIFY_NOT_REACHED(); +} + // https://webidl.spec.whatwg.org/#dfn-get-buffer-source-copy ErrorOr get_buffer_source_copy(JS::Object const& buffer_source) { diff --git a/Libraries/LibWeb/WebIDL/AbstractOperations.h b/Libraries/LibWeb/WebIDL/AbstractOperations.h index 46fb1acb5f..6051a8d0ef 100644 --- a/Libraries/LibWeb/WebIDL/AbstractOperations.h +++ b/Libraries/LibWeb/WebIDL/AbstractOperations.h @@ -17,6 +17,8 @@ namespace Web::WebIDL { +bool is_buffer_source_type(JS::Value); +GC::Ptr underlying_buffer_source(JS::Object& buffer_source); ErrorOr get_buffer_source_copy(JS::Object const& buffer_source); JS::Completion call_user_object_operation(WebIDL::CallbackType& callback, String const& operation_name, Optional this_argument, GC::MarkedVector args);