Changeset 215322 in webkit


Ignore:
Timestamp:
Apr 13, 2017 9:40:25 AM (7 years ago)
Author:
commit-queue@webkit.org
Message:

[Readable Streams API] Implement cloneArrayBuffer in WebCore
https://bugs.webkit.org/show_bug.cgi?id=170008

Patch by Romain Bellessort <romain.bellessort@crf.canon.fr> on 2017-04-13
Reviewed by Youenn Fablet.

Source/WebCore:

Implemented cloneArrayBuffer based on existing structuredCloneArrayBuffer
implementation. The code has been factorized so that both cloneArrayBuffer
and structuredCloneArrayBuffer rely on the same code (which is basically
the previous implementation of structuredCloneArrayBuffer + the ability
to clone only a part of considered buffer).

Test: streams/clone-array-buffer.html

  • Modules/streams/ReadableByteStreamInternals.js: Deleted cloneArrayBuffer JS implementation.
  • bindings/js/JSDOMGlobalObject.cpp:

(WebCore::JSDOMGlobalObject::addBuiltinGlobals): Add cloneArrayBuffer private declaration.

  • bindings/js/StructuredClone.cpp:

(WebCore::cloneArrayBufferImpl): Added (mostly based on previous structuredCloneArrayBuffer).
(WebCore::cloneArrayBuffer): Added.
(WebCore::structuredCloneArrayBuffer): Updated.

  • bindings/js/StructuredClone.h: Added cloneArrayBuffer declaration.
  • bindings/js/WebCoreBuiltinNames.h: Added cloneArrayBuffer declaration.
  • testing/Internals.cpp: Added support for testing cloneArrayBuffer.
  • testing/Internals.h: Added support for testing cloneArrayBuffer.
  • testing/Internals.idl: Added support for testing cloneArrayBuffer.

LayoutTests:

Added test to check cloneArrayBuffer behaviour.

  • streams/clone-array-buffer-expected.txt: Added.
  • streams/clone-array-buffer.html: Added.
