Title: [218701] trunk
Revision
218701
Author
[email protected]
Date
2017-06-22 09:17:20 -0700 (Thu, 22 Jun 2017)

Log Message

[Readable Streams API] Implement ReadableStreamBYOBReader read()
https://bugs.webkit.org/show_bug.cgi?id=172714

Patch by Romain Bellessort <[email protected]> on 2017-06-22
Reviewed by Youenn Fablet.

LayoutTests/imported/w3c:

Updated expectations.
Some tests are not passing yet due to 2 bugs not directly related to read() implementation
(172716 and 172717) that will be fixed distinctly.

* web-platform-tests/streams/readable-byte-streams/general-expected.txt:
* web-platform-tests/streams/readable-byte-streams/general.dedicatedworker-expected.txt:

Source/WebCore:

Implemented read() method of ReadableStreamBYOBReader [1]. Also added code related
to BYOB features that were previously described as FIXMEs and that now become reachable.

In addition, WPT tests that involve read() have allowed to identify 2 bugs not directly
related to read() (172716 and 172717). They will be fixed distinctly. Once done, all WPT
tests should pass.

[1] https://streams.spec.whatwg.org/#byob-reader-read

WPT tests (web-platform-tests/streams/readable-byte-streams/general.js) already cover
most cases for read() usage. Corresponding expectations have been updated. In addition,
1 test has been added to WebKit tests (in streams/readable-stream-byob-reader.js) to
check that read() can only be applied to a ReadableStreamBYOBReader.

* Modules/streams/ReadableByteStreamInternals.js:
(readableByteStreamControllerClearPendingPullIntos): Implemented.
(readableByteStreamControllerEnqueue): Updated with support for BYOBReader.
(readableByteStreamControllerPullInto): Added.
(readableStreamAddReadIntoRequest): Added.
* Modules/streams/ReadableStreamBYOBReader.js:
(read): Added.

LayoutTests:

Added 1 test to check that read() can only be applied to a ReadableStreamBYOBReader.
Other behaviors are checked by WPT (web-platform-tests/streams/readable-byte-streams/general.js).

* streams/readable-stream-byob-reader-expected.txt: Updated.
* streams/readable-stream-byob-reader.js: Added 1 test.

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (218700 => 218701)


--- trunk/LayoutTests/ChangeLog	2017-06-22 15:32:51 UTC (rev 218700)
+++ trunk/LayoutTests/ChangeLog	2017-06-22 16:17:20 UTC (rev 218701)
@@ -1,3 +1,17 @@
+2017-06-22  Romain Bellessort  <[email protected]>
+
+        [Readable Streams API] Implement ReadableStreamBYOBReader read()
+        https://bugs.webkit.org/show_bug.cgi?id=172714
+
+        Reviewed by Youenn Fablet.
+
+        Added 1 test to check that read() can only be applied to a ReadableStreamBYOBReader.
+        Other behaviors are checked by WPT (web-platform-tests/streams/readable-byte-streams/general.js).
+
+        * streams/readable-stream-byob-reader-expected.txt: Updated.
+        * streams/readable-stream-byob-reader.js: Added 1 test.
+
+
 2017-06-22  Youenn Fablet  <[email protected]>
 
         [WebRTC] Prevent capturing at unconventional resolutions when using the SW encoder on Mac

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (218700 => 218701)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2017-06-22 15:32:51 UTC (rev 218700)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2017-06-22 16:17:20 UTC (rev 218701)
@@ -1,3 +1,17 @@
+2017-06-22  Romain Bellessort  <[email protected]>
+
+        [Readable Streams API] Implement ReadableStreamBYOBReader read()
+        https://bugs.webkit.org/show_bug.cgi?id=172714
+
+        Reviewed by Youenn Fablet.
+
+        Updated expectations. 
+        Some tests are not passing yet due to 2 bugs not directly related to read() implementation
+        (172716 and 172717) that will be fixed distinctly. 
+
+        * web-platform-tests/streams/readable-byte-streams/general-expected.txt:
+        * web-platform-tests/streams/readable-byte-streams/general.dedicatedworker-expected.txt:
+
 2017-06-22  Frederic Wang  <[email protected]>
 
         Remove testRunner.overridePreference from WPT tests

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/streams/readable-byte-streams/general-expected.txt (218700 => 218701)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/streams/readable-byte-streams/general-expected.txt	2017-06-22 15:32:51 UTC (rev 218700)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/streams/readable-byte-streams/general-expected.txt	2017-06-22 16:17:20 UTC (rev 218701)
@@ -17,55 +17,55 @@
 PASS ReadableStream with byte source: Automatic pull() after start() 
 PASS ReadableStream with byte source: Automatic pull() after start() and read() 
 PASS ReadableStream with byte source: autoAllocateChunkSize 
