Title: [203162] trunk
Revision
203162
Author
[email protected]
Date
2016-07-13 09:08:51 -0700 (Wed, 13 Jul 2016)

Log 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 <[email protected]> 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.

Modified Paths

Diff

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (203161 => 203162)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2016-07-13 14:48:09 UTC (rev 203161)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2016-07-13 16:08:51 UTC (rev 203162)
@@ -1,3 +1,12 @@
+2016-07-13  Youenn Fablet  <[email protected]>
+
+        [Fetch API] Response should not become disturbed on the ReadableStream creation
+        https://bugs.webkit.org/show_bug.cgi?id=159714
+
+        Reviewed by Alex Christensen.
+
+        * web-platform-tests/fetch/api/response/response-stream-disturbed-1-expected.txt:
+
 2016-07-12  Youenn Fablet  <[email protected]>
 
         [Fetch API] isRedirected should be conveyed in workers

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-stream-disturbed-1-expected.txt (203161 => 203162)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-stream-disturbed-1-expected.txt	2016-07-13 14:48:09 UTC (rev 203161)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-stream-disturbed-1-expected.txt	2016-07-13 16:08:51 UTC (rev 203162)
@@ -1,6 +1,6 @@
 
-FAIL Getting blob after getting the Response body - not disturbed, not locked promise_test: Unhandled rejection with value: object "TypeError: Type error"
-FAIL Getting text after getting the Response body - not disturbed, not locked promise_test: Unhandled rejection with value: object "TypeError: Type error"
-FAIL Getting json after getting the Response body - not disturbed, not locked promise_test: Unhandled rejection with value: object "TypeError: Type error"
-FAIL Getting arrayBuffer after getting the Response body - not disturbed, not locked promise_test: Unhandled rejection with value: object "TypeError: Type error"
+PASS Getting blob after getting the Response body - not disturbed, not locked 
+PASS Getting text after getting the Response body - not disturbed, not locked 
+PASS Getting json after getting the Response body - not disturbed, not locked 
+PASS Getting arrayBuffer after getting the Response body - not disturbed, not locked 
 

Modified: trunk/Source/WebCore/ChangeLog (203161 => 203162)


--- trunk/Source/WebCore/ChangeLog	2016-07-13 14:48:09 UTC (rev 203161)
+++ trunk/Source/WebCore/ChangeLog	2016-07-13 16:08:51 UTC (rev 203162)
@@ -1,3 +1,26 @@
+2016-07-13  Youenn Fablet  <[email protected]>
+
+        [Fetch API] Response should not become disturbed on the ReadableStream creation
+        https://bugs.webkit.org/show_bug.cgi?id=159714
+
+        Reviewed by Alex Christensen.
+
+        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.
+
 2016-07-13  Philippe Normand  <[email protected]>
 
         [GStreamer][GL] crash within triggerRepaint

Modified: trunk/Source/WebCore/Modules/fetch/FetchResponse.cpp (203161 => 203162)


--- trunk/Source/WebCore/Modules/fetch/FetchResponse.cpp	2016-07-13 14:48:09 UTC (rev 203161)
+++ trunk/Source/WebCore/Modules/fetch/FetchResponse.cpp	2016-07-13 16:08:51 UTC (rev 203162)
@@ -287,6 +287,13 @@
     ASSERT(m_loader);
     return m_loader->startStreaming();
 }
+
+void FetchResponse::cancel()
+{
+    m_isDisturbed = true;
+    stop();
+}
+
 #endif
 
 void FetchResponse::stop()

Modified: trunk/Source/WebCore/Modules/fetch/FetchResponse.h (203161 => 203162)


--- trunk/Source/WebCore/Modules/fetch/FetchResponse.h	2016-07-13 14:48:09 UTC (rev 203161)
+++ trunk/Source/WebCore/Modules/fetch/FetchResponse.h	2016-07-13 16:08:51 UTC (rev 203162)
@@ -73,6 +73,7 @@
 #if ENABLE(STREAMS_API)
     ReadableStreamSource* createReadableStreamSource();
     void consumeBodyAsStream();
+    void cancel();
 #endif
 
 private:

Modified: trunk/Source/WebCore/Modules/fetch/FetchResponseSource.cpp (203161 => 203162)


--- trunk/Source/WebCore/Modules/fetch/FetchResponseSource.cpp	2016-07-13 14:48:09 UTC (rev 203161)
+++ trunk/Source/WebCore/Modules/fetch/FetchResponseSource.cpp	2016-07-13 16:08:51 UTC (rev 203162)
@@ -55,17 +55,21 @@
     m_response.unsetPendingActivity(&m_response);
 }
 
