[Streams API] Update implementation with the latest spec
authorcalvaris@igalia.com <calvaris@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 18 Aug 2015 08:25:22 +0000 (08:25 +0000)
committercalvaris@igalia.com <calvaris@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 18 Aug 2015 08:25:22 +0000 (08:25 +0000)
https://bugs.webkit.org/show_bug.cgi?id=147978

Reviewed by Darin Adler.

Source/WebCore:

Changed the way the read and closed promises are resolved and the stream is released when an even closes or
errors the stream.

Current tests suffice after changing the order of the promise resolution according to the new spec.

* Modules/streams/ReadableStream.cpp:
(WebCore::ReadableStream::releaseReader): Changed how the promises are resolved.
(WebCore::ReadableStream::changeStateToErrored): Changed how the promises are resolved and manually releasing
the stream instead of calling releaseReader according to the spec.

LayoutTests:

Changed tests about the order of the read and closed promise resolution.

* streams/readable-stream-reader-read.html:
* streams/reference-implementation/readable-stream-tee.html:
* streams/reference-implementation/readable-stream-templated.html:
* streams/reference-implementation/readable-stream.html:

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

LayoutTests/ChangeLog
LayoutTests/streams/readable-stream-reader-read.html
LayoutTests/streams/reference-implementation/readable-stream-tee.html
LayoutTests/streams/reference-implementation/readable-stream-templated.html
LayoutTests/streams/reference-implementation/readable-stream.html
Source/WebCore/ChangeLog
Source/WebCore/Modules/streams/ReadableStream.cpp

index 3a2ecc9..47750f6 100644 (file)
@@ -1,3 +1,17 @@
+2015-08-18  Xabier Rodriguez Calvar  <calvaris@igalia.com>
+
+        [Streams API] Update implementation with the latest spec
+        https://bugs.webkit.org/show_bug.cgi?id=147978
+
+        Reviewed by Darin Adler.
+
+        Changed tests about the order of the read and closed promise resolution.
+
+        * streams/readable-stream-reader-read.html:
+        * streams/reference-implementation/readable-stream-tee.html:
+        * streams/reference-implementation/readable-stream-templated.html:
+        * streams/reference-implementation/readable-stream.html:
+
 2015-08-17  Commit Queue  <commit-queue@webkit.org>
 
         Unreviewed, rolling out r188539, r188544, r188552, and