-FAIL ReadableStream with byte source: Mix of auto allocate and BYOB promise_test: Unhandled rejection with value: object "TypeError: ReadableStreamBYOBReader read() is not implemented"
+PASS ReadableStream with byte source: Mix of auto allocate and BYOB 
 PASS ReadableStream with byte source: Automatic pull() after start() and read(view) 
 PASS ReadableStream with byte source: enqueue(), getReader(), then read() 
 PASS ReadableStream with byte source: Push source that doesn't understand pull signal 
 PASS ReadableStream with byte source: read(), but pull() function is not callable 
-FAIL ReadableStream with byte source: read(view), but pull() function is not callable ReadableStreamBYOBReader read() is not implemented
+PASS ReadableStream with byte source: read(view), but pull() function is not callable 
 PASS ReadableStream with byte source: enqueue() with Uint16Array, getReader(), then read() 
-FAIL ReadableStream with byte source: enqueue(), read(view) partially, then read() ReadableStreamBYOBReader read() is not implemented
+FAIL ReadableStream with byte source: enqueue(), read(view) partially, then read() assert_equals: expected 1 but got 0
 PASS ReadableStream with byte source: getReader(), enqueue(), close(), then read() 
 PASS ReadableStream with byte source: enqueue(), close(), getReader(), then read() 
 PASS ReadableStream with byte source: Respond to pull() by enqueue() 
 PASS ReadableStream with byte source: Respond to pull() by enqueue() asynchronously 
-FAIL ReadableStream with byte source: read(view), then respond() ReadableStreamBYOBReader read() is not implemented
-FAIL ReadableStream with byte source: read(view), then respond() with a transferred ArrayBuffer ReadableStreamBYOBReader read() is not implemented
-FAIL ReadableStream with byte source: read(view), then respond() with too big value ReadableStreamBYOBReader read() is not implemented
-FAIL ReadableStream with byte source: respond(3) to read(view) with 2 element Uint16Array enqueues the 1 byte remainder ReadableStreamBYOBReader read() is not implemented
-FAIL ReadableStream with byte source: enqueue(), getReader(), then read(view) ReadableStreamBYOBReader read() is not implemented
+PASS ReadableStream with byte source: read(view), then respond() 
+PASS ReadableStream with byte source: read(view), then respond() with a transferred ArrayBuffer 
+PASS ReadableStream with byte source: read(view), then respond() with too big value 
+FAIL ReadableStream with byte source: respond(3) to read(view) with 2 element Uint16Array enqueues the 1 byte remainder assert_equals: expected 1 but got 2
+FAIL ReadableStream with byte source: enqueue(), getReader(), then read(view) assert_unreached: pull() should not be called Reached unreachable code
 PASS ReadableStream with byte source: enqueue(), getReader(), then cancel() (mode = not BYOB) 
 PASS ReadableStream with byte source: enqueue(), getReader(), then cancel() (mode = BYOB) 
