Title: [185648] trunk
Revision
185648
Author
[email protected]
Date
2015-06-17 00:45:51 -0700 (Wed, 17 Jun 2015)

Log Message

[Streams API] ReadableJSStream should handle promises returned by JS source pull callback
https://bugs.webkit.org/show_bug.cgi?id=145965

Reviewed by Darin Adler.

Source/WebCore:

Implemented asynchronous pulling.
In particular, ensuring that doPull is not called as long as previous call to doPull is finished.
Storing whether to pull automatically when the current pull is finished.

Covered by rebased tests.

* Modules/streams/ReadableStream.cpp:
(WebCore::ReadableStream::pull): stores whether to pull again.
(WebCore::ReadableStream::finishPulling): called when pulling finishes.
* Modules/streams/ReadableStream.h:
* bindings/js/ReadableJSStream.cpp:
(WebCore::createPullResultFulfilledFunction): The promise resolve callback.
(WebCore::ReadableJSStream::doPull): Handling of promise.
* bindings/js/ReadableJSStream.h:

LayoutTests:

Rebasing tests and removing timeout: 50 for test that is passing..

* streams/reference-implementation/readable-stream-expected.txt:
* streams/reference-implementation/readable-stream.html:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (185647 => 185648)


--- trunk/LayoutTests/ChangeLog	2015-06-17 07:20:37 UTC (rev 185647)
+++ trunk/LayoutTests/ChangeLog	2015-06-17 07:45:51 UTC (rev 185648)
@@ -1,3 +1,15 @@
+2015-06-17  Xabier Rodriguez Calvar  <[email protected]> and Youenn Fablet <[email protected]>
+
+        [Streams API] ReadableJSStream should handle promises returned by JS source pull callback
+        https://bugs.webkit.org/show_bug.cgi?id=145965
+
+        Reviewed by Darin Adler.
+
+        Rebasing tests and removing timeout: 50 for test that is passing..
+
+        * streams/reference-implementation/readable-stream-expected.txt:
+        * streams/reference-implementation/readable-stream.html:
+
 2015-06-16  Youenn Fablet <[email protected]> and Xabier Rodriguez Calvar  <[email protected]>
 
         [Streams API] Implement ReadableStream locked property

Modified: trunk/LayoutTests/streams/reference-implementation/readable-stream-expected.txt (185647 => 185648)


--- trunk/LayoutTests/streams/reference-implementation/readable-stream-expected.txt	2015-06-17 07:20:37 UTC (rev 185647)
+++ trunk/LayoutTests/streams/reference-implementation/readable-stream-expected.txt	2015-06-17 07:45:51 UTC (rev 185648)
@@ -11,13 +11,13 @@
 PASS ReadableStream start should be able to return a promise 
 TIMEOUT ReadableStream start should be able to return a promise and reject it Test timed out
 PASS ReadableStream should be able to enqueue different objects. 
-TIMEOUT ReadableStream: if pull rejects, it should error the stream Test timed out
+PASS ReadableStream: if pull rejects, it should error the stream 
 PASS ReadableStream: should only call pull once upon starting the stream 
 FAIL ReadableStream: should call pull when trying to read from a started, empty stream assert_equals: pull should be called again in reaction to calling read expected 2 but got 3
 PASS ReadableStream: should only call pull once on a non-empty stream read from before start fulfills 
 PASS ReadableStream: should only call pull once on a non-empty stream read from after start fulfills 
 PASS ReadableStream: should not call pull() in reaction to read()ing the last chunk, if draining 
-FAIL ReadableStream: should not call pull until the previous pull call's promise fulfills assert_equals: pull should have been called once after start, but not yet have been called a second time expected 1 but got 2
+PASS ReadableStream: should not call pull until the previous pull call's promise fulfills 
 FAIL ReadableStream: should pull after start, and after every read assert_equals: pull() should be called exactly four times expected 4 but got 1
 PASS ReadableStream: should not call pull after start if the stream is now closed 
 FAIL ReadableStream: should call pull after enqueueing from inside pull (with no read requests), if strategy allows assert_equals: pull() should have been called four times expected 4 but got 1

Modified: trunk/LayoutTests/streams/reference-implementation/readable-stream.html (185647 => 185648)


--- trunk/LayoutTests/streams/reference-implementation/readable-stream.html	2015-06-17 07:20:37 UTC (rev 185647)
+++ trunk/LayoutTests/streams/reference-implementation/readable-stream.html	2015-06-17 07:45:51 UTC (rev 185648)
@@ -224,7 +224,7 @@
     }));
 });
 
