diff --git a/Libraries/LibWeb/WebIDL/AbstractOperations.cpp b/Libraries/LibWeb/WebIDL/AbstractOperations.cpp index 405bc700f3c..ca0cb380f98 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 46fb1acb5fb..6051a8d0efc 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);