From 7a3cbb76a9b6bdeb2cc3b6509a73b49c767cec69 Mon Sep 17 00:00:00 2001 From: Kyle Huey Date: Wed, 23 Nov 2011 09:15:15 -0500 Subject: [PATCH] Bug 702809: Allow creating indexes with empty keyPaths. r=sicking --- dom/indexedDB/IDBObjectStore.cpp | 17 ++-- dom/indexedDB/test/Makefile.in | 1 + .../test/test_index_empty_keyPath.html | 95 +++++++++++++++++++ 3 files changed, 105 insertions(+), 8 deletions(-) create mode 100644 dom/indexedDB/test/test_index_empty_keyPath.html diff --git a/dom/indexedDB/IDBObjectStore.cpp b/dom/indexedDB/IDBObjectStore.cpp index 181a67aa1e0..65895e3dadb 100644 --- a/dom/indexedDB/IDBObjectStore.cpp +++ b/dom/indexedDB/IDBObjectStore.cpp @@ -428,7 +428,9 @@ GetKeyFromValue(JSContext* aCx, Key& aKey) { NS_ASSERTION(aCx, "Null pointer!"); - NS_ASSERTION(!JSVAL_IS_PRIMITIVE(aVal), "Why are we here!?"); + // aVal can be primitive iff the key path is empty. + NS_ASSERTION(!JSVAL_IS_PRIMITIVE(aVal) || aKeyPath.IsEmpty(), + "Why are we here!?"); NS_ASSERTION(IDBObjectStore::IsValidKeyPath(aCx, aKeyPath), "This will explode!"); @@ -580,7 +582,6 @@ IDBObjectStore::GetKeyPathValueFromStructuredData(const PRUint8* aData, { NS_ASSERTION(aData, "Null pointer!"); NS_ASSERTION(aDataLength, "Empty data!"); - NS_ASSERTION(!aKeyPath.IsEmpty(), "Empty keyPath!"); NS_ASSERTION(aCx, "Null pointer!"); JSAutoRequest ar(aCx); @@ -592,7 +593,7 @@ IDBObjectStore::GetKeyPathValueFromStructuredData(const PRUint8* aData, return NS_ERROR_DOM_DATA_CLONE_ERR; } - if (JSVAL_IS_PRIMITIVE(clone)) { + if (JSVAL_IS_PRIMITIVE(clone) && !aKeyPath.IsEmpty()) { // This isn't an object, so just leave the key unset. aValue.Unset(); return NS_OK; @@ -614,7 +615,7 @@ IDBObjectStore::GetIndexUpdateInfo(ObjectStoreInfo* aObjectStoreInfo, JSObject* cloneObj = nsnull; PRUint32 count = aObjectStoreInfo->indexes.Length(); - if (count && !JSVAL_IS_PRIMITIVE(aObject)) { + if (count) { if (!aUpdateInfoArray.SetCapacity(count)) { NS_ERROR("Out of memory!"); return NS_ERROR_OUT_OF_MEMORY; @@ -623,6 +624,10 @@ IDBObjectStore::GetIndexUpdateInfo(ObjectStoreInfo* aObjectStoreInfo, for (PRUint32 indexesIndex = 0; indexesIndex < count; indexesIndex++) { const IndexInfo& indexInfo = aObjectStoreInfo->indexes[indexesIndex]; + if (JSVAL_IS_PRIMITIVE(aObject) && !indexInfo.keyPath.IsEmpty()) { + continue; + } + Key value; nsresult rv = GetKeyFromValue(aCx, aObject, indexInfo.keyPath, value); NS_ENSURE_SUCCESS(rv, rv); @@ -1334,10 +1339,6 @@ IDBObjectStore::CreateIndex(const nsAString& aName, { NS_PRECONDITION(NS_IsMainThread(), "Wrong thread!"); - if (aKeyPath.IsEmpty()) { - return NS_ERROR_DOM_INDEXEDDB_NON_TRANSIENT_ERR; - } - if (!IsValidKeyPath(aCx, aKeyPath)) { return NS_ERROR_DOM_SYNTAX_ERR; } diff --git a/dom/indexedDB/test/Makefile.in b/dom/indexedDB/test/Makefile.in index 719b315929d..3e5c0a24495 100644 --- a/dom/indexedDB/test/Makefile.in +++ b/dom/indexedDB/test/Makefile.in @@ -75,6 +75,7 @@ TEST_FILES = \ test_exceptions_in_success_events.html \ test_getAll.html \ test_global_data.html \ + test_index_empty_keyPath.html \ test_index_getAll.html \ test_index_getAllObjects.html \ test_index_object_cursors.html \ diff --git a/dom/indexedDB/test/test_index_empty_keyPath.html b/dom/indexedDB/test/test_index_empty_keyPath.html new file mode 100644 index 00000000000..f9e7e2bad24 --- /dev/null +++ b/dom/indexedDB/test/test_index_empty_keyPath.html @@ -0,0 +1,95 @@ + + + + Indexed Database Property Test + + + + + + + + + + +