-FAIL ReadableStream with byte source: getReader(), read(view), then cancel() ReadableStreamBYOBReader read() is not implemented
-FAIL ReadableStream with byte source: cancel() with partially filled pending pull() request promise_test: Unhandled rejection with value: object "TypeError: ReadableStreamBYOBReader read() is not implemented"
-FAIL ReadableStream with byte source: enqueue(), getReader(), then read(view) where view.buffer is not fully covered by view ReadableStreamBYOBReader read() is not implemented
-FAIL ReadableStream with byte source: Multiple enqueue(), getReader(), then read(view) ReadableStreamBYOBReader read() is not implemented
-FAIL ReadableStream with byte source: enqueue(), getReader(), then read(view) with a bigger view ReadableStreamBYOBReader read() is not implemented
-FAIL ReadableStream with byte source: enqueue(), getReader(), then read(view) with a smaller views ReadableStreamBYOBReader read() is not implemented
-FAIL ReadableStream with byte source: enqueue() 1 byte, getReader(), then read(view) with Uint16Array ReadableStreamBYOBReader read() is not implemented
-FAIL ReadableStream with byte source: enqueue() 3 byte, getReader(), then read(view) with 2-element Uint16Array promise_test: Unhandled rejection with value: object "TypeError: ReadableStreamBYOBReader read() is not implemented"
-FAIL ReadableStream with byte source: read(view) with Uint16Array on close()-d stream with 1 byte enqueue()-d must fail ReadableStreamBYOBReader read() is not implemented
-FAIL ReadableStream with byte source: A stream must be errored if close()-d before fulfilling read(view) with Uint16Array ReadableStreamBYOBReader read() is not implemented
+PASS ReadableStream with byte source: getReader(), read(view), then cancel() 
+FAIL ReadableStream with byte source: cancel() with partially filled pending pull() request assert_equals: 1 pull() should have been made in response to partial fill by enqueue() expected 1 but got 0
+FAIL ReadableStream with byte source: enqueue(), getReader(), then read(view) where view.buffer is not fully covered by view assert_equals: expected 1 but got 0
+FAIL ReadableStream with byte source: Multiple enqueue(), getReader(), then read(view) assert_equals: Contents are set from the first chunk expected 123 but got 0
+FAIL ReadableStream with byte source: enqueue(), getReader(), then read(view) with a bigger view assert_equals: expected 1 but got 0
+FAIL ReadableStream with byte source: enqueue(), getReader(), then read(view) with a smaller views assert_equals: expected 1 but got 0
+FAIL ReadableStream with byte source: enqueue() 1 byte, getReader(), then read(view) with Uint16Array assert_equals: expected 43775 but got 43520
+FAIL ReadableStream with byte source: enqueue() 3 byte, getReader(), then read(view) with 2-element Uint16Array assert_equals: Contents are set expected 1 but got 0
+PASS ReadableStream with byte source: read(view) with Uint16Array on close()-d stream with 1 byte enqueue()-d must fail 
+PASS ReadableStream with byte source: A stream must be errored if close()-d before fulfilling read(view) with Uint16Array 
 PASS ReadableStream with byte source: Throw if close()-ed more than once 
 PASS ReadableStream with byte source: Throw on enqueue() after close() 
-FAIL ReadableStream with byte source: read(view), then respond() and close() in pull() ReadableStreamBYOBReader read() is not implemented
-FAIL ReadableStream with byte source: read(view) with Uint32Array, then fill it by multiple respond() calls ReadableStreamBYOBReader read() is not implemented
+PASS ReadableStream with byte source: read(view), then respond() and close() in pull() 
+PASS ReadableStream with byte source: read(view) with Uint32Array, then fill it by multiple respond() calls 
 PASS ReadableStream with byte source: read() twice, then enqueue() twice 
-FAIL ReadableStream with byte source: Multiple read(view), close() and respond() ReadableStreamBYOBReader read() is not implemented
-FAIL ReadableStream with byte source: Multiple read(view), big enqueue() ReadableStreamBYOBReader read() is not implemented
-FAIL ReadableStream with byte source: Multiple read(view) and multiple enqueue() ReadableStreamBYOBReader read() is not implemented
-FAIL ReadableStream with byte source: read(view) with passing undefined as view must fail ReadableStreamBYOBReader read() is not implemented
-FAIL ReadableStream with byte source: read(view) with zero-length view must fail ReadableStreamBYOBReader read() is not implemented
-FAIL ReadableStream with byte source: read(view) with passing an empty object as view must fail ReadableStreamBYOBReader read() is not implemented
-FAIL ReadableStream with byte source: Even read(view) with passing ArrayBufferView like object as view must fail ReadableStreamBYOBReader read() is not implemented
+PASS ReadableStream with byte source: Multiple read(view), close() and respond() 
+FAIL ReadableStream with byte source: Multiple read(view), big enqueue() assert_unreached: pull() should not be called Reached unreachable code
+PASS ReadableStream with byte source: Multiple read(view) and multiple enqueue() 
+PASS ReadableStream with byte source: read(view) with passing undefined as view must fail 
+PASS ReadableStream with byte source: read(view) with zero-length view must fail 
+PASS ReadableStream with byte source: read(view) with passing an empty object as view must fail 
+PASS ReadableStream with byte source: Even read(view) with passing ArrayBufferView like object as view must fail 
 PASS ReadableStream with byte source: read() on an errored stream 
 PASS ReadableStream with byte source: read(), then error() 
-FAIL ReadableStream with byte source: read(view) on an errored stream ReadableStreamBYOBReader read() is not implemented
-FAIL ReadableStream with byte source: read(view), then error() ReadableStreamBYOBReader read() is not implemented
+PASS ReadableStream with byte source: read(view) on an errored stream 
+PASS ReadableStream with byte source: read(view), then error() 
 PASS ReadableStream with byte source: Throwing in pull function must error the stream 
 PASS ReadableStream with byte source: Throwing in pull in response to read() must be ignored if the stream is errored in it 
