<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[208382] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/208382">208382</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2016-11-04 03:39:09 -0700 (Fri, 04 Nov 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>[Readable Streams API] Implement ByteStreamController error()
https://bugs.webkit.org/show_bug.cgi?id=164319

Patch by Romain Bellessort &lt;romain.bellessort@crf.canon.fr&gt; on 2016-11-04
Reviewed by Youenn Fablet.

Source/WebCore:

Implemented error() method of ReadableByteStreamController.

Updated test expectations for error() and added IDL-related tests.

* Modules/streams/ReadableByteStreamController.js:
(error): Implemented.
* Modules/streams/ReadableByteStreamInternals.js:
(privateInitializeReadableByteStreamController):
(isReadableByteStreamController): Added.
(readableByteStreamControllerError): Added.
(readableByteStreamControllerClearPendingPullIntos): Added.
* Modules/streams/ReadableStream.js:
(initializeReadableStream): More detailed error message.
* Modules/streams/ReadableStreamDefaultController.js:
(error): Removed unnecessary variable declaration.
* bindings/js/WebCoreBuiltinNames.h: Added totalQueuedBytes.

LayoutTests:

Updated test expectation for error() test (previously FAIL, now PASS).
Added IDL-related tests for ReadableByteStreamController.

* streams/readable-byte-stream-controller-expected.txt:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsstreamsreadablebytestreamcontrollerexpectedtxt">trunk/LayoutTests/streams/readable-byte-stream-controller-expected.txt</a></li>
<li><a href="#trunkLayoutTestsstreamsreadablebytestreamcontrollerjs">trunk/LayoutTests/streams/readable-byte-stream-controller.js</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreModulesstreamsReadableByteStreamControllerjs">trunk/Source/WebCore/Modules/streams/ReadableByteStreamController.js</a></li>
<li><a href="#trunkSourceWebCoreModulesstreamsReadableByteStreamInternalsjs">trunk/Source/WebCore/Modules/streams/ReadableByteStreamInternals.js</a></li>
<li><a href="#trunkSourceWebCoreModulesstreamsReadableStreamjs">trunk/Source/WebCore/Modules/streams/ReadableStream.js</a></li>
<li><a href="#trunkSourceWebCoreModulesstreamsReadableStreamDefaultControllerjs">trunk/Source/WebCore/Modules/streams/ReadableStreamDefaultController.js</a></li>
<li><a href="#trunkSourceWebCorebindingsjsWebCoreBuiltinNamesh">trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (208381 => 208382)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2016-11-04 09:35:36 UTC (rev 208381)
+++ trunk/LayoutTests/ChangeLog        2016-11-04 10:39:09 UTC (rev 208382)
</span><span class="lines">@@ -1,3 +1,15 @@
</span><ins>+2016-11-04  Romain Bellessort  &lt;romain.bellessort@crf.canon.fr&gt;
+
+        [Readable Streams API] Implement ByteStreamController error()
+        https://bugs.webkit.org/show_bug.cgi?id=164319
+
+        Reviewed by Youenn Fablet.
+
+        Updated test expectation for error() test (previously FAIL, now PASS).
+        Added IDL-related tests for ReadableByteStreamController.
+
+        * streams/readable-byte-stream-controller-expected.txt:
+
</ins><span class="cx"> 2016-11-04  Per Arne Vollan  &lt;pvollan@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [Win] Page visibility tests are timing out.
</span></span></pre></div>
<a id="trunkLayoutTestsstreamsreadablebytestreamcontrollerexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/streams/readable-byte-stream-controller-expected.txt (208381 => 208382)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/streams/readable-byte-stream-controller-expected.txt        2016-11-04 09:35:36 UTC (rev 208381)
+++ trunk/LayoutTests/streams/readable-byte-stream-controller-expected.txt        2016-11-04 10:39:09 UTC (rev 208382)
</span><span class="lines">@@ -1,10 +1,14 @@
</span><span class="cx"> 
</span><span class="cx"> PASS Creating a ReadableStream with an underlyingSource with type property set to 'bytes' should succeed 
</span><del>-FAIL Calling read() on a reader associated to a controller that has been errored should be rejected ReadableByteStreamController error() is not implemented
</del><ins>+PASS ReadableByteStreamController instances should have the correct list of properties 
+PASS Calling error() with a this object different from ReadableByteStreamController should fail 
+PASS Calling read() on a reader associated to a controller that has been errored should be rejected 
</ins><span class="cx"> FAIL Calling read() on a reader associated to a controller that has been closed should not be rejected ReadableByteStreamController close() is not implemented
</span><span class="cx"> FAIL Calling read() after a chunk has been enqueued should result in obtaining said chunk ReadableByteStreamController enqueue() is not implemented
</span><span class="cx"> PASS Creating a ReadableStream with an underlyingSource with type property set to 'bytes' should succeed 
</span><del>-FAIL Calling read() on a reader associated to a controller that has been errored should be rejected ReadableByteStreamController error() is not implemented
</del><ins>+PASS ReadableByteStreamController instances should have the correct list of properties 
+PASS Calling error() with a this object different from ReadableByteStreamController should fail 
+PASS Calling read() on a reader associated to a controller that has been errored should be rejected 
</ins><span class="cx"> FAIL Calling read() on a reader associated to a controller that has been closed should not be rejected ReadableByteStreamController close() is not implemented
</span><span class="cx"> FAIL Calling read() after a chunk has been enqueued should result in obtaining said chunk ReadableByteStreamController enqueue() is not implemented
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkLayoutTestsstreamsreadablebytestreamcontrollerjs"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/streams/readable-byte-stream-controller.js (208381 => 208382)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/streams/readable-byte-stream-controller.js        2016-11-04 09:35:36 UTC (rev 208381)
+++ trunk/LayoutTests/streams/readable-byte-stream-controller.js        2016-11-04 10:39:09 UTC (rev 208382)
</span><span class="lines">@@ -10,6 +10,59 @@
</span><span class="cx">     });
</span><span class="cx"> }, &quot;Creating a ReadableStream with an underlyingSource with type property set to 'bytes' should succeed&quot;);
</span><span class="cx"> 
</span><ins>+test(() =&gt; {
+    const methods = ['close', 'constructor', 'enqueue', 'error'];
+    // FIXME: Add byobRequest when implemented.
+    const properties = methods.concat(['desiredSize']).sort();
+
+    let controller;
+
+    const rs = new ReadableStream({
+        start: function(c) {
+            controller = c;
+        },
+        type: &quot;bytes&quot;
+    });
+
+    const proto = Object.getPrototypeOf(controller);
+
+    assert_array_equals(Object.getOwnPropertyNames(proto).sort(), properties);
+
+    for (const m of methods) {
+        const propDesc = Object.getOwnPropertyDescriptor(proto, m);
+        assert_equals(propDesc.enumerable, false, 'method should be non-enumerable');
+        assert_equals(propDesc.configurable, true, 'method should be configurable');
+        assert_equals(propDesc.writable, true, 'method should be writable');
+        assert_equals(typeof controller[m], 'function', 'should have be a method');
+    }
+
+    const desiredSizePropDesc = Object.getOwnPropertyDescriptor(proto, 'desiredSize');
+    assert_equals(desiredSizePropDesc.enumerable, false, 'desiredSize should be non-enumerable');
+    assert_equals(desiredSizePropDesc.configurable, true, 'desiredSize should be configurable');
+    assert_not_equals(desiredSizePropDesc.get, undefined, 'desiredSize should have a getter');
+    assert_equals(desiredSizePropDesc.set, undefined, 'desiredSize should not have a setter');
+
+    assert_equals(controller.close.length, 0, 'close has 0 parameter');
+    assert_equals(controller.constructor.length, 3, 'constructor has 3 parameters');
+    assert_equals(controller.enqueue.length, 1, 'enqueue has 1 parameter');
+    assert_equals(controller.error.length, 1, 'error has 1 parameter');
+
+}, 'ReadableByteStreamController instances should have the correct list of properties');
+
+test(function() {
+    let controller;
+
+    const rs = new ReadableStream({
+        start: function(c) {
+            controller = c;
+        },
+        type: &quot;bytes&quot;
+    });
+
+    assert_throws(new TypeError(&quot;Can only call ReadableByteStreamController.error on instances of ReadableByteStreamController&quot;),
+        function() { controller.error.apply(rs); });
+}, &quot;Calling error() with a this object different from ReadableByteStreamController should fail&quot;);
+
</ins><span class="cx"> const test2 = async_test(&quot;Calling read() on a reader associated to a controller that has been errored should be rejected&quot;);
</span><span class="cx"> test2.step(function() {
</span><span class="cx">     let controller;
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (208381 => 208382)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-11-04 09:35:36 UTC (rev 208381)
+++ trunk/Source/WebCore/ChangeLog        2016-11-04 10:39:09 UTC (rev 208382)
</span><span class="lines">@@ -1,3 +1,27 @@
</span><ins>+2016-11-04  Romain Bellessort  &lt;romain.bellessort@crf.canon.fr&gt;
+
+        [Readable Streams API] Implement ByteStreamController error()
+        https://bugs.webkit.org/show_bug.cgi?id=164319
+
+        Reviewed by Youenn Fablet.
+
+        Implemented error() method of ReadableByteStreamController.
+
+        Updated test expectations for error() and added IDL-related tests.
+
+        * Modules/streams/ReadableByteStreamController.js:
+        (error): Implemented.
+        * Modules/streams/ReadableByteStreamInternals.js:
+        (privateInitializeReadableByteStreamController):
+        (isReadableByteStreamController): Added.
+        (readableByteStreamControllerError): Added.
+        (readableByteStreamControllerClearPendingPullIntos): Added.
+        * Modules/streams/ReadableStream.js:
+        (initializeReadableStream): More detailed error message.
+        * Modules/streams/ReadableStreamDefaultController.js:
+        (error): Removed unnecessary variable declaration.
+        * bindings/js/WebCoreBuiltinNames.h: Added totalQueuedBytes.
+
</ins><span class="cx"> 2016-11-03  Brady Eidson  &lt;beidson@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         IndexedDB 2.0: Handle IDBIndex rename behavior properly when version change transaction aborts.
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesstreamsReadableByteStreamControllerjs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/streams/ReadableByteStreamController.js (208381 => 208382)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/streams/ReadableByteStreamController.js        2016-11-04 09:35:36 UTC (rev 208381)
+++ trunk/Source/WebCore/Modules/streams/ReadableByteStreamController.js        2016-11-04 10:39:09 UTC (rev 208382)
</span><span class="lines">@@ -37,8 +37,13 @@
</span><span class="cx"> {
</span><span class="cx">     &quot;use strict&quot;;
</span><span class="cx"> 
</span><del>-    //FIXME: Implement appropriate behavior.
-    @throwTypeError(&quot;ReadableByteStreamController error() is not implemented&quot;);
</del><ins>+    if (!@isReadableByteStreamController(this))
+        throw @makeThisTypeError(&quot;ReadableByteStreamController&quot;, &quot;error&quot;);
+
+    if (this.@controlledReadableStream.@state !== @streamReadable)
+        @throwTypeError(&quot;ReadableStream is not readable&quot;);
+
+    @readableByteStreamControllerError(this, error);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> function close()
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesstreamsReadableByteStreamInternalsjs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/streams/ReadableByteStreamInternals.js (208381 => 208382)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/streams/ReadableByteStreamInternals.js        2016-11-04 09:35:36 UTC (rev 208381)
+++ trunk/Source/WebCore/Modules/streams/ReadableByteStreamInternals.js        2016-11-04 10:39:09 UTC (rev 208382)
</span><span class="lines">@@ -39,11 +39,13 @@
</span><span class="cx"> 
</span><span class="cx">     this.@controlledReadableStream = stream;
</span><span class="cx">     this.@underlyingByteSource = underlyingByteSource;
</span><ins>+    this.@pullAgain = false;
+    this.@pulling = false;
+    @readableByteStreamControllerClearPendingPullIntos(this);
</ins><span class="cx">     this.@queue = @newQueue();
</span><ins>+    this.@totalQueuedBytes = 0;
</ins><span class="cx">     this.@started = false;
</span><span class="cx">     this.@closeRequested = false;
</span><del>-    this.@pullAgain = false;
-    this.@pulling = false;
</del><span class="cx"> 
</span><span class="cx">     let hwm = @Number(highWaterMark);
</span><span class="cx">     if (@isNaN(hwm) || hwm &lt; 0)
</span><span class="lines">@@ -50,8 +52,6 @@
</span><span class="cx">         @throwRangeError(&quot;highWaterMark value is negative or not a number&quot;);
</span><span class="cx">     this.@strategyHWM = hwm;
</span><span class="cx"> 
</span><del>-    // FIXME: Implement readableByteStreamControllerClearPendingPullIntos.
-
</del><span class="cx">     let autoAllocateChunkSize = underlyingByteSource.autoAllocateChunkSize;
</span><span class="cx">     if (autoAllocateChunkSize !== @undefined) {
</span><span class="cx">         autoAllocateChunkSize = @Number(autoAllocateChunkSize);
</span><span class="lines">@@ -75,3 +75,29 @@
</span><span class="cx"> 
</span><span class="cx">     return this;
</span><span class="cx"> }
</span><ins>+
+function isReadableByteStreamController(controller)
+{
+    &quot;use strict&quot;;
+
+    // Same test mechanism as in isReadableStreamDefaultController (ReadableStreamInternals.js).
+    // See corresponding function for explanations.
+    return @isObject(controller) &amp;&amp; !!controller.@underlyingByteSource;
+}
+
+function readableByteStreamControllerError(controller, e)
+{
+    &quot;use strict&quot;;
+
+    @assert(controller.@controlledReadableStream.@state === @streamReadable);
+    @readableByteStreamControllerClearPendingPullIntos(controller);
+    controller.@queue = @newQueue();
+    @readableStreamError(controller.@controlledReadableStream, e);
+}
+
+function readableByteStreamControllerClearPendingPullIntos(controller)
+{
+    &quot;use strict&quot;;
+
+    // FIXME: To be implemented in conjunction with ReadableStreamBYOBRequest.
+}
</ins></span></pre></div>
<a id="trunkSourceWebCoreModulesstreamsReadableStreamjs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/streams/ReadableStream.js (208381 => 208382)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/streams/ReadableStream.js        2016-11-04 09:35:36 UTC (rev 208381)
+++ trunk/Source/WebCore/Modules/streams/ReadableStream.js        2016-11-04 10:39:09 UTC (rev 208382)
</span><span class="lines">@@ -58,10 +58,11 @@
</span><span class="cx">         // Constructor is not necessarily available if the byteStream part of Readeable Stream API is not activated. Therefore, a
</span><span class="cx">         // specific handling of error is done.
</span><span class="cx">         try {
</span><del>-            this.@readableStreamController = new @ReadableByteStreamController(this, underlyingSource, strategy.highWaterMark);
</del><ins>+            let readableByteStreamControllerConstructor = @ReadableByteStreamController;
</ins><span class="cx">         } catch (e) {
</span><del>-            @throwTypeError(&quot;ReadableByteStreamController could not be created&quot;);
</del><ins>+            @throwTypeError(&quot;ReadableByteStreamController is not implemented&quot;);
</ins><span class="cx">         }
</span><ins>+        this.@readableStreamController = new @ReadableByteStreamController(this, underlyingSource, strategy.highWaterMark);
</ins><span class="cx">     } else if (type === @undefined) {
</span><span class="cx">         if (strategy.highWaterMark === @undefined)
</span><span class="cx">             strategy.highWaterMark = 1;
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesstreamsReadableStreamDefaultControllerjs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/streams/ReadableStreamDefaultController.js (208381 => 208382)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/streams/ReadableStreamDefaultController.js        2016-11-04 09:35:36 UTC (rev 208381)
+++ trunk/Source/WebCore/Modules/streams/ReadableStreamDefaultController.js        2016-11-04 10:39:09 UTC (rev 208382)
</span><span class="lines">@@ -48,8 +48,7 @@
</span><span class="cx">     if (!@isReadableStreamDefaultController(this))
</span><span class="cx">         throw @makeThisTypeError(&quot;ReadableStreamDefaultController&quot;, &quot;error&quot;);
</span><span class="cx"> 
</span><del>-    const stream = this.@controlledReadableStream;
-    if (stream.@state !== @streamReadable)
</del><ins>+    if (this.@controlledReadableStream.@state !== @streamReadable)
</ins><span class="cx">         @throwTypeError(&quot;ReadableStream is not readable&quot;);
</span><span class="cx"> 
</span><span class="cx">     @readableStreamDefaultControllerError(this, error);
</span></span></pre></div>
<a id="trunkSourceWebCorebindingsjsWebCoreBuiltinNamesh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h (208381 => 208382)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h        2016-11-04 09:35:36 UTC (rev 208381)
+++ trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h        2016-11-04 10:39:09 UTC (rev 208382)
</span><span class="lines">@@ -97,6 +97,7 @@
</span><span class="cx">     macro(streamWritable) \
</span><span class="cx">     macro(structuredCloneArrayBuffer) \
</span><span class="cx">     macro(structuredCloneArrayBufferView) \
</span><ins>+    macro(totalQueuedBytes) \
</ins><span class="cx">     macro(underlyingByteSource) \
</span><span class="cx">     macro(underlyingSink) \
</span><span class="cx">     macro(underlyingSource) \
</span></span></pre>
</div>
</div>

</body>
</html>