[Streams API] Activate assertions
authoryouenn.fablet@crf.canon.fr <youenn.fablet@crf.canon.fr@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 9 Nov 2015 18:06:51 +0000 (18:06 +0000)
committeryouenn.fablet@crf.canon.fr <youenn.fablet@crf.canon.fr@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 9 Nov 2015 18:06:51 +0000 (18:06 +0000)
https://bugs.webkit.org/show_bug.cgi?id=151021

Reviewed by Darin Adler.

Activating assertions in streams API.
Fixing a bug in ReadableStream implementation: when pull promise is rejected,
the readable stream may already be errored by some other means.

Covered by existing test sets in Debug builds.

* Modules/streams/ReadableStreamInternals.js:
(teeReadableStream):
(teeReadableStreamPullFunction):
(errorReadableStream):
(requestReadableStreamPull):
(finishClosingReadableStream):
(closeReadableStream):
(enqueueInReadableStream):
(readFromReadableStreamReader):
* Modules/streams/ReadableStreamReader.js:
(cancel):
* Modules/streams/StreamInternals.js:
(peekQueueValue):
* Modules/streams/WritableStream.js:
(write):
(state):
* Modules/streams/WritableStreamInternals.js:
(syncWritableStreamStateWithQueue):
(closeWritableStream): Deleted.

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

Source/WebCore/ChangeLog
Source/WebCore/Modules/streams/ReadableStreamInternals.js
Source/WebCore/Modules/streams/ReadableStreamReader.js
Source/WebCore/Modules/streams/StreamInternals.js
Source/WebCore/Modules/streams/WritableStream.js
Source/WebCore/Modules/streams/WritableStreamInternals.js

index face0b6..770810c 100644 (file)
@@ -1,3 +1,36 @@
+2015-11-09  Youenn Fablet  <youenn.fablet@crf.canon.fr>
+
+        [Streams API] Activate assertions
+        https://bugs.webkit.org/show_bug.cgi?id=151021
+
+        Reviewed by Darin Adler.
+
+        Activating assertions in streams API.
+        Fixing a bug in ReadableStream implementation: when pull promise is rejected,
+        the readable stream may already be errored by some other means.
+
+        Covered by existing test sets in Debug builds.
+
+        * Modules/streams/ReadableStreamInternals.js:
+        (teeReadableStream):
+        (teeReadableStreamPullFunction):
+        (errorReadableStream):
+        (requestReadableStreamPull):
+        (finishClosingReadableStream):
+        (closeReadableStream):
+        (enqueueInReadableStream):
+        (readFromReadableStreamReader):
+        * Modules/streams/ReadableStreamReader.js:
+        (cancel):
+        * Modules/streams/StreamInternals.js:
+        (peekQueueValue):
+        * Modules/streams/WritableStream.js:
+        (write):
+        (state):
+        * Modules/streams/WritableStreamInternals.js:
+        (syncWritableStreamStateWithQueue):
+        (closeWritableStream): Deleted.
+
 2015-11-09  Xabier Rodriguez Calvar  <calvaris@igalia.com>
 
         [Streams API] Shield implementation from mangling then and catch promise methods
index 55d17fe..77783a6 100644 (file)
@@ -76,8 +76,8 @@ function teeReadableStream(stream, shouldClone)
 {
     "use strict";
 
-    // TODO: Assert: IsReadableStream(stream) is true.
-    // TODO: Assert: Type(shouldClone) is Boolean.
+    @assert(@isReadableStream(stream));
+    @assert(typeof(shouldClone) === "boolean");
 
     let reader = stream.getReader();
 
@@ -133,11 +133,11 @@ function teeReadableStreamPullFunction(teeState, reader, shouldClone)
             if (teeState.closedOrErrored)
                 return;
             if (!teeState.canceled1) {
-                // TODO: Implement cloning if shouldClone is true
+                // FIXME: Implement cloning if shouldClone is true
                 @enqueueInReadableStream(teeState.branch1, result.value);
             }
             if (!teeState.canceled2) {
-                // TODO: Implement cloning if shouldClone is true
+                // FIXME: Implement cloning if shouldClone is true
                 @enqueueInReadableStream(teeState.branch2, result.value);
             }
         });
@@ -195,7 +195,7 @@ function errorReadableStream(stream, error)
 {
     "use strict";
 
-    // FIXME: ASSERT(stream.@state === @streamReadable);
+    @assert(stream.@state === @streamReadable);
     stream.@queue = @newQueue();
     stream.@storedError = error;
     stream.@state = @streamErrored;
@@ -244,7 +244,8 @@ function requestReadableStreamPull(stream)
             @requestReadableStreamPull(stream);
         }
     }, function(error) {
-        @errorReadableStream(stream, error);
+        if (stream.@state === @streamReadable)
+            @errorReadableStream(stream, error);
     });
 }
 