-FAIL ReadableStream with byte source: Throwing in pull in response to read(view) function must error the stream ReadableStreamBYOBReader read() is not implemented
-FAIL ReadableStream with byte source: Throwing in pull in response to read(view) must be ignored if the stream is errored in it ReadableStreamBYOBReader read() is not implemented
+PASS ReadableStream with byte source: Throwing in pull in response to read(view) function must error the stream 
+PASS ReadableStream with byte source: Throwing in pull in response to read(view) must be ignored if the stream is errored in it 
 PASS ReadableStream with byte source: default reader + autoAllocateChunkSize + byobRequest interaction 
 PASS ReadableStreamBYOBReader can be constructed directly 
 PASS ReadableStreamBYOBReader constructor requires a ReadableStream argument 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/streams/readable-byte-streams/general.dedicatedworker-expected.txt (218700 => 218701)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/streams/readable-byte-streams/general.dedicatedworker-expected.txt	2017-06-22 15:32:51 UTC (rev 218700)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/streams/readable-byte-streams/general.dedicatedworker-expected.txt	2017-06-22 16:17:20 UTC (rev 218701)
@@ -17,55 +17,55 @@
 PASS ReadableStream with byte source: Automatic pull() after start() 
 PASS ReadableStream with byte source: Automatic pull() after start() and read() 
 PASS ReadableStream with byte source: autoAllocateChunkSize 
-FAIL ReadableStream with byte source: Mix of auto allocate and BYOB promise_test: Unhandled rejection with value: object "TypeError: ReadableStreamBYOBReader read() is not implemented"
+PASS ReadableStream with byte source: Mix of auto allocate and BYOB 
 PASS ReadableStream with byte source: Automatic pull() after start() and read(view) 
 PASS ReadableStream with byte source: enqueue(), getReader(), then read() 
 PASS ReadableStream with byte source: Push source that doesn't understand pull signal 
 PASS ReadableStream with byte source: read(), but pull() function is not callable 
-FAIL ReadableStream with byte source: read(view), but pull() function is not callable ReadableStreamBYOBReader read() is not implemented
+PASS ReadableStream with byte source: read(view), but pull() function is not callable 
 PASS ReadableStream with byte source: enqueue() with Uint16Array, getReader(), then read() 
-FAIL ReadableStream with byte source: enqueue(), read(view) partially, then read() ReadableStreamBYOBReader read() is not implemented
+FAIL ReadableStream with byte source: enqueue(), read(view) partially, then read() assert_equals: expected 1 but got 0
 PASS ReadableStream with byte source: getReader(), enqueue(), close(), then read() 
 PASS ReadableStream with byte source: enqueue(), close(), getReader(), then read() 
 PASS ReadableStream with byte source: Respond to pull() by enqueue() 
 PASS ReadableStream with byte source: Respond to pull() by enqueue() asynchronously 
-FAIL ReadableStream with byte source: read(view), then respond() ReadableStreamBYOBReader read() is not implemented
-FAIL ReadableStream with byte source: read(view), then respond() with a transferred ArrayBuffer ReadableStreamBYOBReader read() is not implemented
-FAIL ReadableStream with byte source: read(view), then respond() with too big value ReadableStreamBYOBReader read() is not implemented
-FAIL ReadableStream with byte source: respond(3) to read(view) with 2 element Uint16Array enqueues the 1 byte remainder ReadableStreamBYOBReader read() is not implemented
-FAIL ReadableStream with byte source: enqueue(), getReader(), then read(view) ReadableStreamBYOBReader read() is not implemented
+PASS ReadableStream with byte source: read(view), then respond() 
+PASS ReadableStream with byte source: read(view), then respond() with a transferred ArrayBuffer 
+PASS ReadableStream with byte source: read(view), then respond() with too big value 
+FAIL ReadableStream with byte source: respond(3) to read(view) with 2 element Uint16Array enqueues the 1 byte remainder assert_equals: expected 1 but got 2
+FAIL ReadableStream with byte source: enqueue(), getReader(), then read(view) assert_unreached: pull() should not be called Reached unreachable code
 PASS ReadableStream with byte source: enqueue(), getReader(), then cancel() (mode = not BYOB) 
 PASS ReadableStream with byte source: enqueue(), getReader(), then cancel() (mode = BYOB) 