Location:
trunk
Files:
2 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r215321 r215322  
     12017-04-13  Romain Bellessort  <romain.bellessort@crf.canon.fr>
     2
     3        [Readable Streams API] Implement cloneArrayBuffer in WebCore
     4        https://bugs.webkit.org/show_bug.cgi?id=170008
     5
     6        Reviewed by Youenn Fablet.
     7
     8        Added test to check cloneArrayBuffer behaviour.
     9
     10        * streams/clone-array-buffer-expected.txt: Added.
     11        * streams/clone-array-buffer.html: Added.
     12
    1132017-04-13  Youenn Fablet  <youenn@apple.com>
    214
  • trunk/Source/WebCore/ChangeLog

    r215321 r215322  
     12017-04-13  Romain Bellessort  <romain.bellessort@crf.canon.fr>
     2
     3        [Readable Streams API] Implement cloneArrayBuffer in WebCore
     4        https://bugs.webkit.org/show_bug.cgi?id=170008
     5
     6        Reviewed by Youenn Fablet.
     7
     8        Implemented cloneArrayBuffer based on existing structuredCloneArrayBuffer
     9        implementation. The code has been factorized so that both cloneArrayBuffer
     10        and structuredCloneArrayBuffer rely on the same code (which is basically
     11        the previous implementation of structuredCloneArrayBuffer + the ability
     12        to clone only a part of considered buffer).
     13
     14        Test: streams/clone-array-buffer.html
     15
     16        * Modules/streams/ReadableByteStreamInternals.js: Deleted cloneArrayBuffer JS implementation.
     17        * bindings/js/JSDOMGlobalObject.cpp:
     18        (WebCore::JSDOMGlobalObject::addBuiltinGlobals): Add cloneArrayBuffer private declaration.
     19        * bindings/js/StructuredClone.cpp:
     20        (WebCore::cloneArrayBufferImpl): Added (mostly based on previous structuredCloneArrayBuffer).
     21        (WebCore::cloneArrayBuffer): Added.
     22        (WebCore::structuredCloneArrayBuffer): Updated.
     23        * bindings/js/StructuredClone.h: Added cloneArrayBuffer declaration.
     24        * bindings/js/WebCoreBuiltinNames.h: Added cloneArrayBuffer declaration.
     25        * testing/Internals.cpp: Added support for testing cloneArrayBuffer.
     26        * testing/Internals.h: Added support for testing cloneArrayBuffer.
     27        * testing/Internals.idl: Added support for testing cloneArrayBuffer.
     28
    1292017-04-13  Youenn Fablet  <youenn@apple.com>
    230
  • trunk/Source/WebCore/Modules/streams/ReadableByteStreamInternals.js

    r215043 r215322  
    397397}
    398398
    399 function cloneArrayBuffer(srcBuffer, srcByteOffset, srcLength)
    400 {
    401     "use strict";
    402 
    403     // FIXME: Below implementation returns the appropriate data but does not perform
    404     // exactly what is described by ECMAScript CloneArrayBuffer operation. This should
    405     // be fixed in a follow up patch implementing cloneArrayBuffer in JSC (similarly to
    406     // structuredCloneArrayBuffer implementation).
    407     return srcBuffer.slice(srcByteOffset, srcByteOffset + srcLength);
    408 }
    409 
    410399function readableByteStreamControllerRespondInReadableState(controller, bytesWritten, pullIntoDescriptor)
    411400{
  • trunk/Source/WebCore/bindings/js/JSDOMGlobalObject.cpp

    r214713 r215322  
    143143        JSDOMGlobalObject::GlobalPropertyInfo(clientData.builtinNames().makeGetterTypeErrorPrivateName(),
    144144            JSFunction::create(vm, this, 2, String(), makeGetterTypeErrorForBuiltins), DontDelete | ReadOnly),
     145        JSDOMGlobalObject::GlobalPropertyInfo(clientData.builtinNames().cloneArrayBufferPrivateName(),
     146            JSFunction::create(vm, this, 3, String(), cloneArrayBuffer), DontDelete | ReadOnly),
    145147        JSDOMGlobalObject::GlobalPropertyInfo(clientData.builtinNames().structuredCloneArrayBufferPrivateName(),
    146148            JSFunction::create(vm, this, 1, String(), structuredCloneArrayBuffer), DontDelete | ReadOnly),
  • trunk/Source/WebCore/bindings/js/StructuredClone.cpp

    r214713 r215322  
    3636namespace WebCore {
    3737
    38 EncodedJSValue JSC_HOST_CALL structuredCloneArrayBuffer(ExecState* state)
     38enum class CloneMode {
     39    Full,
     40    Partial,
     41};
     42
     43EncodedJSValue JSC_HOST_CALL cloneArrayBufferImpl(ExecState*, CloneMode);
     44
     45EncodedJSValue JSC_HOST_CALL cloneArrayBufferImpl(ExecState* state, CloneMode mode)
    3946{
    4047    ASSERT(state);
     
    4956        return { };
    5057    }
     58    if (mode == CloneMode::Partial) {
     59        ASSERT(state->argumentCount() == 3);
     60        int srcByteOffset = static_cast<int>(state->uncheckedArgument(1).toNumber(state));
     61        int srcLength = static_cast<int>(state->uncheckedArgument(2).toNumber(state));
     62        return JSValue::encode(JSArrayBuffer::create(state->vm(), state->lexicalGlobalObject()->arrayBufferStructure(ArrayBufferSharingMode::Default), buffer->slice(srcByteOffset, srcByteOffset + srcLength)));
     63    }
    5164    return JSValue::encode(JSArrayBuffer::create(state->vm(), state->lexicalGlobalObject()->arrayBufferStructure(ArrayBufferSharingMode::Default), ArrayBuffer::tryCreate(buffer->data(), buffer->byteLength())));
     65}
     66
     67EncodedJSValue JSC_HOST_CALL cloneArrayBuffer(ExecState* state)
     68{
     69    return cloneArrayBufferImpl(state, CloneMode::Partial);
     70}
     71
     72EncodedJSValue JSC_HOST_CALL structuredCloneArrayBuffer(ExecState* state)
     73{
     74    return cloneArrayBufferImpl(state, CloneMode::Full);
    5275}
    5376
  • trunk/Source/WebCore/bindings/js/StructuredClone.h

    r214713 r215322  
    3232namespace WebCore {
    3333
     34JSC::EncodedJSValue JSC_HOST_CALL cloneArrayBuffer(JSC::ExecState*);
    3435JSC::EncodedJSValue JSC_HOST_CALL structuredCloneArrayBuffer(JSC::ExecState*);
    3536JSC::EncodedJSValue JSC_HOST_CALL structuredCloneArrayBufferView(JSC::ExecState*);
  • trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h

    r214713 r215322  
    4040    macro(byobRequest) \
    4141    macro(cancel) \
     42    macro(cloneArrayBuffer) \
    4243    macro(cloneForJS) \
    4344    macro(closeRequested) \
  • trunk/Source/WebCore/testing/Internals.cpp

    r215263 r215322  
    355355    else
    356356        return false;
    357    
     357
    358358    return true;
    359359}
     
    395395
    396396    page.setDefersLoading(false);
    397    
     397
    398398    page.mainFrame().setTextZoomFactor(1.0f);
    399    
     399
    400400    FrameView* mainFrameView = page.mainFrame().view();
    401401    if (mainFrameView) {
     
    599599    ResourceRequest request(contextDocument()->completeURL(url));
    600600    request.setDomainForCachePartition(contextDocument()->topOrigin().domainForCachePartition());
    601    
     601
    602602    CachedResource* resource = MemoryCache::singleton().resourceForRequest(request, contextDocument()->page()->sessionID());
    603603    return resource && resource->status() == CachedResource::Cached;
     
    756756    if (!cachedImage)
    757757        return;
    758    
     758
    759759    auto* image = cachedImage->image();
    760760    if (!is<BitmapImage>(image))
    761761        return;
    762    
     762
    763763    downcast<BitmapImage>(*image).setFrameDecodingDurationForTesting(Seconds { duration });
    764764}
     
    10311031            continue;
    10321032        }
    1033        
     1033
    10341034        StyleRuleGroup* groupRule = nullptr;
    10351035        if (is<StyleRuleMedia>(rule.get()))
     
    10391039        if (!groupRule)
    10401040            continue;
    1041        
     1041
    10421042        auto* groupChildRules = groupRule->childRulesWithoutDeferredParsing();
    10431043        if (!groupChildRules)
    10441044            continue;
    1045        
     1045
    10461046        count += deferredStyleRulesCountForList(*groupChildRules);
    10471047    }
     
    10661066        if (!groupRule)
    10671067            continue;
    1068        
     1068
    10691069        auto* groupChildRules = groupRule->childRulesWithoutDeferredParsing();
    10701070        if (!groupChildRules)
     
    10911091            continue;
    10921092        }
    1093        
     1093
    10941094        StyleRuleGroup* groupRule = nullptr;
    10951095        if (is<StyleRuleMedia>(rule.get()))
     
    10991099        if (!groupRule)
    11001100            continue;
    1101        
     1101
    11021102        auto* groupChildRules = groupRule->childRulesWithoutDeferredParsing();
    11031103        if (!groupChildRules)
    11041104            continue;
    1105        
     1105
    11061106        count += deferredKeyframesRulesCountForList(*groupChildRules);
    11071107    }
    1108    
     1108
    11091109    return count;
    11101110}
     
    11791179    if (!behavior)
    11801180        return std::nullopt;
    1181    
     1181
    11821182    switch (behavior.value()) {
    11831183    case WebCore::EventThrottlingBehavior::Responsive:
     
    12441244    if (!synthesis)
    12451245        return;
    1246    
     1246
    12471247    synthesis->setPlatformSynthesizer(std::make_unique<PlatformSpeechSynthesizerMock>(synthesis));
    12481248}
     
    16931693
    16941694    document->updateLayoutIgnorePendingStylesheets();
    1695    
     1695
    16961696    HitTestResult result = document->frame()->mainFrame().eventHandler().hitTestResultAtPoint(IntPoint(x, y));
    16971697    NSDictionary *options = nullptr;
     
    18491849        HitTestResult result(point, topPadding, rightPadding, bottomPadding, leftPadding);
    18501850        renderView->hitTest(request, result);
    1851        
     1851
    18521852        const HitTestResult::NodeSet& nodeSet = result.rectBasedTestResult();
    18531853        matches.reserveInitialCapacity(nodeSet.size());
     
    19701970    return document->frame()->editor().selectionStartHasMarkerFor(DocumentMarker::Spelling, from, length);
    19711971}
    1972    
     1972
    19731973bool Internals::hasAutocorrectedMarker(int from, int length)
    19741974{
     
    22232223    return count;
    22242224}
    2225    
     2225
    22262226ExceptionOr<bool> Internals::isPageBoxVisible(int pageNumber)
    22272227{
     
    22762276    if (!layerModelObject.layer()->isComposited())
    22772277        return Exception { NOT_FOUND_ERR };
    2278    
     2278
    22792279    auto* backing = layerModelObject.layer()->backing();
    22802280    return backing->graphicsLayer()->primaryLayerID();
     
    23452345    if (!element.renderer()->hasLayer())
    23462346        return Exception { INVALID_ACCESS_ERR };
    2347    
     2347
    23482348    RenderLayer* layer = downcast<RenderLayerModelObject>(element.renderer())->layer();
    23492349    if (!layer->isComposited())
    23502350        return Exception { INVALID_ACCESS_ERR };
    2351    
     2351
    23522352    layer->backing()->setUsesDisplayListDrawing(usesDisplayListDrawing);
    23532353    return { };
     
    23742374    if (!layer->isComposited())
    23752375        return Exception { INVALID_ACCESS_ERR };
    2376    
     2376
    23772377    layer->backing()->setIsTrackingDisplayListReplay(isTrackingReplay);
    23782378    return { };
     
    26142614    document->view()->setFooterHeight(height);
    26152615}
    2616    
     2616
    26172617void Internals::setTopContentInset(float contentInset)
    26182618{
     
    27582758    if (!document)
    27592759        return Exception { INVALID_ACCESS_ERR };
    2760    
     2760
    27612761    return document->styleRecalcCount();
    27622762}
     
    27852785    if (!document || !document->renderView())
    27862786        return Exception { INVALID_ACCESS_ERR };
    2787    
     2787
    27882788    return document->renderView()->compositor().compositingUpdateCount();
    27892789}
     
    30773077    if (!document || !document->page())
    30783078        return Exception { INVALID_ACCESS_ERR };
    3079    
     3079
    30803080#if ENABLE(VIDEO_TRACK)
    30813081    auto& captionPreferences = document->page()->group().captionPreferences();
    3082    
     3082
    30833083    if (equalLettersIgnoringASCIICase(mode, "automatic"))
    30843084        captionPreferences.setCaptionDisplayMode(CaptionUserPreferences::Automatic);
     
    31453145    return downcast<RenderEmbeddedObject>(*renderer).isReplacementObscured();
    31463146}
    3147    
     3147
    31483148bool Internals::isPluginSnapshotted(Element& element)
    31493149{
    31503150    return is<HTMLPlugInElement>(element) && downcast<HTMLPlugInElement>(element).displayState() <= HTMLPlugInElement::DisplayingSnapshot;
    31513151}
    3152    
     3152
    31533153#if ENABLE(MEDIA_SOURCE)
    31543154
     
    31683168    return buffer.bufferedSamplesForTrackID(trackID);
    31693169}
    3170    
     3170
    31713171Vector<String> Internals::enqueuedSamplesForTrackID(SourceBuffer& buffer, const AtomicString& trackID)
    31723172{
     
    32083208    if (equalLettersIgnoringASCIICase(flagsString, "mayresumeplaying"))
    32093209        flags = PlatformMediaSession::MayResumePlaying;
    3210    
     3210
    32113211    PlatformMediaSessionManager::sharedManager().endInterruption(flags);
    32123212}
     
    33633363    else
    33643364        return Exception { INVALID_ACCESS_ERR };
    3365    
     3365
    33663366    PlatformMediaSessionManager::sharedManager().didReceiveRemoteControlCommand(command, &parameter);
    33673367    return { };
     
    36383638        else
    36393639            justStarting = false;
    3640        
     3640
    36413641        builder.append(String::number(coordinate.toUnsigned()));
    36423642    }
    36433643    builder.appendLiteral(" }");
    36443644}
    3645    
     3645
    36463646void Internals::setPlatformMomentumScrollingPredictionEnabled(bool enabled)
    36473647{
     
    36583658    RenderBox& box = *element.renderBox();
    36593659    ScrollableArea* scrollableArea;
    3660    
     3660
    36613661    if (box.isBody()) {
    36623662        FrameView* frameView = box.frame().mainFrame().view();
     
    36643664            return Exception { INVALID_ACCESS_ERR };
    36653665        scrollableArea = frameView;
    3666        
     3666
    36673667    } else {
    36683668        if (!box.canBeScrolledAndHasScrollableArea())
     
    36733673    if (!scrollableArea)
    36743674        return String();
    3675    
     3675
    36763676    StringBuilder result;
    36773677
     
    37623762    if (!document)
    37633763        return;
    3764    
     3764
    37653765    Page* page = document->page();
    37663766    if (!page)
     
    37953795}
    37963796
     3797#if ENABLE(READABLE_BYTE_STREAM_API)
     3798
     3799JSValue Internals::cloneArrayBuffer(JSC::ExecState& state, JSValue buffer, JSValue srcByteOffset, JSValue srcLength)
     3800{
     3801    JSGlobalObject* globalObject = state.vmEntryGlobalObject();
     3802    JSVMClientData* clientData = static_cast<JSVMClientData*>(state.vm().clientData);
     3803    const Identifier& privateName = clientData->builtinNames().cloneArrayBufferPrivateName();
     3804    JSValue value;
     3805    PropertySlot propertySlot(value, PropertySlot::InternalMethodType::Get);
     3806    globalObject->methodTable()->getOwnPropertySlot(globalObject, &state, privateName, propertySlot);
     3807    value = propertySlot.getValue(&state, privateName);
     3808    ASSERT(value.isFunction());
     3809
     3810    JSObject* function = value.getObject();
     3811    CallData callData;
     3812    CallType callType = JSC::getCallData(function, callData);
     3813    ASSERT(callType != JSC::CallType::None);
     3814    MarkedArgumentBuffer arguments;
     3815    arguments.append(buffer);
     3816    arguments.append(srcByteOffset);
     3817    arguments.append(srcLength);
     3818
     3819    return JSC::call(&state, function, callType, callData, JSC::jsUndefined(), arguments);
     3820}
     3821
     3822#endif
    37973823#endif
    37983824
  • trunk/Source/WebCore/testing/Internals.h

    r215263 r215322  
    196196    void invalidateFontCache();
    197197    void setFontSmoothingEnabled(bool);
    198    
     198
    199199    ExceptionOr<void> setLowPowerModeEnabled(bool);
    200200
    201201    ExceptionOr<void> setScrollViewPosition(int x, int y);
    202    
     202
    203203    ExceptionOr<Ref<ClientRect>> layoutViewportRect();
    204204    ExceptionOr<Ref<ClientRect>> visualViewportRect();
    205    
     205
    206206    ExceptionOr<void> setViewBaseBackgroundColor(const String& colorValue);
    207207
     
    376376    ExceptionOr<void> startTrackingLayerFlushes();
    377377    ExceptionOr<unsigned> layerFlushCount();
    378    
     378
    379379    ExceptionOr<void> startTrackingStyleRecalcs();
    380380    ExceptionOr<unsigned> styleRecalcCount();
     
    532532#if ENABLE(READABLE_STREAM_API)
    533533    bool isReadableStreamDisturbed(JSC::ExecState&, JSC::JSValue);
     534#if ENABLE(READABLE_BYTE_STREAM_API)
     535    JSC::JSValue cloneArrayBuffer(JSC::ExecState&, JSC::JSValue, JSC::JSValue, JSC::JSValue);
     536#endif
    534537#endif
    535538
    536539    String composedTreeAsText(Node&);
    537    
     540
    538541    bool isProcessingUserGesture();
    539542    double lastHandledUserGestureTimestamp();
     
    545548
    546549    bool userPrefersReducedMotion() const;
    547    
     550
    548551    void reportBacktrace();
    549552
  • trunk/Source/WebCore/testing/Internals.idl

    r215263 r215322  
    494494    void setShowAllPlugins(boolean showAll);
    495495
     496    [Conditional=READABLE_STREAM_API&READABLE_BYTE_STREAM_API, CallWith=ScriptState] any cloneArrayBuffer(any buffer, any srcByteOffset, any byteLength);
    496497    [Conditional=READABLE_STREAM_API, CallWith=ScriptState] boolean isReadableStreamDisturbed(any stream);
    497498
Note: See TracChangeset for help on using the changeset viewer.