Changeset 214663 in webkit


Ignore:
Timestamp:
Mar 31, 2017 3:37:06 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-03-31
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).

Added test to check cloneArrayBuffer behaviour.

  • 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/readable-stream-byob-request.js:
Location:
trunk
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r214662 r214663  
     12017-03-31  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/readable-stream-byob-request.js:
     11
    1122017-03-31  Oleksandr Skachkov  <gskachkov@gmail.com>
    213
  • trunk/LayoutTests/streams/readable-stream-byob-request-expected.txt

    r214265 r214663  
    1111PASS Calling respond() with a bytesWritten value greater than autoAllocateChunkSize should fail
    1212PASS Calling respond() with a bytesWritten value lower than autoAllocateChunkSize should succeed
     13PASS Test cloneArrayBuffer implementation
    1314PASS ReadableStreamBYOBRequest instances should have the correct list of properties
    1415PASS By default, byobRequest should be undefined
  • trunk/LayoutTests/streams/readable-stream-byob-request.js

    r214265 r214663  
    242242// so that more code can be covered.
    243243
     244if (!self.importScripts) {
     245    // Test only if not Worker.
     246    const CloneArrayBuffer = internals.cloneArrayBuffer.bind(internals);
     247
     248    test(function() {
     249        const typedArray = new Uint8Array([3, 5, 7]);
     250        const clonedBuffer = CloneArrayBuffer(typedArray.buffer, 1, 1);
     251        const otherArray = new Uint8Array(clonedBuffer);
     252        assert_equals(otherArray.byteLength, 1);
     253        assert_equals(otherArray.byteOffset, 0);
     254        assert_equals(otherArray.buffer.byteLength, 1);
     255        assert_equals(otherArray[0], 5);
     256        // Check that when typedArray is modified, otherArray is not modified.
     257        typedArray[1] = 0;
     258        assert_equals(otherArray[0], 5);
     259    }, "Test cloneArrayBuffer implementation");
     260}
     261
    244262done();
  • trunk/Source/WebCore/ChangeLog

    r214659 r214663  
     12017-03-31  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        Added test to check cloneArrayBuffer behaviour.
     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-03-31  Antoine Quint  <graouts@apple.com>
    230
  • trunk/Source/WebCore/Modules/streams/ReadableByteStreamInternals.js

    r214265 r214663  
    379379}
    380380
    381 function cloneArrayBuffer(srcBuffer, srcByteOffset, srcLength)
    382 {
    383     "use strict";
    384 
    385     // FIXME: Below implementation returns the appropriate data but does not perform
    386     // exactly what is described by ECMAScript CloneArrayBuffer operation. This should
    387     // be fixed in a follow up patch implementing cloneArrayBuffer in JSC (similarly to
    388     // structuredCloneArrayBuffer implementation).
    389     return srcBuffer.slice(srcByteOffset, srcByteOffset + srcLength);
    390 }
    391 
    392381function readableByteStreamControllerRespondInReadableState(controller, bytesWritten, pullIntoDescriptor)
    393382{
  • trunk/Source/WebCore/bindings/js/JSDOMGlobalObject.cpp

    r214080 r214663  
    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

    r211403 r214663  
    3636namespace WebCore {
    3737
    38 EncodedJSValue JSC_HOST_CALL structuredCloneArrayBuffer(ExecState* state)
     38EncodedJSValue JSC_HOST_CALL cloneArrayBufferImpl(ExecState*, bool);
     39
     40EncodedJSValue JSC_HOST_CALL cloneArrayBufferImpl(ExecState* state, bool isPartialClone)
    3941{
    4042    ASSERT(state);
     
    4951        return { };
    5052    }
     53    if (isPartialClone) {
     54        ASSERT(state->argumentCount() == 3);
     55        int srcByteOffset = static_cast<int>(state->uncheckedArgument(1).toNumber(state));
     56        int srcLength = static_cast<int>(state->uncheckedArgument(2).toNumber(state));
     57        buffer = buffer->slice(srcByteOffset, srcByteOffset + srcLength).get();
     58    }
    5159    return JSValue::encode(JSArrayBuffer::create(state->vm(), state->lexicalGlobalObject()->arrayBufferStructure(ArrayBufferSharingMode::Default), ArrayBuffer::tryCreate(buffer->data(), buffer->byteLength())));
     60}
     61
     62EncodedJSValue JSC_HOST_CALL cloneArrayBuffer(ExecState* state)
     63{
     64    return cloneArrayBufferImpl(state, true);
     65}
     66
     67EncodedJSValue JSC_HOST_CALL structuredCloneArrayBuffer(ExecState* state)
     68{
     69    return cloneArrayBufferImpl(state, false);
    5270}
    5371
  • trunk/Source/WebCore/bindings/js/StructuredClone.h

    r205117 r214663  
    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

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

    r214604 r214663  
    352352    else
    353353        return false;
    354    
     354
    355355    return true;
    356356}
     
    392392
    393393    page.setDefersLoading(false);
    394    
     394
    395395    page.mainFrame().setTextZoomFactor(1.0f);
    396    
     396
    397397    FrameView* mainFrameView = page.mainFrame().view();
    398398    if (mainFrameView) {
     
    597597    ResourceRequest request(contextDocument()->completeURL(url));
    598598    request.setDomainForCachePartition(contextDocument()->topOrigin().domainForCachePartition());
    599    
     599
    600600    CachedResource* resource = MemoryCache::singleton().resourceForRequest(request, contextDocument()->page()->sessionID());
    601601    return resource && resource->status() == CachedResource::Cached;
     
    725725    if (!cachedImage)
    726726        return;
    727    
     727
    728728    auto* image = cachedImage->image();
    729729    if (!is<BitmapImage>(image))
    730730        return;
    731    
     731
    732732    downcast<BitmapImage>(*image).setFrameDecodingDurationForTesting(duration);
    733733}
     
    989989            continue;
    990990        }
    991        
     991
    992992        StyleRuleGroup* groupRule = nullptr;
    993993        if (is<StyleRuleMedia>(rule.get()))
     
    997997        if (!groupRule)
    998998            continue;
    999        
     999
    10001000        auto* groupChildRules = groupRule->childRulesWithoutDeferredParsing();
    10011001        if (!groupChildRules)
    10021002            continue;
    1003        
     1003
    10041004        count += deferredStyleRulesCountForList(*groupChildRules);
    10051005    }
     
    10241024        if (!groupRule)
    10251025            continue;
    1026        
     1026
    10271027        auto* groupChildRules = groupRule->childRulesWithoutDeferredParsing();
    10281028        if (!groupChildRules)
     
    10491049            continue;
    10501050        }
    1051        
     1051
    10521052        StyleRuleGroup* groupRule = nullptr;
    10531053        if (is<StyleRuleMedia>(rule.get()))
     
    10571057        if (!groupRule)
    10581058            continue;
    1059        
     1059
    10601060        auto* groupChildRules = groupRule->childRulesWithoutDeferredParsing();
    10611061        if (!groupChildRules)
    10621062            continue;
    1063        
     1063
    10641064        count += deferredKeyframesRulesCountForList(*groupChildRules);
    10651065    }
    1066    
     1066
    10671067    return count;
    10681068}
     
    11371137    if (!behavior)
    11381138        return std::nullopt;
    1139    
     1139
    11401140    switch (behavior.value()) {
    11411141    case WebCore::EventThrottlingBehavior::Responsive:
     
    12021202    if (!synthesis)
    12031203        return;
    1204    
     1204
    12051205    synthesis->setPlatformSynthesizer(std::make_unique<PlatformSpeechSynthesizerMock>(synthesis));
    12061206}
     
    16341634
    16351635    document->updateLayoutIgnorePendingStylesheets();
    1636    
     1636
    16371637    HitTestResult result = document->frame()->mainFrame().eventHandler().hitTestResultAtPoint(IntPoint(x, y));
    16381638    NSDictionary *options = nullptr;
     
    17901790        HitTestResult result(point, topPadding, rightPadding, bottomPadding, leftPadding);
    17911791        renderView->hitTest(request, result);
    1792        
     1792
    17931793        const HitTestResult::NodeSet& nodeSet = result.rectBasedTestResult();
    17941794        matches.reserveInitialCapacity(nodeSet.size());
     
    19111911    return document->frame()->editor().selectionStartHasMarkerFor(DocumentMarker::Spelling, from, length);
    19121912}
    1913    
     1913
    19141914bool Internals::hasAutocorrectedMarker(int from, int length)
    19151915{
     
    21642164    return count;
    21652165}
    2166    
     2166
    21672167ExceptionOr<bool> Internals::isPageBoxVisible(int pageNumber)
    21682168{
     
    22172217    if (!layerModelObject.layer()->isComposited())
    22182218        return Exception { NOT_FOUND_ERR };
    2219    
     2219
    22202220    auto* backing = layerModelObject.layer()->backing();
    22212221    return backing->graphicsLayer()->primaryLayerID();
     
    22862286    if (!element.renderer()->hasLayer())
    22872287        return Exception { INVALID_ACCESS_ERR };
    2288    
     2288
    22892289    RenderLayer* layer = downcast<RenderLayerModelObject>(element.renderer())->layer();
    22902290    if (!layer->isComposited())
    22912291        return Exception { INVALID_ACCESS_ERR };
    2292    
     2292
    22932293    layer->backing()->setUsesDisplayListDrawing(usesDisplayListDrawing);
    22942294    return { };
     
    23152315    if (!layer->isComposited())
    23162316        return Exception { INVALID_ACCESS_ERR };
    2317    
     2317
    23182318    layer->backing()->setIsTrackingDisplayListReplay(isTrackingReplay);
    23192319    return { };
     
    25552555    document->view()->setFooterHeight(height);
    25562556}
    2557    
     2557
    25582558void Internals::setTopContentInset(float contentInset)
    25592559{
     
    26992699    if (!document)
    27002700        return Exception { INVALID_ACCESS_ERR };
    2701    
     2701
    27022702    return document->styleRecalcCount();
    27032703}
     
    27262726    if (!document || !document->renderView())
    27272727        return Exception { INVALID_ACCESS_ERR };
    2728    
     2728
    27292729    return document->renderView()->compositor().compositingUpdateCount();
    27302730}
     
    30183018    if (!document || !document->page())
    30193019        return Exception { INVALID_ACCESS_ERR };
    3020    
     3020
    30213021#if ENABLE(VIDEO_TRACK)
    30223022    auto& captionPreferences = document->page()->group().captionPreferences();
    3023    
     3023
    30243024    if (equalLettersIgnoringASCIICase(mode, "automatic"))
    30253025        captionPreferences.setCaptionDisplayMode(CaptionUserPreferences::Automatic);
     
    30863086    return downcast<RenderEmbeddedObject>(*renderer).isReplacementObscured();
    30873087}
    3088    
     3088
    30893089bool Internals::isPluginSnapshotted(Element& element)
    30903090{
    30913091    return is<HTMLPlugInElement>(element) && downcast<HTMLPlugInElement>(element).displayState() <= HTMLPlugInElement::DisplayingSnapshot;
    30923092}
    3093    
     3093
    30943094#if ENABLE(MEDIA_SOURCE)
    30953095
     
    31093109    return buffer.bufferedSamplesForTrackID(trackID);
    31103110}
    3111    
     3111
    31123112Vector<String> Internals::enqueuedSamplesForTrackID(SourceBuffer& buffer, const AtomicString& trackID)
    31133113{
     
    31493149    if (equalLettersIgnoringASCIICase(flagsString, "mayresumeplaying"))
    31503150        flags = PlatformMediaSession::MayResumePlaying;
    3151    
     3151
    31523152    PlatformMediaSessionManager::sharedManager().endInterruption(flags);
    31533153}
     
    33023302    else
    33033303        return Exception { INVALID_ACCESS_ERR };
    3304    
     3304
    33053305    PlatformMediaSessionManager::sharedManager().didReceiveRemoteControlCommand(command, &parameter);
    33063306    return { };
     
    35733573        else
    35743574            justStarting = false;
    3575        
     3575
    35763576        builder.append(String::number(coordinate.toUnsigned()));
    35773577    }
    35783578    builder.appendLiteral(" }");
    35793579}
    3580    
     3580
    35813581void Internals::setPlatformMomentumScrollingPredictionEnabled(bool enabled)
    35823582{
     
    35933593    RenderBox& box = *element.renderBox();
    35943594    ScrollableArea* scrollableArea;
    3595    
     3595
    35963596    if (box.isBody()) {
    35973597        FrameView* frameView = box.frame().mainFrame().view();
     
    35993599            return Exception { INVALID_ACCESS_ERR };
    36003600        scrollableArea = frameView;
    3601        
     3601
    36023602    } else {
    36033603        if (!box.canBeScrolledAndHasScrollableArea())
     
    36083608    if (!scrollableArea)
    36093609        return String();
    3610    
     3610
    36113611    StringBuilder result;
    36123612
     
    36973697    if (!document)
    36983698        return;
    3699    
     3699
    37003700    Page* page = document->page();
    37013701    if (!page)
     
    37303730}
    37313731
     3732#if ENABLE(READABLE_BYTE_STREAM_API)
     3733
     3734JSValue Internals::cloneArrayBuffer(JSC::ExecState& state, JSValue buffer, JSValue srcByteOffset, JSValue srcLength)
     3735{
     3736    JSGlobalObject* globalObject = state.vmEntryGlobalObject();
     3737    JSVMClientData* clientData = static_cast<JSVMClientData*>(state.vm().clientData);
     3738    const Identifier& privateName = clientData->builtinNames().cloneArrayBufferPrivateName();
     3739    JSValue value;
     3740    PropertySlot propertySlot(value, PropertySlot::InternalMethodType::Get);
     3741    globalObject->methodTable()->getOwnPropertySlot(globalObject, &state, privateName, propertySlot);
     3742    value = propertySlot.getValue(&state, privateName);
     3743    ASSERT(value.isFunction());
     3744
     3745    JSObject* function = value.getObject();
     3746    CallData callData;
     3747    CallType callType = JSC::getCallData(function, callData);
     3748    ASSERT(callType != JSC::CallType::None);
     3749    MarkedArgumentBuffer arguments;
     3750    arguments.append(buffer);
     3751    arguments.append(srcByteOffset);
     3752    arguments.append(srcLength);
     3753
     3754    return JSC::call(&state, function, callType, callData, JSC::jsUndefined(), arguments);
     3755}
     3756
     3757#endif
    37323758#endif
    37333759
  • trunk/Source/WebCore/testing/Internals.h

    r214604 r214663  
    189189    void invalidateFontCache();
    190190    void setFontSmoothingEnabled(bool);
    191    
     191
    192192    ExceptionOr<void> setLowPowerModeEnabled(bool);
    193193
    194194    ExceptionOr<void> setScrollViewPosition(int x, int y);
    195    
     195
    196196    ExceptionOr<Ref<ClientRect>> layoutViewportRect();
    197197    ExceptionOr<Ref<ClientRect>> visualViewportRect();
    198    
     198
    199199    ExceptionOr<void> setViewBaseBackgroundColor(const String& colorValue);
    200200
     
    369369    ExceptionOr<void> startTrackingLayerFlushes();
    370370    ExceptionOr<unsigned> layerFlushCount();
    371    
     371
    372372    ExceptionOr<void> startTrackingStyleRecalcs();
    373373    ExceptionOr<unsigned> styleRecalcCount();
     
    524524#if ENABLE(READABLE_STREAM_API)
    525525    bool isReadableStreamDisturbed(JSC::ExecState&, JSC::JSValue);
     526#if ENABLE(READABLE_BYTE_STREAM_API)
     527    JSC::JSValue cloneArrayBuffer(JSC::ExecState&, JSC::JSValue, JSC::JSValue, JSC::JSValue);
     528#endif
    526529#endif
    527530
    528531    String composedTreeAsText(Node&);
    529    
     532
    530533    bool isProcessingUserGesture();
    531534
     
    536539
    537540    bool userPrefersReducedMotion() const;
    538    
     541
    539542    void reportBacktrace();
    540543
  • trunk/Source/WebCore/testing/Internals.idl

    r214604 r214663  
    491491    void setShowAllPlugins(boolean showAll);
    492492
     493    [Conditional=READABLE_STREAM_API&READABLE_BYTE_STREAM_API, CallWith=ScriptState] any cloneArrayBuffer(any buffer, any srcByteOffset, any byteLength);
    493494    [Conditional=READABLE_STREAM_API, CallWith=ScriptState] boolean isReadableStreamDisturbed(any stream);
    494495
Note: See TracChangeset for help on using the changeset viewer.