Changeset 203162 in webkit


Ignore:
Timestamp:
Jul 13, 2016 9:08:51 AM (8 years ago)
Author:
commit-queue@webkit.org
Message:

[Fetch API] Response should not become disturbed on the ReadableStream creation
https://bugs.webkit.org/show_bug.cgi?id=159714

Patch by Youenn Fablet <youenn@apple.com> on 2016-07-13
Reviewed by Alex Christensen.

LayoutTests/imported/w3c:

  • web-platform-tests/fetch/api/response/response-stream-disturbed-1-expected.txt:

Source/WebCore:

Covered by rebased test and existing tests.

  • Modules/fetch/FetchResponse.cpp:

(WebCore::FetchResponse::stop): Making the response disturbed if cancelled.

  • Modules/fetch/FetchResponseSource.cpp:

(WebCore::FetchResponseSource::firstReadCallback): Start enqueueing as soon as first read is made.
(WebCore::FetchResponseSource::doStart): Keep the start promise unresolved so that pull is not called.
FetchResponse is a push source.

  • Modules/fetch/FetchResponseSource.h:
  • Modules/streams/ReadableStreamInternals.js:

(readFromReadableStreamReader): Calling @firstReadCallback.

  • Modules/streams/ReadableStreamSource.h:

(WebCore::ReadableStreamSource::firstReadCallback): Default implementation (does nothing).

  • Modules/streams/ReadableStreamSource.idl: Adding firstReadCallback private method.
  • bindings/js/WebCoreBuiltinNames.h: Adding @firstReadCallback.
