<!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>[201232] 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/201232">201232</a></dd>
<dt>Author</dt> <dd>beidson@apple.com</dd>
<dt>Date</dt> <dd>2016-05-20 16:15:15 -0700 (Fri, 20 May 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>Modern IDB: Properly handle blobs in Workers.
https://bugs.webkit.org/show_bug.cgi?id=157947

Reviewed by Alex Christensen.

Source/WebCore:

Test: storage/indexeddb/modern/blob-simple-workers.html

* Modules/indexeddb/IDBTransaction.cpp:
(WebCore::IDBTransaction::putOrAddOnServer): Use writeBlobsToDiskForIndexedDBSynchronously from
  background threads instead of the asynchronous form.

Add ability to set an existing empty IDBValue to be an isolated copy of a different IDBValue:
* Modules/indexeddb/IDBValue.cpp:
(WebCore::IDBValue::setAsIsolatedCopy):
(WebCore::IDBValue::isolatedCopy):
* Modules/indexeddb/IDBValue.h:

Add a method - only to be called from a non-main thread - that synchronously writes blobs to disk:
* bindings/js/SerializedScriptValue.cpp:
(WebCore::SerializedScriptValue::writeBlobsToDiskForIndexedDBSynchronously):
* bindings/js/SerializedScriptValue.h:

LayoutTests:

* storage/indexeddb/modern/blob-simple-workers-expected.txt: Added.
* storage/indexeddb/modern/blob-simple-workers.html: Added.
* storage/indexeddb/modern/resources/blob-simple-workers.js: Added.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbIDBTransactioncpp">trunk/Source/WebCore/Modules/indexeddb/IDBTransaction.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbIDBValuecpp">trunk/Source/WebCore/Modules/indexeddb/IDBValue.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbIDBValueh">trunk/Source/WebCore/Modules/indexeddb/IDBValue.h</a></li>
<li><a href="#trunkSourceWebCorebindingsjsSerializedScriptValuecpp">trunk/Source/WebCore/bindings/js/SerializedScriptValue.cpp</a></li>
<li><a href="#trunkSourceWebCorebindingsjsSerializedScriptValueh">trunk/Source/WebCore/bindings/js/SerializedScriptValue.h</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsstorageindexeddbmodernblobsimpleworkersexpectedtxt">trunk/LayoutTests/storage/indexeddb/modern/blob-simple-workers-expected.txt</a></li>
<li><a href="#trunkLayoutTestsstorageindexeddbmodernblobsimpleworkershtml">trunk/LayoutTests/storage/indexeddb/modern/blob-simple-workers.html</a></li>
<li><a href="#trunkLayoutTestsstorageindexeddbmodernresourcesblobsimpleworkersjs">trunk/LayoutTests/storage/indexeddb/modern/resources/blob-simple-workers.js</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (201231 => 201232)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2016-05-20 22:53:35 UTC (rev 201231)
+++ trunk/LayoutTests/ChangeLog        2016-05-20 23:15:15 UTC (rev 201232)
</span><span class="lines">@@ -1,3 +1,14 @@
</span><ins>+2016-05-20  Brady Eidson  &lt;beidson@apple.com&gt;
+
+        Modern IDB: Properly handle blobs in Workers.
+        https://bugs.webkit.org/show_bug.cgi?id=157947
+
+        Reviewed by Alex Christensen.
+
+        * storage/indexeddb/modern/blob-simple-workers-expected.txt: Added.
+        * storage/indexeddb/modern/blob-simple-workers.html: Added.
+        * storage/indexeddb/modern/resources/blob-simple-workers.js: Added.
+        
</ins><span class="cx"> 2016-05-20  Myles C. Maxfield  &lt;mmaxfield@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [Cocoa] REGRESSION(r184899): Ascent adjustments are applied to web fonts
</span></span></pre></div>
<a id="trunkLayoutTestsstorageindexeddbmodernblobsimpleworkersexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/storage/indexeddb/modern/blob-simple-workers-expected.txt (0 => 201232)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/storage/indexeddb/modern/blob-simple-workers-expected.txt                                (rev 0)
+++ trunk/LayoutTests/storage/indexeddb/modern/blob-simple-workers-expected.txt        2016-05-20 23:15:15 UTC (rev 201232)
</span><span class="lines">@@ -0,0 +1,48 @@
</span><ins>+[Worker] This tests basic operations putting blobs into an object store and then retrieving them.
+
+On success, you will see a series of &quot;PASS&quot; messages, followed by &quot;TEST COMPLETE&quot;.
+
+
+Starting worker: resources/blob-simple-workers.js
+[Worker] indexedDB = self.indexedDB || self.webkitIndexedDB || self.mozIndexedDB || self.msIndexedDB || self.OIndexedDB;
+[Worker] 
+[Worker] indexedDB.deleteDatabase(dbname)
+[Worker] indexedDB.open(dbname)
+[Worker] Initial upgrade needed: Old version - 0 New version - 1
+[Worker] Let's create a blob and store it in IndexedDB twice.
+[Worker] Added blob to database once
+[Worker] Added blob to database twice
+[Worker] Let's retrieve the blob again and verify the contents is the same.
+[Worker] Got blob from database
+[Worker] Correct text: true
+[Worker] Let's retrieve it again, create an object URL for the blob, load it via an XMLHttpRequest, and verify the contents are the same.
+[Worker] Got blob from database
+[Worker] Correct responseText: true
+[Worker] Retrieve both blob entries from the database and verify contents.
+[Worker] Correct text on first value: true
+[Worker] Correct text on second value: true
+[Worker] Got item from cursor
+[Worker] Got item from cursor
+[Worker] Finished cursor
+[Worker] Got right number of items: true
+[Worker] Correct text: true
+[Worker] Retrieve blobs from database via index and verify contents.
+[Worker] Got blob from database
+[Worker] Correct text: true
+[Worker] Got item from cursor
+[Worker] Got item from cursor
+[Worker] Finished cursor
+[Worker] Got right number of items: true
+[Worker] Correct text: true
+[Worker] Correct text: true
+[Worker] Slice the the retrieved blob and verify its contents.
+[Worker] Correct text: true
+[Worker] Store a blob back in the database, and keep holding on to the blob, verifying that it still can be read.
+[Worker] Got blob from database
+[Worker] Stored blob back into database
+[Worker] Correct text: true
+[Worker] Correct responseText: true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestsstorageindexeddbmodernblobsimpleworkershtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/storage/indexeddb/modern/blob-simple-workers.html (0 => 201232)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/storage/indexeddb/modern/blob-simple-workers.html                                (rev 0)
+++ trunk/LayoutTests/storage/indexeddb/modern/blob-simple-workers.html        2016-05-20 23:15:15 UTC (rev 201232)
</span><span class="lines">@@ -0,0 +1,12 @@
</span><ins>+&lt;html&gt;
+&lt;head&gt;
+&lt;script src=&quot;../../../resources/js-test.js&quot;&gt;&lt;/script&gt;
+&lt;script src=&quot;../resources/shared.js&quot;&gt;&lt;/script&gt;
+&lt;/head&gt;
+&lt;body&gt;
+&lt;script&gt;
+if (window.internals)
+    window.internals.settings.setIndexedDBWorkersEnabled(true);
+worker = startWorker('resources/blob-simple-workers.js');&lt;/script&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsstorageindexeddbmodernresourcesblobsimpleworkersjs"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/storage/indexeddb/modern/resources/blob-simple-workers.js (0 => 201232)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/storage/indexeddb/modern/resources/blob-simple-workers.js                                (rev 0)
+++ trunk/LayoutTests/storage/indexeddb/modern/resources/blob-simple-workers.js        2016-05-20 23:15:15 UTC (rev 201232)
</span><span class="lines">@@ -0,0 +1,270 @@
</span><ins>+if (this.importScripts) {
+    importScripts('../../../../resources/js-test.js');
+    importScripts('../../resources/shared.js');
+}
+
+// Original implementation of test from Mozilla: ./dom/indexedDB/test/test_blob_simple.html
+description(&quot;This tests basic operations putting blobs into an object store and then retrieving them.&quot;);
+
+indexedDBTest(prepareDatabase);
+
+function done()
+{
+    finishJSTest();
+}
+
+function log(message)
+{
+    debug(message);
+}
+
+var testGenerator;
+
+function continueWithEvent(event)
+{
+    testGenerator.next(event);
+}
+
+function asyncContinue()
+{
+    setTimeout(&quot;testGenerator.next();&quot;, 0);
+}
+
+function idbRequest(request)
+{
+    request.onerror = continueWithEvent;
+    request.onsuccess = continueWithEvent;
+}
+
+var db;
+
+function prepareDatabase(event)
+{
+    debug(&quot;Initial upgrade needed: Old version - &quot; + event.oldVersion + &quot; New version - &quot; + event.newVersion);
+
+    db = event.target.result;
+    db.createObjectStore(&quot;foo&quot;, { autoIncrement: true }).createIndex(&quot;foo&quot;, &quot;index&quot;);
+    event.target.onsuccess = function() {
+        testGenerator = testSteps();
+        testGenerator.next();
+    };
+}
+
+function is(a, b, message) {
+    result = a == b ? &quot;true&quot; : &quot;false&quot;;
+    debug(message + &quot;: &quot; + result);
+}
+
+function* testSteps()
+{
+    debug(&quot;Let's create a blob and store it in IndexedDB twice.&quot;);
+
+    const BLOB_DATA = [&quot;fun &quot;, &quot;times &quot;, &quot;all &quot;, &quot;around!&quot;];
+    const INDEX_KEY = 5;
+    let blob = new Blob(BLOB_DATA, { type: &quot;text/plain&quot; });
+    let data = { blob: blob, index: INDEX_KEY };
+
+    objectStore = db.transaction(&quot;foo&quot;, &quot;readwrite&quot;).objectStore(&quot;foo&quot;);
+    
+    idbRequest(objectStore.add(data));
+    event = yield;
+    
+    debug(&quot;Added blob to database once&quot;);
+
+    let key1 = event.target.result;
+
+    idbRequest(objectStore.add(data));
+    event = yield;
+
+    debug(&quot;Added blob to database twice&quot;);
+    
+    let key2 = event.target.result;
+
+    debug(&quot;Let's retrieve the blob again and verify the contents is the same.&quot;);
+
+    objectStore = db.transaction(&quot;foo&quot;).objectStore(&quot;foo&quot;);
+    idbRequest(objectStore.get(key1));
+    event = yield;
+
+    debug(&quot;Got blob from database&quot;);
+    
+    let fileReader = new FileReader();
+    fileReader.onload = continueWithEvent;
+    fileReader.readAsText(event.target.result.blob);
+    event = yield;
+
+    is(event.target.result, BLOB_DATA.join(&quot;&quot;), &quot;Correct text&quot;);
+
+    debug(&quot;Let's retrieve it again, create an object URL for the blob, load it via an XMLHttpRequest, and verify the contents are the same.&quot;);
+    
+    objectStore = db.transaction(&quot;foo&quot;).objectStore(&quot;foo&quot;);
+    idbRequest(objectStore.get(key1));
+    event = yield;
+    
+    debug(&quot;Got blob from database&quot;);
+    
+    let blobURL = URL.createObjectURL(event.target.result.blob);
+    
+    let xhr = new XMLHttpRequest();
+    xhr.open(&quot;GET&quot;, blobURL);
+    xhr.onload = continueWithEvent;
+    xhr.send();
+    yield;
+    
+    URL.revokeObjectURL(blobURL);    
+    is(xhr.responseText, BLOB_DATA.join(&quot;&quot;), &quot;Correct responseText&quot;);
+    
+    debug(&quot;Retrieve both blob entries from the database and verify contents.&quot;);
+
+    var objects = []
+    
+    objectStore = db.transaction(&quot;foo&quot;).objectStore(&quot;foo&quot;);
+    idbRequest(objectStore.get(key1));
+    event = yield;
+    
+    objects.push(event.target.result);
+    
+    objectStore = db.transaction(&quot;foo&quot;).objectStore(&quot;foo&quot;);
+    idbRequest(objectStore.get(key2));
+    event = yield;
+    
+    objects.push(event.target.result);
+        
+    fileReader = new FileReader();
+    fileReader.onload = continueWithEvent;
+    fileReader.readAsText(objects[0].blob);
+    event = yield;
+
+    is(event.target.result, BLOB_DATA.join(&quot;&quot;), &quot;Correct text on first value&quot;);
+
+    fileReader = new FileReader();
+    fileReader.onload = continueWithEvent;
+    fileReader.readAsText(objects[1].blob);
+    event = yield;
+
+    is(event.target.result, BLOB_DATA.join(&quot;&quot;), &quot;Correct text on second value&quot;);
+
+    let cursorResults = [];
+    
+    objectStore = db.transaction(&quot;foo&quot;).objectStore(&quot;foo&quot;);
+    objectStore.openCursor().onsuccess = function(event) {
+      let cursor = event.target.result;
+      if (cursor) {
+        debug(&quot;Got item from cursor&quot;);
+        cursorResults.push(cursor.value);
+        cursor.continue();
+      }
+      else {
+        debug(&quot;Finished cursor&quot;);
+        asyncContinue();
+      }
+    };
+    yield;
+
+    is(cursorResults.length, 2, &quot;Got right number of items&quot;);
+
+    fileReader = new FileReader();
+    fileReader.onload = continueWithEvent;
+    fileReader.readAsText(cursorResults[0].blob);
+    event = yield;
+    
+    is(event.target.result, BLOB_DATA.join(&quot;&quot;), &quot;Correct text&quot;);
+
+    debug(&quot;Retrieve blobs from database via index and verify contents.&quot;);
+    
+    index = db.transaction(&quot;foo&quot;).objectStore(&quot;foo&quot;).index(&quot;foo&quot;);
+    idbRequest(index.get(INDEX_KEY)); 
+    event = yield;
+    
+    debug(&quot;Got blob from database&quot;);
+    
+    fileReader = new FileReader();
+    fileReader.onload = continueWithEvent;
+    fileReader.readAsText(event.target.result.blob);
+    event = yield;
+    
+    is(event.target.result, BLOB_DATA.join(&quot;&quot;), &quot;Correct text&quot;);
+        
+    cursorResults = [];
+    
+    index = db.transaction(&quot;foo&quot;).objectStore(&quot;foo&quot;).index(&quot;foo&quot;);
+    index.openCursor().onsuccess = function(event) {
+      let cursor = event.target.result;
+      if (cursor) {
+        debug(&quot;Got item from cursor&quot;);
+        cursorResults.push(cursor.value);
+        cursor.continue();
+      }
+      else {
+        debug(&quot;Finished cursor&quot;);
+        asyncContinue();
+      }
+    };
+    yield;
+    
+    is(cursorResults.length, 2, &quot;Got right number of items&quot;);
+    
+    fileReader = new FileReader();
+    fileReader.onload = continueWithEvent;
+    fileReader.readAsText(cursorResults[0].blob);
+    event = yield;
+    
+    is(event.target.result, BLOB_DATA.join(&quot;&quot;), &quot;Correct text&quot;);
+    
+    fileReader = new FileReader();
+    fileReader.onload = continueWithEvent;
+    fileReader.readAsText(cursorResults[1].blob);
+    event = yield;
+    
+    is(event.target.result, BLOB_DATA.join(&quot;&quot;), &quot;Correct text&quot;);
+    
+    debug(&quot;Slice the the retrieved blob and verify its contents.&quot;);
+    
+    let slice = cursorResults[1].blob.slice(0, BLOB_DATA[0].length);
+    
+    fileReader = new FileReader();
+    fileReader.onload = continueWithEvent;
+    fileReader.readAsText(slice);
+    event = yield;
+    
+    is(event.target.result, BLOB_DATA[0], &quot;Correct text&quot;);
+    
+    debug(&quot;Store a blob back in the database, and keep holding on to the &quot; +
+         &quot;blob, verifying that it still can be read.&quot;);
+    
+    objectStore = db.transaction(&quot;foo&quot;).objectStore(&quot;foo&quot;);
+    idbRequest(objectStore.get(key1)); 
+    event = yield;
+    
+    let blobFromDB = event.target.result.blob;
+    debug(&quot;Got blob from database&quot;);
+    
+    let txn = db.transaction(&quot;foo&quot;, &quot;readwrite&quot;);
+    txn.objectStore(&quot;foo&quot;).put(event.target.result, key1);
+    txn.oncomplete = continueWithEvent;
+    event = yield;
+    
+    debug(&quot;Stored blob back into database&quot;);
+    
+    fileReader = new FileReader();
+    fileReader.onload = continueWithEvent;
+    fileReader.readAsText(blobFromDB);
+    event = yield;
+    
+    is(event.target.result, BLOB_DATA.join(&quot;&quot;), &quot;Correct text&quot;);
+    
+    blobURL = URL.createObjectURL(blobFromDB);
+    
+    xhr = new XMLHttpRequest();
+    xhr.open(&quot;GET&quot;, blobURL);
+    xhr.onload = continueWithEvent;
+    xhr.send();
+    yield;
+    
+    URL.revokeObjectURL(blobURL);
+    
+    is(xhr.responseText, BLOB_DATA.join(&quot;&quot;), &quot;Correct responseText&quot;);
+    
+    finishJSTest();
+ }

</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (201231 => 201232)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-05-20 22:53:35 UTC (rev 201231)
+++ trunk/Source/WebCore/ChangeLog        2016-05-20 23:15:15 UTC (rev 201232)
</span><span class="lines">@@ -1,3 +1,27 @@
</span><ins>+2016-05-20  Brady Eidson  &lt;beidson@apple.com&gt;
+
+        Modern IDB: Properly handle blobs in Workers.
+        https://bugs.webkit.org/show_bug.cgi?id=157947
+
+        Reviewed by Alex Christensen.
+
+        Test: storage/indexeddb/modern/blob-simple-workers.html
+
+        * Modules/indexeddb/IDBTransaction.cpp:
+        (WebCore::IDBTransaction::putOrAddOnServer): Use writeBlobsToDiskForIndexedDBSynchronously from
+          background threads instead of the asynchronous form.
+        
+        Add ability to set an existing empty IDBValue to be an isolated copy of a different IDBValue:
+        * Modules/indexeddb/IDBValue.cpp:
+        (WebCore::IDBValue::setAsIsolatedCopy):
+        (WebCore::IDBValue::isolatedCopy):
+        * Modules/indexeddb/IDBValue.h:
+        
+        Add a method - only to be called from a non-main thread - that synchronously writes blobs to disk:
+        * bindings/js/SerializedScriptValue.cpp:
+        (WebCore::SerializedScriptValue::writeBlobsToDiskForIndexedDBSynchronously):
+        * bindings/js/SerializedScriptValue.h:
+        
</ins><span class="cx"> 2016-05-20  Anders Carlsson  &lt;andersca@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Allow named images on iOS
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbIDBTransactioncpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/IDBTransaction.cpp (201231 => 201232)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/IDBTransaction.cpp        2016-05-20 22:53:35 UTC (rev 201231)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBTransaction.cpp        2016-05-20 23:15:15 UTC (rev 201232)
</span><span class="lines">@@ -938,7 +938,7 @@
</span><span class="cx"> void IDBTransaction::putOrAddOnServer(IDBClient::TransactionOperation&amp; operation, RefPtr&lt;IDBKey&gt; key, RefPtr&lt;SerializedScriptValue&gt; value, const IndexedDB::ObjectStoreOverwriteMode&amp; overwriteMode)
</span><span class="cx"> {
</span><span class="cx">     LOG(IndexedDB, &quot;IDBTransaction::putOrAddOnServer&quot;);
</span><del>-    ASSERT(currentThread() == m_database-&gt;originThreadID());
</del><ins>+    ASSERT(currentThread() == originThreadID());
</ins><span class="cx">     ASSERT(!isReadOnly());
</span><span class="cx">     ASSERT(value);
</span><span class="cx"> 
</span><span class="lines">@@ -947,9 +947,30 @@
</span><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    // Due to current limitations on our ability to post tasks back to a worker thread,
+    // workers currently write blobs to disk synchronously.
+    // FIXME: https://bugs.webkit.org/show_bug.cgi?id=157958 - Make this asynchronous after refactoring allows it.
+    if (!isMainThread()) {
+        auto idbValue = value-&gt;writeBlobsToDiskForIndexedDBSynchronously();
+        if (idbValue.data().data())
+            m_database-&gt;connectionProxy().putOrAdd(operation, key.get(), idbValue, overwriteMode);
+        else {
+            // If the IDBValue doesn't have any data, then something went wrong writing the blobs to disk.
+            // In that case, we cannot successfully store this record, so we callback with an error.
+            RefPtr&lt;IDBClient::TransactionOperation&gt; protectedOperation(&amp;operation);
+            auto result = IDBResultData::error(operation.identifier(), { IDBDatabaseException::UnknownError, ASCIILiteral(&quot;Error preparing Blob/File data to be stored in object store&quot;) });
+            scriptExecutionContext()-&gt;postTask([protectedOperation, result](ScriptExecutionContext&amp;) {
+                protectedOperation-&gt;completed(result);
+            });
+        }
+        return;
+    }
+
</ins><span class="cx">     RefPtr&lt;IDBTransaction&gt; protectedThis(this);
</span><span class="cx">     RefPtr&lt;IDBClient::TransactionOperation&gt; protectedOperation(&amp;operation);
</span><span class="cx">     value-&gt;writeBlobsToDiskForIndexedDB([protectedThis, this, protectedOperation, key, value, overwriteMode](const IDBValue&amp; idbValue) {
</span><ins>+        ASSERT(currentThread() == originThreadID());
+        ASSERT(isMainThread());
</ins><span class="cx">         if (idbValue.data().data()) {
</span><span class="cx">             m_database-&gt;connectionProxy().putOrAdd(*protectedOperation, key.get(), idbValue, overwriteMode);
</span><span class="cx">             return;
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbIDBValuecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/IDBValue.cpp (201231 => 201232)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/IDBValue.cpp        2016-05-20 22:53:35 UTC (rev 201231)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBValue.cpp        2016-05-20 23:15:15 UTC (rev 201232)
</span><span class="lines">@@ -28,6 +28,7 @@
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(INDEXED_DATABASE)
</span><span class="cx"> 
</span><ins>+#include &quot;CrossThreadCopier.h&quot;
</ins><span class="cx"> #include &quot;SerializedScriptValue.h&quot;
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="lines">@@ -69,19 +70,19 @@
</span><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void IDBValue::setAsIsolatedCopy(const IDBValue&amp; other)
+{
+    ASSERT(m_blobURLs.isEmpty() &amp;&amp; m_blobFilePaths.isEmpty());
+
+    m_data = other.m_data;
+    m_blobURLs = CrossThreadCopier&lt;Vector&lt;String&gt;&gt;::copy(other.m_blobURLs);
+    m_blobFilePaths = CrossThreadCopier&lt;Vector&lt;String&gt;&gt;::copy(other.m_blobFilePaths);
+}
+
</ins><span class="cx"> IDBValue IDBValue::isolatedCopy() const
</span><span class="cx"> {
</span><span class="cx">     IDBValue result;
</span><del>-    result.m_data = m_data;
-
-    result.m_blobURLs.reserveInitialCapacity(m_blobURLs.size());
-    for (auto&amp; url : m_blobURLs)
-        result.m_blobURLs.uncheckedAppend(url.isolatedCopy());
-
-    result.m_blobFilePaths.reserveInitialCapacity(m_blobFilePaths.size());
-    for (auto&amp; path : m_blobFilePaths)
-        result.m_blobFilePaths.uncheckedAppend(path.isolatedCopy());
-
</del><ins>+    result.setAsIsolatedCopy(*this);
</ins><span class="cx">     return result;
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbIDBValueh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/IDBValue.h (201231 => 201232)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/IDBValue.h        2016-05-20 22:53:35 UTC (rev 201231)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBValue.h        2016-05-20 23:15:15 UTC (rev 201232)
</span><span class="lines">@@ -42,6 +42,7 @@
</span><span class="cx">     IDBValue(const ThreadSafeDataBuffer&amp;, Vector&lt;String&gt;&amp;&amp; blobURLs, Vector&lt;String&gt;&amp;&amp; blobFilePaths);
</span><span class="cx">     IDBValue(const ThreadSafeDataBuffer&amp;, const Vector&lt;String&gt;&amp; blobURLs, const Vector&lt;String&gt;&amp; blobFilePaths);
</span><span class="cx"> 
</span><ins>+    void setAsIsolatedCopy(const IDBValue&amp;);
</ins><span class="cx">     IDBValue isolatedCopy() const;
</span><span class="cx"> 
</span><span class="cx">     const ThreadSafeDataBuffer&amp; data() const { return m_data; }
</span></span></pre></div>
<a id="trunkSourceWebCorebindingsjsSerializedScriptValuecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/bindings/js/SerializedScriptValue.cpp (201231 => 201232)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/bindings/js/SerializedScriptValue.cpp        2016-05-20 22:53:35 UTC (rev 201231)
+++ trunk/Source/WebCore/bindings/js/SerializedScriptValue.cpp        2016-05-20 23:15:15 UTC (rev 201232)
</span><span class="lines">@@ -79,6 +79,7 @@
</span><span class="cx"> #include &lt;runtime/TypedArrays.h&gt;
</span><span class="cx"> #include &lt;wtf/HashTraits.h&gt;
</span><span class="cx"> #include &lt;wtf/MainThread.h&gt;
</span><ins>+#include &lt;wtf/RunLoop.h&gt;
</ins><span class="cx"> #include &lt;wtf/Vector.h&gt;
</span><span class="cx"> 
</span><span class="cx"> using namespace JSC;
</span><span class="lines">@@ -2816,6 +2817,33 @@
</span><span class="cx">         completionHandler({ *this, m_blobURLs, blobFilePaths });
</span><span class="cx">     });
</span><span class="cx"> }
</span><ins>+
+IDBValue SerializedScriptValue::writeBlobsToDiskForIndexedDBSynchronously()
+{
+    ASSERT(!isMainThread());
+
+    IDBValue value;
+    IDBValue* valuePtr = &amp;value;
+
+    Lock lock;
+    Condition condition;
+    Condition* conditionPtr = &amp;condition;
+    lock.lock();
+
+    RunLoop::main().dispatch([this, conditionPtr, valuePtr] {
+        writeBlobsToDiskForIndexedDB([conditionPtr, valuePtr](const IDBValue&amp; result) {
+            ASSERT(isMainThread());
+            valuePtr-&gt;setAsIsolatedCopy(result);
+
+            conditionPtr-&gt;notifyAll();
+        });
+    });
+
+    condition.wait(lock);
+
+    return value;
+}
+
</ins><span class="cx"> #endif // ENABLE(INDEXED_DATABASE)
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCorebindingsjsSerializedScriptValueh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/bindings/js/SerializedScriptValue.h (201231 => 201232)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/bindings/js/SerializedScriptValue.h        2016-05-20 22:53:35 UTC (rev 201231)
+++ trunk/Source/WebCore/bindings/js/SerializedScriptValue.h        2016-05-20 23:15:15 UTC (rev 201232)
</span><span class="lines">@@ -87,6 +87,7 @@
</span><span class="cx"> #if ENABLE(INDEXED_DATABASE)
</span><span class="cx">     Vector&lt;String&gt; blobURLsIsolatedCopy() const;
</span><span class="cx">     void writeBlobsToDiskForIndexedDB(std::function&lt;void (const IDBValue&amp;)&gt; completionHandler);
</span><ins>+    IDBValue writeBlobsToDiskForIndexedDBSynchronously();
</ins><span class="cx"> #endif // ENABLE(INDEXED_DATABASE)
</span><span class="cx"> 
</span><span class="cx">     static Ref&lt;SerializedScriptValue&gt; createFromWireBytes(Vector&lt;uint8_t&gt;&amp;&amp; data)
</span></span></pre>
</div>
</div>

</body>
</html>