@@ -287,7 +288,7 @@ function finishClosingReadableStream(stream)
 {
     "use strict";
 
-    // FIXME: ASSERT(stream.@state ===  @streamReadable);
+    @assert(stream.@state ===  @streamReadable);
     stream.@state = @streamClosed;
     var reader = stream.@reader;
     if (reader)
@@ -298,8 +299,8 @@ function closeReadableStream(stream)
 {
     "use strict";
 
-    // FIXME: ASSERT(!stream.@closeRequested);
-    // FIXME: ASSERT(stream.@state !== @streamErrored);
+    @assert(!stream.@closeRequested);
+    @assert(stream.@state !== @streamErrored);
     if (stream.@state === @streamClosed)
         return; 
     stream.@closeRequested = true;
@@ -324,8 +325,8 @@ function enqueueInReadableStream(stream, chunk)
 {
     "use strict";
 
-    // FIXME: ASSERT(!stream.@closeRequested);
-    // FIXME: ASSERT(stream.@state !== @streamErrored);
+    @assert(!stream.@closeRequested);
+    @assert(stream.@state !== @streamErrored);
     if (stream.@state === @streamClosed)
         return undefined;
     if (@isReadableStreamLocked(stream) && stream.@reader.@readRequests.length) {
@@ -357,8 +358,8 @@ function readFromReadableStreamReader(reader)
         return @Promise.@resolve({value: undefined, done: true});
     if (reader.@state === @streamErrored)
         return @Promise.@reject(reader.@storedError);
-    // FIXME: ASSERT(!!reader.@ownerReadableStream);
-    // FIXME: ASSERT(reader.@ownerReadableStream.@state === @streamReadable);
+    @assert(!!reader.@ownerReadableStream);
+    @assert(reader.@ownerReadableStream.@state === @streamReadable);
     var stream = reader.@ownerReadableStream;
     if (stream.@queue.content.length) {
         var chunk = @dequeueValue(stream.@queue);
index 95d32a3..71e10e6 100644 (file)
@@ -38,8 +38,8 @@ function cancel(reason)
     if (this.@state === @streamErrored)
         return @Promise.@reject(this.@storedError);
 
-    // FIXME: ASSERT(@isReadableStream(this.@ownerReadableStream));
-    // FIXME: ASSERT(this.@ownerReadableStream.@state === @streamReadable);
+    @assert(@isReadableStream(this.@ownerReadableStream));
+    @assert(this.@ownerReadableStream.@state === @streamReadable);
     return @cancelReadableStream(this.@ownerReadableStream, reason);
 }
 
index 630408f..cbc1b21 100644 (file)
@@ -117,8 +117,7 @@ function enqueueValueWithSize(queue, value, size)
 
 function peekQueueValue(queue)
 {
-    // FIXME
-    // assert(queue.content.length > 0);
+    @assert(queue.content.length > 0);
 
     return queue.content[0].value;
 }
index e5e400f..eac956c 100644 (file)
@@ -121,8 +121,7 @@ function write(chunk)
     if (this.@state === @streamErrored)
         return @Promise.@reject(this.@storedError);
 
-    // FIXME
-    // assert(this.@state === @streamWritable || this.@state === @streamWaiting);
+    @assert(this.@state === @streamWritable || this.@state === @streamWaiting);
 
     let chunkSize = 1;
     if (this.@strategy.size !== undefined) {
@@ -188,8 +187,5 @@ function state()
         return "writable";
     }
 
-    // FIXME
-    // assert_not_reached();
-
-    return undefined;
+    @assert(false);
 }
index 9858de6..9cd34a5 100644 (file)
@@ -41,8 +41,7 @@ function syncWritableStreamStateWithQueue(stream)
     if (stream.@state === @streamClosing)
         return;
 
-    // FIXME
-    // assert(stream.@state === @streamWritable || stream.@state === @streamWaiting);
+    @assert(stream.@state === @streamWritable || stream.@state === @streamWaiting);
 
     const shouldApplyBackpressure = stream.@queue.size > stream.@strategy.highWaterMark;
     if (shouldApplyBackpressure && stream.@state === @streamWritable) {
@@ -91,11 +90,9 @@ function writableStreamAdvanceQueue(stream)
 
     const writeRecord = @peekQueueValue(stream.@queue);
     if (writeRecord === "close") {
-        // FIXME
-        // assert(stream.@state === @streamClosing);
+        @assert(stream.@state === @streamClosing);
         @dequeueValue(stream.@queue);
-        // FIXME
-        // assert(stream.@queue.content.length === 0);
+        @assert(stream.@queue.content.length === 0);
         @closeWritableStream(stream);
         return undefined;
     }
@@ -121,14 +118,12 @@ function writableStreamAdvanceQueue(stream)
 
 function closeWritableStream(stream)
 {
-    // FIXME
-    // assert(stream.@state === @streamClosing);
+    @assert(stream.@state === @streamClosing);
     @promiseInvokeOrNoop(stream.@underlyingSink, "close").@then(
         function() {
             if (stream.@state === @streamErrored)
                 return;
-            // FIXME
-            // assert(stream.@state === @streamClosing);
+            @assert(stream.@state === @streamClosing);
             stream.@closedPromiseCapability.@resolve.@call(undefined, undefined);
             stream.@state = @streamClosed;
         },