-FAIL ReadableStream with byte source: getReader(), read(view), then cancel() ReadableStreamBYOBReader read() is not implemented
-FAIL ReadableStream with byte source: cancel() with partially filled pending pull() request promise_test: Unhandled rejection with value: object "TypeError: ReadableStreamBYOBReader read() is not implemented"
-FAIL ReadableStream with byte source: enqueue(), getReader(), then read(view) where view.buffer is not fully covered by view ReadableStreamBYOBReader read() is not implemented
-FAIL ReadableStream with byte source: Multiple enqueue(), getReader(), then read(view) ReadableStreamBYOBReader read() is not implemented
-FAIL ReadableStream with byte source: enqueue(), getReader(), then read(view) with a bigger view ReadableStreamBYOBReader read() is not implemented
-FAIL ReadableStream with byte source: enqueue(), getReader(), then read(view) with a smaller views ReadableStreamBYOBReader read() is not implemented
-FAIL ReadableStream with byte source: enqueue() 1 byte, getReader(), then read(view) with Uint16Array ReadableStreamBYOBReader read() is not implemented
-FAIL ReadableStream with byte source: enqueue() 3 byte, getReader(), then read(view) with 2-element Uint16Array promise_test: Unhandled rejection with value: object "TypeError: ReadableStreamBYOBReader read() is not implemented"
-FAIL ReadableStream with byte source: read(view) with Uint16Array on close()-d stream with 1 byte enqueue()-d must fail ReadableStreamBYOBReader read() is not implemented
-FAIL ReadableStream with byte source: A stream must be errored if close()-d before fulfilling read(view) with Uint16Array ReadableStreamBYOBReader read() is not implemented
+PASS ReadableStream with byte source: getReader(), read(view), then cancel() 
+FAIL ReadableStream with byte source: cancel() with partially filled pending pull() request assert_equals: 1 pull() should have been made in response to partial fill by enqueue() expected 1 but got 0
+FAIL ReadableStream with byte source: enqueue(), getReader(), then read(view) where view.buffer is not fully covered by view assert_equals: expected 1 but got 0
+FAIL ReadableStream with byte source: Multiple enqueue(), getReader(), then read(view) assert_equals: Contents are set from the first chunk expected 123 but got 0
+FAIL ReadableStream with byte source: enqueue(), getReader(), then read(view) with a bigger view assert_equals: expected 1 but got 0
+FAIL ReadableStream with byte source: enqueue(), getReader(), then read(view) with a smaller views assert_equals: expected 1 but got 0
+FAIL ReadableStream with byte source: enqueue() 1 byte, getReader(), then read(view) with Uint16Array assert_equals: expected 43775 but got 43520
+FAIL ReadableStream with byte source: enqueue() 3 byte, getReader(), then read(view) with 2-element Uint16Array assert_equals: Contents are set expected 1 but got 0
+PASS ReadableStream with byte source: read(view) with Uint16Array on close()-d stream with 1 byte enqueue()-d must fail 
+PASS ReadableStream with byte source: A stream must be errored if close()-d before fulfilling read(view) with Uint16Array 
 PASS ReadableStream with byte source: Throw if close()-ed more than once 
 PASS ReadableStream with byte source: Throw on enqueue() after close() 
-FAIL ReadableStream with byte source: read(view), then respond() and close() in pull() ReadableStreamBYOBReader read() is not implemented
-FAIL ReadableStream with byte source: read(view) with Uint32Array, then fill it by multiple respond() calls ReadableStreamBYOBReader read() is not implemented
+PASS ReadableStream with byte source: read(view), then respond() and close() in pull() 
+PASS ReadableStream with byte source: read(view) with Uint32Array, then fill it by multiple respond() calls 
 PASS ReadableStream with byte source: read() twice, then enqueue() twice 
-FAIL ReadableStream with byte source: Multiple read(view), close() and respond() ReadableStreamBYOBReader read() is not implemented
-FAIL ReadableStream with byte source: Multiple read(view), big enqueue() ReadableStreamBYOBReader read() is not implemented
-FAIL ReadableStream with byte source: Multiple read(view) and multiple enqueue() ReadableStreamBYOBReader read() is not implemented
-FAIL ReadableStream with byte source: read(view) with passing undefined as view must fail ReadableStreamBYOBReader read() is not implemented
-FAIL ReadableStream with byte source: read(view) with zero-length view must fail ReadableStreamBYOBReader read() is not implemented
-FAIL ReadableStream with byte source: read(view) with passing an empty object as view must fail ReadableStreamBYOBReader read() is not implemented
-FAIL ReadableStream with byte source: Even read(view) with passing ArrayBufferView like object as view must fail ReadableStreamBYOBReader read() is not implemented
+PASS ReadableStream with byte source: Multiple read(view), close() and respond() 
+FAIL ReadableStream with byte source: Multiple read(view), big enqueue() assert_unreached: pull() should not be called Reached unreachable code
+PASS ReadableStream with byte source: Multiple read(view) and multiple enqueue() 
+PASS ReadableStream with byte source: read(view) with passing undefined as view must fail 
+PASS ReadableStream with byte source: read(view) with zero-length view must fail 
+PASS ReadableStream with byte source: read(view) with passing an empty object as view must fail 
+PASS ReadableStream with byte source: Even read(view) with passing ArrayBufferView like object as view must fail 
 PASS ReadableStream with byte source: read() on an errored stream 
 PASS ReadableStream with byte source: read(), then error() 
