From da4c7e7ed675c3bf405668739c3012d140856109 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 15 May 2024 05:34:42 +0200 Subject: Adding upstream version 126.0. Signed-off-by: Daniel Baumann --- dom/indexedDB/IDBObjectStore.cpp | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'dom/indexedDB/IDBObjectStore.cpp') diff --git a/dom/indexedDB/IDBObjectStore.cpp b/dom/indexedDB/IDBObjectStore.cpp index e6464d2410..728f10b105 100644 --- a/dom/indexedDB/IDBObjectStore.cpp +++ b/dom/indexedDB/IDBObjectStore.cpp @@ -410,13 +410,20 @@ RefPtr IDBObjectStore::Create( void IDBObjectStore::AppendIndexUpdateInfo( const int64_t aIndexID, const KeyPath& aKeyPath, const bool aMultiEntry, const nsCString& aLocale, JSContext* const aCx, JS::Handle aVal, - nsTArray* const aUpdateInfoArray, ErrorResult* const aRv) { + nsTArray* const aUpdateInfoArray, + const VoidOrObjectStoreKeyPathString& aAutoIncrementedObjectStoreKeyPath, + ErrorResult* const aRv) { // This precondition holds when `aVal` is the result of a structured clone. js::AutoAssertNoContentJS noContentJS(aCx); + static_assert(std::is_same_v, + "Inconsistent types"); + if (!aMultiEntry) { Key key; - *aRv = aKeyPath.ExtractKey(aCx, aVal, key); + *aRv = + aKeyPath.ExtractKey(aCx, aVal, key, aAutoIncrementedObjectStoreKeyPath); // If an index's keyPath doesn't match an object, we ignore that object. if (aRv->ErrorCodeIs(NS_ERROR_DOM_INDEXEDDB_DATA_ERR) || key.IsUnset()) { @@ -625,6 +632,21 @@ void IDBObjectStore::GetAddInfo(JSContext* aCx, ValueWrapper& aValueWrapper, const nsTArray& indexes = mSpec->indexes(); const uint32_t idxCount = indexes.Length(); + const auto& autoIncrementedObjectStoreKeyPath = + [this]() -> const nsAString& { + if (AutoIncrement() && GetKeyPath().IsValid()) { + // By https://w3c.github.io/IndexedDB/#database-interface , + // createObjectStore algorithm, step 8, neither arrays nor empty paths + // are allowed for autoincremented object stores. + // See also KeyPath::IsAllowedForObjectStore. + MOZ_ASSERT(GetKeyPath().IsString()); + MOZ_ASSERT(!GetKeyPath().IsEmpty()); + return GetKeyPath().mStrings[0]; + } + + return VoidString(); + }(); + aUpdateInfoArray.SetCapacity(idxCount); // Pretty good estimate for (uint32_t idxIndex = 0; idxIndex < idxCount; idxIndex++) { @@ -632,7 +654,8 @@ void IDBObjectStore::GetAddInfo(JSContext* aCx, ValueWrapper& aValueWrapper, AppendIndexUpdateInfo(metadata.id(), metadata.keyPath(), metadata.multiEntry(), metadata.locale(), aCx, - aValueWrapper.Value(), &aUpdateInfoArray, &aRv); + aValueWrapper.Value(), &aUpdateInfoArray, + autoIncrementedObjectStoreKeyPath, &aRv); if (NS_WARN_IF(aRv.Failed())) { return; } -- cgit v1.2.3