-void FetchResponseSource::doStart()
+void FetchResponseSource::firstReadCallback()
 {
-    // FIXME: We should consume body only if stream reader requested data, i.e. is disturbed.
-    // We might need a callback to be notified of the stream being disturbed.
     m_response.consumeBodyAsStream();
 }
 
+void FetchResponseSource::doStart()
+{
+    // startFinished should not be called as this is a push source, hence overriding default implementation.
+}
+
+
 void FetchResponseSource::doCancel()
 {
     m_isCancelling = true;
-    static_cast<ActiveDOMObject&>(m_response).stop();
+    m_response.cancel();
 }
 
 void FetchResponseSource::close()

Modified: trunk/Source/WebCore/Modules/fetch/FetchResponseSource.h (203161 => 203162)


--- trunk/Source/WebCore/Modules/fetch/FetchResponseSource.h	2016-07-13 14:48:09 UTC (rev 203161)
+++ trunk/Source/WebCore/Modules/fetch/FetchResponseSource.h	2016-07-13 16:08:51 UTC (rev 203162)
@@ -26,8 +26,7 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef FetchResponseSource_h
-#define FetchResponseSource_h
+#pragma once
 
 #if ENABLE(FETCH_API) && ENABLE(STREAMS_API)
 
@@ -49,6 +48,7 @@
     bool isReadableStreamLocked() const;
 
 private:
+    void firstReadCallback() final;
     void doStart() final;
     void doCancel() final;
     void setActive() final;
@@ -61,5 +61,3 @@
 } // namespace WebCore
 
 #endif // ENABLE(FETCH_API) && ENABLE(STREAMS_API)
-
-#endif // FetchResponseSource_h

Modified: trunk/Source/WebCore/Modules/streams/ReadableStreamInternals.js (203161 => 203162)


--- trunk/Source/WebCore/Modules/streams/ReadableStreamInternals.js	2016-07-13 14:48:09 UTC (rev 203161)
+++ trunk/Source/WebCore/Modules/streams/ReadableStreamInternals.js	2016-07-13 16:08:51 UTC (rev 203162)
@@ -341,6 +341,11 @@
 
     const stream = reader.@ownerReadableStream;
     @assert(!!stream);
+
+    // Native sources may want to start enqueueing at the time of the first read request.
+    if (!stream.@disturbed && stream.@underlyingSource.@firstReadCallback)
+        stream.@underlyingSource.@firstReadCallback();
+
     stream.@disturbed = true;
     if (stream.@state === @streamClosed)
         return @Promise.@resolve({value: @undefined, done: true});

Modified: trunk/Source/WebCore/Modules/streams/ReadableStreamSource.h (203161 => 203162)


--- trunk/Source/WebCore/Modules/streams/ReadableStreamSource.h	2016-07-13 14:48:09 UTC (rev 203161)
+++ trunk/Source/WebCore/Modules/streams/ReadableStreamSource.h	2016-07-13 16:08:51 UTC (rev 203162)
@@ -26,10 +26,8 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#pragma once
 
-#ifndef ReadableStreamSource_h
-#define ReadableStreamSource_h
-
 #if ENABLE(STREAMS_API)
 
 #include "JSDOMPromise.h"
@@ -46,6 +44,7 @@
 
     typedef DOMPromise<std::nullptr_t> Promise;
 
+    virtual void firstReadCallback() { }
     void start(ReadableStreamController&&, Promise&&);
     void cancel(JSC::JSValue);
 
@@ -103,5 +102,3 @@
 } // namespace WebCore
 
 #endif // ENABLE(STREAMS_API)
-
-#endif // ReadableStreamSource_h

Modified: trunk/Source/WebCore/Modules/streams/ReadableStreamSource.idl (203161 => 203162)


--- trunk/Source/WebCore/Modules/streams/ReadableStreamSource.idl	2016-07-13 14:48:09 UTC (rev 203161)
+++ trunk/Source/WebCore/Modules/streams/ReadableStreamSource.idl	2016-07-13 16:08:51 UTC (rev 203162)
@@ -35,6 +35,8 @@
     [Custom] Promise start(ReadableStreamController controller);
     void cancel(any reason);
 
+    [PrivateIdentifier] void firstReadCallback();
+
     // Place holder to keep the controller linked to the source.
     [CachedAttribute, CustomGetter] readonly attribute any controller;
 };

Modified: trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h (203161 => 203162)


--- trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h	2016-07-13 14:48:09 UTC (rev 203161)
+++ trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h	2016-07-13 16:08:51 UTC (rev 203162)
@@ -40,6 +40,7 @@
     macro(controller) \
     macro(disturbed) \
     macro(fillFromJS) \
+    macro(firstReadCallback) \
     macro(getUserMediaFromJS) \
     macro(getRemoteStreams) \
     macro(getSenders) \
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to