<!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>[205289] 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/205289">205289</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2016-09-01 07:14:05 -0700 (Thu, 01 Sep 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>[Streams API] Align internal structure of ReadableStream with spec
https://bugs.webkit.org/show_bug.cgi?id=160299

Patch by Romain Bellessort &lt;romain.bellessort@crf.canon.fr&gt; on 2016-09-01
Reviewed by Xabier Rodriguez-Calvar.

LayoutTests/imported/w3c:

Aligned internal structure of ReadableStream with spec. Fixed one expectation
that was set to FAIL while it is now PASSing.

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

Source/WebCore:

Aligned internal structure of ReadableStream with spec. Various
internal properties have been moved to ReadableStreamDefaultController.
In addition, various behaviors had to be updated. Several other changes
will have to be performed in order to align with spec, e.g. changing
functions names. This patch does not change them in order to make the
structural changes easier to follow.

No change in functionality except support for 1 specific case where
an error was not thrown while it should have been. Changed corresponding
test expectation (now PASS instead of FAIL).
Modified test expectation: web-platform-tests/streams/readable-streams/general.https-expected.txt

* Modules/fetch/FetchResponse.js:
(initializeFetchResponse): Replaced reference to underlyingSource as no
more a property of readableStream (use readableStreamController instead,
as defined by spec).
* Modules/streams/ReadableStream.js:
(initializeReadableStream): Removed various properties now hanlded by
ReadableStreamDefaultController.
* Modules/streams/ReadableStreamDefaultController.js:
(enqueue): Updated based on new properties repartition between reader and controller.
(error): Updated based on new properties repartition between reader and controller.
(close): Updated based on new properties repartition between reader and controller.
(desiredSize): Updated based on new properties repartition between reader and controller.
* Modules/streams/ReadableStreamInternals.js:
(privateInitializeReadableStreamDefaultController): Added various properties now handled by
ReadableStreamDefaultController, as well as an internal pull function defined by spec.
(readableStreamDefaultControllerError): Added based on spec (error handling at controller level).
(teeReadableStream): Fixed typo and use readableStreamDefaultControllerError instead of errorReadableStream.
(doStructuredClone): Added &quot;use strict&quot;;.
(teeReadableStreamPullFunction): Use readableStreamDefaultControllerClose instead of closeReadableStream.
(isReadableStream): Replaced check of underlyingSource by check that object is actually an instance of
ReadableStream (spec requires checking that readableStreamController slot is present, but this cannot
be checked).
(isReadableStreamDefaultReader): Replaced check of ownerReadableStream presence by check of readRequests,
in line with spec.
(isReadableStreamDefaultController): Replaced check of controlledReadableStream presence by check of unerlyingSource,
in line with spec.
(errorReadableStream): Updated based on new properties repartition between reader and controller.
(requestReadableStreamPull): Updated based on new properties repartition between reader and controller.
(readableStreamDefaultControllerGetDesiredSize): Replaces getReadableStreamDesiredSize (size now depends
on controller; new function name aligned with spec).
(cancelReadableStream): Updated based on new properties repartition between reader and controller.
(readableStreamDefaultControllerClose): Added based on spec (closing controller).
(closeReadableStream): Updated based on new properties repartition between reader and controller.
(enqueueInReadableStream): Updated based on new properties repartition between reader and controller.
(readFromReadableStreamDefaultReader): Updated based on new properties repartition between reader and controller.
* bindings/js/WebCoreBuiltinNames.h: Added pull (internal function of ReadableStreamDefaultController)
and readableStreamController (defined by spec)</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsimportedw3cChangeLog">trunk/LayoutTests/imported/w3c/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsstreamsreadablestreamsgeneralhttpsexpectedtxt">trunk/LayoutTests/imported/w3c/web-platform-tests/streams/readable-streams/general.https-expected.txt</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreModulesfetchFetchResponsejs">trunk/Source/WebCore/Modules/fetch/FetchResponse.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="#trunkSourceWebCoreModulesstreamsReadableStreamInternalsjs">trunk/Source/WebCore/Modules/streams/ReadableStreamInternals.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="trunkLayoutTestsimportedw3cChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/ChangeLog (205288 => 205289)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/ChangeLog        2016-09-01 12:01:00 UTC (rev 205288)
+++ trunk/LayoutTests/imported/w3c/ChangeLog        2016-09-01 14:14:05 UTC (rev 205289)
</span><span class="lines">@@ -1,3 +1,16 @@
</span><ins>+2016-09-01  Romain Bellessort  &lt;romain.bellessort@crf.canon.fr&gt;
+
+        [Streams API] Align internal structure of ReadableStream with spec
+        https://bugs.webkit.org/show_bug.cgi?id=160299
+
+        Reviewed by Xabier Rodriguez-Calvar.
+
+        Aligned internal structure of ReadableStream with spec. Fixed one expectation
+        that was set to FAIL while it is now PASSing.
+
+        * web-platform-tests/streams/readable-streams/general.https-expected.txt:
+
+
</ins><span class="cx"> 2016-08-31  Youenn Fablet  &lt;youenn@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [Fetch API] Fetch API should be able to load data URL in Same Origin mode
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsstreamsreadablestreamsgeneralhttpsexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/streams/readable-streams/general.https-expected.txt (205288 => 205289)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/streams/readable-streams/general.https-expected.txt        2016-09-01 12:01:00 UTC (rev 205288)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/streams/readable-streams/general.https-expected.txt        2016-09-01 14:14:05 UTC (rev 205289)
</span><span class="lines">@@ -1,7 +1,7 @@
</span><span class="cx"> 
</span><span class="cx"> PASS ReadableStream can be constructed with no errors 
</span><span class="cx"> PASS ReadableStream can't be constructed with garbage 
</span><del>-FAIL ReadableStream can't be constructed with an invalid type assert_throws: constructor should throw when the type is null function &quot;() =&gt; new ReadableStream({ type: null })&quot; did not throw
</del><ins>+PASS ReadableStream can't be constructed with an invalid type 
</ins><span class="cx"> FAIL ReadableStream instances should have the correct list of properties assert_equals: getReader should have no parameters expected 0 but got 1
</span><span class="cx"> PASS ReadableStream constructor should throw for non-function start arguments 
</span><span class="cx"> PASS ReadableStream constructor can get initial garbage as cancel argument 
</span><span class="lines">@@ -38,7 +38,7 @@
</span><span class="cx"> FAIL Untitled undefined is not an object (evaluating 'navigator.serviceWorker.getRegistration')
</span><span class="cx"> PASS ReadableStream can be constructed with no errors 
</span><span class="cx"> PASS ReadableStream can't be constructed with garbage 
</span><del>-FAIL ReadableStream can't be constructed with an invalid type assert_throws: constructor should throw when the type is null function &quot;() =&gt; new ReadableStream({ type: null })&quot; did not throw
</del><ins>+PASS ReadableStream can't be constructed with an invalid type 
</ins><span class="cx"> FAIL ReadableStream instances should have the correct list of properties assert_equals: getReader should have no parameters expected 0 but got 1
</span><span class="cx"> PASS ReadableStream constructor should throw for non-function start arguments 
</span><span class="cx"> PASS ReadableStream constructor can get initial garbage as cancel argument 
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (205288 => 205289)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-09-01 12:01:00 UTC (rev 205288)
+++ trunk/Source/WebCore/ChangeLog        2016-09-01 14:14:05 UTC (rev 205289)
</span><span class="lines">@@ -1,3 +1,60 @@
</span><ins>+2016-09-01  Romain Bellessort  &lt;romain.bellessort@crf.canon.fr&gt;
+
+        [Streams API] Align internal structure of ReadableStream with spec
+        https://bugs.webkit.org/show_bug.cgi?id=160299
+
+        Reviewed by Xabier Rodriguez-Calvar.
+
+        Aligned internal structure of ReadableStream with spec. Various
+        internal properties have been moved to ReadableStreamDefaultController.
+        In addition, various behaviors had to be updated. Several other changes
+        will have to be performed in order to align with spec, e.g. changing
+        functions names. This patch does not change them in order to make the
+        structural changes easier to follow.
+
+        No change in functionality except support for 1 specific case where
+        an error was not thrown while it should have been. Changed corresponding
+        test expectation (now PASS instead of FAIL).
+        Modified test expectation: web-platform-tests/streams/readable-streams/general.https-expected.txt
+
+        * Modules/fetch/FetchResponse.js:
+        (initializeFetchResponse): Replaced reference to underlyingSource as no
+        more a property of readableStream (use readableStreamController instead,
+        as defined by spec).
+        * Modules/streams/ReadableStream.js:
+        (initializeReadableStream): Removed various properties now hanlded by
+        ReadableStreamDefaultController.
+        * Modules/streams/ReadableStreamDefaultController.js:
+        (enqueue): Updated based on new properties repartition between reader and controller. 
+        (error): Updated based on new properties repartition between reader and controller. 
+        (close): Updated based on new properties repartition between reader and controller. 
+        (desiredSize): Updated based on new properties repartition between reader and controller. 
+        * Modules/streams/ReadableStreamInternals.js:
+        (privateInitializeReadableStreamDefaultController): Added various properties now handled by
+        ReadableStreamDefaultController, as well as an internal pull function defined by spec.
+        (readableStreamDefaultControllerError): Added based on spec (error handling at controller level).
+        (teeReadableStream): Fixed typo and use readableStreamDefaultControllerError instead of errorReadableStream.
+        (doStructuredClone): Added &quot;use strict&quot;;.
+        (teeReadableStreamPullFunction): Use readableStreamDefaultControllerClose instead of closeReadableStream.
+        (isReadableStream): Replaced check of underlyingSource by check that object is actually an instance of
+        ReadableStream (spec requires checking that readableStreamController slot is present, but this cannot
+        be checked).
+        (isReadableStreamDefaultReader): Replaced check of ownerReadableStream presence by check of readRequests,
+        in line with spec.
+        (isReadableStreamDefaultController): Replaced check of controlledReadableStream presence by check of unerlyingSource,
+        in line with spec.
+        (errorReadableStream): Updated based on new properties repartition between reader and controller.
+        (requestReadableStreamPull): Updated based on new properties repartition between reader and controller.
+        (readableStreamDefaultControllerGetDesiredSize): Replaces getReadableStreamDesiredSize (size now depends
+        on controller; new function name aligned with spec).
+        (cancelReadableStream): Updated based on new properties repartition between reader and controller. 
+        (readableStreamDefaultControllerClose): Added based on spec (closing controller).
+        (closeReadableStream): Updated based on new properties repartition between reader and controller. 
+        (enqueueInReadableStream): Updated based on new properties repartition between reader and controller. 
+        (readFromReadableStreamDefaultReader): Updated based on new properties repartition between reader and controller. 
+        * bindings/js/WebCoreBuiltinNames.h: Added pull (internal function of ReadableStreamDefaultController)
+        and readableStreamController (defined by spec)
+
</ins><span class="cx"> 2016-09-01  Csaba Osztrogonác  &lt;ossy@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         Unreviewed, fix the !ENABLE(SVG_FONTS) and !ENABLE(XSLT) build after r205269.
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesfetchFetchResponsejs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/fetch/FetchResponse.js (205288 => 205289)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/fetch/FetchResponse.js        2016-09-01 12:01:00 UTC (rev 205288)
+++ trunk/Source/WebCore/Modules/fetch/FetchResponse.js        2016-09-01 14:14:05 UTC (rev 205289)
</span><span class="lines">@@ -50,7 +50,7 @@
</span><span class="cx">             throw new @TypeError(&quot;Response cannot have a body with the given status&quot;);
</span><span class="cx"> 
</span><span class="cx">         // FIXME: Use @isReadableStream once it is no longer guarded by STREAMS_API guard.
</span><del>-        let isBodyReadableStream = (@isObject(body) &amp;&amp; !!body.@underlyingSource);
</del><ins>+        let isBodyReadableStream = (@isObject(body) &amp;&amp; !!body.@readableStreamController);
</ins><span class="cx">         if (isBodyReadableStream)
</span><span class="cx">           this.@body = body;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesstreamsReadableStreamjs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/streams/ReadableStream.js (205288 => 205289)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/streams/ReadableStream.js        2016-09-01 12:01:00 UTC (rev 205288)
+++ trunk/Source/WebCore/Modules/streams/ReadableStream.js        2016-09-01 14:14:05 UTC (rev 205289)
</span><span class="lines">@@ -41,28 +41,26 @@
</span><span class="cx">     if (strategy !== @undefined &amp;&amp; !@isObject(strategy))
</span><span class="cx">         throw new @TypeError(&quot;ReadableStream constructor takes an object as second argument, if any&quot;);
</span><span class="cx"> 
</span><del>-    this.@underlyingSource = underlyingSource;
-
-    this.@queue = @newQueue();
</del><span class="cx">     this.@state = @streamReadable;
</span><del>-    this.@started = false;
-    this.@closeRequested = false;
-    this.@pullAgain = false;
-    this.@pulling = false;
</del><span class="cx">     this.@reader = @undefined;
</span><span class="cx">     this.@storedError = @undefined;
</span><span class="cx">     this.@disturbed = false;
</span><del>-    this.@controller = new @ReadableStreamDefaultController(this);
-    this.@strategy = @validateAndNormalizeQueuingStrategy(strategy.size, strategy.highWaterMark);
</del><ins>+    // Initialized with null value to enable distinction with undefined case.
+    this.@readableStreamController = null;
</ins><span class="cx"> 
</span><del>-    @promiseInvokeOrNoopNoCatch(underlyingSource, &quot;start&quot;, [this.@controller]).@then(() =&gt; {
-        this.@started = true;
-        @requestReadableStreamPull(this);
-    }, (error) =&gt; {
-        if (this.@state === @streamReadable)
-            @errorReadableStream(this, error);
-    });
</del><ins>+    const type = underlyingSource.type;
+    const typeString = @String(type);
</ins><span class="cx"> 
</span><ins>+    if (typeString === &quot;bytes&quot;) {
+         // FIXME: Implement support of ReadableByteStreamController.
+        throw new @TypeError(&quot;ReadableByteStreamController is not implemented&quot;);
+    } else if (type === @undefined) {
+        if (strategy.highWaterMark === @undefined)
+            strategy.highWaterMark = 1;
+        this.@readableStreamController = new @ReadableStreamDefaultController(this, underlyingSource, strategy.size, strategy.highWaterMark);
+    } else
+        throw new @RangeError(&quot;Invalid type for underlying source&quot;);
+
</ins><span class="cx">     return this;
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesstreamsReadableStreamDefaultControllerjs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/streams/ReadableStreamDefaultController.js (205288 => 205289)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/streams/ReadableStreamDefaultController.js        2016-09-01 12:01:00 UTC (rev 205288)
+++ trunk/Source/WebCore/Modules/streams/ReadableStreamDefaultController.js        2016-09-01 14:14:05 UTC (rev 205289)
</span><span class="lines">@@ -32,15 +32,13 @@
</span><span class="cx">     if (!@isReadableStreamDefaultController(this))
</span><span class="cx">         throw @makeThisTypeError(&quot;ReadableStreamDefaultController&quot;, &quot;enqueue&quot;);
</span><span class="cx"> 
</span><del>-    const stream = this.@controlledReadableStream;
</del><ins>+    if (this.@closeRequested)
+        throw new @TypeError(&quot;ReadableStreamDefaultController is requested to close&quot;);
</ins><span class="cx"> 
</span><del>-    if (stream.@closeRequested)
-        throw new @TypeError(&quot;ReadableStream is requested to close&quot;);
-
-    if (stream.@state !== @streamReadable)
</del><ins>+    if (this.@controlledReadableStream.@state !== @streamReadable)
</ins><span class="cx">         throw new @TypeError(&quot;ReadableStream is not readable&quot;);
</span><span class="cx"> 
</span><del>-    return @enqueueInReadableStream(stream, chunk);
</del><ins>+    return @enqueueInReadableStream(this, chunk);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> function error(error)
</span><span class="lines">@@ -64,14 +62,13 @@
</span><span class="cx">     if (!@isReadableStreamDefaultController(this))
</span><span class="cx">         throw @makeThisTypeError(&quot;ReadableStreamDefaultController&quot;, &quot;close&quot;);
</span><span class="cx"> 
</span><del>-    const stream = this.@controlledReadableStream;
-    if (stream.@closeRequested)
-        throw new @TypeError(&quot;ReadableStream is already requested to close&quot;);
</del><ins>+    if (this.@closeRequested)
+        throw new @TypeError(&quot;ReadableStreamDefaultController is already requested to close&quot;);
</ins><span class="cx"> 
</span><del>-    if (stream.@state !== @streamReadable)
</del><ins>+    if (this.@controlledReadableStream.@state !== @streamReadable)
</ins><span class="cx">         throw new @TypeError(&quot;ReadableStream is not readable&quot;);
</span><span class="cx"> 
</span><del>-    @closeReadableStream(stream);
</del><ins>+    @readableStreamDefaultControllerClose(this);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> function desiredSize()
</span><span class="lines">@@ -81,5 +78,6 @@
</span><span class="cx">     if (!@isReadableStreamDefaultController(this))
</span><span class="cx">         throw @makeGetterTypeError(&quot;ReadableStreamDefaultController&quot;, &quot;desiredSize&quot;);
</span><span class="cx"> 
</span><del>-    return @getReadableStreamDesiredSize(this.@controlledReadableStream);
</del><ins>+    return @readableStreamDefaultControllerGetDesiredSize(this);
</ins><span class="cx"> }
</span><ins>+
</ins></span></pre></div>
<a id="trunkSourceWebCoreModulesstreamsReadableStreamInternalsjs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/streams/ReadableStreamInternals.js (205288 => 205289)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/streams/ReadableStreamInternals.js        2016-09-01 12:01:00 UTC (rev 205288)
+++ trunk/Source/WebCore/Modules/streams/ReadableStreamInternals.js        2016-09-01 14:14:05 UTC (rev 205289)
</span><span class="lines">@@ -53,19 +53,65 @@
</span><span class="cx">     return this;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-function privateInitializeReadableStreamDefaultController(stream)
</del><ins>+function privateInitializeReadableStreamDefaultController(stream, underlyingSource, size, highWaterMark)
</ins><span class="cx"> {
</span><span class="cx">     &quot;use strict&quot;;
</span><span class="cx"> 
</span><span class="cx">     if (!@isReadableStream(stream))
</span><span class="cx">         throw new @TypeError(&quot;ReadableStreamDefaultController needs a ReadableStream&quot;);
</span><del>-    if (stream.@controller !== @undefined)
</del><ins>+
+    // readableStreamController is initialized with null value.
+    if (stream.@readableStreamController !== null)
</ins><span class="cx">         throw new @TypeError(&quot;ReadableStream already has a controller&quot;);
</span><ins>+
</ins><span class="cx">     this.@controlledReadableStream = stream;
</span><ins>+    this.@underlyingSource = underlyingSource;
+    this.@queue = @newQueue();
+    this.@started = false;
+    this.@closeRequested = false;
+    this.@pullAgain = false;
+    this.@pulling = false;
+    this.@strategy = @validateAndNormalizeQueuingStrategy(size, highWaterMark);
</ins><span class="cx"> 
</span><ins>+    const controller = this;
+    const startResult = @promiseInvokeOrNoopNoCatch(underlyingSource, &quot;start&quot;, [this]).@then(() =&gt; {
+        controller.@started = true;
+        @requestReadableStreamPull(controller);
+    }, (error) =&gt; {
+        if (stream.@state === @streamReadable)
+            @readableStreamDefaultControllerError(controller, error);
+    });
+
+    this.@pull = function() {
+        &quot;use strict&quot;;
+
+        const stream = controller.@controlledReadableStream;
+        if (controller.@queue.content.length) {
+            const chunk = @dequeueValue(controller.@queue);
+            if (controller.@closeRequested &amp;&amp; controller.@queue.content.length === 0)
+                @closeReadableStream(stream);
+            else
+                @requestReadableStreamPull(controller);
+            return @Promise.@resolve({value: chunk, done: false});
+        }
+        const pendingPromise = @readableStreamAddReadRequest(stream);
+        @requestReadableStreamPull(controller);
+        return pendingPromise;
+    }
+
</ins><span class="cx">     return this;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+function readableStreamDefaultControllerError(controller, error)
+{
+    &quot;use strict&quot;;
+
+    const stream = controller.@controlledReadableStream;
+    @assert(stream.@state === @streamReadable);
+    controller.@queue = @newQueue();
+    @errorReadableStream(stream, error);
+}
+
</ins><span class="cx"> function teeReadableStream(stream, shouldClone)
</span><span class="cx"> {
</span><span class="cx">     &quot;use strict&quot;;
</span><span class="lines">@@ -80,7 +126,7 @@
</span><span class="cx">         canceled1: false,
</span><span class="cx">         canceled2: false,
</span><span class="cx">         reason1: @undefined,
</span><del>-        reason: @undefined,
</del><ins>+        reason2: @undefined,
</ins><span class="cx">     };
</span><span class="cx"> 
</span><span class="cx">     teeState.cancelPromiseCapability = @newPromiseCapability(@InternalPromise);
</span><span class="lines">@@ -99,8 +145,8 @@
</span><span class="cx">     reader.@closedPromiseCapability.@promise.@then(@undefined, function(e) {
</span><span class="cx">         if (teeState.closedOrErrored)
</span><span class="cx">             return;
</span><del>-        @errorReadableStream(branch1, e);
-        @errorReadableStream(branch2, e);
</del><ins>+        @readableStreamDefaultControllerError(branch1.@readableStreamController, e);
+        @readableStreamDefaultControllerError(branch2.@readableStreamController, e);
</ins><span class="cx">         teeState.closedOrErrored = true;
</span><span class="cx">     });
</span><span class="cx"> 
</span><span class="lines">@@ -113,6 +159,8 @@
</span><span class="cx"> 
</span><span class="cx"> function doStructuredClone(object)
</span><span class="cx"> {
</span><ins>+    &quot;use strict&quot;;
+
</ins><span class="cx">     // FIXME: We should implement http://w3c.github.io/html/infrastructure.html#ref-for-structured-clone-4
</span><span class="cx">     // Implementation is currently limited to ArrayBuffer/ArrayBufferView to meet Fetch API needs.
</span><span class="cx"> 
</span><span class="lines">@@ -134,16 +182,18 @@
</span><span class="cx">             @assert(@isObject(result));
</span><span class="cx">             @assert(typeof result.done === &quot;boolean&quot;);
</span><span class="cx">             if (result.done &amp;&amp; !teeState.closedOrErrored) {
</span><del>-                @closeReadableStream(teeState.branch1);
-                @closeReadableStream(teeState.branch2);
</del><ins>+                if (!teeState.canceled1)
+                    @readableStreamDefaultControllerClose(teeState.branch1.@readableStreamController);
+                if (!teeState.canceled2)
+                    @readableStreamDefaultControllerClose(teeState.branch2.@readableStreamController);
</ins><span class="cx">                 teeState.closedOrErrored = true;
</span><span class="cx">             }
</span><span class="cx">             if (teeState.closedOrErrored)
</span><span class="cx">                 return;
</span><span class="cx">             if (!teeState.canceled1)
</span><del>-                @enqueueInReadableStream(teeState.branch1, shouldClone ? @doStructuredClone(result.value) : result.value);
</del><ins>+                @enqueueInReadableStream(teeState.branch1.@readableStreamController, shouldClone ? @doStructuredClone(result.value) : result.value);
</ins><span class="cx">             if (!teeState.canceled2)
</span><del>-                @enqueueInReadableStream(teeState.branch2, shouldClone ? @doStructuredClone(result.value) : result.value);
</del><ins>+                @enqueueInReadableStream(teeState.branch2.@readableStreamController, shouldClone ? @doStructuredClone(result.value) : result.value);
</ins><span class="cx">         });
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="lines">@@ -184,7 +234,10 @@
</span><span class="cx"> {
</span><span class="cx">     &quot;use strict&quot;;
</span><span class="cx"> 
</span><del>-    return @isObject(stream) &amp;&amp; !!stream.@underlyingSource;
</del><ins>+    // Spec tells to return true only if stream has a readableStreamController internal slot.
+    // However, since it is a private slot, it cannot be checked using hasOwnProperty().
+    // Therefore, readableStreamController is initialized with null value.
+    return @isObject(stream) &amp;&amp; stream.@readableStreamController !== @undefined;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> function isReadableStreamDefaultReader(reader)
</span><span class="lines">@@ -191,9 +244,10 @@
</span><span class="cx"> {
</span><span class="cx">     &quot;use strict&quot;;
</span><span class="cx"> 
</span><del>-    // To reset @ownerReadableStream it must be set to null instead of undefined because there is no way to distinguish
-    // between a non-existent slot and an slot set to undefined.
-    return @isObject(reader) &amp;&amp; reader.@ownerReadableStream !== @undefined;
</del><ins>+    // Spec tells to return true only if reader has a readRequests internal slot.
+    // However, since it is a private slot, it cannot be checked using hasOwnProperty().
+    // Since readRequests is initialized with an empty array, the following test is ok.
+    return @isObject(reader) &amp;&amp; !!reader.@readRequests;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> function isReadableStreamDefaultController(controller)
</span><span class="lines">@@ -200,7 +254,11 @@
</span><span class="cx"> {
</span><span class="cx">     &quot;use strict&quot;;
</span><span class="cx"> 
</span><del>-    return @isObject(controller) &amp;&amp; !!controller.@controlledReadableStream;
</del><ins>+    // Spec tells to return true only if controller has an underlyingSource internal slot.
+    // However, since it is a private slot, it cannot be checked using hasOwnProperty().
+    // underlyingSource is obtained in ReadableStream constructor: if undefined, it is set
+    // to an empty object. Therefore, following test is ok.
+    return @isObject(controller) &amp;&amp; !!controller.@underlyingSource;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> function errorReadableStream(stream, error)
</span><span class="lines">@@ -207,52 +265,59 @@
</span><span class="cx"> {
</span><span class="cx">     &quot;use strict&quot;;
</span><span class="cx"> 
</span><ins>+    @assert(@isReadableStream(stream));
</ins><span class="cx">     @assert(stream.@state === @streamReadable);
</span><del>-    stream.@queue = @newQueue();
</del><ins>+    stream.@state = @streamErrored;
</ins><span class="cx">     stream.@storedError = error;
</span><del>-    stream.@state = @streamErrored;
</del><span class="cx"> 
</span><span class="cx">     if (!stream.@reader)
</span><span class="cx">         return;
</span><ins>+
</ins><span class="cx">     const reader = stream.@reader;
</span><span class="cx"> 
</span><del>-    const requests = reader.@readRequests;
-    for (let index = 0, length = requests.length; index &lt; length; ++index)
-        requests[index].@reject.@call(@undefined, error);
-    reader.@readRequests = [];
</del><ins>+    if (@isReadableStreamDefaultReader(reader)) {
+        const requests = reader.@readRequests;
+        for (let index = 0, length = requests.length; index &lt; length; ++index)
+            requests[index].@reject.@call(@undefined, error);
+        reader.@readRequests = [];
+    } else
+        // FIXME: Implement ReadableStreamBYOBReader.
+        throw new @TypeError(&quot;Only ReadableStreamDefaultReader is currently supported&quot;);
</ins><span class="cx"> 
</span><span class="cx">     reader.@closedPromiseCapability.@reject.@call(@undefined, error);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-function requestReadableStreamPull(stream)
</del><ins>+function requestReadableStreamPull(controller)
</ins><span class="cx"> {
</span><span class="cx">     &quot;use strict&quot;;
</span><span class="cx"> 
</span><ins>+    const stream = controller.@controlledReadableStream;
+
</ins><span class="cx">     if (stream.@state === @streamClosed || stream.@state === @streamErrored)
</span><span class="cx">         return;
</span><del>-    if (stream.@closeRequested)
</del><ins>+    if (controller.@closeRequested)
</ins><span class="cx">         return;
</span><del>-    if (!stream.@started)
</del><ins>+    if (!controller.@started)
</ins><span class="cx">         return;
</span><del>-    if ((!@isReadableStreamLocked(stream) || !stream.@reader.@readRequests.length) &amp;&amp; @getReadableStreamDesiredSize(stream) &lt;= 0)
</del><ins>+    if ((!@isReadableStreamLocked(stream) || !stream.@reader.@readRequests.length) &amp;&amp; @readableStreamDefaultControllerGetDesiredSize(controller) &lt;= 0)
</ins><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    if (stream.@pulling) {
-        stream.@pullAgain = true;
</del><ins>+    if (controller.@pulling) {
+        controller.@pullAgain = true;
</ins><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    stream.@pulling = true;
</del><ins>+    controller.@pulling = true;
</ins><span class="cx"> 
</span><del>-    @promiseInvokeOrNoop(stream.@underlyingSource, &quot;pull&quot;, [stream.@controller]).@then(function() {
-        stream.@pulling = false;
-        if (stream.@pullAgain) {
-            stream.@pullAgain = false;
-            @requestReadableStreamPull(stream);
</del><ins>+    @promiseInvokeOrNoop(controller.@underlyingSource, &quot;pull&quot;, [controller]).@then(function() {
+        controller.@pulling = false;
+        if (controller.@pullAgain) {
+            controller.@pullAgain = false;
+            @requestReadableStreamPull(controller);
</ins><span class="cx">         }
</span><span class="cx">     }, function(error) {
</span><span class="cx">         if (stream.@state === @streamReadable)
</span><del>-            @errorReadableStream(stream, error);
</del><ins>+            @readableStreamDefaultControllerError(controller, error);
</ins><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -264,11 +329,11 @@
</span><span class="cx">     return !!stream.@reader;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-function getReadableStreamDesiredSize(stream)
</del><ins>+function readableStreamDefaultControllerGetDesiredSize(controller)
</ins><span class="cx"> {
</span><span class="cx">    &quot;use strict&quot;;
</span><span class="cx"> 
</span><del>-   return stream.@strategy.highWaterMark - stream.@queue.size;
</del><ins>+   return controller.@strategy.highWaterMark - controller.@queue.size;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> function cancelReadableStream(stream, reason)
</span><span class="lines">@@ -280,69 +345,78 @@
</span><span class="cx">         return @Promise.@resolve();
</span><span class="cx">     if (stream.@state === @streamErrored)
</span><span class="cx">         return @Promise.@reject(stream.@storedError);
</span><del>-    stream.@queue = @newQueue();
-    @finishClosingReadableStream(stream);
-    return @promiseInvokeOrNoop(stream.@underlyingSource, &quot;cancel&quot;, [reason]).@then(function() { });
</del><ins>+    @closeReadableStream(stream);
+    // FIXME: Fix below, which is a temporary solution to the case where controller is undefined.
+    // This issue is due to the fact that in previous version of the spec, cancel was associated
+    // to underlyingSource, whereas in new version it is associated to controller. As this patch
+    // does not yet fully implement the new version, this solution is used.
+    const controller = stream.@readableStreamController;
+    var underlyingSource = @undefined;
+    if (controller !== @undefined)
+        underlyingSource = controller.@underlyingSource;
+    return @promiseInvokeOrNoop(underlyingSource, &quot;cancel&quot;, [reason]).@then(function() { });
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-function finishClosingReadableStream(stream)
</del><ins>+
+function readableStreamDefaultControllerClose(controller)
</ins><span class="cx"> {
</span><span class="cx">     &quot;use strict&quot;;
</span><span class="cx"> 
</span><ins>+    const stream = controller.@controlledReadableStream;
+    @assert(!controller.@closeRequested);
</ins><span class="cx">     @assert(stream.@state === @streamReadable);
</span><ins>+    controller.@closeRequested = true;
+    if (controller.@queue.content.length === 0)
+        @closeReadableStream(stream);
+}
+
+function closeReadableStream(stream)
+{
+    &quot;use strict&quot;;
+
+    @assert(stream.@state === @streamReadable);
</ins><span class="cx">     stream.@state = @streamClosed;
</span><span class="cx">     const reader = stream.@reader;
</span><ins>+
</ins><span class="cx">     if (!reader)
</span><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    const requests = reader.@readRequests;
-    for (let index = 0, length = requests.length; index &lt; length; ++index)
-        requests[index].@resolve.@call(@undefined, {value:@undefined, done: true});
-    reader.@readRequests = [];
</del><ins>+    if (@isReadableStreamDefaultReader(reader)) {
+        const requests = reader.@readRequests;
+        for (let index = 0, length = requests.length; index &lt; length; ++index)
+            requests[index].@resolve.@call(@undefined, {value:@undefined, done: true});
+        reader.@readRequests = [];
+    }
+
</ins><span class="cx">     reader.@closedPromiseCapability.@resolve.@call();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-function closeReadableStream(stream)
</del><ins>+function enqueueInReadableStream(controller, chunk)
</ins><span class="cx"> {
</span><span class="cx">     &quot;use strict&quot;;
</span><span class="cx"> 
</span><del>-    @assert(!stream.@closeRequested);
-    @assert(stream.@state !== @streamErrored);
-    if (stream.@state === @streamClosed)
-        return;
-    stream.@closeRequested = true;
-    if (!stream.@queue.content.length)
-        @finishClosingReadableStream(stream);
-}
</del><ins>+    const stream = controller.@controlledReadableStream;
+    @assert(!controller.@closeRequested);
+    @assert(stream.@state === @streamReadable);
</ins><span class="cx"> 
</span><del>-function enqueueInReadableStream(stream, chunk)
-{
-    &quot;use strict&quot;;
-
-    @assert(!stream.@closeRequested);
-    @assert(stream.@state !== @streamErrored);
-    if (stream.@state === @streamClosed)
-        return;
</del><span class="cx">     if (@isReadableStreamLocked(stream) &amp;&amp; stream.@reader.@readRequests.length) {
</span><span class="cx">         stream.@reader.@readRequests.@shift().@resolve.@call(@undefined, {value: chunk, done: false});
</span><del>-        @requestReadableStreamPull(stream);
</del><ins>+        @requestReadableStreamPull(controller);
</ins><span class="cx">         return;
</span><span class="cx">     }
</span><ins>+
</ins><span class="cx">     try {
</span><del>-        let size = 1;
-        if (stream.@strategy.size) {
-            size = @Number(stream.@strategy.size(chunk));
-            if (!@isFinite(size) || size &lt; 0)
-                throw new @RangeError(&quot;Chunk size is not valid&quot;);
-        }
-        @enqueueValueWithSize(stream.@queue, chunk, size);
</del><ins>+        let chunkSize = 1;
+        if (controller.@strategy.size !== @undefined)
+            chunkSize = controller.@strategy.size(chunk);
+        @enqueueValueWithSize(controller.@queue, chunk, chunkSize);
</ins><span class="cx">     }
</span><span class="cx">     catch(error) {
</span><span class="cx">         if (stream.@state === @streamReadable)
</span><del>-            @errorReadableStream(stream, error);
</del><ins>+            @readableStreamDefaultControllerError(controller, error);
</ins><span class="cx">         throw error;
</span><span class="cx">     }
</span><del>-    @requestReadableStreamPull(stream);
</del><ins>+    @requestReadableStreamPull(controller);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> function readFromReadableStreamDefaultReader(reader)
</span><span class="lines">@@ -353,8 +427,8 @@
</span><span class="cx">     @assert(!!stream);
</span><span class="cx"> 
</span><span class="cx">     // Native sources may want to start enqueueing at the time of the first read request.
</span><del>-    if (!stream.@disturbed &amp;&amp; stream.@state === @streamReadable &amp;&amp; stream.@underlyingSource.@firstReadCallback)
-        stream.@underlyingSource.@firstReadCallback();
</del><ins>+    if (!stream.@disturbed &amp;&amp; stream.@state === @streamReadable &amp;&amp; stream.@readableStreamController.@underlyingSource.@firstReadCallback)
+        stream.@readableStreamController.@underlyingSource.@firstReadCallback();
</ins><span class="cx"> 
</span><span class="cx">     stream.@disturbed = true;
</span><span class="cx">     if (stream.@state === @streamClosed)
</span><span class="lines">@@ -362,20 +436,23 @@
</span><span class="cx">     if (stream.@state === @streamErrored)
</span><span class="cx">         return @Promise.@reject(stream.@storedError);
</span><span class="cx">     @assert(stream.@state === @streamReadable);
</span><del>-    if (stream.@queue.content.length) {
-        const chunk = @dequeueValue(stream.@queue);
-        if (stream.@closeRequested &amp;&amp; stream.@queue.content.length === 0)
-            @finishClosingReadableStream(stream);
-        else
-            @requestReadableStreamPull(stream);
-        return @Promise.@resolve({value: chunk, done: false});
-    }
-    const readPromiseCapability = @newPromiseCapability(@Promise);
-    reader.@readRequests.@push(readPromiseCapability);
-    @requestReadableStreamPull(stream);
-    return readPromiseCapability.@promise;
</del><ins>+
+    return stream.@readableStreamController.@pull();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+function readableStreamAddReadRequest(stream)
+{
+    &quot;use strict&quot;;
+
+    @assert(@isReadableStreamDefaultReader(stream.@reader));
+    @assert(stream.@state == @streamReadable);
+
+    const readRequest = @newPromiseCapability(@Promise);
+    stream.@reader.@readRequests.@push(readRequest);
+
+    return readRequest.@promise;
+}
+
</ins><span class="cx"> function isReadableStreamDisturbed(stream)
</span><span class="cx"> {
</span><span class="cx">     &quot;use strict&quot;;
</span></span></pre></div>
<a id="trunkSourceWebCorebindingsjsWebCoreBuiltinNamesh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h (205288 => 205289)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h        2016-09-01 12:01:00 UTC (rev 205288)
+++ trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h        2016-09-01 14:14:05 UTC (rev 205289)
</span><span class="lines">@@ -61,6 +61,7 @@
</span><span class="cx">     macro(operations) \
</span><span class="cx">     macro(ownerReadableStream) \
</span><span class="cx">     macro(privateGetStats) \
</span><ins>+    macro(pull) \
</ins><span class="cx">     macro(pulling) \
</span><span class="cx">     macro(pullAgain) \
</span><span class="cx">     macro(queue) \
</span><span class="lines">@@ -71,6 +72,7 @@
</span><span class="cx">     macro(queuedSetRemoteDescription) \
</span><span class="cx">     macro(reader) \
</span><span class="cx">     macro(readRequests) \
</span><ins>+    macro(readableStreamController) \
</ins><span class="cx">     macro(readyPromiseCapability) \
</span><span class="cx">     macro(removeTrack) \
</span><span class="cx">     macro(responseCacheIsValid) \
</span></span></pre>
</div>
</div>

</body>
</html>