[Streams API] Implement ReadableStreamReader.releaseLock
authorcalvaris@igalia.com <calvaris@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 18 Jun 2015 08:58:18 +0000 (08:58 +0000)
committercalvaris@igalia.com <calvaris@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 18 Jun 2015 08:58:18 +0000 (08:58 +0000)
https://bugs.webkit.org/show_bug.cgi?id=145299

Reviewed by Darin Adler.

Source/WebCore:

Covered by rebased tests.

* Modules/streams/ReadableStream.cpp:
(WebCore::ReadableStream::close): Moving some close code to newly added releaseReader.
(WebCore::ReadableStream::releaseReader): Implements reader release and callbacks finalization.
(WebCore::ReadableStream::changeStateToErrored): Calls releaseReader.
* Modules/streams/ReadableStream.h:
(WebCore::ReadableStream::hasReadPendingRequests): Added to enable reader.releaseLock throwing if read requests are pending.
* Modules/streams/ReadableStreamReader.cpp:
(WebCore::ReadableStreamReader::releaseLock): Implementation of releaseLock
* Modules/streams/ReadableStreamReader.h:
* Modules/streams/ReadableStreamReader.idl:
(WebCore::releaseLock): Deleted.

LayoutTests:

* streams/reference-implementation/readable-stream-expected.txt: Rebasing expectations.
* streams/reference-implementation/readable-stream-reader-expected.txt: Ditto.
* streams/reference-implementation/readable-stream-templated-expected.txt: Ditto.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@185697 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/streams/reference-implementation/readable-stream-expected.txt
LayoutTests/streams/reference-implementation/readable-stream-reader-expected.txt
LayoutTests/streams/reference-implementation/readable-stream-templated-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/Modules/streams/ReadableStream.cpp
Source/WebCore/Modules/streams/ReadableStream.h
Source/WebCore/Modules/streams/ReadableStreamReader.cpp
Source/WebCore/Modules/streams/ReadableStreamReader.h
Source/WebCore/Modules/streams/ReadableStreamReader.idl
Source/WebCore/bindings/js/JSReadableStreamReaderCustom.cpp

index 63770da..9c48cb3 100644 (file)
@@ -1,5 +1,16 @@
 2015-06-18  Youenn Fablet <youenn.fablet@crf.canon.fr> and Xabier Rodriguez Calvar  <calvaris@igalia.com>
 
+        [Streams API] Implement ReadableStreamReader.releaseLock
+        https://bugs.webkit.org/show_bug.cgi?id=145299
+
+        Reviewed by Darin Adler.
+
+        * streams/reference-implementation/readable-stream-expected.txt: Rebasing expectations.
+        * streams/reference-implementation/readable-stream-reader-expected.txt: Ditto.
+        * streams/reference-implementation/readable-stream-templated-expected.txt: Ditto.
+
+2015-06-18  Youenn Fablet <youenn.fablet@crf.canon.fr> and Xabier Rodriguez Calvar  <calvaris@igalia.com>
+
         [Streams API] Rejected start promise test does not timeout anymore
         https://bugs.webkit.org/show_bug.cgi?id=146065
 
index f382e58..98d91f2 100644 (file)
@@ -25,7 +25,7 @@ PASS ReadableStream pull should be able to close a stream.
 PASS ReadableStream: enqueue should throw when the stream is readable but draining 
 PASS ReadableStream: enqueue should throw when the stream is closed 
 PASS ReadableStream: enqueue should throw the stored error when the stream is errored 
-FAIL ReadableStream: should call underlying source methods as methods releaseLock is not implemented
+FAIL ReadableStream: should call underlying source methods as methods cancel is not implemented
 FAIL ReadableStream strategies: the default strategy should give desiredSize of 1 to start, decreasing by 1 per enqueue assert_equals: expected (number) 1 but got (undefined) undefined
 FAIL ReadableStream strategies: the default strategy should continue giving desiredSize of 1 if the chunks are read immediately assert_equals: desiredSize should start at 1 expected (number) 1 but got (undefined) undefined
 PASS ReadableStream integration test: adapting a random push source 
index 79b0034..ee7eb82 100644 (file)
@@ -12,10 +12,10 @@ PASS Constructing a ReadableStreamReader directly should be OK if the stream is
 PASS Reading from a reader for an empty stream will wait until a chunk is available 
 FAIL cancel() on a reader releases the reader before calling through cancel is not implemented
 PASS closed should be fulfilled after stream is closed (.closed access before acquiring) 
