summaryrefslogtreecommitdiffstats
path: root/dom/indexedDB/IDBObjectStore.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'dom/indexedDB/IDBObjectStore.cpp')
-rw-r--r--dom/indexedDB/IDBObjectStore.cpp29
1 files changed, 26 insertions, 3 deletions
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> IDBObjectStore::Create(
void IDBObjectStore::AppendIndexUpdateInfo(
const int64_t aIndexID, const KeyPath& aKeyPath, const bool aMultiEntry,
const nsCString& aLocale, JSContext* const aCx, JS::Handle<JS::Value> aVal,
- nsTArray<IndexUpdateInfo>* const aUpdateInfoArray, ErrorResult* const aRv) {
+ nsTArray<IndexUpdateInfo>* 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<IDBObjectStore::VoidOrObjectStoreKeyPathString,
+ KeyPath::VoidOrObjectStoreKeyPathString>,
+ "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<IndexMetadata>& 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;
}