Skip to content
Permalink
Browse files
Generate IndexedDB object serializers
https://bugs.webkit.org/show_bug.cgi?id=244691

Reviewed by Sihui Liu and Brady Eidson.

* Source/WebCore/Modules/indexeddb/IDBDatabaseIdentifier.cpp:
(WebCore::IDBDatabaseIdentifier::IDBDatabaseIdentifier):
* Source/WebCore/Modules/indexeddb/IDBDatabaseIdentifier.h:
(WebCore::IDBDatabaseIdentifier::encode const): Deleted.
(WebCore::IDBDatabaseIdentifier::decode): Deleted.
* Source/WebCore/Modules/indexeddb/IDBFactory.cpp:
(WebCore::IDBFactory::openInternal):
(WebCore::IDBFactory::deleteDatabase):
* Source/WebCore/Modules/indexeddb/IDBGetAllResult.h:
(WebCore::IDBGetAllResult::IDBGetAllResult):
(WebCore::IDBGetAllResult::encode const): Deleted.
(WebCore::IDBGetAllResult::decode): Deleted.
* Source/WebCore/Modules/indexeddb/IDBGetResult.h:
(WebCore::IDBGetResult::IDBGetResult):
(WebCore::IDBGetResult::encode const): Deleted.
(WebCore::IDBGetResult::decode): Deleted.
* Source/WebCore/Modules/indexeddb/IDBKeyRangeData.cpp:
(WebCore::IDBKeyRangeData::IDBKeyRangeData):
* Source/WebCore/Modules/indexeddb/IDBKeyRangeData.h:
(WebCore::IDBKeyRangeData::IDBKeyRangeData):
(WebCore::IDBKeyRangeData::encode const): Deleted.
(WebCore::IDBKeyRangeData::decode): Deleted.
* Source/WebCore/Modules/indexeddb/IDBValue.h:
(WebCore::IDBValue::encode const): Deleted.
(WebCore::IDBValue::decode): Deleted.
* Source/WebCore/Modules/indexeddb/shared/IDBCursorInfo.h:
(WebCore::IDBCursorInfo::transactionIdentifier const):
(WebCore::IDBCursorInfo::encode const): Deleted.
(WebCore::IDBCursorInfo::decode): Deleted.
* Source/WebCore/Modules/indexeddb/shared/IDBCursorRecord.h:
(WebCore::IDBCursorRecord::isolatedCopy const):
(WebCore::IDBCursorRecord::encode const): Deleted.
(WebCore::IDBCursorRecord::decode): Deleted.
* Source/WebCore/Modules/indexeddb/shared/IDBDatabaseInfo.cpp:
(WebCore::IDBDatabaseInfo::IDBDatabaseInfo):
* Source/WebCore/Modules/indexeddb/shared/IDBDatabaseInfo.h:
(WebCore::IDBDatabaseInfo::IDBDatabaseInfo):
(WebCore::IDBDatabaseInfo::encode const): Deleted.
(WebCore::IDBDatabaseInfo::decode): Deleted.
* Source/WebCore/Modules/indexeddb/shared/IDBDatabaseNameAndVersion.h:
(WebCore::IDBDatabaseNameAndVersion::encode const): Deleted.
(WebCore::IDBDatabaseNameAndVersion::decode): Deleted.
* Source/WebCore/Modules/indexeddb/shared/IDBError.h:
(WebCore::IDBError::messageForSerialization const):
(WebCore::IDBError::encode const): Deleted.
(WebCore::IDBError::decode): Deleted.
* Source/WebCore/Modules/indexeddb/shared/IDBGetAllRecordsData.h:
(WebCore::IDBGetAllRecordsData::encode const): Deleted.
(WebCore::IDBGetAllRecordsData::decode): Deleted.
* Source/WebCore/Modules/indexeddb/shared/IDBGetRecordData.h:
(WebCore::IDBGetRecordData::encode const): Deleted.
(WebCore::IDBGetRecordData::decode): Deleted.
* Source/WebCore/Modules/indexeddb/shared/IDBIndexInfo.h:
(WebCore::IDBIndexInfo::encode const): Deleted.
(WebCore::IDBIndexInfo::decode): Deleted.
* Source/WebCore/Modules/indexeddb/shared/IDBIterateCursorData.h:
(WebCore::IDBIterateCursorData::encode const): Deleted.
(WebCore::IDBIterateCursorData::decode): Deleted.
* Source/WebCore/Modules/indexeddb/shared/IDBObjectStoreInfo.cpp:
(WebCore::IDBObjectStoreInfo::IDBObjectStoreInfo):
* Source/WebCore/Modules/indexeddb/shared/IDBObjectStoreInfo.h:
(WebCore::IDBObjectStoreInfo::IDBObjectStoreInfo):
(WebCore::IDBObjectStoreInfo::encode const): Deleted.
(WebCore::IDBObjectStoreInfo::decode): Deleted.
* Source/WebCore/Modules/indexeddb/shared/IDBRequestData.cpp:
* Source/WebCore/Modules/indexeddb/shared/IDBRequestData.h:
(WebCore::IDBRequestData::IDBRequestData):
(WebCore::IDBRequestData::encode const): Deleted.
(WebCore::IDBRequestData::decode): Deleted.
* Source/WebCore/Modules/indexeddb/shared/IDBResourceIdentifier.h:
(WebCore::IDBResourceIdentifier::encode const): Deleted.
(WebCore::IDBResourceIdentifier::decode): Deleted.
* Source/WebCore/Modules/indexeddb/shared/IDBResultData.h:
(WebCore::IDBResultData::encode const): Deleted.
(WebCore::IDBResultData::decode): Deleted.
* Source/WebCore/Modules/indexeddb/shared/IDBTransactionInfo.cpp:
* Source/WebCore/Modules/indexeddb/shared/IDBTransactionInfo.h:
(WebCore::IDBTransactionInfo::IDBTransactionInfo):
(WebCore::IDBTransactionInfo::encode const): Deleted.
(WebCore::IDBTransactionInfo::decode): Deleted.
* Source/WebCore/bindings/js/JSIDBRequestCustom.cpp:
(WebCore::JSIDBRequest::result const):
* Source/WebKit/Scripts/generate-serializers.py:
(SerializedType.__init__):
(MemberVariable.unique_ptr_type):
(generate_cpp):
(parse_serialized_types):
* Source/WebKit/Scripts/webkit/tests/GeneratedSerializers.cpp:
(IPC::ArgumentCoder<Namespace::Subnamespace::StructName>::decode):
(IPC::ArgumentCoder<Namespace::OtherClass>::encode):
(IPC::ArgumentCoder<Namespace::OtherClass>::decode):
(IPC::ArgumentCoder<Namespace::ReturnRefClass>::encode):
(IPC::ArgumentCoder<Namespace::ReturnRefClass>::decode):
(IPC::ArgumentCoder<Namespace::EmptyConstructorStruct>::encode):
(IPC::ArgumentCoder<Namespace::EmptyConstructorStruct>::decode):
* Source/WebKit/Scripts/webkit/tests/GeneratedSerializers.h:
* Source/WebKit/Scripts/webkit/tests/SerializedTypeInfo.cpp:
(WebKit::allSerializedTypes):
* Source/WebKit/Scripts/webkit/tests/TestSerializedType.serialization.in:
* Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in:

Canonical link: https://commits.webkit.org/254196@main
  • Loading branch information
Alex Christensen authored and achristensen07 committed Sep 6, 2022
1 parent a728674 commit d4d3c5e42fefdd31a508016a05e758c4067e4915
Show file tree
Hide file tree
Showing 31 changed files with 444 additions and 886 deletions.
@@ -27,6 +27,7 @@

#include "ClientOrigin.h"
#include "SecurityOriginData.h"
#include <wtf/ArgumentCoder.h>

namespace WebCore {

@@ -73,16 +74,15 @@ class IDBDatabaseIdentifier {
String databaseDirectoryRelativeToRoot(const String& rootDirectory, ASCIILiteral versionString = "v1"_s) const;
WEBCORE_EXPORT static String databaseDirectoryRelativeToRoot(const ClientOrigin&, const String& rootDirectory, ASCIILiteral versionString);

template<class Encoder> void encode(Encoder&) const;
template<class Decoder> static std::optional<IDBDatabaseIdentifier> decode(Decoder&);

#if !LOG_DISABLED
String loggingString() const;
#endif

bool isRelatedToOrigin(const SecurityOriginData& other) const { return m_origin.isRelated(other); }

private:
friend struct IPC::ArgumentCoder<IDBDatabaseIdentifier, void>;

String m_databaseName;
ClientOrigin m_origin;
bool m_isTransient { false };
@@ -105,37 +105,6 @@ struct IDBDatabaseIdentifierHashTraits : SimpleClassHashTraits<IDBDatabaseIdenti
static bool isEmptyValue(const IDBDatabaseIdentifier& info) { return info.isEmpty(); }
};

template<class Encoder>
void IDBDatabaseIdentifier::encode(Encoder& encoder) const
{
encoder << m_databaseName << m_origin << m_isTransient;
}

template<class Decoder>
std::optional<IDBDatabaseIdentifier> IDBDatabaseIdentifier::decode(Decoder& decoder)
{
std::optional<String> databaseName;
decoder >> databaseName;
if (!databaseName)
return std::nullopt;

std::optional<ClientOrigin> origin;
decoder >> origin;
if (!origin)
return std::nullopt;

std::optional<bool> isTransient;
decoder >> isTransient;
if (!isTransient)
return std::nullopt;

IDBDatabaseIdentifier identifier;
identifier.m_databaseName = WTFMove(*databaseName); // FIXME: When decoding from IPC, databaseName can be null, and the non-empty constructor asserts that this is not the case.
identifier.m_origin = WTFMove(*origin);
identifier.m_isTransient = *isTransient;
return identifier;
}

} // namespace WebCore