Location:
trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r203153 r203162  
     12016-07-13  Youenn Fablet  <youenn@apple.com>
     2
     3        [Fetch API] Response should not become disturbed on the ReadableStream creation
     4        https://bugs.webkit.org/show_bug.cgi?id=159714
     5
     6        Reviewed by Alex Christensen.
     7
     8        * web-platform-tests/fetch/api/response/response-stream-disturbed-1-expected.txt:
     9
    1102016-07-12  Youenn Fablet  <youenn@apple.com>
    211
  • trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-stream-disturbed-1-expected.txt

    r199641 r203162  
    11
    2 FAIL Getting blob after getting the Response body - not disturbed, not locked promise_test: Unhandled rejection with value: object "TypeError: Type error"
    3 FAIL Getting text after getting the Response body - not disturbed, not locked promise_test: Unhandled rejection with value: object "TypeError: Type error"
    4 FAIL Getting json after getting the Response body - not disturbed, not locked promise_test: Unhandled rejection with value: object "TypeError: Type error"
    5 FAIL Getting arrayBuffer after getting the Response body - not disturbed, not locked promise_test: Unhandled rejection with value: object "TypeError: Type error"
     2PASS Getting blob after getting the Response body - not disturbed, not locked
     3PASS Getting text after getting the Response body - not disturbed, not locked
     4PASS Getting json after getting the Response body - not disturbed, not locked
     5PASS Getting arrayBuffer after getting the Response body - not disturbed, not locked
    66
  • trunk/Source/WebCore/ChangeLog

    r203159 r203162  
     12016-07-13  Youenn Fablet  <youenn@apple.com>
     2
     3        [Fetch API] Response should not become disturbed on the ReadableStream creation
     4        https://bugs.webkit.org/show_bug.cgi?id=159714
     5
     6        Reviewed by Alex Christensen.
     7
     8        Covered by rebased test and existing tests.
     9
     10        * Modules/fetch/FetchResponse.cpp:
     11        (WebCore::FetchResponse::stop): Making the response disturbed if cancelled.
     12        * Modules/fetch/FetchResponseSource.cpp:
     13        (WebCore::FetchResponseSource::firstReadCallback): Start enqueueing as soon as first read is made.
     14        (WebCore::FetchResponseSource::doStart): Keep the start promise unresolved so that pull is not called.
     15        FetchResponse is a push source.
     16        * Modules/fetch/FetchResponseSource.h:
     17        * Modules/streams/ReadableStreamInternals.js:
     18        (readFromReadableStreamReader): Calling @firstReadCallback.
     19        * Modules/streams/ReadableStreamSource.h:
     20        (WebCore::ReadableStreamSource::firstReadCallback): Default implementation (does nothing).
     21        * Modules/streams/ReadableStreamSource.idl: Adding firstReadCallback private method.
     22        * bindings/js/WebCoreBuiltinNames.h: Adding @firstReadCallback.
     23
    1242016-07-13  Philippe Normand  <pnormand@igalia.com>
    225
  • trunk/Source/WebCore/Modules/fetch/FetchResponse.cpp

    r202910 r203162  
    288288    return m_loader->startStreaming();
    289289}
     290
     291void FetchResponse::cancel()
     292{
     293    m_isDisturbed = true;
     294    stop();
     295}
     296
    290297#endif
    291298
  • trunk/Source/WebCore/Modules/fetch/FetchResponse.h

    r202162 r203162  
    7474    ReadableStreamSource* createReadableStreamSource();
    7575    void consumeBodyAsStream();
     76    void cancel();
    7677#endif
    7778
  • trunk/Source/WebCore/Modules/fetch/FetchResponseSource.cpp

    r199641 r203162  
    5656}
    5757
     58void FetchResponseSource::firstReadCallback()
     59{
     60    m_response.consumeBodyAsStream();
     61}
     62
    5863void FetchResponseSource::doStart()
    5964{
    60     // FIXME: We should consume body only if stream reader requested data, i.e. is disturbed.
    61     // We might need a callback to be notified of the stream being disturbed.
    62     m_response.consumeBodyAsStream();
     65    // startFinished should not be called as this is a push source, hence overriding default implementation.
    6366}
     67
    6468
    6569void FetchResponseSource::doCancel()
    6670{
    6771    m_isCancelling = true;
    68     static_cast<ActiveDOMObject&>(m_response).stop();
     72    m_response.cancel();
    6973}
    7074
  • trunk/Source/WebCore/Modules/fetch/FetchResponseSource.h

    r199641 r203162  
    2727 */
    2828
    29 #ifndef FetchResponseSource_h
    30 #define FetchResponseSource_h
     29#pragma once
    3130
    3231#if ENABLE(FETCH_API) && ENABLE(STREAMS_API)
     
    5049
    5150private:
     51    void firstReadCallback() final;
    5252    void doStart() final;
    5353    void doCancel() final;
     
    6262
    6363#endif // ENABLE(FETCH_API) && ENABLE(STREAMS_API)
    64 
    65 #endif // FetchResponseSource_h
  • trunk/Source/WebCore/Modules/streams/ReadableStreamInternals.js

    r198776 r203162  
    342342    const stream = reader.@ownerReadableStream;
    343343    @assert(!!stream);
     344
     345    // Native sources may want to start enqueueing at the time of the first read request.
     346    if (!stream.@disturbed && stream.@underlyingSource.@firstReadCallback)
     347        stream.@underlyingSource.@firstReadCallback();
     348
    344349    stream.@disturbed = true;
    345350    if (stream.@state === @streamClosed)
  • trunk/Source/WebCore/Modules/streams/ReadableStreamSource.h

    r201013 r203162  
    2727 */
    2828
    29 
    30 #ifndef ReadableStreamSource_h
    31 #define ReadableStreamSource_h
     29#pragma once
    3230
    3331#if ENABLE(STREAMS_API)
     
    4745    typedef DOMPromise<std::nullptr_t> Promise;
    4846
     47    virtual void firstReadCallback() { }
    4948    void start(ReadableStreamController&&, Promise&&);
    5049    void cancel(JSC::JSValue);
     
    104103
    105104#endif // ENABLE(STREAMS_API)
    106 
    107 #endif // ReadableStreamSource_h
  • trunk/Source/WebCore/Modules/streams/ReadableStreamSource.idl

    r199641 r203162  
    3636    void cancel(any reason);
    3737
     38    [PrivateIdentifier] void firstReadCallback();
     39
    3840    // Place holder to keep the controller linked to the source.
    3941    [CachedAttribute, CustomGetter] readonly attribute any controller;
  • trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h

    r203029 r203162  
    4141    macro(disturbed) \
    4242    macro(fillFromJS) \
     43    macro(firstReadCallback) \
    4344    macro(getUserMediaFromJS) \
    4445    macro(getRemoteStreams) \
Note: See TracChangeset for help on using the changeset viewer.