<!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>[278393] trunk/Source/WebCore</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/278393">278393</a></dd>
<dt>Author</dt> <dd>sihui_liu@apple.com</dd>
<dt>Date</dt> <dd>2021-06-02 21:57:45 -0700 (Wed, 02 Jun 2021)</dd>
</dl>

<h3>Log Message</h3>
<pre>Introduce a shared IDB serialization thread
https://bugs.webkit.org/show_bug.cgi?id=226228
<rdar://problem/78725516>

Reviewed by Chris Dumez.

Currently each WebIDBServer has its own thread, and does serialization/deserialization on that thread. To
prepare for making WebIDBServer use WorkQueue, like the other storage manager classes, let's create a shared
thread for handling all serialization/deserialization operations, which cannot be done on WorkQueue as VM needs
to access thread-specific data. Now IDB tasks will call callOnIDBSerializationThreadAndWait to perform
serialization/deserialization operations synchronously.

* Modules/indexeddb/server/IDBBackingStore.h:
* Modules/indexeddb/server/IDBSerializationContext.cpp: Removed. Moved to IDBBindingUtilities.cpp as
IDBSerializationContext is only used by IDBSerialization thread now.
* Modules/indexeddb/server/IDBSerializationContext.h: Removed.
* Modules/indexeddb/server/MemoryIDBBackingStore.cpp:
(WebCore::IDBServer::MemoryIDBBackingStore::MemoryIDBBackingStore):
(WebCore::IDBServer::MemoryIDBBackingStore::serializationContext): Deleted.
* Modules/indexeddb/server/MemoryIDBBackingStore.h:
* Modules/indexeddb/server/MemoryObjectStore.cpp:
(WebCore::IDBServer::MemoryObjectStore::MemoryObjectStore):
(WebCore::IDBServer::MemoryObjectStore::addRecord):
(WebCore::IDBServer::MemoryObjectStore::populateIndexWithExistingRecords):
* Modules/indexeddb/server/MemoryObjectStore.h:
* Modules/indexeddb/server/SQLiteIDBBackingStore.cpp:
(WebCore::IDBServer::SQLiteIDBBackingStore::SQLiteIDBBackingStore):
(WebCore::IDBServer::SQLiteIDBBackingStore::updateOneIndexForAddRecord):
(WebCore::IDBServer::SQLiteIDBBackingStore::serializationContext): Deleted.
* Modules/indexeddb/server/SQLiteIDBBackingStore.h:
* Modules/indexeddb/server/UniqueIDBDatabase.cpp:
(WebCore::IDBServer::UniqueIDBDatabase::putOrAdd):
* Sources.txt:
* bindings/js/IDBBindingUtilities.cpp:
(WebCore::IDBSerializationContext::IDBSerializationContext):
(WebCore::IDBSerializationContext::~IDBSerializationContext):
(WebCore::IDBSerializationContext::globalObject):
(WebCore::IDBSerializationContext::initializeVM):
(WebCore::callOnIDBSerializationThreadAndWait): Create a IDBSerialization thread if not exists, and dispatch a
synchronous task to it.
* bindings/js/IDBBindingUtilities.h:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbserverIDBBackingStoreh">trunk/Source/WebCore/Modules/indexeddb/server/IDBBackingStore.h</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbserverMemoryIDBBackingStorecpp">trunk/Source/WebCore/Modules/indexeddb/server/MemoryIDBBackingStore.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbserverMemoryIDBBackingStoreh">trunk/Source/WebCore/Modules/indexeddb/server/MemoryIDBBackingStore.h</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbserverMemoryObjectStorecpp">trunk/Source/WebCore/Modules/indexeddb/server/MemoryObjectStore.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbserverMemoryObjectStoreh">trunk/Source/WebCore/Modules/indexeddb/server/MemoryObjectStore.h</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbserverSQLiteIDBBackingStorecpp">trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbserverSQLiteIDBBackingStoreh">trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.h</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbserverUniqueIDBDatabasecpp">trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp</a></li>
<li><a href="#trunkSourceWebCoreSourcestxt">trunk/Source/WebCore/Sources.txt</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>