-var test5 = async_test('ReadableStream: if pull rejects, it should error the stream', { timeout: 50 });
+var test5 = async_test('ReadableStream: if pull rejects, it should error the stream');
 test5.step(function() {
     var error = new Error('pull failure');
     var rs = new ReadableStream({

Modified: trunk/Source/WebCore/ChangeLog (185647 => 185648)


--- trunk/Source/WebCore/ChangeLog	2015-06-17 07:20:37 UTC (rev 185647)
+++ trunk/Source/WebCore/ChangeLog	2015-06-17 07:45:51 UTC (rev 185648)
@@ -1,3 +1,25 @@
+2015-06-17  Xabier Rodriguez Calvar  <[email protected]> and Youenn Fablet <[email protected]>
+
+        [Streams API] ReadableJSStream should handle promises returned by JS source pull callback
+        https://bugs.webkit.org/show_bug.cgi?id=145965
+
+        Reviewed by Darin Adler.
+
+        Implemented asynchronous pulling.
+        In particular, ensuring that doPull is not called as long as previous call to doPull is finished.
+        Storing whether to pull automatically when the current pull is finished. 
+
+        Covered by rebased tests.
+
+        * Modules/streams/ReadableStream.cpp:
+        (WebCore::ReadableStream::pull): stores whether to pull again.
+        (WebCore::ReadableStream::finishPulling): called when pulling finishes.
+        * Modules/streams/ReadableStream.h:
+        * bindings/js/ReadableJSStream.cpp:
+        (WebCore::createPullResultFulfilledFunction): The promise resolve callback.
+        (WebCore::ReadableJSStream::doPull): Handling of promise.
+        * bindings/js/ReadableJSStream.h:
+
 2015-06-16  Carlos Garcia Campos  <[email protected]>
 
         WebProcess crashes after too many redirect error when there's an active NPAPI plugin

Modified: trunk/Source/WebCore/Modules/streams/ReadableStream.cpp (185647 => 185648)


--- trunk/Source/WebCore/Modules/streams/ReadableStream.cpp	2015-06-17 07:20:37 UTC (rev 185647)
+++ trunk/Source/WebCore/Modules/streams/ReadableStream.cpp	2015-06-17 07:45:51 UTC (rev 185648)
@@ -124,10 +124,26 @@
     // FIXME: Implement queueSize check.
     if (m_readRequests.isEmpty() && hasValue())
         return;
-    // FIXME: Implement async pull check.
-    doPull();
+
+    if (m_isPulling) {
+        m_shouldPullAgain = true;
+        return;
+    }
+
+    m_isPulling = true;
+    if (doPull())
+        finishPulling();
 }
 
+void ReadableStream::finishPulling()
+{
+    m_isPulling = false;
+    if (m_shouldPullAgain) {
+        m_shouldPullAgain = false;
+        pull();
+    }
+}
+
 ReadableStreamReader& ReadableStream::getReader()
 {
     ASSERT(!m_reader);

Modified: trunk/Source/WebCore/Modules/streams/ReadableStream.h (185647 => 185648)


--- trunk/Source/WebCore/Modules/streams/ReadableStream.h	2015-06-17 07:20:37 UTC (rev 185647)
+++ trunk/Source/WebCore/Modules/streams/ReadableStream.h	2015-06-17 07:45:51 UTC (rev 185648)
@@ -76,6 +76,7 @@
     void start();
     void changeStateToClosed();
     void changeStateToErrored();
+    void finishPulling();
 
     typedef std::function<void(JSC::JSValue)> FailureCallback;
 
@@ -102,7 +103,7 @@
 
     virtual bool hasValue() const = 0;
     virtual JSC::JSValue read() = 0;
-    virtual void doPull() = 0;
+    virtual bool doPull() = 0;
 
     std::unique_ptr<ReadableStreamReader> m_reader;
     Vector<std::unique_ptr<ReadableStreamReader>> m_releasedReaders;
@@ -118,6 +119,8 @@
     Deque<ReadCallbacks> m_readRequests;
 
     bool m_isStarted { false };
+    bool m_isPulling { false };
+    bool m_shouldPullAgain { false };
     bool m_closeRequested { false };
     State m_state { State::Readable };
 };

Modified: trunk/Source/WebCore/bindings/js/ReadableJSStream.cpp (185647 => 185648)


--- trunk/Source/WebCore/bindings/js/ReadableJSStream.cpp	2015-06-17 07:20:37 UTC (rev 185647)
+++ trunk/Source/WebCore/bindings/js/ReadableJSStream.cpp	2015-06-17 07:45:51 UTC (rev 185648)
@@ -133,19 +133,32 @@
     thenPromise(exec, promise, createStartResultFulfilledFunction(exec, *this), m_errorFunction.get());
 }
 
-void ReadableJSStream::doPull()
+static inline JSFunction* createPullResultFulfilledFunction(ExecState& exec, ReadableJSStream& stream)
 {
+    RefPtr<ReadableJSStream> readableStream = &stream;
+    return JSFunction::create(exec.vm(), exec.callee()->globalObject(), 0, String(), [readableStream](ExecState*) {
+        readableStream->finishPulling();
+        return JSValue::encode(jsUndefined());
+    });
+}
+
+bool ReadableJSStream::doPull()
+{
     ExecState& state = *globalObject()->globalExec();
     JSLockHolder lock(&state);
 
-    invoke(state, "pull");
+    JSPromise* promise = invoke(state, "pull");
 
+    if (promise)
+        thenPromise(state, promise, createPullResultFulfilledFunction(state, *this), m_errorFunction.get());
+
     if (state.hadException()) {
         storeException(state);
         ASSERT(!state.hadException());
-        return;
+        return true;
     }
-    // FIXME: Implement handling promise as result of calling pull function.
+
+    return !promise;
 }
 
 RefPtr<ReadableJSStream> ReadableJSStream::create(ExecState& exec, ScriptExecutionContext& scriptExecutionContext)

Modified: trunk/Source/WebCore/bindings/js/ReadableJSStream.h (185647 => 185648)


--- trunk/Source/WebCore/bindings/js/ReadableJSStream.h	2015-06-17 07:20:37 UTC (rev 185647)
+++ trunk/Source/WebCore/bindings/js/ReadableJSStream.h	2015-06-17 07:45:51 UTC (rev 185648)
@@ -71,7 +71,7 @@
 
     virtual bool hasValue() const override;
     virtual JSC::JSValue read() override;
-    virtual void doPull() override;
+    virtual bool doPull() override;
 
     JSDOMGlobalObject* globalObject();
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to