index dfd6488..67a6e9d 100644 (file)
@@ -15,18 +15,15 @@ test1.step(function() {
 
     reader.read().then(test1.step_func(function(result) {
         assert_object_equals(result, { value: undefined, done: true }, 'read() should fulfill with close');
-        assert_equals(counter, 1);
-        counter++;
+        assert_equals(++counter, 1);
     }));
     reader.read().then(test1.step_func(function(result) {
         assert_object_equals(result, { value: undefined, done: true }, 'read() should fulfill with close');
-        assert_equals(counter, 2);
-        counter++;
-        test1.done();
+        assert_equals(++counter, 2);
     }));
     reader.closed.then(test1.step_func(function() {
-        assert_equals(counter, 0);
-        counter++;
+        assert_equals(++counter, 3);
+        test1.done();
     }));
 
     controller.close();
@@ -118,23 +115,20 @@ test4.step(function() {
         assert_unreached('read() should reject on an errored stream');
     }), test4.step_func(function(err) {
         assert_equals(myError, err);
-        assert_equals(counter, 1);
-        counter++;
+        assert_equals(++counter, 1);
     }));
     reader.read().then(test4.step_func(function() {
         assert_unreached('read() should reject on an errored stream');
     }), test4.step_func(function(err) {
         assert_equals(myError, err);
-        assert_equals(counter, 2);
-        counter++;
-        test4.done();
+        assert_equals(++counter, 2);
     }));
     reader.closed.then(test4.step_func(function() {
         assert_unreached('read() should reject on an errored stream');
     }), test4.step_func(function(err) {
         assert_equals(myError, err);
-        assert_equals(counter, 0);
-        counter++;
+        assert_equals(++counter, 3);
+        test4.done();
     }));
 
     var myError = { potato: 'mashed' };
index 14cb0ad..b8f549e 100644 (file)
@@ -16,7 +16,6 @@ test(function() {
 
 var test1 = async_test('ReadableStream teeing: should be able to read one branch to the end without affecting the other');
 test1.step(function() {
-    var closedCalled = false;
     var readCalls = 0;
     const rs = new ReadableStream({
         start: function(c) {
@@ -33,7 +32,8 @@ test1.step(function() {
     var reader2 = branch2.getReader();
 
     reader1.closed.then(test1.step_func(function() {
-        closedCalled = true;
+        assert_equals(readCalls, 4);
+        test1.done();
     })).catch(test1.step_func(function(e) { assert_unreached(e); }));
     reader2.closed.then(test1.step_func(function() { assert_unreached('branch2 should not be closed'); }));
 
@@ -47,9 +47,7 @@ test1.step(function() {
     }));
     reader1.read().then(test1.step_func(function(r) {
         assert_object_equals(r, { value: undefined, done: true }, 'third read() from branch1 should be done');
-        assert_true(closedCalled);
-        assert_equals(++readCalls, 4);
-        test1.done();
+        ++readCalls;
     }));
 
     reader2.read().then(test1.step_func(function(r) {
index 38b7530..da38e47 100644 (file)
@@ -81,12 +81,13 @@ function templatedRSErrored(label, factory, error) {
 
         reader.closed.catch(test1.step_func(function(e) {
             assert_equals(e, error, 'reader.closed should reject with the error');
-            ++promisesCount;
+            if (++promisesCount === 2)
+                test1.done();
         }));
         reader.read().catch(test1.step_func(function(e) {
             assert_equals(e, error, 'reader.read() should reject with the error');
-            assert_equals(++promisesCount, 2);
-            test1.done();
+            if (++promisesCount === 2)
+                test1.done();
         }));
     });
 
index 2ad02a4..f71b32c 100644 (file)
@@ -240,15 +240,15 @@ test5.step(function() {
 
     reader.closed.catch(test5.step_func(function(e) {
         closed = true;
-        assert_false(read);
+        assert_true(read);
         assert_equals(e, error, 'closed should reject with the thrown error');
+        test5.done();
     }));
 
     reader.read().catch(test5.step_func(function(e) {
         read = true;
-        assert_true(closed);
+        assert_false(closed);
         assert_equals(e, error, 'read() should reject with the thrown error');
-        test5.done();
     }));
 });
 
index 2c5a9fe..59a8dce 100644 (file)
@@ -1,3 +1,20 @@
+2015-08-18  Xabier Rodriguez Calvar  <calvaris@igalia.com>
+
+        [Streams API] Update implementation with the latest spec
+        https://bugs.webkit.org/show_bug.cgi?id=147978
+
+        Reviewed by Darin Adler.
+
+        Changed the way the read and closed promises are resolved and the stream is released when an even closes or
+        errors the stream.
+
+        Current tests suffice after changing the order of the promise resolution according to the new spec.
+
+        * Modules/streams/ReadableStream.cpp:
+        (WebCore::ReadableStream::releaseReader): Changed how the promises are resolved.
+        (WebCore::ReadableStream::changeStateToErrored): Changed how the promises are resolved and manually releasing
+        the stream instead of calling releaseReader according to the spec.
+
 2015-08-17  Zalan Bujtas  <zalan@apple.com>
 
         Outline with auto style leaves bits behind when the the box is moved.
index 69af5a1..40edeba 100644 (file)
@@ -90,15 +90,14 @@ void ReadableStream::close()
 
 void ReadableStream::releaseReader()
 {
-    if (m_closedPromise)
-        m_closedPromise.value().resolve(nullptr);
-
     for (auto& request : m_readRequests)
         request.resolveEnd();
-
-    clearCallbacks();
     if (m_reader)
         m_releasedReaders.append(WTF::move(m_reader));
+
+    if (m_closedPromise)
+        m_closedPromise.value().resolve(nullptr);
+    clearCallbacks();
 }
 
 void ReadableStream::changeStateToErrored()
@@ -107,18 +106,20 @@ void ReadableStream::changeStateToErrored()
         return;
 
     clearValues();
+
     m_state = State::Errored;
 
-    JSC::JSValue error = this->error();
-    if (m_closedPromise)
-        m_closedPromise.value().reject(error);
+    if (!m_reader)
+        return;
 
+    JSC::JSValue error = this->error();
     for (auto& request : m_readRequests)
         request.reject(error);
+    m_releasedReaders.append(WTF::move(m_reader));
 
+    if (m_closedPromise)
+        m_closedPromise.value().reject(error);
     clearCallbacks();
-    if (m_reader)
-        releaseReader();
 }
 
 void ReadableStream::start()