<!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>[192798] 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/192798">192798</a></dd>
<dt>Author</dt> <dd>beidson@apple.com</dd>
<dt>Date</dt> <dd>2015-11-30 10:11:34 -0800 (Mon, 30 Nov 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>Modern IDB: Support keyPath injection into object store records.
https://bugs.webkit.org/show_bug.cgi?id=151640

Reviewed by Andy Estes.

Source/WebCore:

No new tests (At least one existing failure now passes and is unskipped,
while many other existing failures are now closer to passing).

* Modules/indexeddb/server/MemoryObjectStore.cpp:
(WebCore::IDBServer::MemoryObjectStore::updateIndexesForPutRecord): Use the new UniqueIDBDatabase VM/ExecState.
(WebCore::IDBServer::MemoryObjectStore::populateIndexWithExistingRecords): Ditto
(WebCore::IDBServer::indexVM): Deleted.
(WebCore::IDBServer::indexGlobalExec): Deleted.

* Modules/indexeddb/server/UniqueIDBDatabase.cpp:
(WebCore::IDBServer::UniqueIDBDatabase::databaseThreadVM):
(WebCore::IDBServer::UniqueIDBDatabase::databaseThreadExecState):
(WebCore::IDBServer::UniqueIDBDatabase::performPutOrAdd): If appropriate, inject the key that will be used into
  the value before storing the record.
* Modules/indexeddb/server/UniqueIDBDatabase.h:

Add modern JSValue/ExecState&amp; version of some binding utilities, for use today and in preparation of getting
rid of the DOMRequestState and Deprecated::ScriptValue versions later:
* bindings/js/IDBBindingUtilities.cpp:
(WebCore::idbKeyToJSValue):
(WebCore::injectIDBKeyIntoScriptValue):
(WebCore::deserializeIDBValueData):
(WebCore::deserializeIDBValueDataToJSValue):
* bindings/js/IDBBindingUtilities.h:

LayoutTests:

* platform/mac-wk1/TestExpectations:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsplatformmacwk1TestExpectations">trunk/LayoutTests/platform/mac-wk1/TestExpectations</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbserverMemoryObjectStorecpp">trunk/Source/WebCore/Modules/indexeddb/server/MemoryObjectStore.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbserverUniqueIDBDatabasecpp">trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbserverUniqueIDBDatabaseh">trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.h</a></li>
<li><a href="#trunkSourceWebCorebindingsjsIDBBindingUtilitiescpp">trunk/Source/WebCore/bindings/js/IDBBindingUtilities.cpp</a></li>
<li><a href="#trunkSourceWebCorebindingsjsIDBBindingUtilitiesh">trunk/Source/WebCore/bindings/js/IDBBindingUtilities.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (192797 => 192798)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2015-11-30 18:06:23 UTC (rev 192797)
+++ trunk/LayoutTests/ChangeLog        2015-11-30 18:11:34 UTC (rev 192798)
</span><span class="lines">@@ -1,3 +1,12 @@
</span><ins>+2015-11-30  Brady Eidson  &lt;beidson@apple.com&gt;
+
+        Modern IDB: Support keyPath injection into object store records.
+        https://bugs.webkit.org/show_bug.cgi?id=151640
+
+        Reviewed by Andy Estes.
+
+        * platform/mac-wk1/TestExpectations:
+
</ins><span class="cx"> 2015-11-29  Antoine Quint  &lt;graouts@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Browser does not fall back to SVG attribute value when CSS style value is invalid or not supported
</span></span></pre></div>
<a id="trunkLayoutTestsplatformmacwk1TestExpectations"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/platform/mac-wk1/TestExpectations (192797 => 192798)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/platform/mac-wk1/TestExpectations        2015-11-30 18:06:23 UTC (rev 192797)
+++ trunk/LayoutTests/platform/mac-wk1/TestExpectations        2015-11-30 18:11:34 UTC (rev 192798)
</span><span class="lines">@@ -73,6 +73,7 @@
</span><span class="cx"> # But Modern IndexedDB is.
</span><span class="cx"> storage/indexeddb/modern [ Pass ]
</span><span class="cx"> storage/indexeddb/mozilla/add-twice-failure.html [ Pass ]
</span><ins>+storage/indexeddb/mozilla/autoincrement-indexes.html [ Pass ]
</ins><span class="cx"> storage/indexeddb/mozilla/bad-keypath.html [ Pass ]
</span><span class="cx"> storage/indexeddb/mozilla/create-index-unique.html [ Pass ]
</span><span class="cx"> storage/indexeddb/mozilla/create-index-with-integer-keys.html [ Pass ]
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (192797 => 192798)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2015-11-30 18:06:23 UTC (rev 192797)
+++ trunk/Source/WebCore/ChangeLog        2015-11-30 18:11:34 UTC (rev 192798)
</span><span class="lines">@@ -1,3 +1,35 @@
</span><ins>+2015-11-30  Brady Eidson  &lt;beidson@apple.com&gt;
+
+        Modern IDB: Support keyPath injection into object store records.
+        https://bugs.webkit.org/show_bug.cgi?id=151640
+
+        Reviewed by Andy Estes.
+
+        No new tests (At least one existing failure now passes and is unskipped,
+        while many other existing failures are now closer to passing).
+
+        * Modules/indexeddb/server/MemoryObjectStore.cpp:
+        (WebCore::IDBServer::MemoryObjectStore::updateIndexesForPutRecord): Use the new UniqueIDBDatabase VM/ExecState.
+        (WebCore::IDBServer::MemoryObjectStore::populateIndexWithExistingRecords): Ditto
+        (WebCore::IDBServer::indexVM): Deleted.
+        (WebCore::IDBServer::indexGlobalExec): Deleted.
+        
+        * Modules/indexeddb/server/UniqueIDBDatabase.cpp:
+        (WebCore::IDBServer::UniqueIDBDatabase::databaseThreadVM):
+        (WebCore::IDBServer::UniqueIDBDatabase::databaseThreadExecState):
+        (WebCore::IDBServer::UniqueIDBDatabase::performPutOrAdd): If appropriate, inject the key that will be used into
+          the value before storing the record.
+        * Modules/indexeddb/server/UniqueIDBDatabase.h:
+
+        Add modern JSValue/ExecState&amp; version of some binding utilities, for use today and in preparation of getting 
+        rid of the DOMRequestState and Deprecated::ScriptValue versions later:
+        * bindings/js/IDBBindingUtilities.cpp:
+        (WebCore::idbKeyToJSValue):
+        (WebCore::injectIDBKeyIntoScriptValue):
+        (WebCore::deserializeIDBValueData):
+        (WebCore::deserializeIDBValueDataToJSValue):
+        * bindings/js/IDBBindingUtilities.h:
+
</ins><span class="cx"> 2015-11-25  Andy Estes  &lt;aestes@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [Content Filtering] Avoid creating a ContentFilter when loading the empty document
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbserverMemoryObjectStorecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/server/MemoryObjectStore.cpp (192797 => 192798)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/server/MemoryObjectStore.cpp        2015-11-30 18:06:23 UTC (rev 192797)
+++ trunk/Source/WebCore/Modules/indexeddb/server/MemoryObjectStore.cpp        2015-11-30 18:11:34 UTC (rev 192798)
</span><span class="lines">@@ -35,6 +35,7 @@
</span><span class="cx"> #include &quot;IndexKey.h&quot;
</span><span class="cx"> #include &quot;Logging.h&quot;
</span><span class="cx"> #include &quot;MemoryBackingStoreTransaction.h&quot;
</span><ins>+#include &quot;UniqueIDBDatabase.h&quot;
</ins><span class="cx"> 
</span><span class="cx"> #include &lt;wtf/NeverDestroyed.h&gt;
</span><span class="cx"> 
</span><span class="lines">@@ -267,27 +268,6 @@
</span><span class="cx">     return error;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static VM&amp; indexVM()
-{
-    ASSERT(!isMainThread());
-    static NeverDestroyed&lt;RefPtr&lt;VM&gt;&gt; vm = VM::create();
-    return *vm.get();
-}
-
-static ExecState&amp; indexGlobalExec()
-{
-    ASSERT(!isMainThread());
-    static NeverDestroyed&lt;Strong&lt;JSGlobalObject&gt;&gt; globalObject;
-    static bool initialized = false;
-    if (!initialized) {
-        globalObject.get().set(indexVM(), JSGlobalObject::create(indexVM(), JSGlobalObject::createStructure(indexVM(), jsNull())));
-        initialized = true;
-    }
-
-    RELEASE_ASSERT(globalObject.get()-&gt;globalExec());
-    return *globalObject.get()-&gt;globalExec();
-}
-
</del><span class="cx"> void MemoryObjectStore::updateCursorsForPutRecord(std::set&lt;IDBKeyData&gt;::iterator iterator)
</span><span class="cx"> {
</span><span class="cx">     for (auto&amp; cursor : m_cursors.values())
</span><span class="lines">@@ -308,9 +288,9 @@
</span><span class="cx"> 
</span><span class="cx"> IDBError MemoryObjectStore::updateIndexesForPutRecord(const IDBKeyData&amp; key, const ThreadSafeDataBuffer&amp; value)
</span><span class="cx"> {
</span><del>-    JSLockHolder locker(indexVM());
</del><ins>+    JSLockHolder locker(UniqueIDBDatabase::databaseThreadVM());
</ins><span class="cx"> 
</span><del>-    auto jsValue = idbValueDataToJSValue(indexGlobalExec(), value);
</del><ins>+    auto jsValue = idbValueDataToJSValue(UniqueIDBDatabase::databaseThreadExecState(), value);
</ins><span class="cx">     if (jsValue.isUndefinedOrNull())
</span><span class="cx">         return { };
</span><span class="cx"> 
</span><span class="lines">@@ -319,7 +299,7 @@
</span><span class="cx"> 
</span><span class="cx">     for (auto* index : m_indexesByName.values()) {
</span><span class="cx">         IndexKey indexKey;
</span><del>-        generateIndexKeyForValue(indexGlobalExec(), index-&gt;info(), jsValue, indexKey);
</del><ins>+        generateIndexKeyForValue(UniqueIDBDatabase::databaseThreadExecState(), index-&gt;info(), jsValue, indexKey);
</ins><span class="cx"> 
</span><span class="cx">         if (indexKey.isNull())
</span><span class="cx">             continue;
</span><span class="lines">@@ -340,21 +320,20 @@
</span><span class="cx">     return error;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-
</del><span class="cx"> IDBError MemoryObjectStore::populateIndexWithExistingRecords(MemoryIndex&amp; index)
</span><span class="cx"> {
</span><span class="cx">     if (!m_keyValueStore)
</span><span class="cx">         return { };
</span><span class="cx"> 
</span><del>-    JSLockHolder locker(indexVM());
</del><ins>+    JSLockHolder locker(UniqueIDBDatabase::databaseThreadVM());
</ins><span class="cx"> 
</span><span class="cx">     for (auto iterator : *m_keyValueStore) {
</span><del>-        auto jsValue = idbValueDataToJSValue(indexGlobalExec(), iterator.value);
</del><ins>+        auto jsValue = idbValueDataToJSValue(UniqueIDBDatabase::databaseThreadExecState(), iterator.value);
</ins><span class="cx">         if (jsValue.isUndefinedOrNull())
</span><span class="cx">             return { };
</span><span class="cx"> 
</span><span class="cx">         IndexKey indexKey;
</span><del>-        generateIndexKeyForValue(indexGlobalExec(), index.info(), jsValue, indexKey);
</del><ins>+        generateIndexKeyForValue(UniqueIDBDatabase::databaseThreadExecState(), index.info(), jsValue, indexKey);
</ins><span class="cx"> 
</span><span class="cx">         if (indexKey.isNull())
</span><span class="cx">             continue;
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbserverUniqueIDBDatabasecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp (192797 => 192798)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp        2015-11-30 18:06:23 UTC (rev 192797)
+++ trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp        2015-11-30 18:11:34 UTC (rev 192798)
</span><span class="lines">@@ -36,8 +36,11 @@
</span><span class="cx"> #include &quot;Logging.h&quot;
</span><span class="cx"> #include &quot;UniqueIDBDatabaseConnection.h&quot;
</span><span class="cx"> #include &lt;wtf/MainThread.h&gt;
</span><ins>+#include &lt;wtf/NeverDestroyed.h&gt;
</ins><span class="cx"> #include &lt;wtf/ThreadSafeRefCounted.h&gt;
</span><span class="cx"> 
</span><ins>+using namespace JSC;
+
</ins><span class="cx"> namespace WebCore {
</span><span class="cx"> namespace IDBServer {
</span><span class="cx">     
</span><span class="lines">@@ -479,9 +482,26 @@
</span><span class="cx">     m_server.postDatabaseTask(createCrossThreadTask(*this, &amp;UniqueIDBDatabase::performPutOrAdd, callbackID, requestData.transactionIdentifier(), requestData.objectStoreIdentifier(), keyData, valueData, overwriteMode));
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void UniqueIDBDatabase::performPutOrAdd(uint64_t callbackIdentifier, const IDBResourceIdentifier&amp; transactionIdentifier, uint64_t objectStoreIdentifier, const IDBKeyData&amp; keyData, const ThreadSafeDataBuffer&amp; valueData, IndexedDB::ObjectStoreOverwriteMode overwriteMode)
</del><ins>+VM&amp; UniqueIDBDatabase::databaseThreadVM()
</ins><span class="cx"> {
</span><span class="cx">     ASSERT(!isMainThread());
</span><ins>+    static VM* vm = &amp;VM::create().leakRef();
+    return *vm;
+}
+
+ExecState&amp; UniqueIDBDatabase::databaseThreadExecState()
+{
+    ASSERT(!isMainThread());
+
+    static NeverDestroyed&lt;Strong&lt;JSGlobalObject&gt;&gt; globalObject(databaseThreadVM(), JSGlobalObject::create(databaseThreadVM(), JSGlobalObject::createStructure(databaseThreadVM(), jsNull())));
+
+    RELEASE_ASSERT(globalObject.get()-&gt;globalExec());
+    return *globalObject.get()-&gt;globalExec();
+}
+
+void UniqueIDBDatabase::performPutOrAdd(uint64_t callbackIdentifier, const IDBResourceIdentifier&amp; transactionIdentifier, uint64_t objectStoreIdentifier, const IDBKeyData&amp; keyData, const ThreadSafeDataBuffer&amp; originalRecordValue, IndexedDB::ObjectStoreOverwriteMode overwriteMode)
+{
+    ASSERT(!isMainThread());
</ins><span class="cx">     LOG(IndexedDB, &quot;(db) UniqueIDBDatabase::performPutOrAdd&quot;);
</span><span class="cx"> 
</span><span class="cx">     ASSERT(m_backingStore);
</span><span class="lines">@@ -497,6 +517,7 @@
</span><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    bool usedKeyIsGenerated = false;
</ins><span class="cx">     if (objectStoreInfo-&gt;autoIncrement() &amp;&amp; !keyData.isValid()) {
</span><span class="cx">         uint64_t keyNumber;
</span><span class="cx">         error = m_backingStore-&gt;generateKeyNumber(transactionIdentifier, objectStoreIdentifier, keyNumber);
</span><span class="lines">@@ -506,6 +527,7 @@
</span><span class="cx">         }
</span><span class="cx">         
</span><span class="cx">         usedKey.setNumberValue(keyNumber);
</span><ins>+        usedKeyIsGenerated = true;
</ins><span class="cx">     } else
</span><span class="cx">         usedKey = keyData;
</span><span class="cx"> 
</span><span class="lines">@@ -521,6 +543,33 @@
</span><span class="cx">         }
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    // 3.4.1.2 Object Store Storage Operation
+    // If ObjectStore has a key path and the key is autogenerated, then inject the key into the value
+    // using steps to assign a key to a value using a key path.
+    ThreadSafeDataBuffer injectedRecordValue;
+    if (usedKeyIsGenerated &amp;&amp; !objectStoreInfo-&gt;keyPath().isNull()) {
+        JSLockHolder locker(databaseThreadVM());
+
+        JSValue value = deserializeIDBValueDataToJSValue(databaseThreadExecState(), originalRecordValue);
+        if (value.isUndefined()) {
+            m_server.postDatabaseTaskReply(createCrossThreadTask(*this, &amp;UniqueIDBDatabase::didPerformPutOrAdd, callbackIdentifier, IDBError(IDBExceptionCode::ConstraintError, ASCIILiteral(&quot;Unable to deserialize record value for record key injection&quot;)), usedKey));
+            return;
+        }
+
+        if (!injectIDBKeyIntoScriptValue(databaseThreadExecState(), usedKey, value, objectStoreInfo-&gt;keyPath())) {
+            m_server.postDatabaseTaskReply(createCrossThreadTask(*this, &amp;UniqueIDBDatabase::didPerformPutOrAdd, callbackIdentifier, IDBError(IDBExceptionCode::ConstraintError, ASCIILiteral(&quot;Unable to inject record key into record value&quot;)), usedKey));
+            return;
+        }
+
+        auto serializedValue = SerializedScriptValue::create(&amp;databaseThreadExecState(), value, nullptr, nullptr);
+        if (databaseThreadExecState().hadException()) {
+            m_server.postDatabaseTaskReply(createCrossThreadTask(*this, &amp;UniqueIDBDatabase::didPerformPutOrAdd, callbackIdentifier, IDBError(IDBExceptionCode::ConstraintError, ASCIILiteral(&quot;Unable to serialize record value after injecting record key&quot;)), usedKey));
+            return;
+        }
+
+        injectedRecordValue = ThreadSafeDataBuffer::copyVector(serializedValue-&gt;data());
+    }
+
</ins><span class="cx">     // 3.4.1 Object Store Storage Operation
</span><span class="cx">     // ...If a record already exists in store ...
</span><span class="cx">     // then remove the record from store using the steps for deleting records from an object store...
</span><span class="lines">@@ -531,7 +580,7 @@
</span><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    error = m_backingStore-&gt;addRecord(transactionIdentifier, objectStoreIdentifier, usedKey, valueData);
</del><ins>+    error = m_backingStore-&gt;addRecord(transactionIdentifier, objectStoreIdentifier, usedKey, injectedRecordValue.data() ? injectedRecordValue : originalRecordValue);
</ins><span class="cx"> 
</span><span class="cx">     m_server.postDatabaseTaskReply(createCrossThreadTask(*this, &amp;UniqueIDBDatabase::didPerformPutOrAdd, callbackIdentifier, error, usedKey));
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbserverUniqueIDBDatabaseh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.h (192797 => 192798)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.h        2015-11-30 18:06:23 UTC (rev 192797)
+++ trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.h        2015-11-30 18:11:34 UTC (rev 192798)
</span><span class="lines">@@ -29,6 +29,7 @@
</span><span class="cx"> #if ENABLE(INDEXED_DATABASE)
</span><span class="cx"> 
</span><span class="cx"> #include &quot;IDBBackingStore.h&quot;
</span><ins>+#include &quot;IDBBindingUtilities.h&quot;
</ins><span class="cx"> #include &quot;IDBDatabaseIdentifier.h&quot;
</span><span class="cx"> #include &quot;IDBDatabaseInfo.h&quot;
</span><span class="cx"> #include &quot;IDBGetResult.h&quot;
</span><span class="lines">@@ -97,6 +98,9 @@
</span><span class="cx">     void handleDelete(IDBConnectionToClient&amp;, const IDBRequestData&amp;);
</span><span class="cx">     bool deletePending() const { return m_deletePending; }
</span><span class="cx"> 
</span><ins>+    static JSC::VM&amp; databaseThreadVM();
+    static JSC::ExecState&amp; databaseThreadExecState();
+
</ins><span class="cx"> private:
</span><span class="cx">     UniqueIDBDatabase(IDBServer&amp;, const IDBDatabaseIdentifier&amp;);
</span><span class="cx">     
</span></span></pre></div>
<a id="trunkSourceWebCorebindingsjsIDBBindingUtilitiescpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/bindings/js/IDBBindingUtilities.cpp (192797 => 192798)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/bindings/js/IDBBindingUtilities.cpp        2015-11-30 18:06:23 UTC (rev 192797)
+++ trunk/Source/WebCore/bindings/js/IDBBindingUtilities.cpp        2015-11-30 18:11:34 UTC (rev 192798)
</span><span class="lines">@@ -115,7 +115,7 @@
</span><span class="cx"> 
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static JSValue idbKeyToJSValue(ExecState* exec, JSDOMGlobalObject* globalObject, IDBKey* key)
</del><ins>+static JSValue idbKeyToJSValue(ExecState* exec, JSGlobalObject* globalObject, IDBKey* key)
</ins><span class="cx"> {
</span><span class="cx">     if (!key || !exec) {
</span><span class="cx">         // This should be undefined, not null.
</span><span class="lines">@@ -294,12 +294,40 @@
</span><span class="cx">     if (parent.isUndefined())
</span><span class="cx">         return false;
</span><span class="cx"> 
</span><del>-    if (!set(exec, parent, keyPathElements.last(), idbKeyToJSValue(exec, jsCast&lt;JSDOMGlobalObject*&gt;(exec-&gt;lexicalGlobalObject()), key.get())))
</del><ins>+    if (!set(exec, parent, keyPathElements.last(), idbKeyToJSValue(exec, exec-&gt;lexicalGlobalObject(), key.get())))
</ins><span class="cx">         return false;
</span><span class="cx"> 
</span><span class="cx">     return true;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+bool injectIDBKeyIntoScriptValue(JSC::ExecState&amp; exec, const IDBKeyData&amp; keyData, JSC::JSValue value, const IDBKeyPath&amp; keyPath)
+{
+    LOG(IndexedDB, &quot;injectIDBKeyIntoScriptValue&quot;);
+
+    ASSERT(keyPath.type() == IndexedDB::KeyPathType::String);
+
+    Vector&lt;String&gt; keyPathElements;
+    IDBKeyPathParseError error;
+    IDBParseKeyPath(keyPath.string(), keyPathElements, error);
+    ASSERT(error == IDBKeyPathParseError::None);
+
+    if (keyPathElements.isEmpty())
+        return false;
+
+    JSValue parent = ensureNthValueOnKeyPath(&amp;exec, value, keyPathElements, keyPathElements.size() - 1);
+    if (parent.isUndefined())
+        return false;
+
+    auto key = keyData.maybeCreateIDBKey();
+    if (!key)
+        return false;
+
+    if (!set(&amp;exec, parent, keyPathElements.last(), idbKeyToJSValue(&amp;exec, exec.lexicalGlobalObject(), key.get())))
+        return false;
+
+    return true;
+}
+
</ins><span class="cx"> RefPtr&lt;IDBKey&gt; createIDBKeyFromScriptValueAndKeyPath(ExecState* exec, const Deprecated::ScriptValue&amp; value, const IDBKeyPath&amp; keyPath)
</span><span class="cx"> {
</span><span class="cx">     LOG(StorageAPI, &quot;createIDBKeyFromScriptValueAndKeyPath&quot;);
</span><span class="lines">@@ -409,21 +437,26 @@
</span><span class="cx">     if (!execState)
</span><span class="cx">         return Deprecated::ScriptValue();
</span><span class="cx"> 
</span><ins>+    return Deprecated::ScriptValue(execState-&gt;vm(), deserializeIDBValueDataToJSValue(*execState, valueData));
+}
+
+JSC::JSValue deserializeIDBValueDataToJSValue(JSC::ExecState&amp; exec, const ThreadSafeDataBuffer&amp; valueData)
+{
</ins><span class="cx">     if (!valueData.data())
</span><del>-        return Deprecated::ScriptValue(execState-&gt;vm(), jsUndefined());
</del><ins>+        return jsUndefined();
</ins><span class="cx"> 
</span><span class="cx">     const Vector&lt;uint8_t&gt;&amp; data = *valueData.data();
</span><span class="cx">     JSValue result;
</span><span class="cx">     if (data.size()) {
</span><span class="cx">         RefPtr&lt;SerializedScriptValue&gt; serializedValue = SerializedScriptValue::createFromWireBytes(data);
</span><span class="cx"> 
</span><del>-        execState-&gt;vm().apiLock().lock();
-        result = serializedValue-&gt;deserialize(execState, execState-&gt;lexicalGlobalObject(), 0, NonThrowing);
-        execState-&gt;vm().apiLock().unlock();
</del><ins>+        exec.vm().apiLock().lock();
+        result = serializedValue-&gt;deserialize(&amp;exec, exec.lexicalGlobalObject(), 0, NonThrowing);
+        exec.vm().apiLock().unlock();
</ins><span class="cx">     } else
</span><span class="cx">         result = jsNull();
</span><span class="cx"> 
</span><del>-    return Deprecated::ScriptValue(execState-&gt;vm(), result);
</del><ins>+    return result;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> Deprecated::ScriptValue deserializeIDBValueBuffer(DOMRequestState* requestState, PassRefPtr&lt;SharedBuffer&gt; prpBuffer, bool keyIsDefined)
</span></span></pre></div>
<a id="trunkSourceWebCorebindingsjsIDBBindingUtilitiesh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/bindings/js/IDBBindingUtilities.h (192797 => 192798)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/bindings/js/IDBBindingUtilities.h        2015-11-30 18:06:23 UTC (rev 192797)
+++ trunk/Source/WebCore/bindings/js/IDBBindingUtilities.h        2015-11-30 18:11:34 UTC (rev 192798)
</span><span class="lines">@@ -48,6 +48,7 @@
</span><span class="cx"> IDBKeyPath idbKeyPathFromValue(JSC::ExecState*, JSC::JSValue);
</span><span class="cx"> 
</span><span class="cx"> bool injectIDBKeyIntoScriptValue(DOMRequestState*, PassRefPtr&lt;IDBKey&gt;, Deprecated::ScriptValue&amp;, const IDBKeyPath&amp;);
</span><ins>+bool injectIDBKeyIntoScriptValue(JSC::ExecState&amp;, const IDBKeyData&amp;, JSC::JSValue, const IDBKeyPath&amp;);
</ins><span class="cx"> 
</span><span class="cx"> RefPtr&lt;IDBKey&gt; createIDBKeyFromScriptValueAndKeyPath(JSC::ExecState*, const Deprecated::ScriptValue&amp;, const IDBKeyPath&amp;);
</span><span class="cx"> RefPtr&lt;IDBKey&gt; maybeCreateIDBKeyFromScriptValueAndKeyPath(JSC::ExecState&amp;, const Deprecated::ScriptValue&amp;, const IDBKeyPath&amp;);
</span><span class="lines">@@ -61,6 +62,8 @@
</span><span class="cx"> Deprecated::ScriptValue deserializeIDBValueBuffer(DOMRequestState*, PassRefPtr&lt;SharedBuffer&gt;, bool keyIsDefined);
</span><span class="cx"> WEBCORE_EXPORT Deprecated::ScriptValue deserializeIDBValueBuffer(JSC::ExecState*, const Vector&lt;uint8_t&gt;&amp;, bool keyIsDefined);
</span><span class="cx"> 
</span><ins>+JSC::JSValue deserializeIDBValueDataToJSValue(JSC::ExecState&amp;, const ThreadSafeDataBuffer&amp; valueData);
+
</ins><span class="cx"> Deprecated::ScriptValue idbKeyToScriptValue(DOMRequestState*, PassRefPtr&lt;IDBKey&gt;);
</span><span class="cx"> RefPtr&lt;IDBKey&gt; scriptValueToIDBKey(DOMRequestState*, const JSC::JSValue&amp;);
</span><span class="cx"> RefPtr&lt;IDBKey&gt; scriptValueToIDBKey(JSC::ExecState&amp;, const JSC::JSValue&amp;);
</span></span></pre>
</div>
</div>

</body>
</html>