-FAIL ReadableStream with byte source: read(view) on an errored stream ReadableStreamBYOBReader read() is not implemented
-FAIL ReadableStream with byte source: read(view), then error() ReadableStreamBYOBReader read() is not implemented
+PASS ReadableStream with byte source: read(view) on an errored stream 
+PASS ReadableStream with byte source: read(view), then error() 
 PASS ReadableStream with byte source: Throwing in pull function must error the stream 
 PASS ReadableStream with byte source: Throwing in pull in response to read() must be ignored if the stream is errored in it 
-FAIL ReadableStream with byte source: Throwing in pull in response to read(view) function must error the stream ReadableStreamBYOBReader read() is not implemented
-FAIL ReadableStream with byte source: Throwing in pull in response to read(view) must be ignored if the stream is errored in it ReadableStreamBYOBReader read() is not implemented
+PASS ReadableStream with byte source: Throwing in pull in response to read(view) function must error the stream 
+PASS ReadableStream with byte source: Throwing in pull in response to read(view) must be ignored if the stream is errored in it 
 PASS ReadableStream with byte source: default reader + autoAllocateChunkSize + byobRequest interaction 
 PASS ReadableStreamBYOBReader can be constructed directly 
 PASS ReadableStreamBYOBReader constructor requires a ReadableStream argument 

Modified: trunk/LayoutTests/streams/readable-stream-byob-reader-expected.txt (218700 => 218701)


--- trunk/LayoutTests/streams/readable-stream-byob-reader-expected.txt	2017-06-22 15:32:51 UTC (rev 218700)
+++ trunk/LayoutTests/streams/readable-stream-byob-reader-expected.txt	2017-06-22 16:17:20 UTC (rev 218701)
@@ -13,6 +13,7 @@
 PASS Calling ReadableStreamBYOBReader.releaseLock() with a this object different from ReadableStreamBYOBReader should be rejected 
 PASS Calling ReadableStreamBYOBReader.releaseLock() on a stream that is readable should result in ReadableStreamBYOBReader.closed promise to be rejected with a TypeError 
 PASS Calling ReadableStreamBYOBReader.releaseLock() on a stream that is not readable should result in ReadableStreamBYOBReader.closed promise to be rejected with a TypeError 
+PASS Calling ReadableStreamBYOBReader.read() with a this object different from ReadableStreamBYOBReader should be rejected 
 PASS Getting a ReadableStreamBYOBReader should succeed 
 PASS ReadableStreamBYOBReader instances should have the correct list of properties 
 PASS Calling getReader() with a this object different from ReadableStream should throw a TypeError 
@@ -27,4 +28,5 @@
 PASS Calling ReadableStreamBYOBReader.releaseLock() with a this object different from ReadableStreamBYOBReader should be rejected 
 PASS Calling ReadableStreamBYOBReader.releaseLock() on a stream that is readable should result in ReadableStreamBYOBReader.closed promise to be rejected with a TypeError 
 PASS Calling ReadableStreamBYOBReader.releaseLock() on a stream that is not readable should result in ReadableStreamBYOBReader.closed promise to be rejected with a TypeError 
+PASS Calling ReadableStreamBYOBReader.read() with a this object different from ReadableStreamBYOBReader should be rejected 
 

Modified: trunk/LayoutTests/streams/readable-stream-byob-reader.js (218700 => 218701)


--- trunk/LayoutTests/streams/readable-stream-byob-reader.js	2017-06-22 15:32:51 UTC (rev 218700)
+++ trunk/LayoutTests/streams/readable-stream-byob-reader.js	2017-06-22 16:17:20 UTC (rev 218701)
@@ -215,4 +215,13 @@
     return promise_rejects(test, myError, reader.closed);
 }, "Calling ReadableStreamBYOBReader.releaseLock() on a stream that is not readable should result in ReadableStreamBYOBReader.closed promise to be rejected with a TypeError");
 