-FAIL closed should be fulfilled after reader releases its lock (multiple stream locks) releaseLock is not implemented
-FAIL Multiple readers can access the stream in sequence releaseLock is not implemented
-FAIL Cannot use an already-released reader to unlock a stream again releaseLock is not implemented
-FAIL cancel() on a released reader is a no-op and does not pass through releaseLock is not implemented
+PASS closed should be fulfilled after reader releases its lock (multiple stream locks) 
+PASS Multiple readers can access the stream in sequence 
+PASS Cannot use an already-released reader to unlock a stream again 
+FAIL cancel() on a released reader is a no-op and does not pass through cancel is not implemented
 PASS Getting a second reader after erroring the stream should succeed 
 PASS Garbage-collecting a ReadableStreamReader should not unlock its stream 
 
index 892a197..3e32794 100644 (file)
@@ -8,10 +8,10 @@ PASS read() should never settle
 PASS two read()s should both never settle 
 PASS read() should return distinct promises each time 
 PASS getReader() again on the stream should fail 
-FAIL releasing the lock with pending read requests should throw but the read requests should stay pending releaseLock is not implemented
-FAIL releasing the lock should cause further read() calls to resolve as if the stream is closed releaseLock is not implemented
-FAIL releasing the lock should cause closed to fulfill releaseLock is not implemented
-FAIL releasing the lock should cause locked to become false releaseLock is not implemented
+FAIL releasing the lock with pending read requests should throw but the read requests should stay pending Type error
+PASS releasing the lock should cause further read() calls to resolve as if the stream is closed 
+PASS releasing the lock should cause closed to fulfill 
+PASS releasing the lock should cause locked to become false 
 FAIL canceling via the reader should cause the reader to act closed cancel is not implemented
 FAIL canceling via the stream should fail cancel is not implemented
 PASS Running templatedRSClosed with ReadableStream (closed via call in start) 
@@ -54,7 +54,7 @@ PASS Running templatedRSTwoChunksClosedReader with ReadableStream (two chunks en
 PASS third read(), without waiting, should give { value: undefined, done: true } 
 PASS third read, with waiting, should give { value: undefined, done: true } 
 PASS draining the stream via read() should cause the reader closed promise to fulfill and locked to be false 
-FAIL releasing the lock after the stream is closed should do nothing releaseLock is not implemented
-FAIL releasing the lock should cause read() to act as if the stream is closed releaseLock is not implemented
-FAIL reader's closed property always returns the same promise releaseLock is not implemented
+PASS releasing the lock after the stream is closed should do nothing 
+PASS releasing the lock should cause read() to act as if the stream is closed 
+PASS reader's closed property always returns the same promise 
 
index 6bf9ad7..23b6034 100644 (file)
@@ -1,3 +1,24 @@
+2015-06-18  Youenn Fablet <youenn.fablet@crf.canon.fr> and Xabier Rodriguez Calvar  <calvaris@igalia.com>
+
+        [Streams API] Implement ReadableStreamReader.releaseLock
+        https://bugs.webkit.org/show_bug.cgi?id=145299
+
+        Reviewed by Darin Adler.
+
+        Covered by rebased tests.
+
+        * Modules/streams/ReadableStream.cpp:
+        (WebCore::ReadableStream::close): Moving some close code to newly added releaseReader.
+        (WebCore::ReadableStream::releaseReader): Implements reader release and callbacks finalization.
+        (WebCore::ReadableStream::changeStateToErrored): Calls releaseReader.
+        * Modules/streams/ReadableStream.h:
+        (WebCore::ReadableStream::hasReadPendingRequests): Added to enable reader.releaseLock throwing if read requests are pending.
+        * Modules/streams/ReadableStreamReader.cpp:
+        (WebCore::ReadableStreamReader::releaseLock): Implementation of releaseLock
+        * Modules/streams/ReadableStreamReader.h:
+        * Modules/streams/ReadableStreamReader.idl:
+        (WebCore::releaseLock): Deleted.
+
 2015-06-18  Youenn Fablet  <youenn.fablet@crf.canon.fr>
 
         GObject and ObjC bindings generator should not generate code for promise-based APIs
index 8f4f329..8b4f894 100644 (file)
@@ -79,10 +79,11 @@ void ReadableStream::changeStateToClosed()
 void ReadableStream::close()
 {
     m_state = State::Closed;
+    releaseReader();
+}
 
-    if (m_reader)
-        m_releasedReaders.append(WTF::move(m_reader));
-
+void ReadableStream::releaseReader()
+{
     if (m_closedSuccessCallback)
         m_closedSuccessCallback();
 
@@ -90,6 +91,8 @@ void ReadableStream::close()
         request.endCallback();
 
     clearCallbacks();
+    if (m_reader)
+        m_releasedReaders.append(WTF::move(m_reader));
 }
 
 void ReadableStream::changeStateToErrored()
@@ -98,9 +101,6 @@ void ReadableStream::changeStateToErrored()
         return;
     m_state = State::Errored;
 
-    if (m_reader)
-        m_releasedReaders.append(WTF::move(m_reader));
-
     JSC::JSValue error = this->error();
     if (m_closedFailureCallback)
         m_closedFailureCallback(error);
@@ -109,6 +109,8 @@ void ReadableStream::changeStateToErrored()
         request.failureCallback(error);
 
     clearCallbacks();
+    if (m_reader)
+        releaseReader();
 }
 
 void ReadableStream::start()
