Changeset 208002 in webkit
- Timestamp:
- Oct 27, 2016 1:36:12 PM (7 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r208001 r208002 1 2016-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 1 32 2016-10-27 Chris Dumez <cdumez@apple.com> 2 33 -
trunk/Source/WebCore/Modules/mediasource/SourceBuffer.cpp
r207890 r208002 235 235 ExceptionOr<void> SourceBuffer::appendBuffer(const BufferSource& data) 236 236 { 237 return appendBufferInternal(static_cast<const unsigned char*>(data.data ), data.length);237 return appendBufferInternal(static_cast<const unsigned char*>(data.data()), data.length()); 238 238 } 239 239 -
trunk/Source/WebCore/bindings/generic/IDLTypes.h
r207829 r208002 31 31 32 32 namespace JSC { 33 class ArrayBuffer; 34 class ArrayBufferView; 33 35 class JSValue; 34 36 } … … 36 38 namespace WebCore { 37 39 38 class BufferSource;39 40 template <typename Value> class DOMPromise; 40 41 … … 138 139 }; 139 140 140 struct IDLBufferSource : IDLType<BufferSource> { };141 using IDLBufferSource = IDLUnion<IDLInterface<JSC::ArrayBufferView>, IDLInterface<JSC::ArrayBuffer>>; 141 142 142 143 // Helper predicates -
trunk/Source/WebCore/bindings/js/BufferSource.h
r207462 r208002 26 26 #pragma once 27 27 28 #include <runtime/ArrayBuffer.h> 29 #include <runtime/ArrayBufferView.h> 30 #include <wtf/RefPtr.h> 31 #include <wtf/Variant.h> 32 28 33 namespace WebCore { 29 34 30 35 class BufferSource { 31 36 public: 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 55 private: 56 WTF::Variant<RefPtr<JSC::ArrayBufferView>, RefPtr<JSC::ArrayBuffer>> m_variant; 34 57 }; 35 58 -
trunk/Source/WebCore/bindings/js/JSDOMConvert.h
r207912 r208002 1032 1032 1033 1033 // MARK: - 1034 // MARK: BufferSource type1035 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: -1055 1034 // MARK: Date type 1056 1035
Note: See TracChangeset
for help on using the changeset viewer.