+promise_test(function(test) {
+    const rs = new ReadableStream({ type: 'bytes' });
+    const reader = rs.getReader({ mode: 'byob' });
+    let rp = reader.read.apply(rs);
+    const myError= new TypeError("Can only call ReadableStreamBYOBReader.read() on instances of ReadableStreamBYOBReader");
+
+    return promise_rejects(test, myError, rp);
+}, "Calling ReadableStreamBYOBReader.read() with a this object different from ReadableStreamBYOBReader should be rejected");
+
 done();

Modified: trunk/Source/WebCore/ChangeLog (218700 => 218701)


--- trunk/Source/WebCore/ChangeLog	2017-06-22 15:32:51 UTC (rev 218700)
+++ trunk/Source/WebCore/ChangeLog	2017-06-22 16:17:20 UTC (rev 218701)
@@ -1,3 +1,32 @@
+2017-06-22  Romain Bellessort  <[email protected]>
+
+        [Readable Streams API] Implement ReadableStreamBYOBReader read()
+        https://bugs.webkit.org/show_bug.cgi?id=172714
+
+        Reviewed by Youenn Fablet.
+
+        Implemented read() method of ReadableStreamBYOBReader [1]. Also added code related 
+        to BYOB features that were previously described as FIXMEs and that now become reachable.
+
+        In addition, WPT tests that involve read() have allowed to identify 2 bugs not directly 
+        related to read() (172716 and 172717). They will be fixed distinctly. Once done, all WPT
+        tests should pass.
+
+        [1] https://streams.spec.whatwg.org/#byob-reader-read
+
+        WPT tests (web-platform-tests/streams/readable-byte-streams/general.js) already cover
+        most cases for read() usage. Corresponding expectations have been updated. In addition,
+        1 test has been added to WebKit tests (in streams/readable-stream-byob-reader.js) to 
+        check that read() can only be applied to a ReadableStreamBYOBReader.
+
+        * Modules/streams/ReadableByteStreamInternals.js:
+        (readableByteStreamControllerClearPendingPullIntos): Implemented.
+        (readableByteStreamControllerEnqueue): Updated with support for BYOBReader.
+        (readableByteStreamControllerPullInto): Added.
+        (readableStreamAddReadIntoRequest): Added.
+        * Modules/streams/ReadableStreamBYOBReader.js:
+        (read): Added.
+
 2017-06-22  Youenn Fablet  <[email protected]>
 
         [WebRTC] Prevent capturing at unconventional resolutions when using the SW encoder on Mac

Modified: trunk/Source/WebCore/Modules/streams/ReadableByteStreamInternals.js (218700 => 218701)


--- trunk/Source/WebCore/Modules/streams/ReadableByteStreamInternals.js	2017-06-22 15:32:51 UTC (rev 218700)
+++ trunk/Source/WebCore/Modules/streams/ReadableByteStreamInternals.js	2017-06-22 16:17:20 UTC (rev 218701)
@@ -179,7 +179,8 @@
 {
     "use strict";
 
-    // FIXME: To be implemented in conjunction with ReadableStreamBYOBRequest.
+    @readableByteStreamControllerInvalidateBYOBRequest(controller);
+    controller.@pendingPullIntos = [];
 }
 
 function readableByteStreamControllerGetDesiredSize(controller)
@@ -348,9 +349,8 @@
     }
 
     if (@readableStreamHasBYOBReader(stream)) {
-        // FIXME: To be implemented once ReadableStreamBYOBReader has been implemented (for the moment,
-        // test cannot be true).
-        @throwTypeError("ReadableByteStreamController enqueue operation has no support for BYOB reader");
+        @readableByteStreamControllerEnqueueChunk(controller, transferredBuffer, byteOffset, byteLength);
+        @readableByteStreamControllerProcessPullDescriptors(controller);
         return;
     }
 
@@ -596,3 +596,98 @@
 
     stream.@reader.@readIntoRequests.@shift().@resolve.@call(@undefined, {value: chunk, done: done});
 }