index 8b474eb..e52995b 100644 (file)
@@ -67,6 +67,9 @@ public:
 
     bool locked() const { return !!m_reader; }
 
+    void releaseReader();
+    bool hasReadPendingRequests() { return !m_readRequests.isEmpty(); }
+
     bool isErrored() const { return m_state == State::Errored; }
     bool isReadable() const { return m_state == State::Readable; }
     bool isCloseRequested() const { return m_closeRequested; }
index f1abf58..2b27096 100644 (file)
@@ -30,6 +30,7 @@
 #include "config.h"
 #include "ReadableStreamReader.h"
 
+#include "ExceptionCode.h"
 #include <runtime/JSCJSValueInlines.h>
 
 #if ENABLE(STREAMS_API)
@@ -54,6 +55,17 @@ void ReadableStreamReader::read(ReadableStream::ReadSuccessCallback&& successCal
     m_stream.read(WTF::move(successCallback), WTF::move(endCallback), WTF::move(failureCallback));
 }
 
+void ReadableStreamReader::releaseLock(ExceptionCode& ec)
+{
+    if (m_stream.reader() != this)
+        return;
+    if (m_stream.hasReadPendingRequests()) {
+        ec = TypeError;
+        return;
+    }
+    m_stream.releaseReader();
+}
+
 }
 
 #endif
index ed20b73..0710c8f 100644 (file)
@@ -41,6 +41,8 @@
 
 namespace WebCore {
 
+typedef int ExceptionCode;
+
 // ReadableStreamReader implements access to ReadableStream from JavaScript.
 // It basically allows access to the ReadableStream iff the ReadableStreamReader instance is the active reader
 // of the ReadableStream.
@@ -53,6 +55,7 @@ public:
 
     void closed(ReadableStream::ClosedSuccessCallback&&, ReadableStream::FailureCallback&&);
     void read(ReadableStream::ReadSuccessCallback&&, ReadableStream::ReadEndCallback&&, ReadableStream::FailureCallback&&);
+    void releaseLock(ExceptionCode&);
 
     void ref() { m_stream.ref(); }
     void deref() { m_stream.deref(); }
index c72c602..7c90390 100644 (file)
@@ -36,7 +36,7 @@
     // FIXME: Remove RaisesException once methods are implemented.
     [Custom, RaisesException] Object read();
     [Custom, RaisesException] Promise cancel(DOMString reason);
-    [Custom, RaisesException] void releaseLock();
+    [RaisesException] void releaseLock();
 
     [CustomGetter] readonly attribute Promise closed;
 };
index 8d44fc5..4fed7e8 100644 (file)
@@ -92,12 +92,6 @@ JSValue JSReadableStreamReader::cancel(ExecState* exec)
     return exec->vm().throwException(exec, error);
 }
 
-JSValue JSReadableStreamReader::releaseLock(ExecState* exec)
-{
-    JSValue error = createError(exec, ASCIILiteral("releaseLock is not implemented"));
-    return exec->vm().throwException(exec, error);
-}
-
 EncodedJSValue JSC_HOST_CALL constructJSReadableStreamReader(ExecState* exec)
 {
     if (!exec->argumentCount())