Changeset 207462 in webkit


Ignore:
Timestamp:
Oct 18, 2016 6:15:40 AM (8 years ago)
Author:
zandobersek@gmail.com
Message:

[WebIDL] Support BufferSource
https://bugs.webkit.org/show_bug.cgi?id=163541

Reviewed by Youenn Fablet.

Add support for the BufferSource typedef in WebIDL. The implementation
adds the necessary handling for this type in the generator scripts and
the specialization of the Converter<> template for the IDLBufferSource
struct that enables exposing ArrayBuffer or ArrayBufferView objects by
having WebCore::BufferSource objects pointing to their data.

The SourceBuffer interface in the MSE module has the appendBuffer()
operation modified to accept a BufferSource parameter, instead of
overloading it for ArrayBuffer and ArrayBufferView parameters.

The bindings generator tests cover BufferSource as both an operation
parameter and as a dictionary member.

  • Modules/mediasource/SourceBuffer.cpp:

(WebCore::SourceBuffer::appendBuffer):
(WebCore::SourceBuffer::appendBufferInternal):

  • Modules/mediasource/SourceBuffer.h:
  • Modules/mediasource/SourceBuffer.idl:
  • WebCore.xcodeproj/project.pbxproj:
  • bindings/generic/IDLTypes.h:
  • bindings/js/BufferSource.h: Added.
  • bindings/js/JSDOMConvert.h:

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

  • bindings/scripts/CodeGenerator.pm:

(SkipIncludeHeader):
(IsWrapperType):

  • bindings/scripts/CodeGeneratorJS.pm:

(AddClassForwardIfNeeded):
(GetBaseIDLType):
(IsHandledByDOMConvert):

  • bindings/scripts/test/JS/JSTestObj.cpp:

(WebCore::convertDictionary<TestObj::Dictionary>):
(WebCore::jsTestObjPrototypeFunctionBufferSourceParameter):
(WebCore::jsTestObjPrototypeFunctionBufferSourceParameterCaller):

  • bindings/scripts/test/TestObj.idl:
