Changeset 208002 in webkit


Ignore:
Timestamp:
Oct 27, 2016 1:36:12 PM (7 years ago)
Author:
commit-queue@webkit.org
Message:

BufferSource should behave as an union
https://bugs.webkit.org/show_bug.cgi?id=164056

Patch by Zan Dobersek <zdobersek@igalia.com> on 2016-10-27
Reviewed by Chris Dumez.

WebIDL typedefs BufferSource as (ArrayBufferView or ArrayBuffer).
To follow that definition, IDLBufferSource is now type-aliased
to IDLUnion<IDLInterface<ArrayBufferView>, IDLInterface<ArrayBuffer>>.

Converter<IDLBufferSource> template specialization can now be
removed since the default specialization for IDLUnion will be
used.

C++ implementations still work through a BufferSource object.
That class now has an implicit constructor that consumes the
Variant object. The data() and length() methods on the class
now iterate the variant to find an existing object that can
provide a pointer to the data or the length of it.

  • Modules/mediasource/SourceBuffer.cpp:

(WebCore::SourceBuffer::appendBuffer):

  • bindings/generic/IDLTypes.h:
  • bindings/js/BufferSource.h:

(WebCore::BufferSource::BufferSource):
(WebCore::BufferSource::data):
(WebCore::BufferSource::length):

  • bindings/js/JSDOMConvert.h:

(WebCore::Converter<IDLBufferSource>::convert): Deleted.

Location:
trunk/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r208001 r208002  
     12016-10-27  Zan Dobersek  <zdobersek@igalia.com>
     2
     3        BufferSource should behave as an union
     4        https://bugs.webkit.org/show_bug.cgi?id=164056
     5
     6        Reviewed by Chris Dumez.
     7
     8        WebIDL typedefs BufferSource as (ArrayBufferView or ArrayBuffer).
     9        To follow that definition, IDLBufferSource is now type-aliased
     10        to IDLUnion<IDLInterface<ArrayBufferView>, IDLInterface<ArrayBuffer>>.
     11
     12        Converter<IDLBufferSource> template specialization can now be
     13        removed since the default specialization for IDLUnion will be
     14        used.
     15
     16        C++ implementations still work through a BufferSource object.
     17        That class now has an implicit constructor that consumes the
     18        Variant object. The data() and length() methods on the class
     19        now iterate the variant to find an existing object that can
     20        provide a pointer to the data or the length of it.
     21
     22        * Modules/mediasource/SourceBuffer.cpp:
     23        (WebCore::SourceBuffer::appendBuffer):
     24        * bindings/generic/IDLTypes.h:
     25        * bindings/js/BufferSource.h:
     26        (WebCore::BufferSource::BufferSource):
     27        (WebCore::BufferSource::data):
     28        (WebCore::BufferSource::length):
     29        * bindings/js/JSDOMConvert.h:
     30        (WebCore::Converter<IDLBufferSource>::convert): Deleted.
     31
    1322016-10-27  Chris Dumez  <cdumez@apple.com>
    233
  • trunk/Source/WebCore/Modules/mediasource/SourceBuffer.cpp

    r207890 r208002  
    235235ExceptionOr<void> SourceBuffer::appendBuffer(const BufferSource& data)
    236236{
    237     return appendBufferInternal(static_cast<const unsigned char*>(data.data), data.length);
     237    return appendBufferInternal(static_cast<const unsigned char*>(data.data()), data.length());
    238238}
    239239
  • trunk/Source/WebCore/bindings/generic/IDLTypes.h

    r207829 r208002  
    3131
    3232namespace JSC {
     33class ArrayBuffer;
     34class ArrayBufferView;
    3335class JSValue;
    3436}
     
    3638namespace WebCore {
    3739
    38 class BufferSource;
    3940template <typename Value> class DOMPromise;
    4041
     
    138139};
    139140
    140 struct IDLBufferSource : IDLType<BufferSource> { };
     141using IDLBufferSource = IDLUnion<IDLInterface<JSC::ArrayBufferView>, IDLInterface<JSC::ArrayBuffer>>;
    141142
    142143// Helper predicates
  • trunk/Source/WebCore/bindings/js/BufferSource.h

    r207462 r208002  
    2626#pragma once
    2727
     28#include <runtime/ArrayBuffer.h>
     29#include <runtime/ArrayBufferView.h>
     30#include <wtf/RefPtr.h>
     31#include <wtf/Variant.h>
     32
    2833namespace WebCore {
    2934
    3035class BufferSource {
    3136public:
    32     const uint8_t* data;
    33     size_t length;
     37    BufferSource(WTF::Variant<RefPtr<JSC::ArrayBufferView>, RefPtr<JSC::ArrayBuffer>>&& variant)
     38        : m_variant(WTFMove(variant))
     39    { }
     40
     41    const uint8_t* data() const
     42    {
     43        return WTF::visit([](auto& buffer) -> const uint8_t* {
     44            return static_cast<const uint8_t*>(buffer->data());
     45        }, m_variant);
     46    }
     47
     48    size_t length() const
     49    {
     50        return WTF::visit([](auto& buffer) -> size_t {
     51            return buffer->byteLength();
     52        }, m_variant);
     53    }
     54
     55private:
     56    WTF::Variant<RefPtr<JSC::ArrayBufferView>, RefPtr<JSC::ArrayBuffer>> m_variant;
    3457};
    3558
  • trunk/Source/WebCore/bindings/js/JSDOMConvert.h

    r207912 r208002  
    10321032
    10331033// MARK: -
    1034 // MARK: BufferSource type
    1035 
    1036 template<> struct Converter<IDLBufferSource> : DefaultConverter<IDLBufferSource> {
    1037     using ReturnType = BufferSource;
    1038 
    1039     static ReturnType convert(JSC::ExecState& state, JSC::JSValue value)
    1040     {
    1041         JSC::VM& vm = state.vm();
    1042         auto scope = DECLARE_THROW_SCOPE(vm);
    1043 
    1044         if (JSC::ArrayBuffer* buffer = JSC::toArrayBuffer(value))
    1045             return { static_cast<uint8_t*>(buffer->data()), buffer->byteLength() };
    1046         if (RefPtr<JSC::ArrayBufferView> bufferView = toArrayBufferView(value))
    1047             return { static_cast<uint8_t*>(bufferView->baseAddress()), bufferView->byteLength() };
    1048 
    1049         throwTypeError(&state, scope, ASCIILiteral("Only ArrayBuffer and ArrayBufferView objects can be passed as BufferSource arguments"));
    1050         return { nullptr, 0 };
    1051     }
    1052 };
    1053 
    1054 // MARK: -
    10551034// MARK: Date type
    10561035
Note: See TracChangeset for help on using the changeset viewer.