Title: [211484] trunk
Revision
211484
Author
commit-qu...@webkit.org
Date
2017-02-01 08:17:52 -0800 (Wed, 01 Feb 2017)

Log Message

[Readable Streams API] Implement ReadableByteStreamController pull()
https://bugs.webkit.org/show_bug.cgi?id=167593

Patch by Romain Bellessort <romain.belless...@crf.canon.fr> on 2017-02-01
Reviewed by Youenn Fablet.

Source/WebCore:

Implemented pull() method for ReadableByteStreamController. Also updated
pendingPullIntos attribute, which was a more complex object than necessary
(an array is enough).

Added 2 tests that allow covering most of new code. Code not yet tested will
become reachable as the rest of the spec is implemented (new tests will then
be added).

* Modules/streams/ReadableByteStreamInternals.js:
(privateInitializeReadableByteStreamController): Updated pendingPullIntos.
(readableByteStreamControllerCancel): Updated pendingPullIntos.
(readableByteStreamControllerClose): Updated pendingPullIntos.
(readableByteStreamControllerHandleQueueDrain): Added.
(readableByteStreamControllerPull): Added.

LayoutTests:

Added 2 tests that allow covering most of new code. Code not yet tested will
become reachable as the rest of the spec is implemented (new tests will then
be added).

* streams/readable-byte-stream-controller-expected.txt:
* streams/readable-byte-stream-controller.js:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (211483 => 211484)


--- trunk/LayoutTests/ChangeLog	2017-02-01 15:28:08 UTC (rev 211483)
+++ trunk/LayoutTests/ChangeLog	2017-02-01 16:17:52 UTC (rev 211484)
@@ -1,3 +1,17 @@
+2017-02-01  Romain Bellessort  <romain.belless...@crf.canon.fr>
+
+        [Readable Streams API] Implement ReadableByteStreamController pull()
+        https://bugs.webkit.org/show_bug.cgi?id=167593
+
+        Reviewed by Youenn Fablet.
+
+        Added 2 tests that allow covering most of new code. Code not yet tested will
+        become reachable as the rest of the spec is implemented (new tests will then
+        be added).
+
+        * streams/readable-byte-stream-controller-expected.txt:
+        * streams/readable-byte-stream-controller.js:
+
 2017-02-01  Yusuke Suzuki  <utatane....@gmail.com>
 
         Propagate networking errors correctly for import() operator

Modified: trunk/LayoutTests/streams/readable-byte-stream-controller-expected.txt (211483 => 211484)


--- trunk/LayoutTests/streams/readable-byte-stream-controller-expected.txt	2017-02-01 15:28:08 UTC (rev 211483)
+++ trunk/LayoutTests/streams/readable-byte-stream-controller-expected.txt	2017-02-01 16:17:52 UTC (rev 211484)
@@ -9,6 +9,8 @@
 PASS Calling close() after calling error() should throw a TypeError 
 PASS Calling read() on a reader associated to a controller that has been errored should fail with provided error 
 PASS Calling read() on a reader associated to a controller that has been closed should not be rejected 
+PASS Pending reading promise should be rejected if controller is errored (case where autoAllocateChunkSize is undefined) 
+FAIL Pending reading promise should be rejected if controller is errored (case where autoAllocateChunkSize is specified) Can't find private variable: @Uint8Array
 FAIL Calling read() after a chunk has been enqueued should result in obtaining said chunk ReadableByteStreamController enqueue() is not implemented
 PASS By default initial value of desiredSize should be 1 
 PASS Calling cancel() on a readable ReadableStream that is not locked to a reader should return a promise whose fulfillment handler returns undefined 
@@ -25,6 +27,8 @@
 PASS Calling close() after calling error() should throw a TypeError 
 PASS Calling read() on a reader associated to a controller that has been errored should fail with provided error 
 PASS Calling read() on a reader associated to a controller that has been closed should not be rejected 
