<!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>[185872] 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/185872">185872</a></dd>
<dt>Author</dt> <dd>youenn.fablet@crf.canon.fr</dd>
<dt>Date</dt> <dd>2015-06-23 04:29:32 -0700 (Tue, 23 Jun 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>[Streams API] Implement ReadableStream js source &quot;'cancel&quot; callback
https://bugs.webkit.org/show_bug.cgi?id=146204

Reviewed by Darin Adler.

Source/WebCore:

Calling &quot;cancel&quot; JS function when web app is cancelling a JS readable stream.
Handling of promise returned value in case of async cancel.

Covered by rebased tests.

* bindings/js/ReadableJSStream.cpp:
(WebCore::ReadableJSStream::invoke): Refactoring to pass cancel reason or controller to the JS function.
(WebCore::ReadableJSStream::doStart): Ditto.
(WebCore::startReadableStreamAsync): Renaming readableStream as protectedStream.
(WebCore::createPullResultFulfilledFunction): Ditto.
(WebCore::ReadableJSStream::doPull): Refactoring to pass cancel reason or controller to the JS function.
(WebCore::createCancelResultFulfilledFunction): Cancel promise fullfil callback.
(WebCore::createCancelResultRejectedFunction): Cancel promise reject callback.
(WebCore::ReadableJSStream::doCancel): Calling cancel JS callback and handling promise returned value.
* bindings/js/ReadableJSStream.h: Refactoring to pass cancel reason or controller to the JS function.

LayoutTests:

* streams/reference-implementation/bad-underlying-sources-expected.txt:
* streams/reference-implementation/readable-stream-cancel-expected.txt:
* streams/reference-implementation/readable-stream-expected.txt:
* streams/reference-implementation/readable-stream-reader-expected.txt:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsstreamsreferenceimplementationbadunderlyingsourcesexpectedtxt">trunk/LayoutTests/streams/reference-implementation/bad-underlying-sources-expected.txt</a></li>
<li><a href="#trunkLayoutTestsstreamsreferenceimplementationreadablestreamcancelexpectedtxt">trunk/LayoutTests/streams/reference-implementation/readable-stream-cancel-expected.txt</a></li>
<li><a href="#trunkLayoutTestsstreamsreferenceimplementationreadablestreamexpectedtxt">trunk/LayoutTests/streams/reference-implementation/readable-stream-expected.txt</a></li>
<li><a href="#trunkLayoutTestsstreamsreferenceimplementationreadablestreamreaderexpectedtxt">trunk/LayoutTests/streams/reference-implementation/readable-stream-reader-expected.txt</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorebindingsjsReadableJSStreamcpp">trunk/Source/WebCore/bindings/js/ReadableJSStream.cpp</a></li>
<li><a href="#trunkSourceWebCorebindingsjsReadableJSStreamh">trunk/Source/WebCore/bindings/js/ReadableJSStream.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (185871 => 185872)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2015-06-23 10:45:29 UTC (rev 185871)
+++ trunk/LayoutTests/ChangeLog        2015-06-23 11:29:32 UTC (rev 185872)
</span><span class="lines">@@ -1,3 +1,15 @@
</span><ins>+2015-06-23  Xabier Rodriguez Calvar  &lt;calvaris@igalia.com&gt; and Youenn Fablet  &lt;youenn.fablet@crf.canon.fr&gt;
+
+        [Streams API] Implement ReadableStream js source &quot;'cancel&quot; callback
+        https://bugs.webkit.org/show_bug.cgi?id=146204
+
+        Reviewed by Darin Adler.
+
+        * streams/reference-implementation/bad-underlying-sources-expected.txt:
+        * streams/reference-implementation/readable-stream-cancel-expected.txt:
+        * streams/reference-implementation/readable-stream-expected.txt:
+        * streams/reference-implementation/readable-stream-reader-expected.txt:
+
</ins><span class="cx"> 2015-06-23  Gyuyoung Kim  &lt;gyuyoung.kim@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         [EFL] Unreviewed, gardening.
</span></span></pre></div>
<a id="trunkLayoutTestsstreamsreferenceimplementationbadunderlyingsourcesexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/streams/reference-implementation/bad-underlying-sources-expected.txt (185871 => 185872)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/streams/reference-implementation/bad-underlying-sources-expected.txt        2015-06-23 10:45:29 UTC (rev 185871)
+++ trunk/LayoutTests/streams/reference-implementation/bad-underlying-sources-expected.txt        2015-06-23 11:29:32 UTC (rev 185872)
</span><span class="lines">@@ -5,8 +5,8 @@
</span><span class="cx"> PASS Underlying source: throwing pull method (initial pull) 
</span><span class="cx"> PASS Underlying source: throwing pull getter (second pull) 
</span><span class="cx"> PASS Underlying source: throwing pull method (second pull) 
</span><del>-FAIL Underlying source: throwing cancel getter assert_unreached: cancel should not fulfill Reached unreachable code
-FAIL Underlying source: throwing cancel method assert_unreached: cancel should not fulfill Reached unreachable code
</del><ins>+PASS Underlying source: throwing cancel getter 
+PASS Underlying source: throwing cancel method 
</ins><span class="cx"> PASS Underlying source: calling enqueue on an empty canceled stream should not throw 
</span><span class="cx"> PASS Underlying source: calling enqueue on a non-empty canceled stream should not throw 
</span><span class="cx"> PASS Underlying source: calling enqueue on a closed stream should throw 
</span></span></pre></div>
<a id="trunkLayoutTestsstreamsreferenceimplementationreadablestreamcancelexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/streams/reference-implementation/readable-stream-cancel-expected.txt (185871 => 185872)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/streams/reference-implementation/readable-stream-cancel-expected.txt        2015-06-23 10:45:29 UTC (rev 185871)
+++ trunk/LayoutTests/streams/reference-implementation/readable-stream-cancel-expected.txt        2015-06-23 11:29:32 UTC (rev 185872)
</span><span class="lines">@@ -1,12 +1,12 @@
</span><span class="cx"> 
</span><del>-FAIL ReadableStream cancellation: integration test on an infinite stream derived from a random push source assert_equals: it returns a promise that is fulfilled when the cancellation finishes expected true but got false
-FAIL ReadableStream cancellation: cancel(reason) should pass through the given reason to the underlying source assert_equals: the error passed to the underlying source's cancel method should equal the one passed to the stream's cancel expected (object) object &quot;Error: Sorry, it just wasn't meant to be.&quot; but got (undefined) undefined
</del><ins>+PASS ReadableStream cancellation: integration test on an infinite stream derived from a random push source 
+PASS ReadableStream cancellation: cancel(reason) should pass through the given reason to the underlying source 
</ins><span class="cx"> PASS ReadableStream cancellation: cancel() on a locked stream should fail and not call the underlying source cancel 
</span><del>-FAIL ReadableStream cancellation: should fulfill promise when cancel callback went fine assert_true: expected true got false
</del><ins>+PASS ReadableStream cancellation: should fulfill promise when cancel callback went fine 
</ins><span class="cx"> PASS ReadableStream cancellation: returning a value from the underlying source's cancel should not affect the fulfillment value of the promise returned by the stream's cancel 
</span><del>-FAIL ReadableStream cancellation: should reject promise when cancel callback raises an exception assert_unreached: cancel should reject Reached unreachable code
</del><ins>+PASS ReadableStream cancellation: should reject promise when cancel callback raises an exception 
</ins><span class="cx"> PASS ReadableStream cancellation: if the underlying source's cancel method returns a promise, the promise returned by the stream's cancel should fulfill when that one does (1) 
</span><del>-FAIL ReadableStream cancellation: if the underlying source's cancel method returns a promise, the promise returned by the stream's cancel should fulfill when that one does (2) assert_true: cancel() return value should be fulfilled only after the promise returned by the underlying source's cancel expected true got false
-FAIL ReadableStream cancellation: if the underlying source's cancel method returns a promise, the promise returned by the stream's cancel should reject when that one does assert_unreached: cancel() return value should not be rejected Reached unreachable code
</del><ins>+PASS ReadableStream cancellation: if the underlying source's cancel method returns a promise, the promise returned by the stream's cancel should fulfill when that one does (2) 
+PASS ReadableStream cancellation: if the underlying source's cancel method returns a promise, the promise returned by the stream's cancel should reject when that one does 
</ins><span class="cx"> PASS ReadableStream cancellation: cancelling before start finishes should prevent pull() from being called 
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkLayoutTestsstreamsreferenceimplementationreadablestreamexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/streams/reference-implementation/readable-stream-expected.txt (185871 => 185872)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/streams/reference-implementation/readable-stream-expected.txt        2015-06-23 10:45:29 UTC (rev 185871)
+++ trunk/LayoutTests/streams/reference-implementation/readable-stream-expected.txt        2015-06-23 11:29:32 UTC (rev 185872)
</span><span class="lines">@@ -25,7 +25,7 @@
</span><span class="cx"> PASS ReadableStream: enqueue should throw when the stream is readable but draining 
</span><span class="cx"> PASS ReadableStream: enqueue should throw when the stream is closed 
</span><span class="cx"> PASS ReadableStream: enqueue should throw the stored error when the stream is errored 
</span><del>-FAIL ReadableStream: should call underlying source methods as methods assert_equals: expected 1 but got 0
</del><ins>+PASS ReadableStream: should call underlying source methods as methods 
</ins><span class="cx"> FAIL ReadableStream strategies: the default strategy should give desiredSize of 1 to start, decreasing by 1 per enqueue assert_equals: expected (number) 1 but got (undefined) undefined
</span><span class="cx"> FAIL ReadableStream strategies: the default strategy should continue giving desiredSize of 1 if the chunks are read immediately assert_equals: desiredSize should start at 1 expected (number) 1 but got (undefined) undefined
</span><span class="cx"> PASS ReadableStream integration test: adapting a random push source 
</span></span></pre></div>
<a id="trunkLayoutTestsstreamsreferenceimplementationreadablestreamreaderexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/streams/reference-implementation/readable-stream-reader-expected.txt (185871 => 185872)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/streams/reference-implementation/readable-stream-reader-expected.txt        2015-06-23 10:45:29 UTC (rev 185871)
+++ trunk/LayoutTests/streams/reference-implementation/readable-stream-reader-expected.txt        2015-06-23 11:29:32 UTC (rev 185872)
</span><span class="lines">@@ -10,7 +10,7 @@
</span><span class="cx"> PASS Constructing a ReadableStreamReader directly should be OK if the stream is closed 
</span><span class="cx"> PASS Constructing a ReadableStreamReader directly should be OK if the stream is errored 
</span><span class="cx"> PASS Reading from a reader for an empty stream will wait until a chunk is available 
</span><del>-FAIL cancel() on a reader releases the reader before calling through assert_true: expected true got false
</del><ins>+PASS cancel() on a reader releases the reader before calling through 
</ins><span class="cx"> PASS closed should be fulfilled after stream is closed (.closed access before acquiring) 
</span><span class="cx"> PASS closed should be fulfilled after reader releases its lock (multiple stream locks) 
</span><span class="cx"> PASS Multiple readers can access the stream in sequence 
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (185871 => 185872)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2015-06-23 10:45:29 UTC (rev 185871)
+++ trunk/Source/WebCore/ChangeLog        2015-06-23 11:29:32 UTC (rev 185872)
</span><span class="lines">@@ -1,3 +1,26 @@
</span><ins>+2015-06-23  Xabier Rodriguez Calvar  &lt;calvaris@igalia.com&gt; and Youenn Fablet  &lt;youenn.fablet@crf.canon.fr&gt;
+
+        [Streams API] Implement ReadableStream js source &quot;'cancel&quot; callback
+        https://bugs.webkit.org/show_bug.cgi?id=146204
+
+        Reviewed by Darin Adler.
+
+        Calling &quot;cancel&quot; JS function when web app is cancelling a JS readable stream.
+        Handling of promise returned value in case of async cancel.
+
+        Covered by rebased tests.
+
+        * bindings/js/ReadableJSStream.cpp:
+        (WebCore::ReadableJSStream::invoke): Refactoring to pass cancel reason or controller to the JS function.
+        (WebCore::ReadableJSStream::doStart): Ditto.
+        (WebCore::startReadableStreamAsync): Renaming readableStream as protectedStream.
+        (WebCore::createPullResultFulfilledFunction): Ditto.
+        (WebCore::ReadableJSStream::doPull): Refactoring to pass cancel reason or controller to the JS function.
+        (WebCore::createCancelResultFulfilledFunction): Cancel promise fullfil callback.
+        (WebCore::createCancelResultRejectedFunction): Cancel promise reject callback.
+        (WebCore::ReadableJSStream::doCancel): Calling cancel JS callback and handling promise returned value.
+        * bindings/js/ReadableJSStream.h: Refactoring to pass cancel reason or controller to the JS function.
+
</ins><span class="cx"> 2015-06-22  Ryuan Choi  &lt;ryuan.choi@navercorp.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [EFL] Hyphenation is not supported
</span></span></pre></div>
<a id="trunkSourceWebCorebindingsjsReadableJSStreamcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/bindings/js/ReadableJSStream.cpp (185871 => 185872)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/bindings/js/ReadableJSStream.cpp        2015-06-23 10:45:29 UTC (rev 185871)
+++ trunk/Source/WebCore/bindings/js/ReadableJSStream.cpp        2015-06-23 11:29:32 UTC (rev 185872)
</span><span class="lines">@@ -60,7 +60,7 @@
</span><span class="cx">     return call(&amp;exec, jsFunction, callType, callData, thisValue, arguments);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-JSPromise* ReadableJSStream::invoke(ExecState&amp; state, const char* propertyName)
</del><ins>+JSPromise* ReadableJSStream::invoke(ExecState&amp; state, const char* propertyName, JSValue parameter)
</ins><span class="cx"> {
</span><span class="cx">     JSValue function = getPropertyFromObject(state, m_source.get(), propertyName);
</span><span class="cx">     if (state.hadException())
</span><span class="lines">@@ -73,7 +73,7 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     MarkedArgumentBuffer arguments;
</span><del>-    arguments.append(jsController(state, globalObject()));
</del><ins>+    arguments.append(parameter);
</ins><span class="cx"> 
</span><span class="cx">     JSPromise* promise = jsDynamicCast&lt;JSPromise*&gt;(callFunction(state, function, m_source.get(), arguments));
</span><span class="cx"> 
</span><span class="lines">@@ -108,11 +108,11 @@
</span><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static inline void startReadableStreamAsync(ReadableStream&amp; readableStream)
</del><ins>+static inline void startReadableStreamAsync(ReadableStream&amp; stream)
</ins><span class="cx"> {
</span><del>-    RefPtr&lt;ReadableStream&gt; stream = &amp;readableStream;
-    stream-&gt;scriptExecutionContext()-&gt;postTask([stream](ScriptExecutionContext&amp;) {
-        stream-&gt;start();
</del><ins>+    RefPtr&lt;ReadableStream&gt; protectedStream = &amp;stream;
+    stream.scriptExecutionContext()-&gt;postTask([protectedStream](ScriptExecutionContext&amp;) {
+        protectedStream-&gt;start();
</ins><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -120,7 +120,7 @@
</span><span class="cx"> {
</span><span class="cx">     JSLockHolder lock(&amp;exec);
</span><span class="cx"> 
</span><del>-    JSPromise* promise = invoke(exec, &quot;start&quot;);
</del><ins>+    JSPromise* promise = invoke(exec, &quot;start&quot;, jsController(exec, globalObject()));
</ins><span class="cx"> 
</span><span class="cx">     if (exec.hadException())
</span><span class="cx">         return;
</span><span class="lines">@@ -135,9 +135,9 @@
</span><span class="cx"> 
</span><span class="cx"> static inline JSFunction* createPullResultFulfilledFunction(ExecState&amp; exec, ReadableJSStream&amp; stream)
</span><span class="cx"> {
</span><del>-    RefPtr&lt;ReadableJSStream&gt; readableStream = &amp;stream;
-    return JSFunction::create(exec.vm(), exec.callee()-&gt;globalObject(), 0, String(), [readableStream](ExecState*) {
-        readableStream-&gt;finishPulling();
</del><ins>+    RefPtr&lt;ReadableJSStream&gt; protectedStream = &amp;stream;
+    return JSFunction::create(exec.vm(), exec.callee()-&gt;globalObject(), 0, String(), [protectedStream](ExecState*) {
+        protectedStream-&gt;finishPulling();
</ins><span class="cx">         return JSValue::encode(jsUndefined());
</span><span class="cx">     });
</span><span class="cx"> }
</span><span class="lines">@@ -147,7 +147,7 @@
</span><span class="cx">     ExecState&amp; state = *globalObject()-&gt;globalExec();
</span><span class="cx">     JSLockHolder lock(&amp;state);
</span><span class="cx"> 
</span><del>-    JSPromise* promise = invoke(state, &quot;pull&quot;);
</del><ins>+    JSPromise* promise = invoke(state, &quot;pull&quot;, jsController(state, globalObject()));
</ins><span class="cx"> 
</span><span class="cx">     if (promise)
</span><span class="cx">         thenPromise(state, promise, createPullResultFulfilledFunction(state, *this), m_errorFunction.get());
</span><span class="lines">@@ -161,6 +161,43 @@
</span><span class="cx">     return !promise;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+static JSFunction* createCancelResultFulfilledFunction(ExecState&amp; exec, ReadableJSStream&amp; stream)
+{
+    RefPtr&lt;ReadableJSStream&gt; protectedStream = &amp;stream;
+    return JSFunction::create(exec.vm(), exec.callee()-&gt;globalObject(), 1, String(), [protectedStream](ExecState*) {
+        protectedStream-&gt;notifyCancelSucceeded();
+        return JSValue::encode(jsUndefined());
+    });
+}
+
+static JSFunction* createCancelResultRejectedFunction(ExecState&amp; exec, ReadableJSStream&amp; stream)
+{
+    RefPtr&lt;ReadableJSStream&gt; protectedStream = &amp;stream;
+    return JSFunction::create(exec.vm(), exec.callee()-&gt;globalObject(), 1, String(), [protectedStream](ExecState* exec) {
+        protectedStream-&gt;storeError(*exec, exec-&gt;argument(0));
+        protectedStream-&gt;notifyCancelFailed();
+        return JSValue::encode(jsUndefined());
+    });
+}
+
+bool ReadableJSStream::doCancel(JSValue reason)
+{
+    ExecState&amp; exec = *globalObject()-&gt;globalExec();
+    JSLockHolder lock(&amp;exec);
+
+    JSPromise* promise = invoke(exec, &quot;cancel&quot;, reason);
+
+    if (promise)
+        thenPromise(exec, promise, createCancelResultFulfilledFunction(exec, *this), createCancelResultRejectedFunction(exec, *this));
+
+    if (exec.hadException()) {
+        storeException(exec);
+        ASSERT(!exec.hadException());
+        return true;
+    }
+    return !promise;
+}
+
</ins><span class="cx"> RefPtr&lt;ReadableJSStream&gt; ReadableJSStream::create(ExecState&amp; exec, ScriptExecutionContext&amp; scriptExecutionContext)
</span><span class="cx"> {
</span><span class="cx">     JSObject* jsSource;
</span><span class="lines">@@ -182,12 +219,6 @@
</span><span class="cx">     return readableStream;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-bool ReadableJSStream::doCancel(JSValue)
-{
-    // FIXME: Implement it.
-    return true;
-}
-
</del><span class="cx"> ReadableJSStream::ReadableJSStream(ScriptExecutionContext&amp; scriptExecutionContext, ExecState&amp; state, JSObject* source)
</span><span class="cx">     : ReadableStream(scriptExecutionContext)
</span><span class="cx"> {
</span></span></pre></div>
<a id="trunkSourceWebCorebindingsjsReadableJSStreamh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/bindings/js/ReadableJSStream.h (185871 => 185872)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/bindings/js/ReadableJSStream.h        2015-06-23 10:45:29 UTC (rev 185871)
+++ trunk/Source/WebCore/bindings/js/ReadableJSStream.h        2015-06-23 11:29:32 UTC (rev 185872)
</span><span class="lines">@@ -66,7 +66,7 @@
</span><span class="cx"> 
</span><span class="cx">     void doStart(JSC::ExecState&amp;);
</span><span class="cx"> 
</span><del>-    JSC::JSPromise* invoke(JSC::ExecState&amp;, const char*);
</del><ins>+    JSC::JSPromise* invoke(JSC::ExecState&amp;, const char*, JSC::JSValue parameter);
</ins><span class="cx">     void storeException(JSC::ExecState&amp;);
</span><span class="cx"> 
</span><span class="cx">     virtual bool hasValue() const override;
</span></span></pre>
</div>
</div>

</body>
</html>