namespace WTF {
@@ -29,18 +29,16 @@
#include "IDBKeyPath.h"
#include "IDBValue.h"
#include "IndexedDB.h"

#include <variant>
#include <wtf/ArgumentCoder.h>
#include <wtf/IsoMalloc.h>

namespace WebCore {

class IDBGetAllResult {
WTF_MAKE_ISO_ALLOCATED_EXPORT(IDBGetAllResult, WEBCORE_EXPORT);
public:
IDBGetAllResult()
{
}
IDBGetAllResult() = default;

IDBGetAllResult(IndexedDB::GetAllType type, const std::optional<IDBKeyPath>& keyPath)
: m_type(type)
@@ -54,18 +52,24 @@ class IDBGetAllResult {

IndexedDB::GetAllType type() const { return m_type; }
const std::optional<IDBKeyPath>& keyPath() const { return m_keyPath; }
const Vector<IDBKeyData>& keys() const;
const Vector<IDBValue>& values() const;
WEBCORE_EXPORT const Vector<IDBKeyData>& keys() const;
WEBCORE_EXPORT const Vector<IDBValue>& values() const;

void addKey(IDBKeyData&&);
void addValue(IDBValue&&);

template<class Encoder> void encode(Encoder&) const;
template<class Decoder> static WARN_UNUSED_RETURN bool decode(Decoder&, IDBGetAllResult&);

WEBCORE_EXPORT Vector<String> allBlobFilePaths() const;

private:
friend struct IPC::ArgumentCoder<IDBGetAllResult, void>;
IDBGetAllResult(IndexedDB::GetAllType type, Vector<IDBKeyData>&& keys, Vector<IDBValue>&& values, std::optional<IDBKeyPath>&& keyPath)
: m_type(type)
, m_keys(WTFMove(keys))
, m_values(WTFMove(values))
, m_keyPath(WTFMove(keyPath))
{
}

static void isolatedCopy(const IDBGetAllResult& source, IDBGetAllResult& destination);

IndexedDB::GetAllType m_type { IndexedDB::GetAllType::Keys };
@@ -74,28 +78,4 @@ class IDBGetAllResult {
std::optional<IDBKeyPath> m_keyPath;
};

template<class Encoder>
void IDBGetAllResult::encode(Encoder& encoder) const
{
encoder << m_type << m_keys << m_values << m_keyPath;
}

template<class Decoder>
bool IDBGetAllResult::decode(Decoder& decoder, IDBGetAllResult& result)
{
if (!decoder.decode(result.m_type))
return false;

if (!decoder.decode(result.m_keys))
return false;

if (!decoder.decode(result.m_values))
return false;

if (!decoder.decode(result.m_keyPath))
return false;

return true;
}

} // namespace WebCore
@@ -68,20 +68,13 @@ class IDBGetResult {
{
}

IDBGetResult(const IDBKeyData& keyData, const IDBKeyData& primaryKeyData, IDBValue&& value, const std::optional<IDBKeyPath>& keyPath)
: m_value(WTFMove(value))
, m_keyData(keyData)
, m_primaryKeyData(primaryKeyData)
, m_keyPath(keyPath)
{
}

IDBGetResult(const IDBKeyData& keyData, const IDBKeyData& primaryKeyData, IDBValue&& value, const std::optional<IDBKeyPath>& keyPath, Vector<IDBCursorRecord>&& prefetechedRecords)
IDBGetResult(const IDBKeyData& keyData, const IDBKeyData& primaryKeyData, IDBValue&& value, const std::optional<IDBKeyPath>& keyPath, Vector<IDBCursorRecord>&& prefetechedRecords = { }, bool isDefined = true)
: m_value(WTFMove(value))
, m_keyData(keyData)
, m_primaryKeyData(primaryKeyData)
, m_keyPath(keyPath)
, m_prefetchedRecords(WTFMove(prefetechedRecords))
, m_isDefined(isDefined)
{
}

@@ -99,9 +92,6 @@ class IDBGetResult {
const Vector<IDBCursorRecord>& prefetchedRecords() const { return m_prefetchedRecords; }
bool isDefined() const { return m_isDefined; }

template<class Encoder> void encode(Encoder&) const;
template<class Decoder> static WARN_UNUSED_RETURN bool decode(Decoder&, IDBGetResult&);

private:
static void isolatedCopy(const IDBGetResult& source, IDBGetResult& destination);

@@ -113,46 +103,4 @@ class IDBGetResult {
bool m_isDefined { true };
};

template<class Encoder>
void IDBGetResult::encode(Encoder& encoder) const
{
encoder << m_keyData << m_primaryKeyData << m_keyPath << m_isDefined << m_value << m_prefetchedRecords;
}

template<class Decoder>
bool IDBGetResult::decode(Decoder& decoder, IDBGetResult& result)
{
std::optional<IDBKeyData> keyData;
decoder >> keyData;
if (!keyData)
return false;
result.m_keyData = WTFMove(*keyData);

std::optional<IDBKeyData> primaryKeyData;
decoder >> primaryKeyData;
if (!primaryKeyData)
return false;
result.m_primaryKeyData = WTFMove(*primaryKeyData);

if (!decoder.decode(result.m_keyPath))
return false;

if (!decoder.decode(result.m_isDefined))
return false;

std::optional<IDBValue> value;
decoder >> value;
if (!value)
return false;
result.m_value = WTFMove(*value);

std::optional<Vector<IDBCursorRecord>> prefetchedRecords;
decoder >> prefetchedRecords;
if (!prefetchedRecords)
return false;
result.m_prefetchedRecords = WTFMove(*prefetchedRecords);

return true;
}

} // namespace WebCore
@@ -27,6 +27,7 @@

#include "IDBKey.h"
#include <variant>
#include <wtf/ArgumentCoder.h>
#include <wtf/Hasher.h>
#include <wtf/StdSet.h>
#include <wtf/text/StringHash.h>
@@ -84,9 +85,6 @@ class IDBKeyData {
void setStringValue(const String&);
void setDateValue(double);
WEBCORE_EXPORT void setNumberValue(double);

template<class Encoder> void encode(Encoder&) const;
template<class Decoder> static std::optional<IDBKeyData> decode(Decoder&);

#if !LOG_DISABLED
WEBCORE_EXPORT String loggingString() const;
@@ -152,6 +150,7 @@ class IDBKeyData {

private:
friend struct IDBKeyDataHashTraits;
friend struct IPC::ArgumentCoder<IDBKeyData, void>;

static void isolatedCopy(const IDBKeyData& source, IDBKeyData& destination);

@@ -213,80 +212,6 @@ struct IDBKeyDataHashTraits : public WTF::CustomHashTraits<IDBKeyData> {
}
};

template<class Encoder>
void IDBKeyData::encode(Encoder& encoder) const
{
encoder << m_isNull;
if (m_isNull)
return;

encoder << m_type;

switch (m_type) {
case IndexedDB::KeyType::Invalid:
case IndexedDB::KeyType::Max:
case IndexedDB::KeyType::Min:
break;
case IndexedDB::KeyType::Array:
encoder << std::get<Vector<IDBKeyData>>(m_value);
break;
case IndexedDB::KeyType::Binary:
encoder << std::get<ThreadSafeDataBuffer>(m_value);
break;
case IndexedDB::KeyType::String:
encoder << std::get<String>(m_value);
break;
case IndexedDB::KeyType::Date:
case IndexedDB::KeyType::Number:
encoder << std::get<double>(m_value);
break;
}
}

template<class Decoder>
std::optional<IDBKeyData> IDBKeyData::decode(Decoder& decoder)
{
IDBKeyData keyData;
if (!decoder.decode(keyData.m_isNull))
return std::nullopt;

if (keyData.m_isNull)
return keyData;

if (!decoder.decode(keyData.m_type))
return std::nullopt;

switch (keyData.m_type) {
case IndexedDB::KeyType::Invalid:
case IndexedDB::KeyType::Max:
case IndexedDB::KeyType::Min:
break;
case IndexedDB::KeyType::Array:
keyData.m_value = Vector<IDBKeyData>();
if (!decoder.decode(std::get<Vector<IDBKeyData>>(keyData.m_value)))
return std::nullopt;
break;
case IndexedDB::KeyType::Binary:
keyData.m_value = ThreadSafeDataBuffer();
if (!decoder.decode(std::get<ThreadSafeDataBuffer>(keyData.m_value)))
return std::nullopt;
break;
case IndexedDB::KeyType::String:
keyData.m_value = String();
if (!decoder.decode(std::get<String>(keyData.m_value)))
return std::nullopt;
break;
case IndexedDB::KeyType::Date:
case IndexedDB::KeyType::Number:
keyData.m_value = 0.0;
if (!decoder.decode(std::get<double>(keyData.m_value)))
return std::nullopt;
break;
}

return keyData;
}

using IDBKeyDataSet = StdSet<IDBKeyData>;

} // namespace WebCore

0 comments on commit d4d3c5e

Please sign in to comment.