Bug 706088 Make .put allow no key being provided if it's an autoIncrement object store. r=bent
authorKyle Huey <khuey@kylehuey.com>
Tue, 06 Dec 2011 02:45:46 -0800
changeset 82068 6393012a8cf2eb9ba58173e1c82d651aee99c480
parent 82067 ed783dfd8179ca651c07991e4732b315710b3cdf
child 82069 18f70e33e44442203e5692bf01ae800cb4c9c815
push id21582
push userbmo@edmorley.co.uk
push dateWed, 07 Dec 2011 09:30:09 +0000
treeherdermozilla-central@489f2d51b011 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbent
bugs706088
milestone11.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 706088 Make .put allow no key being provided if it's an autoIncrement object store. r=bent
dom/indexedDB/IDBObjectStore.cpp
dom/indexedDB/test/test_key_requirements.html
dom/indexedDB/test/test_put_get_values_autoIncrement.html
--- a/dom/indexedDB/IDBObjectStore.cpp
+++ b/dom/indexedDB/IDBObjectStore.cpp
@@ -1104,18 +1104,18 @@ IDBObjectStore::AddOrPut(const jsval& aV
   PRUint64 offset;
 
   nsresult rv =
     GetAddInfo(aCx, aValue, keyval, cloneBuffer, key, updateInfo, &offset);
   if (NS_FAILED(rv)) {
     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;
   }
 
   nsRefPtr<IDBRequest> request = GenerateRequest(this);
   NS_ENSURE_TRUE(request, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
 
   nsRefPtr<AddHelper> helper =
     new AddHelper(mTransaction, request, this, cloneBuffer, key, aOverwrite,
@@ -1788,17 +1788,17 @@ AddHelper::DoDatabaseWork(mozIStorageCon
     }
 
     if (NS_FAILED(rv)) {
       return NS_ERROR_DOM_INDEXEDDB_CONSTRAINT_ERR;
     }
   }
 
   // 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
 
     PRInt64 newIntKey;
     rv = aConnection->GetLastInsertRowID(&newIntKey);
     NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
 
--- a/dom/indexedDB/test/test_key_requirements.html
+++ b/dom/indexedDB/test/test_key_requirements.html
@@ -56,28 +56,28 @@
       request.onerror = errorHandler;
       request.onsuccess = grabEventAndContinueHandler;
       event = yield;
 
       is(event.target.result, key2, "put gave the same key back");
 
       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 {
         objectStore.delete();
         ok(false, "remove with no key should throw!");
       }
       catch (e) {
         ok(true, "remove with no key threw");
@@ -242,28 +242,28 @@
       request.onerror = errorHandler;
       request.onsuccess = grabEventAndContinueHandler;
       event = yield;
 
       is(event.target.result, key2, "put gave the same key back");
 
       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 {
         objectStore.delete();
         ok(false, "remove with no key should throw!");
       }
       catch (e) {
         ok(true, "remove with no key threw");
--- a/dom/indexedDB/test/test_put_get_values_autoIncrement.html
+++ b/dom/indexedDB/test/test_put_get_values_autoIncrement.html
@@ -24,28 +24,28 @@
       request.onupgradeneeded = grabEventAndContinueHandler;
       let event = yield;
 
       let db = event.target.result;
 
       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;
         request = objectStore.get(testString.key);
         request.onerror = errorHandler;
         request.onsuccess = function(event) {
           is(event.target.result, testString.value, "Got the right value");
         };
       };
 
-      request = objectStore.add(testInt.value);
+      request = objectStore.put(testInt.value);
       request.onerror = errorHandler;
       request.onsuccess = function(event) {
         testInt.key = event.target.result;
         request = objectStore.get(testInt.key);
         request.onerror = errorHandler;
         request.onsuccess = function(event) {
           is(event.target.result, testInt.value, "Got the right value");
           finishTest();