+PASS Pending reading promise should be rejected if controller is errored (case where autoAllocateChunkSize is undefined) 
+FAIL Pending reading promise should be rejected if controller is errored (case where autoAllocateChunkSize is specified) Can't find private variable: @Uint8Array
 FAIL Calling read() after a chunk has been enqueued should result in obtaining said chunk ReadableByteStreamController enqueue() is not implemented
 PASS By default initial value of desiredSize should be 1 
 PASS Calling cancel() on a readable ReadableStream that is not locked to a reader should return a promise whose fulfillment handler returns undefined 

Modified: trunk/LayoutTests/streams/readable-byte-stream-controller.js (211483 => 211484)


--- trunk/LayoutTests/streams/readable-byte-stream-controller.js	2017-02-01 15:28:08 UTC (rev 211483)
+++ trunk/LayoutTests/streams/readable-byte-stream-controller.js	2017-02-01 16:17:52 UTC (rev 211484)
@@ -179,6 +179,41 @@
     );
 }, "Calling read() on a reader associated to a controller that has been closed should not be rejected");
 
+promise_test(function(test) {
+    let controller;
+
+    const rs = new ReadableStream({
+        start: function(c) {
+            controller = c;
+        },
+        type: "bytes"
+    });
+
+    const myError = new Error("My error");
+    let readingPromise = rs.getReader().read();
+    controller.error(myError);
+
+    return promise_rejects(test, myError, readingPromise);
+}, "Pending reading promise should be rejected if controller is errored (case where autoAllocateChunkSize is undefined)");
+
+promise_test(function(test) {
+    let controller;
+
+    const rs = new ReadableStream({
+        autoAllocateChunkSize: 128,
+        start: function(c) {
+            controller = c;
+        },
+        type: "bytes"
+    });
+
+    const myError = new Error("My error");
+    let readingPromise = rs.getReader().read();
+    controller.error(myError);
+
+    return promise_rejects(test, myError, readingPromise);
+}, "Pending reading promise should be rejected if controller is errored (case where autoAllocateChunkSize is specified)");
+
 promise_test(function() {
     let controller;
 

Modified: trunk/Source/WebCore/ChangeLog (211483 => 211484)


--- trunk/Source/WebCore/ChangeLog	2017-02-01 15:28:08 UTC (rev 211483)
+++ trunk/Source/WebCore/ChangeLog	2017-02-01 16:17:52 UTC (rev 211484)
@@ -1,3 +1,25 @@
+2017-02-01  Romain Bellessort  <romain.belless...@crf.canon.fr>
+
+        [Readable Streams API] Implement ReadableByteStreamController pull()
+        https://bugs.webkit.org/show_bug.cgi?id=167593
+
+        Reviewed by Youenn Fablet.
+
+        Implemented pull() method for ReadableByteStreamController. Also updated
+        pendingPullIntos attribute, which was a more complex object than necessary
+        (an array is enough).
+
+        Added 2 tests that allow covering most of new code. Code not yet tested will
+        become reachable as the rest of the spec is implemented (new tests will then
+        be added).
+
+        * Modules/streams/ReadableByteStreamInternals.js:
+        (privateInitializeReadableByteStreamController): Updated pendingPullIntos.
+        (readableByteStreamControllerCancel): Updated pendingPullIntos.
+        (readableByteStreamControllerClose): Updated pendingPullIntos.
+        (readableByteStreamControllerHandleQueueDrain): Added.
+        (readableByteStreamControllerPull): Added.
+
 2017-02-01  Enrique Ocaña González  <eoca...@igalia.com>
 
         [GStreamer][MSE] qtdemux: Update the tfdt patch to the version finally accepted upstream

Modified: trunk/Source/WebCore/Modules/streams/ReadableByteStreamInternals.js (211483 => 211484)


--- trunk/Source/WebCore/Modules/streams/ReadableByteStreamInternals.js	2017-02-01 15:28:08 UTC (rev 211483)
+++ trunk/Source/WebCore/Modules/streams/ReadableByteStreamInternals.js	2017-02-01 16:17:52 UTC (rev 211484)
@@ -59,7 +59,7 @@
             @throwRangeError("autoAllocateChunkSize value is negative or equal to positive or negative infinity");
     }
     this.@autoAllocateChunkSize = autoAllocateChunkSize;
-    this.@pendingPullIntos = @newQueue();
+    this.@pendingPullIntos = [];
 
     const controller = this;
     const startResult = @promiseInvokeOrNoopNoCatch(underlyingByteSource, "start", [this]).@then(() => {
@@ -73,7 +73,7 @@
     });
 
     this.@cancel = @readableByteStreamControllerCancel;
-    // FIXME: Implement pull.
+    this.@pull = @readableByteStreamControllerPull;
 
     return this;
 }