+
+function readableStreamBYOBReaderRead(reader, view)
+{
+    "use strict";
+
+    const stream = reader.@ownerReadableStream;
+    @assert(!!stream);
+
+    stream.@disturbed = true;
+    if (stream.@state === @streamErrored)
+        return @Promise.@reject(stream.@storedError);
+
+    return @readableByteStreamControllerPullInto(stream.@readableStreamController, view);
+}
+
+function readableByteStreamControllerPullInto(controller, view)
+{
+    "use strict";
+
+    const stream = controller.@controlledReadableStream;
+    let elementSize = 1;
+    // Spec describes that in the case where view is a TypedArray, elementSize
+    // should be set to the size of an element (e.g. 2 for UInt16Array). For
+    // DataView, BYTES_PER_ELEMENT is undefined, contrary to the same property
+    // for TypedArrays.
+    // FIXME: Getting BYTES_PER_ELEMENT like this is not safe (property is read-only
+    // but can be modified if the prototype is redefined). A safe way of getting
+    // it would be to determine which type of ArrayBufferView view is an instance
+    // of based on typed arrays private variables. However, this is not possible due
+    // to bug 167697, which prevents access to typed arrays through their private
+    // names unless public name has already been met before.
+    if (view.BYTES_PER_ELEMENT !== @undefined)
+        elementSize = view.BYTES_PER_ELEMENT;
+
+    // FIXME: Getting constructor like this is not safe. A safe way of getting
+    // it would be to determine which type of ArrayBufferView view is an instance
+    // of, and to assign appropriate constructor based on this (e.g. ctor =
+    // @Uint8Array). However, this is not possible due to bug 167697, which
+    // prevents access to typed arrays through their private names unless public
+    // name has already been met before.
+    const ctor = view.constructor;
+
+    const pullIntoDescriptor = {
+        buffer: view.buffer,
+        byteOffset: view.byteOffset,
+        byteLength: view.byteLength,
+        bytesFilled: 0,
+        elementSize,
+        ctor,
+        readerType: 'byob'
+    };
+
+    if ([email protected]) {
+        pullIntoDescriptor.buffer = @transferBufferToCurrentRealm(pullIntoDescriptor.buffer);
+        controller.@pendingPullIntos.@push(pullIntoDescriptor);
+        return @readableStreamAddReadIntoRequest(stream);
+    }
+
+    if (stream.@state === @streamClosed) {
+        const emptyView = new ctor(pullIntoDescriptor.buffer, pullIntoDescriptor.byteOffset, 0);
+        return @Promise.@resolve({ value: emptyView, done: true });
+    }
+
+    if (controller.@totalQueuedBytes > 0) {
+        if (@readableByteStreamControllerFillDescriptorFromQueue(controller, pullIntoDescriptor)) {
+            const filledView = @readableByteStreamControllerConvertDescriptor(pullIntoDescriptor);
+            @readableByteStreamControllerHandleQueueDrain(controller);
+            return @Promise.@resolve({ value: filledView, done: false });
+        }
+        if (controller.@closeRequested) {
+            const e = new @TypeError("Closing stream has been requested");
+            @readableByteStreamControllerError(controller, e);
+            return @Promise.@reject(e);
+        }
+    }
+
+    pullIntoDescriptor.buffer = @transferBufferToCurrentRealm(pullIntoDescriptor.buffer);
+    controller.@pendingPullIntos.@push(pullIntoDescriptor);
+    const promise = @readableStreamAddReadIntoRequest(stream);
+    @readableByteStreamControllerCallPullIfNeeded(controller);
+    return promise;
+}
+
+function readableStreamAddReadIntoRequest(stream)
+{
+    "use strict";
+
+    @assert(@isReadableStreamBYOBReader(stream.@reader));
+    @assert(stream.@state === @streamReadable || stream.@state === @streamClosed);
+
+    const readRequest = @newPromiseCapability(@Promise);
+    stream.@reader.@readIntoRequests.@push(readRequest);
+
+    return readRequest.@promise;
+}

Modified: trunk/Source/WebCore/Modules/streams/ReadableStreamBYOBReader.js (218700 => 218701)


--- trunk/Source/WebCore/Modules/streams/ReadableStreamBYOBReader.js	2017-06-22 15:32:51 UTC (rev 218700)
+++ trunk/Source/WebCore/Modules/streams/ReadableStreamBYOBReader.js	2017-06-22 16:17:20 UTC (rev 218701)
@@ -41,8 +41,22 @@
 {
     "use strict";
 
-    // FIXME: Implement appropriate behavior.
-    @throwTypeError("ReadableStreamBYOBReader read() is not implemented");
+    if (!@isReadableStreamBYOBReader(this))
+        return @Promise.@reject(@makeThisTypeError("ReadableStreamBYOBReader", "read"));
+
+    if (!this.@ownerReadableStream)
+        return @Promise.@reject(new @TypeError("read() called on a reader owned by no readable stream"));
+
+    if (!@isObject(view))
+        return @Promise.@reject(new @TypeError("Provided view is not an object"));
+
+    if (!@ArrayBuffer.@isView(view))
+        return @Promise.@reject(new @TypeError("Provided view is not an ArrayBufferView"));
+
+    if (view.byteLength === 0)
+        return @Promise.@reject(new @TypeError("Provided view cannot have a 0 byteLength"));
+
+    return @readableStreamBYOBReaderRead(this, view);
 }
 
 function releaseLock()
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to