Location:
trunk/Source/WebCore
Files:
1 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r207460 r207462  
     12016-10-18  Zan Dobersek  <zdobersek@igalia.com>
     2
     3        [WebIDL] Support BufferSource
     4        https://bugs.webkit.org/show_bug.cgi?id=163541
     5
     6        Reviewed by Youenn Fablet.
     7
     8        Add support for the BufferSource typedef in WebIDL. The implementation
     9        adds the necessary handling for this type in the generator scripts and
     10        the specialization of the Converter<> template for the IDLBufferSource
     11        struct that enables exposing ArrayBuffer or ArrayBufferView objects by
     12        having WebCore::BufferSource objects pointing to their data.
     13
     14        The SourceBuffer interface in the MSE module has the appendBuffer()
     15        operation modified to accept a BufferSource parameter, instead of
     16        overloading it for ArrayBuffer and ArrayBufferView parameters.
     17
     18        The bindings generator tests cover BufferSource as both an operation
     19        parameter and as a dictionary member.
     20
     21        * Modules/mediasource/SourceBuffer.cpp:
     22        (WebCore::SourceBuffer::appendBuffer):
     23        (WebCore::SourceBuffer::appendBufferInternal):
     24        * Modules/mediasource/SourceBuffer.h:
     25        * Modules/mediasource/SourceBuffer.idl:
     26        * WebCore.xcodeproj/project.pbxproj:
     27        * bindings/generic/IDLTypes.h:
     28        * bindings/js/BufferSource.h: Added.
     29        * bindings/js/JSDOMConvert.h:
     30        (WebCore::Converter<IDLBufferSource>::convert):
     31        * bindings/scripts/CodeGenerator.pm:
     32        (SkipIncludeHeader):
     33        (IsWrapperType):
     34        * bindings/scripts/CodeGeneratorJS.pm:
     35        (AddClassForwardIfNeeded):
     36        (GetBaseIDLType):
     37        (IsHandledByDOMConvert):
     38        * bindings/scripts/test/JS/JSTestObj.cpp:
     39        (WebCore::convertDictionary<TestObj::Dictionary>):
     40        (WebCore::jsTestObjPrototypeFunctionBufferSourceParameter):
     41        (WebCore::jsTestObjPrototypeFunctionBufferSourceParameterCaller):
     42        * bindings/scripts/test/TestObj.idl:
     43
    1442016-10-18  Javier Fernandez  <jfernandez@igalia.com>
    245
  • trunk/Source/WebCore/Modules/mediasource/SourceBuffer.cpp

    r207294 r207462  
    3636
    3737#include "AudioTrackList.h"
     38#include "BufferSource.h"
    3839#include "Event.h"
    3940#include "EventNames.h"
     
    232233}
    233234
    234 
    235 ExceptionOr<void> SourceBuffer::appendBuffer(ArrayBuffer& data)
    236 {
    237     return appendBufferInternal(static_cast<unsigned char*>(data.data()), data.byteLength());
    238 }
    239 
    240 ExceptionOr<void> SourceBuffer::appendBuffer(ArrayBufferView& data)
    241 {
    242     return appendBufferInternal(static_cast<unsigned char*>(data.baseAddress()), data.byteLength());
     235ExceptionOr<void> SourceBuffer::appendBuffer(const BufferSource& data)
     236{
     237    return appendBufferInternal(static_cast<const unsigned char*>(data.data), data.length);
    243238}
    244239
     
    497492}
    498493
    499 ExceptionOr<void> SourceBuffer::appendBufferInternal(unsigned char* data, unsigned size)
     494ExceptionOr<void> SourceBuffer::appendBufferInternal(const unsigned char* data, unsigned size)
    500495{
    501496    // Section 3.2 appendBuffer()
  • trunk/Source/WebCore/Modules/mediasource/SourceBuffer.h

    r207007 r207462  
    4848
    4949class AudioTrackList;
     50class BufferSource;
    5051class MediaSource;
    5152class PlatformTimeRanges;
     
    7576    ExceptionOr<void> setAppendWindowEnd(double);
    7677
    77     ExceptionOr<void> appendBuffer(ArrayBuffer&);
    78     ExceptionOr<void> appendBuffer(ArrayBufferView&);
     78    ExceptionOr<void> appendBuffer(const BufferSource&);
    7979    ExceptionOr<void> abort();
    8080    ExceptionOr<void> remove(double start, double end);
     
    151151    void scheduleEvent(const AtomicString& eventName);
    152152
    153     ExceptionOr<void> appendBufferInternal(unsigned char*, unsigned);
     153    ExceptionOr<void> appendBufferInternal(const unsigned char*, unsigned);
    154154    void appendBufferTimerFired();
    155155    void resetParserState();
  • trunk/Source/WebCore/Modules/mediasource/SourceBuffer.idl

    r207007 r207462  
    5858
    5959    // Append segment data.
    60     [MayThrowException] void appendBuffer(ArrayBuffer data);
    61     [MayThrowException] void appendBuffer(ArrayBufferView data);
     60    [MayThrowException] void appendBuffer(BufferSource data);
    6261
    6362    // Abort the current segment append sequence.
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r207458 r207462  
    12571257                2DF512CD1D873E47001D6780 /* ReplaceRangeWithTextCommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2DF512CB1D873E47001D6780 /* ReplaceRangeWithTextCommand.cpp */; };
    12581258                2DF512CE1D873E47001D6780 /* ReplaceRangeWithTextCommand.h in Headers */ = {isa = PBXBuildFile; fileRef = 2DF512CC1D873E47001D6780 /* ReplaceRangeWithTextCommand.h */; };
     1259                2DFA488F1DB541D000362B99 /* BufferSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 2DFA488E1DB541C200362B99 /* BufferSource.h */; settings = {ATTRIBUTES = (Private, ); }; };
    12591260                2E0888D41148848A00AF4265 /* JSDOMFormData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2E0888D21148848A00AF4265 /* JSDOMFormData.cpp */; };
    12601261                2E0888D51148848A00AF4265 /* JSDOMFormData.h in Headers */ = {isa = PBXBuildFile; fileRef = 2E0888D31148848A00AF4265 /* JSDOMFormData.h */; };
     
    59755976                E125F83D182411E700D84CD9 /* JSCryptoOperationData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E125F83B182411E700D84CD9 /* JSCryptoOperationData.cpp */; };
    59765977                E125F83E182411E700D84CD9 /* JSCryptoOperationData.h in Headers */ = {isa = PBXBuildFile; fileRef = E125F83C182411E700D84CD9 /* JSCryptoOperationData.h */; };
     5978
    59775979                E125F8411824253A00D84CD9 /* CryptoAlgorithmAES_CBC.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E125F83F1824253A00D84CD9 /* CryptoAlgorithmAES_CBC.cpp */; };
    59785980                E125F8421824253A00D84CD9 /* CryptoAlgorithmAES_CBC.h in Headers */ = {isa = PBXBuildFile; fileRef = E125F8401824253A00D84CD9 /* CryptoAlgorithmAES_CBC.h */; };
     
    82368238                2DF512CB1D873E47001D6780 /* ReplaceRangeWithTextCommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ReplaceRangeWithTextCommand.cpp; sourceTree = "<group>"; };
    82378239                2DF512CC1D873E47001D6780 /* ReplaceRangeWithTextCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ReplaceRangeWithTextCommand.h; sourceTree = "<group>"; };
     8240                2DFA488E1DB541C200362B99 /* BufferSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BufferSource.h; sourceTree = "<group>"; };
    82388241                2E0888C3114883A900AF4265 /* DOMFormData.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = DOMFormData.idl; sourceTree = "<group>"; };
    82398242                2E0888D21148848A00AF4265 /* JSDOMFormData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSDOMFormData.cpp; sourceTree = "<group>"; };
     
    2141621419                                49B3760A15C6C6840059131D /* ArrayValue.cpp */,
    2141721420                                49B3760B15C6C6840059131D /* ArrayValue.h */,
     21421                                2DFA488E1DB541C200362B99 /* BufferSource.h */,
    2141821422                                BCD533630ED6848900887468 /* CachedScriptSourceProvider.h */,
    2141921423                                93F8B3060A300FEA00F61AB8 /* CodeGeneratorJS.pm */,
     
    2679926803                                9391A991162746CB00297330 /* ScrollingCoordinatorMac.h in Headers */,
    2680026804                                93C38BFF164473C700091EB2 /* ScrollingStateFixedNode.h in Headers */,
     26805                                2DFA488F1DB541D000362B99 /* BufferSource.h in Headers */,
    2680126806                                0FEA3E7B191B2FC5000F1B55 /* ScrollingStateFrameScrollingNode.h in Headers */,
    2680226807                                931CBD0D161A44E900E4C874 /* ScrollingStateNode.h in Headers */,
  • trunk/Source/WebCore/bindings/generic/IDLTypes.h

    r207381 r207462  
    3636namespace WebCore {
    3737
     38class BufferSource;
    3839template <typename Value> class DOMPromise;
    3940
     
    119120};
    120121
     122struct IDLBufferSource : IDLType<BufferSource> { };
    121123
    122124// Helper predicates
  • trunk/Source/WebCore/bindings/js/JSDOMConvert.h

    r207381 r207462  
    2626#pragma once
    2727
     28#include "BufferSource.h"
    2829#include "IDLTypes.h"
    2930#include "JSDOMBinding.h"
     
    639640}
    640641
     642// MARK: -
     643// MARK: BufferSource type
     644
     645template<> struct Converter<IDLBufferSource> : DefaultConverter<IDLBufferSource> {
     646    using ReturnType = BufferSource;
     647
     648    static ReturnType convert(JSC::ExecState& state, JSC::JSValue value)
     649    {
     650        JSC::VM& vm = state.vm();
     651        auto scope = DECLARE_THROW_SCOPE(vm);
     652
     653        if (JSC::ArrayBuffer* buffer = JSC::toArrayBuffer(value))
     654            return { static_cast<uint8_t*>(buffer->data()), buffer->byteLength() };
     655        if (RefPtr<JSC::ArrayBufferView> bufferView = toArrayBufferView(value))
     656            return { static_cast<uint8_t*>(bufferView->baseAddress()), bufferView->byteLength() };
     657
     658        throwTypeError(&state, scope, ASCIILiteral("Only ArrayBuffer and ArrayBufferView objects can be passed as BufferSource arguments"));
     659        return { nullptr, 0 };
     660    }
     661};
     662
    641663} // namespace WebCore
  • trunk/Source/WebCore/bindings/scripts/CodeGenerator.pm

    r207302 r207462  
    372372    return 1 if $object->IsTypedArrayType($type);
    373373    return 1 if $type eq "Array";
     374    return 1 if $type eq "BufferSource";
    374375    return 1 if $type eq "DOMString" or $type eq "USVString";
    375376    return 1 if $type eq "DOMTimeStamp";
     
    867868    return 0 if !$object->IsRefPtrType($type);
    868869    return 0 if $object->IsTypedArrayType($type);
     870    return 0 if $type eq "BufferSource";
    869871    return 0 if $type eq "UNION";
    870872    return 0 if $webCoreTypeHash{$type};
  • trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm

    r207417 r207462  
    320320    # SVGAnimatedLength/Number/etc. are not classes so they can't be forward declared as classes.
    321321    return if $codeGenerator->IsSVGAnimatedType($interfaceName);
     322
    322323    return if $codeGenerator->IsTypedArrayType($interfaceName);
     324    return if $interfaceName eq "BufferSource";
    323325
    324326    push(@headerContent, "class $interfaceName;\n\n");
     
    49944996    return "IDLFrozenArray<" . GetIDLType($interface, @{$idlType->subtypes}[0]) . ">" if $codeGenerator->IsFrozenArrayType($idlType->name);
    49954997    return "IDLUnion<" . join(", ", GetIDLUnionMemberTypes($interface, $idlType)) . ">" if $idlType->isUnion;
     4998    return "IDLBufferSource" if $idlType->name eq "BufferSource";
    49964999    return "IDLInterface<" . $idlType->name . ">";
    49975000}
     
    51155118
    51165119    return 1 if $idlType->isUnion;
     5120    return 1 if $idlType->name eq "BufferSource";
    51175121    return 1 if $idlType->name eq "any";
    51185122    return 1 if $idlType->name eq "boolean";
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp

    r207381 r207462  
    502502    if (!booleanWithoutDefaultValue.isUndefined()) {
    503503        result.booleanWithoutDefault = convert<IDLBoolean>(state, booleanWithoutDefaultValue);
     504        RETURN_IF_EXCEPTION(throwScope, Nullopt);
     505    }
     506    JSValue bufferSourceValueValue = isNullOrUndefined ? jsUndefined() : object->get(&state, Identifier::fromString(&state, "bufferSourceValue"));
     507    if (!bufferSourceValueValue.isUndefined()) {
     508        result.bufferSourceValue = convert<IDLBufferSource>(state, bufferSourceValueValue);
    504509        RETURN_IF_EXCEPTION(throwScope, Nullopt);
    505510    }
     
    994999JSC::EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionAttachShadowRoot(JSC::ExecState*);
    9951000JSC::EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionOperationWithExternalDictionaryParameter(JSC::ExecState*);
     1001JSC::EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionBufferSourceParameter(JSC::ExecState*);
    9961002JSC::EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionToString(JSC::ExecState*);
    9971003JSC::EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionToJSON(JSC::ExecState*);
     
    16051611    { "attachShadowRoot", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionAttachShadowRoot), (intptr_t) (1) } },
    16061612    { "operationWithExternalDictionaryParameter", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionOperationWithExternalDictionaryParameter), (intptr_t) (1) } },
     1613    { "bufferSourceParameter", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionBufferSourceParameter), (intptr_t) (1) } },
    16071614    { "toString", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionToString), (intptr_t) (0) } },
    16081615    { "toJSON", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionToJSON), (intptr_t) (0) } },
     
    77307737}
    77317738
     7739static inline JSC::EncodedJSValue jsTestObjPrototypeFunctionBufferSourceParameterCaller(JSC::ExecState*, JSTestObj*, JSC::ThrowScope&);
     7740
     7741EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionBufferSourceParameter(ExecState* state)
     7742{
     7743    return BindingCaller<JSTestObj>::callOperation<jsTestObjPrototypeFunctionBufferSourceParameterCaller>(state, "bufferSourceParameter");
     7744}
     7745
     7746static inline JSC::EncodedJSValue jsTestObjPrototypeFunctionBufferSourceParameterCaller(JSC::ExecState* state, JSTestObj* castedThis, JSC::ThrowScope& throwScope)
     7747{
     7748    UNUSED_PARAM(state);
     7749    UNUSED_PARAM(throwScope);
     7750    auto& impl = castedThis->wrapped();
     7751    if (UNLIKELY(state->argumentCount() < 1))
     7752        return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
     7753    auto data = convert<IDLBufferSource>(*state, state->uncheckedArgument(0));
     7754    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
     7755    impl.bufferSourceParameter(WTFMove(data));
     7756    return JSValue::encode(jsUndefined());
     7757}
     7758
    77327759static inline JSC::EncodedJSValue jsTestObjPrototypeFunctionToStringCaller(JSC::ExecState*, JSTestObj*, JSC::ThrowScope&);
    77337760
  • trunk/Source/WebCore/bindings/scripts/test/TestObj.idl

    r207381 r207462  
    416416
    417417    serializer = {create, readOnlyStringAttr, enumAttr, longAttr};
     418
     419    void bufferSourceParameter(BufferSource data);
    418420};
    419421
     
    461463    (long or Node) unionMember;
    462464    (long or Node)? nullableUnionMember = null;
     465    BufferSource bufferSourceValue;
    463466};
    464467
Note: See TracChangeset for help on using the changeset viewer.