@@ -101,7 +101,7 @@
 {
     "use strict";
 
-    if (controller.@pendingPullIntos.content.length > 0)
+    if (controller.@pendingPullIntos.length > 0)
         controller.@pendingPullIntos[0].bytesFilled = 0;
     controller.@queue = @newQueue();
     controller.@totalQueuedBytes = 0;
@@ -130,7 +130,7 @@
         return;
     }
 
-    if (controller.@pendingPullIntos.content.length > 0) {
+    if (controller.@pendingPullIntos.length > 0) {
         if (controller.@pendingPullIntos[0].bytesFilled > 0) {
             const e = new @TypeError("Close requested while there remain pending bytes");
             @readableByteStreamControllerError(controller, e);
@@ -169,6 +169,62 @@
     return stream.@reader !== @undefined && @isReadableStreamDefaultReader(stream.@reader);
 }
 
+function readableByteStreamControllerHandleQueueDrain(controller) {
+
+    "use strict";
+
+    @assert(controller.@controlledReadableStream.@state === @streamReadable);
+    if (!controller.@totalQueuedBytes && controller.@closeRequested)
+        @readableStreamClose(controller.@controlledReadableStream);
+    else
+        @readableByteStreamControllerCallPullIfNeeded(controller);
+}
+
+function readableByteStreamControllerPull(controller)
+{
+    "use strict";
+
+    const stream = controller.@controlledReadableStream;
+    @assert(@readableStreamHasDefaultReader(stream));
+
+    if (controller.@totalQueuedBytes > 0) {
+        @assert(stream.@reader.@readRequests.length === 0);
+        const entry = @dequeueValue(controller.@queue);
+        controller.@totalQueuedBytes -= entry.byteLength;
+        @readableByteStreamControllerHandleQueueDrain(controller);
+        let view;
+        try {
+            view = new @Uint8Array(entry.buffer, entry.byteOffset, entry.byteLength);
+        } catch (error) {
+            return @Promise.@reject(error);
+        }
+        return @Promise.@resolve({value: view, done: false});
+    }
+
+    if (controller.@autoAllocateChunkSize !== @undefined) {
+        let buffer;
+        try {
+            buffer = new @ArrayBuffer(controller.@autoAllocateChunkSize);
+        } catch (error) {
+            return @Promise.@reject(error);
+        }
+        const pullIntoDescriptor = {
+            buffer,
+            byteOffset: 0,
+            byteLength: controller.@autoAllocateChunkSize,
+            bytesFilled: 0,
+            elementSize: 1,
+            ctor: @Uint8Array,
+            readerType: 'default'
+        };
+        controller.@pendingPullIntos.@push(pullIntoDescriptor);
+    }
+
+    const promise = @readableStreamAddReadRequest(stream);
+    @readableByteStreamControllerCallPullIfNeeded(controller);
+    return promise;
+}
+
 function readableByteStreamControllerShouldCallPull(controller)
 {
     "use strict";
@@ -181,9 +237,9 @@
         return false;
     if (!controller.@started)
         return false;
-    if (@readableStreamHasDefaultReader(stream) && stream.@reader.@readRequests > 0)
+    if (@readableStreamHasDefaultReader(stream) && stream.@reader.@readRequests.length > 0)
         return true;
-    if (@readableStreamHasBYOBReader(stream) && stream.@reader.@readIntoRequests > 0)
+    if (@readableStreamHasBYOBReader(stream) && stream.@reader.@readIntoRequests.length > 0)
         return true;
     if (@readableByteStreamControllerGetDesiredSize(controller) > 0)
         return true;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to