<!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>[197396] 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/197396">197396</a></dd>
<dt>Author</dt> <dd>youenn.fablet@crf.canon.fr</dd>
<dt>Date</dt> <dd>2016-03-01 02:34:17 -0800 (Tue, 01 Mar 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>[Fetch API] Support Request and Response blob() when body data is a blob
https://bugs.webkit.org/show_bug.cgi?id=154820

Reviewed by Darin Adler.

LayoutTests/imported/w3c:

Adding blob specific tests. New tests are not covered yet as they require converting data from a blob into another form (JSON, text...).
Rebasing expectations with test that is now passing and new failing tests.
Fixing typos in test (Json -&gt; JSON and removing TextDecoder use).

* web-platform-tests/fetch/api/request/request-consume-expected.txt:
* web-platform-tests/fetch/api/request/request-consume.html:
* web-platform-tests/fetch/api/response/response-consume-expected.txt:
* web-platform-tests/fetch/api/response/response-consume.html:

Source/WebCore:

Adding support for returning the same Blob that is stored in Body in case JS blob() is called.
Adding support for Blob creation when data is stored as text.
Updated JSDOMBinding and JSDOMPromise to return a JS ArrayBuffer for Vector&lt;char&gt; as well as Vector&lt;unsigned char&gt;.

Covered by added tests.

* Modules/fetch/FetchBody.cpp:
(WebCore::FetchBody::arrayBuffer):
(WebCore::FetchBody::blob):
(WebCore::FetchBody::extractFromText):
* Modules/fetch/FetchBody.h:
* bindings/js/JSDOMBinding.h:
(WebCore::toJS):
* bindings/js/JSDOMPromise.h:
(WebCore::DeferredWrapper::resolve): Deleted.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsimportedw3cChangeLog">trunk/LayoutTests/imported/w3c/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsfetchapirequestrequestconsumeexpectedtxt">trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-consume-expected.txt</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsfetchapirequestrequestconsumehtml">trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-consume.html</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsfetchapiresponseresponseconsumeexpectedtxt">trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume-expected.txt</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsfetchapiresponseresponseconsumehtml">trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume.html</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreModulesfetchFetchBodycpp">trunk/Source/WebCore/Modules/fetch/FetchBody.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesfetchFetchBodyh">trunk/Source/WebCore/Modules/fetch/FetchBody.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 (197395 => 197396)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/ChangeLog        2016-03-01 09:05:37 UTC (rev 197395)
+++ trunk/LayoutTests/imported/w3c/ChangeLog        2016-03-01 10:34:17 UTC (rev 197396)
</span><span class="lines">@@ -1,3 +1,19 @@
</span><ins>+2016-03-01  Youenn Fablet  &lt;youenn.fablet@crf.canon.fr&gt;
+
+        [Fetch API] Support Request and Response blob() when body data is a blob
+        https://bugs.webkit.org/show_bug.cgi?id=154820
+
+        Reviewed by Darin Adler.
+
+        Adding blob specific tests. New tests are not covered yet as they require converting data from a blob into another form (JSON, text...).
+        Rebasing expectations with test that is now passing and new failing tests.
+        Fixing typos in test (Json -&gt; JSON and removing TextDecoder use).
+
+        * web-platform-tests/fetch/api/request/request-consume-expected.txt:
+        * web-platform-tests/fetch/api/request/request-consume.html:
+        * web-platform-tests/fetch/api/response/response-consume-expected.txt:
+        * web-platform-tests/fetch/api/response/response-consume.html:
+
</ins><span class="cx"> 2016-02-29  Chris Dumez  &lt;cdumez@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Use HTML parsing rules for textarea.maxLength
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsfetchapirequestrequestconsumeexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-consume-expected.txt (197395 => 197396)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-consume-expected.txt        2016-03-01 09:05:37 UTC (rev 197395)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-consume-expected.txt        2016-03-01 10:34:17 UTC (rev 197396)
</span><span class="lines">@@ -1,9 +1,13 @@
</span><span class="cx"> 
</span><span class="cx"> PASS Consume request's body as text 
</span><del>-FAIL Consume request's body as blob promise_test: Unhandled rejection with value: undefined
</del><ins>+PASS Consume request's body as blob 
</ins><span class="cx"> PASS Consume request's body as arrayBuffer 
</span><span class="cx"> PASS Consume request's body as json 
</span><span class="cx"> FAIL Consume request's body as formData promise_test: Unhandled rejection with value: undefined
</span><ins>+PASS Consume blob response's body as blob 
+FAIL Consume blob response's body as text promise_test: Unhandled rejection with value: undefined
+FAIL Consume blob response's body as json promise_test: Unhandled rejection with value: undefined
+FAIL Consume blob response's body as arrayBuffer promise_test: Unhandled rejection with value: undefined
</ins><span class="cx"> PASS Consume JSON from text: '&quot;null&quot;' 
</span><span class="cx"> PASS Consume JSON from text: '&quot;1&quot;' 
</span><span class="cx"> PASS Consume JSON from text: '&quot;true&quot;' 
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsfetchapirequestrequestconsumehtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-consume.html (197395 => 197396)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-consume.html        2016-03-01 09:05:37 UTC (rev 197395)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-consume.html        2016-03-01 10:34:17 UTC (rev 197396)
</span><span class="lines">@@ -79,12 +79,28 @@
</span><span class="cx"> 
</span><span class="cx">     var formData = new FormData();
</span><span class="cx">     formData.append(&quot;name&quot;, &quot;value&quot;)
</span><del>-    checkRequestBody(&quot;This is request's body&quot;, &quot;text&quot;, checkBodyText);
-    checkRequestBody(&quot;This is request's body&quot;, &quot;blob&quot;, checkBodyBlob);
-    checkRequestBody(&quot;This is request's body&quot;, &quot;arrayBuffer&quot;, checkBodyArrayBuffer);
-    checkRequestBody(JSON.stringify(&quot;This is request's body&quot;), &quot;json&quot;, checkBodyJSON);
</del><ins>+    var textData = &quot;This is response's body&quot;;
+    var blob = new Blob([textData], { &quot;type&quot; : &quot;text/plain&quot; });
+
+    checkRequestBody(textData, &quot;text&quot;, checkBodyText);
+    checkRequestBody(textData, &quot;blob&quot;, checkBodyBlob);
+    checkRequestBody(textData, &quot;arrayBuffer&quot;, checkBodyArrayBuffer);
+    checkRequestBody(JSON.stringify(textData), &quot;json&quot;, checkBodyJSON);
</ins><span class="cx">     checkRequestBody(formData, &quot;formData&quot;, checkBodyFormData);
</span><span class="cx"> 
</span><ins>+    function checkBlobResponseBody(blobBody, blobData, bodyType, checkFunction) {
+      promise_test(function(test) {
+        var response = new Response(blobBody);
+        assert_false(response.bodyUsed, &quot;bodyUsed is false at init&quot;);
+        return checkFunction(response, blobData);
+      }, &quot;Consume blob response's body as &quot; + bodyType);
+    }
+
+    checkBlobResponseBody(blob, textData, &quot;blob&quot;, checkBodyBlob);
+    checkBlobResponseBody(blob, textData, &quot;text&quot;, checkBodyText);
+    checkBlobResponseBody(blob, textData, &quot;json&quot;, checkBodyJSON);
+    checkBlobResponseBody(blob, textData, &quot;arrayBuffer&quot;, checkBodyArrayBuffer);
+
</ins><span class="cx">     var goodJSONValues = [&quot;null&quot;, &quot;1&quot;, &quot;true&quot;, &quot;\&quot;string\&quot;&quot;];
</span><span class="cx">     goodJSONValues.forEach(function(value) {
</span><span class="cx">       promise_test(function(test) {
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsfetchapiresponseresponseconsumeexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume-expected.txt (197395 => 197396)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume-expected.txt        2016-03-01 09:05:37 UTC (rev 197395)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume-expected.txt        2016-03-01 10:34:17 UTC (rev 197396)
</span><span class="lines">@@ -1,7 +1,11 @@
</span><span class="cx"> 
</span><span class="cx"> PASS Consume response's body as text 
</span><del>-FAIL Consume response's body as blob promise_test: Unhandled rejection with value: undefined
-FAIL Consume response's body as arrayBuffer promise_test: Unhandled rejection with value: object &quot;ReferenceError: Can't find variable: TextDecoder&quot;
</del><ins>+PASS Consume response's body as blob 
+PASS Consume response's body as arrayBuffer 
</ins><span class="cx"> PASS Consume response's body as json 
</span><span class="cx"> FAIL Consume response's body as formData promise_test: Unhandled rejection with value: undefined
</span><ins>+PASS Consume blob response's body as blob 
+FAIL Consume blob response's body as text promise_test: Unhandled rejection with value: undefined
+FAIL Consume blob response's body as json promise_test: Unhandled rejection with value: undefined
+FAIL Consume blob response's body as arrayBuffer promise_test: Unhandled rejection with value: undefined
</ins><span class="cx"> 
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsfetchapiresponseresponseconsumehtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume.html (197395 => 197396)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume.html        2016-03-01 09:05:37 UTC (rev 197395)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume.html        2016-03-01 10:34:17 UTC (rev 197396)
</span><span class="lines">@@ -37,18 +37,26 @@
</span><span class="cx">       });
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    &lt;!-- Taken from https://developers.google.com --&gt;
+    function str2ab(str) {
+      var buf = new ArrayBuffer(str.length*2); // 2 bytes for each char
+      var bufView = new Uint16Array(buf);
+      for (var i=0, strLen=str.length; i &lt; strLen; i++) {
+        bufView[i] = str.charCodeAt(i);
+      }
+      return buf;
+    }
+
</ins><span class="cx">     function checkBodyArrayBuffer(response, expectedBody) {
</span><span class="cx">       return response.arrayBuffer().then( function(bodyAsArrayBuffer) {
</span><del>-        var decoder = new TextDecoder(&quot;utf-8&quot;);
-        var strBody = decoder.decode(bodyAsArrayBuffer);
-        assert_equals(strBody, expectedBody, &quot;Retrieve and verify response's body&quot;);
</del><ins>+        assert_array_equals(bodyAsArrayBuffer, str2ab(expectedBody), &quot;Retrieve and verify response's body&quot;);
</ins><span class="cx">         assert_true(response.bodyUsed, &quot;body as arrayBuffer: bodyUsed turned true&quot;);
</span><span class="cx">       });
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    function checkBodyJson(response, expectedBody) {
-      return response.json().then(function(bodyAsJson) {
-        var strBody = JSON.stringify(bodyAsJson)
</del><ins>+    function checkBodyJSON(response, expectedBody) {
+      return response.json().then(function(bodyAsJSON) {
+        var strBody = JSON.stringify(bodyAsJSON)
</ins><span class="cx">         assert_equals(strBody, expectedBody, &quot;Retrieve and verify response's body&quot;);
</span><span class="cx">         assert_true(response.bodyUsed, &quot;body as json: bodyUsed turned true&quot;);
</span><span class="cx">       });
</span><span class="lines">@@ -70,12 +78,31 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     var formData = new FormData();
</span><del>-    formData.append(&quot;name&quot;, &quot;value&quot;)
-    checkResponseBody(&quot;This is response's body&quot;, &quot;text&quot;, checkBodyText);
-    checkResponseBody(&quot;This is response's body&quot;, &quot;blob&quot;, checkBodyBlob);
-    checkResponseBody(&quot;This is response's body&quot;, &quot;arrayBuffer&quot;, checkBodyArrayBuffer);
-    checkResponseBody(JSON.stringify(&quot;This is response's body&quot;), &quot;json&quot;, checkBodyJson);
</del><ins>+    formData.append(&quot;name&quot;, &quot;value&quot;);
+    var textData = &quot;This is response's body&quot;;
+    var blob = new Blob([textData], { &quot;type&quot; : &quot;text/plain&quot; });
+
+    checkResponseBody(textData, &quot;text&quot;, checkBodyText);
+    checkResponseBody(textData, &quot;blob&quot;, checkBodyBlob);
+    checkResponseBody(textData, &quot;arrayBuffer&quot;, checkBodyArrayBuffer);
+
+    checkResponseBody(JSON.stringify(&quot;This is response's body&quot;), &quot;json&quot;, checkBodyJSON);
+
</ins><span class="cx">     checkResponseBody(formData, &quot;formData&quot;, checkBodyFormData);
</span><ins>+
+    function checkBlobResponseBody(blobBody, blobData, bodyType, checkFunction) {
+      promise_test(function(test) {
+        var response = new Response(blobBody);
+        assert_false(response.bodyUsed, &quot;bodyUsed is false at init&quot;);
+        return checkFunction(response, blobData);
+      }, &quot;Consume blob response's body as &quot; + bodyType);
+    }
+
+    checkBlobResponseBody(blob, textData, &quot;blob&quot;, checkBodyBlob);
+    checkBlobResponseBody(blob, textData, &quot;text&quot;, checkBodyText);
+    checkBlobResponseBody(blob, textData, &quot;json&quot;, checkBodyJSON);
+    checkBlobResponseBody(blob, textData, &quot;arrayBuffer&quot;, checkBodyArrayBuffer);
+
</ins><span class="cx">     &lt;/script&gt;
</span><span class="cx">   &lt;/body&gt;
</span><span class="cx"> &lt;/html&gt;
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (197395 => 197396)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-03-01 09:05:37 UTC (rev 197395)
+++ trunk/Source/WebCore/ChangeLog        2016-03-01 10:34:17 UTC (rev 197396)
</span><span class="lines">@@ -1,3 +1,26 @@
</span><ins>+2016-03-01  Youenn Fablet  &lt;youenn.fablet@crf.canon.fr&gt;
+
+        [Fetch API] Support Request and Response blob() when body data is a blob
+        https://bugs.webkit.org/show_bug.cgi?id=154820
+
+        Reviewed by Darin Adler.
+
+        Adding support for returning the same Blob that is stored in Body in case JS blob() is called.
+        Adding support for Blob creation when data is stored as text.
+        Updated JSDOMBinding and JSDOMPromise to return a JS ArrayBuffer for Vector&lt;char&gt; as well as Vector&lt;unsigned char&gt;.
+
+        Covered by added tests.
+
+        * Modules/fetch/FetchBody.cpp:
+        (WebCore::FetchBody::arrayBuffer):
+        (WebCore::FetchBody::blob):
+        (WebCore::FetchBody::extractFromText):
+        * Modules/fetch/FetchBody.h:
+        * bindings/js/JSDOMBinding.h:
+        (WebCore::toJS):
+        * bindings/js/JSDOMPromise.h:
+        (WebCore::DeferredWrapper::resolve): Deleted.
+
</ins><span class="cx"> 2016-02-29  Chris Dumez  &lt;cdumez@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Have parseHTMLInteger() / parseHTMLNonNegativeInteger() use WTF::Optional
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesfetchFetchBodycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/fetch/FetchBody.cpp (197395 => 197396)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/fetch/FetchBody.cpp        2016-03-01 09:05:37 UTC (rev 197395)
+++ trunk/Source/WebCore/Modules/fetch/FetchBody.cpp        2016-03-01 10:34:17 UTC (rev 197396)
</span><span class="lines">@@ -33,6 +33,7 @@
</span><span class="cx"> 
</span><span class="cx"> #include &quot;Dictionary.h&quot;
</span><span class="cx"> #include &quot;ExceptionCode.h&quot;
</span><ins>+#include &quot;HTTPParsers.h&quot;
</ins><span class="cx"> #include &quot;JSBlob.h&quot;
</span><span class="cx"> #include &quot;JSDOMFormData.h&quot;
</span><span class="cx"> #include &lt;runtime/JSONObject.h&gt;
</span><span class="lines">@@ -102,12 +103,10 @@
</span><span class="cx">         return;
</span><span class="cx"> 
</span><span class="cx">     if (m_type == Type::Text) {
</span><del>-        // FIXME: promise expects a Vector&lt;unsigned char&gt; that will be converted to an ArrayBuffer.
-        // We should try to create a Vector&lt;unsigned char&gt; or an ArrayBuffer directly from m_text.
-        CString data = m_text.utf8();
-        Vector&lt;unsigned char&gt; value(data.length());
-        memcpy(value.data(), data.data(), data.length());
-        promise.resolve(WTFMove(value));
</del><ins>+        // FIXME: Ideally we would like to have an ArrayBuffer directly from m_text.
+        Vector&lt;char&gt; data = extractFromText();
+        RefPtr&lt;ArrayBuffer&gt; buffer = ArrayBuffer::create(data.data(), data.size());
+        promise.resolve(buffer);
</ins><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx">     // FIXME: Support other types.
</span><span class="lines">@@ -131,6 +130,16 @@
</span><span class="cx">     if (processIfEmptyOrDisturbed(promise))
</span><span class="cx">         return;
</span><span class="cx"> 
</span><ins>+    if (m_type == Type::Blob) {
+        promise.resolve(m_blob);
+        return;
+    }
+    if (m_type == Type::Text) {
+        String contentType = Blob::normalizedContentType(extractMIMETypeFromMediaType(m_mimeType));
+        promise.resolve(Blob::create(extractFromText(), contentType));
+        return;
+    }
+
</ins><span class="cx">     // FIXME: Support other types.
</span><span class="cx">     promise.reject(0);
</span><span class="cx"> }
</span><span class="lines">@@ -165,6 +174,16 @@
</span><span class="cx">     promise.reject(0);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+Vector&lt;char&gt; FetchBody::extractFromText() const
+{
+    ASSERT(m_type == Type::Text);
+    // FIXME: This double allocation is not efficient. Might want to fix that at WTFString level.
+    CString data = m_text.utf8();
+    Vector&lt;char&gt; value(data.length());
+    memcpy(value.data(), data.data(), data.length());
+    return value;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+}
+
</ins><span class="cx"> #endif // ENABLE(FETCH_API)
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesfetchFetchBodyh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/fetch/FetchBody.h (197395 => 197396)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/fetch/FetchBody.h        2016-03-01 09:05:37 UTC (rev 197395)
+++ trunk/Source/WebCore/Modules/fetch/FetchBody.h        2016-03-01 10:34:17 UTC (rev 197396)
</span><span class="lines">@@ -36,6 +36,7 @@
</span><span class="cx"> #include &quot;JSDOMPromise.h&quot;
</span><span class="cx"> 
</span><span class="cx"> namespace JSC {
</span><ins>+class ArrayBuffer;
</ins><span class="cx"> class ExecState;
</span><span class="cx"> class JSValue;
</span><span class="cx"> };
</span><span class="lines">@@ -47,7 +48,7 @@
</span><span class="cx"> 
</span><span class="cx"> class FetchBody {
</span><span class="cx"> public:
</span><del>-    typedef DOMPromise&lt;Vector&lt;unsigned char&gt;, ExceptionCode&gt; ArrayBufferPromise;
</del><ins>+    typedef DOMPromise&lt;RefPtr&lt;JSC::ArrayBuffer&gt;, ExceptionCode&gt; ArrayBufferPromise;
</ins><span class="cx">     void arrayBuffer(ArrayBufferPromise&amp;&amp;);
</span><span class="cx"> 
</span><span class="cx">     typedef DOMPromise&lt;RefPtr&lt;DOMFormData&gt;, ExceptionCode&gt; FormDataPromise;
</span><span class="lines">@@ -81,6 +82,8 @@
</span><span class="cx">     FetchBody(Ref&lt;DOMFormData&gt;&amp;&amp;);
</span><span class="cx">     FetchBody(String&amp;&amp;);
</span><span class="cx"> 
</span><ins>+    Vector&lt;char&gt; extractFromText() const;
+
</ins><span class="cx">     Type m_type = Type::None;
</span><span class="cx">     String m_mimeType;
</span><span class="cx">     bool m_isDisturbed = false;
</span></span></pre>
</div>
</div>

</body>
</html>