<h3>Removed Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreModulesindexeddbserverIDBSerializationContextcpp">trunk/Source/WebCore/Modules/indexeddb/server/IDBSerializationContext.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbserverIDBSerializationContexth">trunk/Source/WebCore/Modules/indexeddb/server/IDBSerializationContext.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (278392 => 278393)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog   2021-06-03 01:54:35 UTC (rev 278392)
+++ trunk/Source/WebCore/ChangeLog      2021-06-03 04:57:45 UTC (rev 278393)
</span><span class="lines">@@ -1,3 +1,47 @@
</span><ins>+2021-06-02  Sihui Liu  <sihui_liu@apple.com>
+
+        Introduce a shared IDB serialization thread
+        https://bugs.webkit.org/show_bug.cgi?id=226228
+        <rdar://problem/78725516>
+
+        Reviewed by Chris Dumez.
+
+        Currently each WebIDBServer has its own thread, and does serialization/deserialization on that thread. To
+        prepare for making WebIDBServer use WorkQueue, like the other storage manager classes, let's create a shared
+        thread for handling all serialization/deserialization operations, which cannot be done on WorkQueue as VM needs 
+        to access thread-specific data. Now IDB tasks will call callOnIDBSerializationThreadAndWait to perform 
+        serialization/deserialization operations synchronously.
+
+        * Modules/indexeddb/server/IDBBackingStore.h:
+        * Modules/indexeddb/server/IDBSerializationContext.cpp: Removed. Moved to IDBBindingUtilities.cpp as 
+        IDBSerializationContext is only used by IDBSerialization thread now.
+        * Modules/indexeddb/server/IDBSerializationContext.h: Removed.
+        * Modules/indexeddb/server/MemoryIDBBackingStore.cpp:
+        (WebCore::IDBServer::MemoryIDBBackingStore::MemoryIDBBackingStore):
+        (WebCore::IDBServer::MemoryIDBBackingStore::serializationContext): Deleted.
+        * Modules/indexeddb/server/MemoryIDBBackingStore.h:
+        * Modules/indexeddb/server/MemoryObjectStore.cpp:
+        (WebCore::IDBServer::MemoryObjectStore::MemoryObjectStore):
+        (WebCore::IDBServer::MemoryObjectStore::addRecord):
+        (WebCore::IDBServer::MemoryObjectStore::populateIndexWithExistingRecords):
+        * Modules/indexeddb/server/MemoryObjectStore.h:
+        * Modules/indexeddb/server/SQLiteIDBBackingStore.cpp:
+        (WebCore::IDBServer::SQLiteIDBBackingStore::SQLiteIDBBackingStore):
+        (WebCore::IDBServer::SQLiteIDBBackingStore::updateOneIndexForAddRecord):
+        (WebCore::IDBServer::SQLiteIDBBackingStore::serializationContext): Deleted.
+        * Modules/indexeddb/server/SQLiteIDBBackingStore.h:
+        * Modules/indexeddb/server/UniqueIDBDatabase.cpp:
+        (WebCore::IDBServer::UniqueIDBDatabase::putOrAdd):
+        * Sources.txt:
+        * bindings/js/IDBBindingUtilities.cpp:
+        (WebCore::IDBSerializationContext::IDBSerializationContext):
+        (WebCore::IDBSerializationContext::~IDBSerializationContext):
+        (WebCore::IDBSerializationContext::globalObject):
+        (WebCore::IDBSerializationContext::initializeVM):
+        (WebCore::callOnIDBSerializationThreadAndWait): Create a IDBSerialization thread if not exists, and dispatch a 
+        synchronous task to it.
+        * bindings/js/IDBBindingUtilities.h:
+
</ins><span class="cx"> 2021-06-02  Chris Dumez  <cdumez@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Port media code to the HTML event loop
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbserverIDBBackingStoreh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/server/IDBBackingStore.h (278392 => 278393)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/server/IDBBackingStore.h  2021-06-03 01:54:35 UTC (rev 278392)
+++ trunk/Source/WebCore/Modules/indexeddb/server/IDBBackingStore.h     2021-06-03 04:57:45 UTC (rev 278393)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2015 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2015-2021 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -55,8 +55,6 @@
</span><span class="cx"> 
</span><span class="cx"> namespace IDBServer {
</span><span class="cx"> 
</span><del>-class IDBSerializationContext;
-
</del><span class="cx"> class IDBBackingStore {
</span><span class="cx"> public:
</span><span class="cx">     virtual ~IDBBackingStore() { RELEASE_ASSERT(!isMainThread()); }
</span><span class="lines">@@ -88,8 +86,6 @@
</span><span class="cx">     virtual IDBError openCursor(const IDBResourceIdentifier& transactionIdentifier, const IDBCursorInfo&, IDBGetResult& outResult) = 0;
</span><span class="cx">     virtual IDBError iterateCursor(const IDBResourceIdentifier& transactionIdentifier, const IDBResourceIdentifier& cursorIdentifier, const IDBIterateCursorData&, IDBGetResult& outResult) = 0;
</span><span class="cx"> 
</span><del>-    virtual IDBSerializationContext& serializationContext() = 0;
-
</del><span class="cx">     virtual IDBObjectStoreInfo* infoForObjectStore(uint64_t objectStoreIdentifier) = 0;
</span><span class="cx">     virtual void deleteBackingStore() = 0;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbserverIDBSerializationContextcpp"></a>
<div class="delfile"><h4>Deleted: trunk/Source/WebCore/Modules/indexeddb/server/IDBSerializationContext.cpp (278392 => 278393)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/server/IDBSerializationContext.cpp        2021-06-03 01:54:35 UTC (rev 278392)
+++ trunk/Source/WebCore/Modules/indexeddb/server/IDBSerializationContext.cpp   2021-06-03 04:57:45 UTC (rev 278393)
</span><span class="lines">@@ -1,109 +0,0 @@
</span><del>-/*
- * Copyright (C) 2019 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-#include "IDBSerializationContext.h"
-
-#include "DOMWrapperWorld.h"
-#include "WebCoreJSClientData.h"
-#include <JavaScriptCore/JSObjectInlines.h>
-#include <wtf/Lock.h>
-
-namespace WebCore {
-
-namespace IDBServer {
-
-static Lock serializationContextMapLock;
-
-static HashMap<Thread*, IDBSerializationContext*>& serializationContextMap() WTF_REQUIRES_LOCK(serializationContextMapLock)
-{
-    static NeverDestroyed<HashMap<Thread*, IDBSerializationContext*>> map;
-    return map;
-}
-
-Ref<IDBSerializationContext> IDBSerializationContext::getOrCreateForCurrentThread()
-{
-    auto& thread = Thread::current();
-    Locker locker { serializationContextMapLock };
-    auto[iter, isNewEntry] = serializationContextMap().add(&thread, nullptr);
-    if (isNewEntry) {
-        Ref<IDBSerializationContext> protectedContext = adoptRef(*new IDBSerializationContext(thread));
-        iter->value = protectedContext.ptr();
-        return protectedContext;
-    }
-
-    return *iter->value;
-}
-
-IDBSerializationContext::~IDBSerializationContext()
-{
-    Locker locker { serializationContextMapLock };
-    ASSERT(this == serializationContextMap().get(&m_thread));
-
-    if (m_vm) {
-        JSC::JSLockHolder lock(*m_vm);
-        m_globalObject.clear();
-        m_vm = nullptr;
-    }
-    serializationContextMap().remove(&m_thread);
-}
-
-void IDBSerializationContext::initializeVM()
-{
-    if (m_vm)
-        return;
-
-    ASSERT(!m_globalObject);
-    m_vm = JSC::VM::create();
-    m_vm->heap.acquireAccess();
-    JSVMClientData::initNormalWorld(m_vm.get(), WorkerThreadType::Worklet);
-
-    JSC::JSLockHolder locker(m_vm.get());
-    m_globalObject.set(*m_vm, JSIDBSerializationGlobalObject::create(*m_vm, JSIDBSerializationGlobalObject::createStructure(*m_vm, JSC::jsNull()), normalWorld(*m_vm)));
-}
-
-JSC::VM& IDBSerializationContext::vm()
-{
-    ASSERT(&m_thread == &Thread::current());
-
-    initializeVM();
-    return *m_vm;
-}
-
-JSC::JSGlobalObject& IDBSerializationContext::globalObject()
-{
-    ASSERT(&m_thread == &Thread::current());
-
-    initializeVM();
-    return *m_globalObject.get();
-}
-
-IDBSerializationContext::IDBSerializationContext(Thread& thread)
-    : m_thread(thread)
-{
-}
-
-} // namespace IDBServer
-} // namespace WebCore
</del></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbserverIDBSerializationContexth"></a>
<div class="delfile"><h4>Deleted: trunk/Source/WebCore/Modules/indexeddb/server/IDBSerializationContext.h (278392 => 278393)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/server/IDBSerializationContext.h  2021-06-03 01:54:35 UTC (rev 278392)
+++ trunk/Source/WebCore/Modules/indexeddb/server/IDBSerializationContext.h     2021-06-03 04:57:45 UTC (rev 278393)
</span><span class="lines">@@ -1,60 +0,0 @@
</span><del>-/*
- * Copyright (C) 2019 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#pragma once
-
-#include "JSIDBSerializationGlobalObject.h"
-#include <JavaScriptCore/StrongInlines.h>
-#include <JavaScriptCore/StructureInlines.h>
-
-namespace JSC {
-class CallFrame;
-class VM;
-}
-
-namespace WebCore {
-
-namespace IDBServer {
-
-class IDBSerializationContext : public RefCounted<IDBSerializationContext> {
-public:
-    static Ref<IDBSerializationContext> getOrCreateForCurrentThread();
-
-    ~IDBSerializationContext();
-
-    JSC::VM& vm();
-    JSC::JSGlobalObject& globalObject();
-
-private:
-    explicit IDBSerializationContext(Thread&);
-    void initializeVM();
-
-    RefPtr<JSC::VM> m_vm;
-    JSC::Strong<JSIDBSerializationGlobalObject> m_globalObject;
-    Thread& m_thread;
-};
-
-} // namespace IDBServer
-} // namespace WebCore
</del></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbserverMemoryIDBBackingStorecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/server/MemoryIDBBackingStore.cpp (278392 => 278393)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/server/MemoryIDBBackingStore.cpp  2021-06-03 01:54:35 UTC (rev 278392)
+++ trunk/Source/WebCore/Modules/indexeddb/server/MemoryIDBBackingStore.cpp     2021-06-03 04:57:45 UTC (rev 278393)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2015 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2015-2021 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -33,7 +33,6 @@
</span><span class="cx"> #include "IDBIndexInfo.h"
</span><span class="cx"> #include "IDBIterateCursorData.h"
</span><span class="cx"> #include "IDBKeyRangeData.h"
</span><del>-#include "IDBSerializationContext.h"
</del><span class="cx"> #include "Logging.h"
</span><span class="cx"> #include "MemoryIndexCursor.h"
</span><span class="cx"> #include "MemoryObjectStore.h"
</span><span class="lines">@@ -48,7 +47,6 @@
</span><span class="cx"> MemoryIDBBackingStore::MemoryIDBBackingStore(PAL::SessionID sessionID, const IDBDatabaseIdentifier& identifier)
</span><span class="cx">     : m_identifier(identifier)
</span><span class="cx">     , m_sessionID(sessionID)
</span><del>-    , m_serializationContext(IDBSerializationContext::getOrCreateForCurrentThread())
</del><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -616,11 +614,6 @@
</span><span class="cx">     return objectStoreByIdentifier;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-IDBSerializationContext& MemoryIDBBackingStore::serializationContext()
-{
-    return m_serializationContext.get();
-}
-
</del><span class="cx"> IDBObjectStoreInfo* MemoryIDBBackingStore::infoForObjectStore(uint64_t objectStoreIdentifier)
</span><span class="cx"> {
</span><span class="cx">     ASSERT(m_databaseInfo);
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbserverMemoryIDBBackingStoreh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/server/MemoryIDBBackingStore.h (278392 => 278393)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/server/MemoryIDBBackingStore.h    2021-06-03 01:54:35 UTC (rev 278392)
+++ trunk/Source/WebCore/Modules/indexeddb/server/MemoryIDBBackingStore.h       2021-06-03 04:57:45 UTC (rev 278393)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2015 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2015-2021 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -36,7 +36,6 @@
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> namespace IDBServer {
</span><span class="cx"> 
</span><del>-class IDBSerializationContext;
</del><span class="cx"> class MemoryObjectStore;
</span><span class="cx"> 
</span><span class="cx"> class MemoryIDBBackingStore final : public IDBBackingStore {
</span><span class="lines">@@ -52,8 +51,6 @@
</span><span class="cx">     void removeObjectStoreForVersionChangeAbort(MemoryObjectStore&);
</span><span class="cx">     void restoreObjectStoreForVersionChangeAbort(Ref<MemoryObjectStore>&&);
</span><span class="cx"> 
</span><del>-    IDBSerializationContext& serializationContext() final;
-
</del><span class="cx"> private:
</span><span class="cx">     IDBError beginTransaction(const IDBTransactionInfo&) final;
</span><span class="cx">     IDBError abortTransaction(const IDBResourceIdentifier& transactionIdentifier) final;
</span><span class="lines">@@ -95,7 +92,6 @@
</span><span class="cx"> 
</span><span class="cx">     IDBDatabaseIdentifier m_identifier;
</span><span class="cx">     PAL::SessionID m_sessionID;
</span><del>-    Ref<IDBSerializationContext> m_serializationContext;
</del><span class="cx">     std::unique_ptr<IDBDatabaseInfo> m_databaseInfo;
</span><span class="cx"> 
</span><span class="cx">     HashMap<IDBResourceIdentifier, std::unique_ptr<MemoryBackingStoreTransaction>> m_transactions;
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbserverMemoryObjectStorecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/server/MemoryObjectStore.cpp (278392 => 278393)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/server/MemoryObjectStore.cpp      2021-06-03 01:54:35 UTC (rev 278392)
+++ trunk/Source/WebCore/Modules/indexeddb/server/MemoryObjectStore.cpp 2021-06-03 04:57:45 UTC (rev 278393)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2015 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2015-2021 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -30,7 +30,6 @@
</span><span class="cx"> #include "IDBError.h"
</span><span class="cx"> #include "IDBGetAllResult.h"
</span><span class="cx"> #include "IDBKeyRangeData.h"
</span><del>-#include "IDBSerializationContext.h"
</del><span class="cx"> #include "IDBValue.h"
</span><span class="cx"> #include "IndexKey.h"
</span><span class="cx"> #include "Logging.h"
</span><span class="lines">@@ -52,7 +51,6 @@
</span><span class="cx"> 
</span><span class="cx"> MemoryObjectStore::MemoryObjectStore(PAL::SessionID, const IDBObjectStoreInfo& info)
</span><span class="cx">     : m_info(info)
</span><del>-    , m_serializationContext(IDBSerializationContext::getOrCreateForCurrentThread())
</del><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -251,7 +249,10 @@
</span><span class="cx"> 
</span><span class="cx"> IDBError MemoryObjectStore::addRecord(MemoryBackingStoreTransaction& transaction, const IDBKeyData& keyData, const IDBValue& value)
</span><span class="cx"> {
</span><del>-    auto indexKeys = generateIndexKeyMapForValue(m_serializationContext->globalObject(), m_info, keyData, value);
</del><ins>+    IndexIDToIndexKeyMap indexKeys;
+    callOnIDBSerializationThreadAndWait([info = m_info.isolatedCopy(), keyData = keyData.isolatedCopy(), value = value.isolatedCopy(), &indexKeys](auto& globalObject) {
+        indexKeys = generateIndexKeyMapForValue(globalObject, info, keyData, value);
+    });
</ins><span class="cx">     return addRecord(transaction, keyData, indexKeys, value);
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -338,20 +339,25 @@
</span><span class="cx">     if (!m_keyValueStore)
</span><span class="cx">         return IDBError { };
</span><span class="cx"> 
</span><del>-    JSLockHolder locker(m_serializationContext->vm());
</del><ins>+    for (const auto& iterator : *m_keyValueStore) {
+        std::optional<IndexKey> resultIndexKey;
+        callOnIDBSerializationThreadAndWait([key = iterator.key.isolatedCopy(), value = iterator.value, info = m_info.isolatedCopy(), indexInfo = index.info().isolatedCopy(), &resultIndexKey](auto& globalObject) {
+            auto jsValue = deserializeIDBValueToJSValue(globalObject, value);
+            if (jsValue.isUndefinedOrNull())
+                return;
</ins><span class="cx"> 
</span><del>-    for (const auto& iterator : *m_keyValueStore) {
-        auto jsValue = deserializeIDBValueToJSValue(m_serializationContext->globalObject(), iterator.value);
-        if (jsValue.isUndefinedOrNull())
</del><ins>+            IndexKey indexKey;
+            generateIndexKeyForValue(globalObject, indexInfo, jsValue, indexKey, info.keyPath(), key);
+            resultIndexKey = indexKey.isolatedCopy();
+        });
+
+        if (!resultIndexKey)
</ins><span class="cx">             return IDBError { };
</span><span class="cx"> 
</span><del>-        IndexKey indexKey;
-        generateIndexKeyForValue(m_serializationContext->globalObject(), index.info(), jsValue, indexKey, m_info.keyPath(), iterator.key);
-
-        if (indexKey.isNull())
</del><ins>+        if (resultIndexKey->isNull())
</ins><span class="cx">             continue;
</span><span class="cx"> 
</span><del>-        IDBError error = index.putIndexKey(iterator.key, indexKey);
</del><ins>+        IDBError error = index.putIndexKey(iterator.key, *resultIndexKey);
</ins><span class="cx">         if (!error.isNull())
</span><span class="cx">             return error;
</span><span class="cx">     }
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbserverMemoryObjectStoreh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/server/MemoryObjectStore.h (278392 => 278393)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/server/MemoryObjectStore.h        2021-06-03 01:54:35 UTC (rev 278392)
+++ trunk/Source/WebCore/Modules/indexeddb/server/MemoryObjectStore.h   2021-06-03 04:57:45 UTC (rev 278393)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2015 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2015-2021 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -55,7 +55,6 @@
</span><span class="cx"> 
</span><span class="cx"> namespace IDBServer {
</span><span class="cx"> 
</span><del>-class IDBSerializationContext;
</del><span class="cx"> class MemoryBackingStoreTransaction;
</span><span class="cx"> 
</span><span class="cx"> typedef HashMap<IDBKeyData, ThreadSafeDataBuffer, IDBKeyDataHash, IDBKeyDataHashTraits> KeyValueMap;
</span><span class="lines">@@ -133,8 +132,6 @@
</span><span class="cx">     HashMap<uint64_t, RefPtr<MemoryIndex>> m_indexesByIdentifier;
</span><span class="cx">     HashMap<String, RefPtr<MemoryIndex>> m_indexesByName;
</span><span class="cx">     HashMap<IDBResourceIdentifier, std::unique_ptr<MemoryObjectStoreCursor>> m_cursors;
</span><del>-
-    Ref<IDBSerializationContext> m_serializationContext;
</del><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace IDBServer
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbserverSQLiteIDBBackingStorecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.cpp (278392 => 278393)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.cpp  2021-06-03 01:54:35 UTC (rev 278392)
+++ trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.cpp     2021-06-03 04:57:45 UTC (rev 278393)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2016-2017 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2016-2021 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -36,7 +36,6 @@
</span><span class="cx"> #include "IDBKeyData.h"
</span><span class="cx"> #include "IDBObjectStoreInfo.h"
</span><span class="cx"> #include "IDBSerialization.h"
</span><del>-#include "IDBSerializationContext.h"
</del><span class="cx"> #include "IDBTransactionInfo.h"
</span><span class="cx"> #include "IDBValue.h"
</span><span class="cx"> #include "IndexKey.h"
</span><span class="lines">@@ -241,7 +240,6 @@
</span><span class="cx">     : m_sessionID(sessionID)
</span><span class="cx">     , m_identifier(identifier)
</span><span class="cx">     , m_databaseRootDirectory(databaseRootDirectory)
</span><del>-    , m_serializationContext(IDBSerializationContext::getOrCreateForCurrentThread())
</del><span class="cx"> {
</span><span class="cx">     m_databaseDirectory = fullDatabaseDirectoryWithUpgrade();
</span><span class="cx"> }
</span><span class="lines">@@ -1886,19 +1884,24 @@
</span><span class="cx"> 
</span><span class="cx"> IDBError SQLiteIDBBackingStore::updateOneIndexForAddRecord(IDBObjectStoreInfo& objectStoreInfo, const IDBIndexInfo& info, const IDBKeyData& key, const ThreadSafeDataBuffer& value, int64_t recordID)
</span><span class="cx"> {
</span><del>-    JSLockHolder locker(m_serializationContext->vm());
</del><ins>+    std::optional<IndexKey> resultIndexKey;
+    callOnIDBSerializationThreadAndWait([objectStoreInfo = objectStoreInfo.isolatedCopy(), info = info.isolatedCopy(), key = key.isolatedCopy(), value, &resultIndexKey](auto& globalObject) {
+        auto jsValue = deserializeIDBValueToJSValue(globalObject, value);
+        if (jsValue.isUndefinedOrNull())
+            return;
</ins><span class="cx"> 
</span><del>-    auto jsValue = deserializeIDBValueToJSValue(m_serializationContext->globalObject(), value);
-    if (jsValue.isUndefinedOrNull())
</del><ins>+        IndexKey indexKey;
+        generateIndexKeyForValue(globalObject, info, jsValue, indexKey, objectStoreInfo.keyPath(), key);
+        resultIndexKey = indexKey.isolatedCopy();
+    });
+
+    if (!resultIndexKey)
</ins><span class="cx">         return IDBError { };
</span><span class="cx"> 
</span><del>-    IndexKey indexKey;
-    generateIndexKeyForValue(m_serializationContext->globalObject(), info, jsValue, indexKey, objectStoreInfo.keyPath(), key);
-
-    if (indexKey.isNull())
</del><ins>+    if (resultIndexKey->isNull())
</ins><span class="cx">         return IDBError { };
</span><span class="cx"> 
</span><del>-    return uncheckedPutIndexKey(info, key, indexKey, recordID);
</del><ins>+    return uncheckedPutIndexKey(info, key, *resultIndexKey, recordID);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> IDBError SQLiteIDBBackingStore::updateAllIndexesForAddRecord(const IDBObjectStoreInfo& info, const IDBKeyData& key, const IndexIDToIndexKeyMap& indexKeys, int64_t recordID)
</span><span class="lines">@@ -2745,11 +2748,6 @@
</span><span class="cx">     return IDBError { };
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-IDBSerializationContext& SQLiteIDBBackingStore::serializationContext()
-{
-    return m_serializationContext.get();
-}
-
</del><span class="cx"> IDBObjectStoreInfo* SQLiteIDBBackingStore::infoForObjectStore(uint64_t objectStoreIdentifier)
</span><span class="cx"> {
</span><span class="cx">     ASSERT(m_databaseInfo);
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbserverSQLiteIDBBackingStoreh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.h (278392 => 278393)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.h    2021-06-03 01:54:35 UTC (rev 278392)
+++ trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.h       2021-06-03 04:57:45 UTC (rev 278393)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2016 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2016-2021 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -46,7 +46,6 @@
</span><span class="cx"> 
</span><span class="cx"> enum class IsSchemaUpgraded : bool { No, Yes };
</span><span class="cx"> 
</span><del>-class IDBSerializationContext;
</del><span class="cx"> class SQLiteIDBCursor;
</span><span class="cx"> 
</span><span class="cx"> class SQLiteIDBBackingStore final : public IDBBackingStore {
</span><span class="lines">@@ -82,8 +81,6 @@
</span><span class="cx">     IDBError openCursor(const IDBResourceIdentifier& transactionIdentifier, const IDBCursorInfo&, IDBGetResult& outResult) final;
</span><span class="cx">     IDBError iterateCursor(const IDBResourceIdentifier& transactionIdentifier, const IDBResourceIdentifier& cursorIdentifier, const IDBIterateCursorData&, IDBGetResult& outResult) final;
</span><span class="cx"> 
</span><del>-    IDBSerializationContext& serializationContext() final;
-
</del><span class="cx">     IDBObjectStoreInfo* infoForObjectStore(uint64_t objectStoreIdentifier) final;
</span><span class="cx">     void deleteBackingStore() final;
</span><span class="cx"> 
</span><span class="lines">@@ -221,8 +218,6 @@
</span><span class="cx"> 
</span><span class="cx">     String m_databaseRootDirectory;
</span><span class="cx">     String m_databaseDirectory;
</span><del>-
-    Ref<IDBSerializationContext> m_serializationContext;
</del><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace IDBServer
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbserverUniqueIDBDatabasecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp (278392 => 278393)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp      2021-06-03 01:54:35 UTC (rev 278392)
+++ trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp 2021-06-03 04:57:45 UTC (rev 278393)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2015, 2016 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2015-2021 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -34,7 +34,7 @@
</span><span class="cx"> #include "IDBIterateCursorData.h"
</span><span class="cx"> #include "IDBKeyRangeData.h"
</span><span class="cx"> #include "IDBResultData.h"
</span><del>-#include "IDBSerializationContext.h"
</del><ins>+#include "IDBSerialization.h"
</ins><span class="cx"> #include "IDBServer.h"
</span><span class="cx"> #include "IDBTransactionInfo.h"
</span><span class="cx"> #include "IDBValue.h"
</span><span class="lines">@@ -744,7 +744,10 @@
</span><span class="cx">         usedKey = keyData;
</span><span class="cx"> 
</span><span class="cx">     // Generate index keys up front for more accurate quota check.
</span><del>-    auto indexKeys = generateIndexKeyMapForValue(m_backingStore->serializationContext().globalObject(), *objectStoreInfo, usedKey, value);
</del><ins>+    IndexIDToIndexKeyMap indexKeys;
+    callOnIDBSerializationThreadAndWait([objectStoreInfo = objectStoreInfo->isolatedCopy(), key = usedKey.isolatedCopy(), value = value.isolatedCopy(), &indexKeys](auto& globalObject) {
+        indexKeys = generateIndexKeyMapForValue(globalObject, objectStoreInfo, key, value);
+    });
</ins><span class="cx"> 
</span><span class="cx">     if (overwriteMode == IndexedDB::ObjectStoreOverwriteMode::NoOverwrite) {
</span><span class="cx">         bool keyExists;
</span></span></pre></div>
<a id="trunkSourceWebCoreSourcestxt"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Sources.txt (278392 => 278393)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Sources.txt 2021-06-03 01:54:35 UTC (rev 278392)
+++ trunk/Source/WebCore/Sources.txt    2021-06-03 04:57:45 UTC (rev 278393)
</span><span class="lines">@@ -94,7 +94,6 @@
</span><span class="cx"> Modules/indexeddb/client/TransactionOperation.cpp
</span><span class="cx"> Modules/indexeddb/server/IDBConnectionToClient.cpp
</span><span class="cx"> Modules/indexeddb/server/IDBSerialization.cpp
</span><del>-Modules/indexeddb/server/IDBSerializationContext.cpp
</del><span class="cx"> Modules/indexeddb/server/IDBServer.cpp
</span><span class="cx"> Modules/indexeddb/server/IndexValueEntry.cpp
</span><span class="cx"> Modules/indexeddb/server/IndexValueStore.cpp
</span></span></pre></div>
<a id="trunkSourceWebCorebindingsjsIDBBindingUtilitiescpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/bindings/js/IDBBindingUtilities.cpp (278392 => 278393)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/bindings/js/IDBBindingUtilities.cpp 2021-06-03 01:54:35 UTC (rev 278392)
+++ trunk/Source/WebCore/bindings/js/IDBBindingUtilities.cpp    2021-06-03 04:57:45 UTC (rev 278393)
</span><span class="lines">@@ -1,7 +1,7 @@
</span><span class="cx"> /*
</span><span class="cx">  * Copyright (C) 2010 Google Inc. All rights reserved.
</span><span class="cx">  * Copyright (C) 2012 Michael Pruett <michael@68k.org>
</span><del>- * Copyright (C) 2014-2020 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2014-2021 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -43,6 +43,7 @@
</span><span class="cx"> #include "JSDOMConvertNullable.h"
</span><span class="cx"> #include "JSDOMExceptionHandling.h"
</span><span class="cx"> #include "JSFile.h"
</span><ins>+#include "JSIDBSerializationGlobalObject.h"
</ins><span class="cx"> #include "Logging.h"
</span><span class="cx"> #include "MessagePort.h"
</span><span class="cx"> #include "ScriptExecutionContext.h"
</span><span class="lines">@@ -49,9 +50,14 @@
</span><span class="cx"> #include "SerializedScriptValue.h"
</span><span class="cx"> #include "SharedBuffer.h"
</span><span class="cx"> #include "ThreadSafeDataBuffer.h"
</span><ins>+#include "WebCoreJSClientData.h"
</ins><span class="cx"> #include <JavaScriptCore/ArrayBuffer.h>
</span><span class="cx"> #include <JavaScriptCore/DateInstance.h>
</span><span class="cx"> #include <JavaScriptCore/ObjectConstructor.h>
</span><ins>+#include <JavaScriptCore/StrongInlines.h>
+#include <wtf/AutodrainedPool.h>
+#include <wtf/MessageQueue.h>
+#include <wtf/threads/BinarySemaphore.h>
</ins><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> using namespace JSC;
</span><span class="lines">@@ -519,4 +525,74 @@
</span><span class="cx">     return jsValue;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+class IDBSerializationContext {
+public:
+    IDBSerializationContext()
+        : m_thread(Thread::current())
+    {
+    }
+
+    ~IDBSerializationContext()
+    {
+        ASSERT(&m_thread == &Thread::current());
+        if (!m_vm)
+            return;
+
+        JSC::JSLockHolder lock(*m_vm);
+        m_globalObject.clear();
+        m_vm = nullptr;
+    }
+
+    JSC::JSGlobalObject& globalObject()
+    {
+        ASSERT(&m_thread == &Thread::current());
+
+        initializeVM();
+        return *m_globalObject.get();
+    }
+
+private:
+    void initializeVM()
+    {
+        if (m_vm)
+            return;
+
+        ASSERT(!m_globalObject);
+        m_vm = JSC::VM::create();
+        m_vm->heap.acquireAccess();
+        JSVMClientData::initNormalWorld(m_vm.get(), WorkerThreadType::Worklet);
+
+        JSC::JSLockHolder locker(m_vm.get());
+        m_globalObject.set(*m_vm, JSIDBSerializationGlobalObject::create(*m_vm, JSIDBSerializationGlobalObject::createStructure(*m_vm, JSC::jsNull()), normalWorld(*m_vm)));
+    }
+
+    RefPtr<JSC::VM> m_vm;
+    JSC::Strong<JSIDBSerializationGlobalObject> m_globalObject;
+    Thread& m_thread;
+};
+
+void callOnIDBSerializationThreadAndWait(Function<void(JSC::JSGlobalObject&)>&& function)
+{
+    static NeverDestroyed<MessageQueue<Function<void(JSC::JSGlobalObject&)>>> queue;
+    static std::once_flag createThread;
+
+    std::call_once(createThread, [] {
+        Thread::create("IndexedDB Serialization", [] {
+            IDBSerializationContext serializationContext;
+            while (auto function = queue->waitForMessage()) {
+                AutodrainedPool pool;
+                (*function)(serializationContext.globalObject());
+            }
+        });
+    });
+
+    BinarySemaphore semaphore;
+    auto newFuntion = [&semaphore, function = WTFMove(function)](JSC::JSGlobalObject& globalObject) {
+        function(globalObject);
+        semaphore.signal();
+    };
+    queue->append(makeUnique<Function<void(JSC::JSGlobalObject&)>>(WTFMove(newFuntion)));
+    semaphore.wait();
+}
+
</ins><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCorebindingsjsIDBBindingUtilitiesh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/bindings/js/IDBBindingUtilities.h (278392 => 278393)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/bindings/js/IDBBindingUtilities.h   2021-06-03 01:54:35 UTC (rev 278392)
+++ trunk/Source/WebCore/bindings/js/IDBBindingUtilities.h      2021-06-03 04:57:45 UTC (rev 278393)
</span><span class="lines">@@ -1,6 +1,6 @@
</span><span class="cx"> /*
</span><span class="cx">  * Copyright (C) 2010 Google Inc. All rights reserved.
</span><del>- * Copyright (C) 2014, 2015, 2016 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2014-2021 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -63,4 +63,7 @@
</span><span class="cx"> JSC::JSValue toJS(JSC::JSGlobalObject*, JSDOMGlobalObject*, const IDBKeyData&);
</span><span class="cx"> 
</span><span class="cx"> std::optional<JSC::JSValue> deserializeIDBValueWithKeyInjection(JSC::JSGlobalObject&, const IDBValue&, const IDBKeyData&, const std::optional<IDBKeyPath>&);
</span><ins>+
+void callOnIDBSerializationThreadAndWait(Function<void(JSC::JSGlobalObject&)>&&);
+
</ins><span class="cx"> }
</span></span></pre>
</div>
</div>

</body>
</html>