diff --git a/dom/indexedDB/IDBObjectStore.cpp b/dom/indexedDB/IDBObjectStore.cpp index 937048162e00..994e08b0a108 100644 --- a/dom/indexedDB/IDBObjectStore.cpp +++ b/dom/indexedDB/IDBObjectStore.cpp @@ -1109,8 +1109,8 @@ IDBObjectStore::AddOrPut(const jsval& aValue, return rv; } - // Put requires a key. - if (aOverwrite && key.IsUnset()) { + // Put requires a key, unless this is an autoIncrementing objectStore. + if (aOverwrite && !mAutoIncrement && key.IsUnset()) { return NS_ERROR_DOM_INDEXEDDB_DATA_ERR; } @@ -1793,7 +1793,7 @@ AddHelper::DoDatabaseWork(mozIStorageConnection* aConnection) } // If we are supposed to generate a key, get the new id. - if (autoIncrement && !mOverwrite) { + if (autoIncrement && !mayOverwrite) { #ifdef DEBUG PRInt64 oldKey = unsetKey ? 0 : mKey.ToInteger(); #endif diff --git a/dom/indexedDB/test/test_key_requirements.html b/dom/indexedDB/test/test_key_requirements.html index 72deede325b9..e057d4177466 100644 --- a/dom/indexedDB/test/test_key_requirements.html +++ b/dom/indexedDB/test/test_key_requirements.html @@ -61,18 +61,18 @@ try { objectStore.put({}); - ok(false, "put with no key should throw!"); + ok(true, "put with no key should not throw with autoIncrement!"); } catch (e) { - ok(true, "put with no key threw"); + ok(false, "put with no key threw with autoIncrement"); } try { objectStore.put({}); - ok(false, "put with no key should throw!"); + ok(true, "put with no key should not throw with autoIncrement!"); } catch (e) { - ok(true, "put with no key threw"); + ok(false, "put with no key threw with autoIncrement"); } try { @@ -247,18 +247,18 @@ try { objectStore.put({}); - ok(false, "put with no key should throw!"); + ok(true, "put with no key should not throw with autoIncrement!"); } catch (e) { - ok(true, "put with no key threw"); + ok(false, "put with no key threw with autoIncrement"); } try { objectStore.put({}); - ok(false, "put with no key should throw!"); + ok(true, "put with no key should not throw with autoIncrement!"); } catch (e) { - ok(true, "put with no key threw"); + ok(false, "put with no key threw with autoIncrement"); } try { diff --git a/dom/indexedDB/test/test_put_get_values_autoIncrement.html b/dom/indexedDB/test/test_put_get_values_autoIncrement.html index 2ee8d5204c18..48fde0445850 100644 --- a/dom/indexedDB/test/test_put_get_values_autoIncrement.html +++ b/dom/indexedDB/test/test_put_get_values_autoIncrement.html @@ -29,7 +29,7 @@ let objectStore = db.createObjectStore(objectStoreName, { autoIncrement: 1 }); - request = objectStore.add(testString.value); + request = objectStore.put(testString.value); request.onerror = errorHandler; request.onsuccess = function(event) { testString.key = event.target.result; @@ -40,7 +40,7 @@ }; }; - request = objectStore.add(testInt.value); + request = objectStore.put(testInt.value); request.onerror = errorHandler; request.onsuccess = function(event) { testInt.key = event.target.result;