Title: [120114] trunk
Revision
120114
Author
[email protected]
Date
2012-06-12 13:45:58 -0700 (Tue, 12 Jun 2012)

Log Message

IndexedDB: Error codes, phase two
https://bugs.webkit.org/show_bug.cgi?id=88690

Patch by Alec Flett <[email protected]> on 2012-06-12
Reviewed by Tony Chang.

Source/WebCore:

Update the next phase of IndexedDB error codes to match the spec.
This update is mostly focused on DATA_ERR vs CONSTRAINT_ERR.

Also moves some of the error checking for the transaction mode
into the frontend and replaces the backend checks with asserts, so that
we can consolidate error checking in one place.

This also removes a few FIXME's that are no longer true (about
I/O errors - the spec was updated and our implementation was
already correct)

No new tests, existing tests cover changed behavior.

* Modules/indexeddb/IDBCursor.cpp:
(WebCore::IDBCursor::deleteFunction):
* Modules/indexeddb/IDBCursorBackendImpl.cpp:
(WebCore::IDBCursorBackendImpl::deleteFunction):
* Modules/indexeddb/IDBDatabaseBackendImpl.cpp:
(WebCore::IDBDatabaseBackendImpl::setVersionInternal):
* Modules/indexeddb/IDBObjectStore.cpp:
(WebCore::IDBObjectStore::add):
(WebCore::IDBObjectStore::put):
(WebCore::IDBObjectStore::deleteFunction):
(WebCore::IDBObjectStore::clear):
* Modules/indexeddb/IDBObjectStoreBackendImpl.cpp:
(WebCore::IDBObjectStoreBackendImpl::put):
(WebCore::IDBObjectStoreBackendImpl::putInternal):
(WebCore::IDBObjectStoreBackendImpl::deleteFunction):
(WebCore::IDBObjectStoreBackendImpl::clear):
* Modules/indexeddb/IDBTransaction.h:
(WebCore::IDBTransaction::enumMode):
* Modules/indexeddb/IDBTransactionBackendImpl.h:

LayoutTests:

* storage/indexeddb/cursor-advance-expected.txt:
* storage/indexeddb/index-unique-expected.txt:
* storage/indexeddb/mozilla/index-prev-no-duplicate-expected.txt:
* storage/indexeddb/mozilla/index-prev-no-duplicate.html:
* storage/indexeddb/objectstore-basics-expected.txt:
* storage/indexeddb/objectstore-basics-workers-expected.txt:
* storage/indexeddb/resources/cursor-advance.js:
(openSuccess):
(createObjectStore.trans.oncomplete):
(createObjectStore):
(populateObjectStore):
* storage/indexeddb/resources/index-unique.js:
(addMoreDataFailed):
* storage/indexeddb/resources/objectstore-basics.js:
(addAgainFailure):

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (120113 => 120114)


--- trunk/LayoutTests/ChangeLog	2012-06-12 20:38:01 UTC (rev 120113)
+++ trunk/LayoutTests/ChangeLog	2012-06-12 20:45:58 UTC (rev 120114)
@@ -1,3 +1,26 @@
+2012-06-12  Alec Flett  <[email protected]>
+
+        IndexedDB: Error codes, phase two
+        https://bugs.webkit.org/show_bug.cgi?id=88690
+
+        Reviewed by Tony Chang.
+
+        * storage/indexeddb/cursor-advance-expected.txt:
+        * storage/indexeddb/index-unique-expected.txt:
+        * storage/indexeddb/mozilla/index-prev-no-duplicate-expected.txt:
+        * storage/indexeddb/mozilla/index-prev-no-duplicate.html:
+        * storage/indexeddb/objectstore-basics-expected.txt:
+        * storage/indexeddb/objectstore-basics-workers-expected.txt:
+        * storage/indexeddb/resources/cursor-advance.js:
+        (openSuccess):
+        (createObjectStore.trans.oncomplete):
+        (createObjectStore):
+        (populateObjectStore):
+        * storage/indexeddb/resources/index-unique.js:
+        (addMoreDataFailed):
+        * storage/indexeddb/resources/objectstore-basics.js:
+        (addAgainFailure):
+
 2012-06-12  Ryosuke Niwa  <[email protected]>
 
         Use testRunner in accessibility tests instead of layoutTestController

Modified: trunk/LayoutTests/storage/indexeddb/cursor-advance-expected.txt (120113 => 120114)


--- trunk/LayoutTests/storage/indexeddb/cursor-advance-expected.txt	2012-06-12 20:38:01 UTC (rev 120113)
+++ trunk/LayoutTests/storage/indexeddb/cursor-advance-expected.txt	2012-06-12 20:45:58 UTC (rev 120114)
@@ -10,7 +10,14 @@
 db = event.target.result
 request = db.setVersion('1')
 Deleted all object stores.
+trans = request.result
 objectStore = db.createObjectStore(objectStoreName);
+Now create the indexes.
+objectStore.createIndex(indexData[i].name, indexData[i].keyPath, indexData[i].options);
+objectStore.createIndex(indexData[i].name, indexData[i].keyPath, indexData[i].options);
+objectStore.createIndex(indexData[i].name, indexData[i].keyPath, indexData[i].options);
+trans = db.transaction(objectStoreName, 'readwrite')
+objectStore = trans.objectStore(objectStoreName)
 First, add all our data to the object store.
 request = objectStore.add(objectStoreData[i].value, objectStoreData[i].key);
 request = objectStore.add(objectStoreData[i].value, objectStoreData[i].key);
@@ -25,11 +32,6 @@
 request = objectStore.add(objectStoreData[i].value, objectStoreData[i].key);
 request = objectStore.add(objectStoreData[i].value, objectStoreData[i].key);
 request = objectStore.add(objectStoreData[i].value, objectStoreData[i].key);
-Now create the indexes.
-objectStore.createIndex(indexData[i].name, indexData[i].keyPath, indexData[i].options);
-objectStore.createIndex(indexData[i].name, indexData[i].keyPath, indexData[i].options);
-objectStore.createIndex(indexData[i].name, indexData[i].keyPath, indexData[i].options);
-testAll()
 testSimple()
 trans = db.transaction(objectStoreName)
 store = trans.objectStore(objectStoreName)

Modified: trunk/LayoutTests/storage/indexeddb/index-unique-expected.txt (120113 => 120114)


--- trunk/LayoutTests/storage/indexeddb/index-unique-expected.txt	2012-06-12 20:38:01 UTC (rev 120113)
+++ trunk/LayoutTests/storage/indexeddb/index-unique-expected.txt	2012-06-12 20:45:58 UTC (rev 120114)
@@ -21,8 +21,8 @@
 transaction.objectStore('store').put({x: 1}, 'bar')
 addMoreDataFailed():
 event.preventDefault()
-PASS event.target.errorCode is IDBDatabaseException.CONSTRAINT_ERR
-PASS event.target.error.name is 'ConstraintError'
+PASS event.target.errorCode is IDBDatabaseException.DATA_ERR
+PASS event.target.error.name is 'DataError'
 transaction.objectStore('store').put({x: 0}, 'foo')
 changeDataSuccess():
 transaction.objectStore('store').index('index').openCursor(IDBKeyRange.lowerBound(1))

Modified: trunk/LayoutTests/storage/indexeddb/mozilla/index-prev-no-duplicate-expected.txt (120113 => 120114)


--- trunk/LayoutTests/storage/indexeddb/mozilla/index-prev-no-duplicate-expected.txt	2012-06-12 20:38:01 UTC (rev 120113)
+++ trunk/LayoutTests/storage/indexeddb/mozilla/index-prev-no-duplicate-expected.txt	2012-06-12 20:45:58 UTC (rev 120114)
@@ -18,6 +18,7 @@
 db = event.target.result
 request = db.setVersion('1')
 Deleted all object stores.
+trans = request.result
 objectStore = db.createObjectStore(objectStoreName);
 First, add all our data to the object store.
 request = objectStore.add(objectStoreData[i].value, objectStoreData[i].key);
@@ -33,6 +34,8 @@
 objectStore.createIndex(indexData[i].name, indexData[i].keyPath, indexData[i].options);
 objectStore.createIndex(indexData[i].name, indexData[i].keyPath, indexData[i].options);
 objectStore.createIndex(indexData[i].name, indexData[i].keyPath, indexData[i].options);
+trans = db.transaction(objectStoreName, 'readwrite')
+objectStore = trans.objectStore(objectStoreName)
 testPrev()
 trans = db.transaction(objectStoreName)
 objectStore = trans.objectStore(objectStoreName);

Modified: trunk/LayoutTests/storage/indexeddb/mozilla/index-prev-no-duplicate.html (120113 => 120114)


--- trunk/LayoutTests/storage/indexeddb/mozilla/index-prev-no-duplicate.html	2012-06-12 20:38:01 UTC (rev 120113)
+++ trunk/LayoutTests/storage/indexeddb/mozilla/index-prev-no-duplicate.html	2012-06-12 20:45:58 UTC (rev 120114)
@@ -78,16 +78,16 @@
     ];
 
     request = evalAndLog("request = db.setVersion('1')");
-    request._onsuccess_ = createAndPopulateObjectStore;
+    request._onsuccess_ = createObjectStore;
     request._onerror_ = unexpectedErrorCallback;
 }
 
-function createAndPopulateObjectStore()
+function createObjectStore()
 {
     deleteAllObjectStores(db);
 
+    evalAndLog("trans = request.result");
     objectStore = evalAndLog("objectStore = db.createObjectStore(objectStoreName);");
-
     debug("First, add all our data to the object store.");
     addedData = 0;
     for (i in objectStoreData) {
@@ -100,6 +100,11 @@
         }
       }
     }
+    trans._oncomplete_ = function() {
+        evalAndLog("trans = db.transaction(objectStoreName, 'readwrite')");
+        evalAndLog("objectStore = trans.objectStore(objectStoreName)");
+        testPrev();
+    };
 }
 
 function createIndexes()
@@ -108,9 +113,6 @@
     for (i in indexData) {
       evalAndLog("objectStore.createIndex(indexData[i].name, indexData[i].keyPath, indexData[i].options);");
     }
-
-
-    testPrev();
 }
 
 function testPrev()

Modified: trunk/LayoutTests/storage/indexeddb/objectstore-basics-expected.txt (120113 => 120114)


--- trunk/LayoutTests/storage/indexeddb/objectstore-basics-expected.txt	2012-06-12 20:38:01 UTC (rev 120113)
+++ trunk/LayoutTests/storage/indexeddb/objectstore-basics-expected.txt	2012-06-12 20:45:58 UTC (rev 120114)
@@ -96,8 +96,8 @@
 PASS event.target.result is "key"
 event.target.source.add({x: 'foo'}, 'zzz')
 addAgainFailure():
-PASS event.target.errorCode is IDBDatabaseException.CONSTRAINT_ERR
-PASS event.target.error.name is 'ConstraintError'
+PASS event.target.errorCode is IDBDatabaseException.DATA_ERR
+PASS event.target.error.name is 'DataError'
 event.preventDefault()
 db.transaction(['storeName'], 'readwrite')
 store = transaction.objectStore('storeName')

Modified: trunk/LayoutTests/storage/indexeddb/objectstore-basics-workers-expected.txt (120113 => 120114)


--- trunk/LayoutTests/storage/indexeddb/objectstore-basics-workers-expected.txt	2012-06-12 20:38:01 UTC (rev 120113)
+++ trunk/LayoutTests/storage/indexeddb/objectstore-basics-workers-expected.txt	2012-06-12 20:45:58 UTC (rev 120114)
@@ -97,8 +97,8 @@
 PASS [Worker] event.target.result is "key"
 [Worker] event.target.source.add({x: 'foo'}, 'zzz')
 [Worker] addAgainFailure():
-PASS [Worker] event.target.errorCode is IDBDatabaseException.CONSTRAINT_ERR
-PASS [Worker] event.target.error.name is 'ConstraintError'
+PASS [Worker] event.target.errorCode is IDBDatabaseException.DATA_ERR
+PASS [Worker] event.target.error.name is 'DataError'
 [Worker] event.preventDefault()
 [Worker] db.transaction(['storeName'], 'readwrite')
 [Worker] store = transaction.objectStore('storeName')

Modified: trunk/LayoutTests/storage/indexeddb/resources/cursor-advance.js (120113 => 120114)


--- trunk/LayoutTests/storage/indexeddb/resources/cursor-advance.js	2012-06-12 20:38:01 UTC (rev 120113)
+++ trunk/LayoutTests/storage/indexeddb/resources/cursor-advance.js	2012-06-12 20:45:58 UTC (rev 120114)
@@ -44,24 +44,32 @@
     objectStoreName = "People";
 
     request = evalAndLog("request = db.setVersion('1')");
-    request._onsuccess_ = createAndPopulateObjectStore;
+    request._onsuccess_ = createObjectStore;
     request._onerror_ = unexpectedErrorCallback;
 }
 
-function createAndPopulateObjectStore()
+function createObjectStore(request)
 {
     deleteAllObjectStores(db);
-
+    trans = evalAndLog("trans = request.result");
     objectStore = evalAndLog("objectStore = db.createObjectStore(objectStoreName);");
+    createIndexes();
+    trans._oncomplete_ = function() {
+        evalAndLog("trans = db.transaction(objectStoreName, 'readwrite')");
+        evalAndLog("objectStore = trans.objectStore(objectStoreName)");
+        populateObjectStore();
+    };
+}
 
+function populateObjectStore()
+{
     debug("First, add all our data to the object store.");
     addedData = 0;
     for (i in objectStoreData) {
         request = evalAndLog("request = objectStore.add(objectStoreData[i].value, objectStoreData[i].key);");
         request._onerror_ = unexpectedErrorCallback;
     }
-    createIndexes();
-    request._onsuccess_ = testAll;
+    request._onsuccess_ = testSimple;
 }
 
 function createIndexes()
@@ -140,11 +148,6 @@
     shouldBeEqualToString("expected", JSON.stringify(simplifyCursor(cursor)));
 }
 
-function testAll()
-{
-    debug("testAll()");
-    testSimple();
-}
 
 function testSimple()
 {

Modified: trunk/LayoutTests/storage/indexeddb/resources/index-unique.js (120113 => 120114)


--- trunk/LayoutTests/storage/indexeddb/resources/index-unique.js	2012-06-12 20:38:01 UTC (rev 120113)
+++ trunk/LayoutTests/storage/indexeddb/resources/index-unique.js	2012-06-12 20:45:58 UTC (rev 120114)
@@ -65,8 +65,8 @@
     // Don't abort the transaction.
     evalAndLog("event.preventDefault()");
 
-    shouldBe("event.target.errorCode", "IDBDatabaseException.CONSTRAINT_ERR");
-    shouldBe("event.target.error.name", "'ConstraintError'");
+    shouldBe("event.target.errorCode", "IDBDatabaseException.DATA_ERR");
+    shouldBe("event.target.error.name", "'DataError'");
 
     // Update the 'foo' entry in object store, changing the value of x.
     request = evalAndLog("transaction.objectStore('store').put({x: 0}, 'foo')");

Modified: trunk/LayoutTests/storage/indexeddb/resources/objectstore-basics.js (120113 => 120114)


--- trunk/LayoutTests/storage/indexeddb/resources/objectstore-basics.js	2012-06-12 20:38:01 UTC (rev 120113)
+++ trunk/LayoutTests/storage/indexeddb/resources/objectstore-basics.js	2012-06-12 20:45:58 UTC (rev 120114)
@@ -175,8 +175,8 @@
 {
     event = evt;
     debug("addAgainFailure():");
-    shouldBe("event.target.errorCode", "IDBDatabaseException.CONSTRAINT_ERR");
-    shouldBe("event.target.error.name", "'ConstraintError'");
+    shouldBe("event.target.errorCode", "IDBDatabaseException.DATA_ERR");
+    shouldBe("event.target.error.name", "'DataError'");
 
     evalAndLog("event.preventDefault()");
 

Modified: trunk/Source/WebCore/ChangeLog (120113 => 120114)


--- trunk/Source/WebCore/ChangeLog	2012-06-12 20:38:01 UTC (rev 120113)
+++ trunk/Source/WebCore/ChangeLog	2012-06-12 20:45:58 UTC (rev 120114)
@@ -1,3 +1,43 @@
+2012-06-12  Alec Flett  <[email protected]>
+
+        IndexedDB: Error codes, phase two
+        https://bugs.webkit.org/show_bug.cgi?id=88690
+
+        Reviewed by Tony Chang.
+
+        Update the next phase of IndexedDB error codes to match the spec.
+        This update is mostly focused on DATA_ERR vs CONSTRAINT_ERR.
+
+        Also moves some of the error checking for the transaction mode
+        into the frontend and replaces the backend checks with asserts, so that
+        we can consolidate error checking in one place.
+
+        This also removes a few FIXME's that are no longer true (about 
+        I/O errors - the spec was updated and our implementation was
+        already correct)
+
+        No new tests, existing tests cover changed behavior.
+
+        * Modules/indexeddb/IDBCursor.cpp:
+        (WebCore::IDBCursor::deleteFunction):
+        * Modules/indexeddb/IDBCursorBackendImpl.cpp:
+        (WebCore::IDBCursorBackendImpl::deleteFunction):
+        * Modules/indexeddb/IDBDatabaseBackendImpl.cpp:
+        (WebCore::IDBDatabaseBackendImpl::setVersionInternal):
+        * Modules/indexeddb/IDBObjectStore.cpp:
+        (WebCore::IDBObjectStore::add):
+        (WebCore::IDBObjectStore::put):
+        (WebCore::IDBObjectStore::deleteFunction):
+        (WebCore::IDBObjectStore::clear):
+        * Modules/indexeddb/IDBObjectStoreBackendImpl.cpp:
+        (WebCore::IDBObjectStoreBackendImpl::put):
+        (WebCore::IDBObjectStoreBackendImpl::putInternal):
+        (WebCore::IDBObjectStoreBackendImpl::deleteFunction):
+        (WebCore::IDBObjectStoreBackendImpl::clear):
+        * Modules/indexeddb/IDBTransaction.h:
+        (WebCore::IDBTransaction::enumMode):
+        * Modules/indexeddb/IDBTransactionBackendImpl.h:
+
 2012-06-12  Min Qin  <[email protected]>
 
         Disable autoplay when user gesture is required for media playback

Modified: trunk/Source/WebCore/Modules/indexeddb/IDBCursor.cpp (120113 => 120114)


--- trunk/Source/WebCore/Modules/indexeddb/IDBCursor.cpp	2012-06-12 20:38:01 UTC (rev 120113)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBCursor.cpp	2012-06-12 20:45:58 UTC (rev 120114)
@@ -205,6 +205,11 @@
 PassRefPtr<IDBRequest> IDBCursor::deleteFunction(ScriptExecutionContext* context, ExceptionCode& ec)
 {
     IDB_TRACE("IDBCursor::delete");
+    if (m_transaction->isReadOnly()) {
+        ec = IDBDatabaseException::READ_ONLY_ERR;
+        return 0;
+    }
+
     if (!m_gotValue) {
         ec = IDBDatabaseException::IDB_INVALID_STATE_ERR;
         return 0;

Modified: trunk/Source/WebCore/Modules/indexeddb/IDBCursorBackendImpl.cpp (120113 => 120114)


--- trunk/Source/WebCore/Modules/indexeddb/IDBCursorBackendImpl.cpp	2012-06-12 20:38:01 UTC (rev 120113)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBCursorBackendImpl.cpp	2012-06-12 20:45:58 UTC (rev 120114)
@@ -163,6 +163,8 @@
 void IDBCursorBackendImpl::deleteFunction(PassRefPtr<IDBCallbacks> prpCallbacks, ExceptionCode& ec)
 {
     IDB_TRACE("IDBCursorBackendImpl::delete");
+    ASSERT(m_transaction->mode() != IDBTransaction::READ_ONLY);
+
     if (!m_cursor || m_cursorType == IndexKeyCursor) {
         ec = IDBDatabaseException::IDB_INVALID_STATE_ERR;
         return;

Modified: trunk/Source/WebCore/Modules/indexeddb/IDBDatabaseBackendImpl.cpp (120113 => 120114)


--- trunk/Source/WebCore/Modules/indexeddb/IDBDatabaseBackendImpl.cpp	2012-06-12 20:38:01 UTC (rev 120113)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBDatabaseBackendImpl.cpp	2012-06-12 20:45:58 UTC (rev 120114)
@@ -249,7 +249,6 @@
     int64_t databaseId = database->id();
     database->m_version = version;
     if (!database->m_backingStore->updateIDBDatabaseMetaData(databaseId, database->m_version)) {
-        // FIXME: The Indexed Database specification does not have an error code dedicated to I/O errors.
         callbacks->onError(IDBDatabaseError::create(IDBDatabaseException::UNKNOWN_ERR, "Error writing data to stable storage."));
         transaction->abort();
         return;

Modified: trunk/Source/WebCore/Modules/indexeddb/IDBObjectStore.cpp (120113 => 120114)


--- trunk/Source/WebCore/Modules/indexeddb/IDBObjectStore.cpp	2012-06-12 20:38:01 UTC (rev 120113)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBObjectStore.cpp	2012-06-12 20:45:58 UTC (rev 120114)
@@ -118,6 +118,11 @@
 PassRefPtr<IDBRequest> IDBObjectStore::add(ScriptExecutionContext* context, PassRefPtr<SerializedScriptValue> prpValue, PassRefPtr<IDBKey> key, ExceptionCode& ec)
 {
     IDB_TRACE("IDBObjectStore::add");
+    if (m_transaction->isReadOnly()) {
+        ec = IDBDatabaseException::READ_ONLY_ERR;
+        return 0;
+    }
+
     if (key && (key->type() == IDBKey::InvalidType)) {
         ec = IDBDatabaseException::DATA_ERR;
         return 0;
@@ -142,6 +147,11 @@
 PassRefPtr<IDBRequest> IDBObjectStore::put(ScriptExecutionContext* context, PassRefPtr<SerializedScriptValue> prpValue, PassRefPtr<IDBKey> key, ExceptionCode& ec)
 {
     IDB_TRACE("IDBObjectStore::put");
+    if (m_transaction->isReadOnly()) {
+        ec = IDBDatabaseException::READ_ONLY_ERR;
+        return 0;
+    }
+
     if (key && (key->type() == IDBKey::InvalidType)) {
         ec = IDBDatabaseException::DATA_ERR;
         return 0;
@@ -166,6 +176,11 @@
 PassRefPtr<IDBRequest> IDBObjectStore::deleteFunction(ScriptExecutionContext* context, PassRefPtr<IDBKeyRange> keyRange, ExceptionCode& ec)
 {
     IDB_TRACE("IDBObjectStore::delete");
+    if (m_transaction->isReadOnly()) {
+        ec = IDBDatabaseException::READ_ONLY_ERR;
+        return 0;
+    }
+
     if (!keyRange) {
         ec = IDBDatabaseException::DATA_ERR;
         return 0;
@@ -183,6 +198,11 @@
 PassRefPtr<IDBRequest> IDBObjectStore::deleteFunction(ScriptExecutionContext* context, PassRefPtr<IDBKey> key, ExceptionCode& ec)
 {
     IDB_TRACE("IDBObjectStore::delete");
+    if (m_transaction->isReadOnly()) {
+        ec = IDBDatabaseException::READ_ONLY_ERR;
+        return 0;
+    }
+
     if (!key || !key->isValid()) {
         ec = IDBDatabaseException::DATA_ERR;
         return 0;
@@ -200,6 +220,11 @@
 PassRefPtr<IDBRequest> IDBObjectStore::clear(ScriptExecutionContext* context, ExceptionCode& ec)
 {
     IDB_TRACE("IDBObjectStore::clear");
+    if (m_transaction->isReadOnly()) {
+        ec = IDBDatabaseException::READ_ONLY_ERR;
+        return 0;
+    }
+
     RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this), m_transaction.get());
     m_backend->clear(request, m_transaction->backend(), ec);
     if (ec) {

Modified: trunk/Source/WebCore/Modules/indexeddb/IDBObjectStoreBackendImpl.cpp (120113 => 120114)


--- trunk/Source/WebCore/Modules/indexeddb/IDBObjectStoreBackendImpl.cpp	2012-06-12 20:38:01 UTC (rev 120113)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBObjectStoreBackendImpl.cpp	2012-06-12 20:45:58 UTC (rev 120114)
@@ -142,11 +142,9 @@
 void IDBObjectStoreBackendImpl::put(PassRefPtr<SerializedScriptValue> prpValue, PassRefPtr<IDBKey> prpKey, PutMode putMode, PassRefPtr<IDBCallbacks> prpCallbacks, IDBTransactionBackendInterface* transactionPtr, ExceptionCode& ec)
 {
     IDB_TRACE("IDBObjectStoreBackendImpl::put");
-    if (transactionPtr->mode() == IDBTransaction::READ_ONLY) {
-        ec = IDBDatabaseException::READ_ONLY_ERR;
-        return;
-    }
 
+    ASSERT(transactionPtr->mode() != IDBTransaction::READ_ONLY);
+
     RefPtr<IDBObjectStoreBackendImpl> objectStore = this;
     RefPtr<SerializedScriptValue> value = prpValue;
     RefPtr<IDBKey> key = prpKey;
@@ -240,7 +238,6 @@
                     if (!valueAfterInjection) {
                         objectStore->resetAutoIncrementKeyCache();
                         // Checks in put() ensure this should only happen if I/O error occurs.
-                        // FIXME: The Indexed Database specification does not have an error code dedicated to I/O errors.
                         callbacks->onError(IDBDatabaseError::create(IDBDatabaseException::UNKNOWN_ERR, "Internal error inserting generated key into the object."));
                         return;
                     }
@@ -278,7 +275,7 @@
 
         if ((!index->multiEntry() || indexKey->type() != IDBKey::ArrayType) && !index->addingKeyAllowed(indexKey.get(), key.get())) {
             objectStore->resetAutoIncrementKeyCache();
-            callbacks->onError(IDBDatabaseError::create(IDBDatabaseException::CONSTRAINT_ERR, "One of the derived (from a keyPath) keys for an index does not satisfy its uniqueness requirements."));
+            callbacks->onError(IDBDatabaseError::create(IDBDatabaseException::DATA_ERR, "One of the derived (from a keyPath) keys for an index does not satisfy its uniqueness requirements."));
             return;
         }
 
@@ -286,7 +283,7 @@
            for (size_t j = 0; j < indexKey->array().size(); ++j) {
                 if (!index->addingKeyAllowed(indexKey->array()[j].get(), key.get())) {
                     objectStore->resetAutoIncrementKeyCache();
-                    callbacks->onError(IDBDatabaseError::create(IDBDatabaseException::CONSTRAINT_ERR, "One of the derived (from a keyPath) keys for an index does not satisfy its uniqueness requirements."));
+                    callbacks->onError(IDBDatabaseError::create(IDBDatabaseException::DATA_ERR, "One of the derived (from a keyPath) keys for an index does not satisfy its uniqueness requirements."));
                     return;
                 }
             }
@@ -298,7 +295,6 @@
     // Before this point, don't do any mutation.  After this point, rollback the transaction in case of error.
 
     if (!objectStore->backingStore()->putObjectStoreRecord(objectStore->databaseId(), objectStore->id(), *key, value->toWireString(), recordIdentifier.get())) {
-        // FIXME: The Indexed Database specification does not have an error code dedicated to I/O errors.
         callbacks->onError(IDBDatabaseError::create(IDBDatabaseException::UNKNOWN_ERR, "Error writing data to stable storage."));
         transaction->abort();
         return;
@@ -311,7 +307,6 @@
             continue; // The index object has been created, but does not exist in the database yet.
 
         if (!objectStore->backingStore()->deleteIndexDataForRecord(objectStore->databaseId(), objectStore->id(), index->id(), recordIdentifier.get())) {
-            // FIXME: The Indexed Database specification does not have an error code dedicated to I/O errors.
             callbacks->onError(IDBDatabaseError::create(IDBDatabaseException::UNKNOWN_ERR, "Error writing data to stable storage."));
             transaction->abort();
             return;
@@ -323,7 +318,6 @@
 
         if (!index->multiEntry() || indexKey->type() != IDBKey::ArrayType) {
             if (!objectStore->backingStore()->putIndexDataForRecord(objectStore->databaseId(), objectStore->id(), index->id(), *indexKey, recordIdentifier.get())) {
-                // FIXME: The Indexed Database specification does not have an error code dedicated to I/O errors.
                 callbacks->onError(IDBDatabaseError::create(IDBDatabaseException::UNKNOWN_ERR, "Error writing data to stable storage."));
                 transaction->abort();
                 return;
@@ -333,7 +327,6 @@
             ASSERT(indexKey->type() == IDBKey::ArrayType);
             for (size_t j = 0; j < indexKey->array().size(); ++j) {
                 if (!objectStore->backingStore()->putIndexDataForRecord(objectStore->databaseId(), objectStore->id(), index->id(), *indexKey->array()[j], recordIdentifier.get())) {
-                    // FIXME: The Indexed Database specification does not have an error code dedicated to I/O errors.
                     callbacks->onError(IDBDatabaseError::create(IDBDatabaseException::UNKNOWN_ERR, "Error writing data to stable storage."));
                     transaction->abort();
                     return;
@@ -364,11 +357,9 @@
 void IDBObjectStoreBackendImpl::deleteFunction(PassRefPtr<IDBKeyRange> prpKeyRange, PassRefPtr<IDBCallbacks> prpCallbacks, IDBTransactionBackendInterface* transaction, ExceptionCode& ec)
 {
     IDB_TRACE("IDBObjectStoreBackendImpl::delete");
-    if (transaction->mode() == IDBTransaction::READ_ONLY) {
-        ec = IDBDatabaseException::READ_ONLY_ERR;
-        return;
-    }
 
+    ASSERT(transaction->mode() != IDBTransaction::READ_ONLY);
+
     RefPtr<IDBObjectStoreBackendImpl> objectStore = this;
     RefPtr<IDBKeyRange> keyRange = prpKeyRange;
     RefPtr<IDBCallbacks> callbacks = prpCallbacks;
@@ -409,11 +400,9 @@
 void IDBObjectStoreBackendImpl::clear(PassRefPtr<IDBCallbacks> prpCallbacks, IDBTransactionBackendInterface* transaction, ExceptionCode& ec)
 {
     IDB_TRACE("IDBObjectStoreBackendImpl::clear");
-    if (transaction->mode() == IDBTransaction::READ_ONLY) {
-        ec = IDBDatabaseException::READ_ONLY_ERR;
-        return;
-    }
 
+    ASSERT(transaction->mode() != IDBTransaction::READ_ONLY);
+
     RefPtr<IDBObjectStoreBackendImpl> objectStore = this;
     RefPtr<IDBCallbacks> callbacks = prpCallbacks;
 

Modified: trunk/Source/WebCore/Modules/indexeddb/IDBTransaction.h (120113 => 120114)


--- trunk/Source/WebCore/Modules/indexeddb/IDBTransaction.h	2012-06-12 20:38:01 UTC (rev 120113)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBTransaction.h	2012-06-12 20:45:58 UTC (rev 120114)
@@ -70,6 +70,7 @@
     bool isFinished() const;
 
     const String& mode() const;
+    bool isReadOnly() const { return m_mode == READ_ONLY; }
     IDBDatabase* db() const;
     PassRefPtr<DOMError> error(ExceptionCode&) const;
     void setError(PassRefPtr<DOMError>);

Modified: trunk/Source/WebCore/Modules/indexeddb/IDBTransactionBackendImpl.h (120113 => 120114)


--- trunk/Source/WebCore/Modules/indexeddb/IDBTransactionBackendImpl.h	2012-06-12 20:38:01 UTC (rev 120113)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBTransactionBackendImpl.h	2012-06-12 20:45:58 UTC (rev 120114)
@@ -76,7 +76,7 @@
     void closeOpenCursors();
 
     RefPtr<DOMStringList> m_objectStoreNames;
-    unsigned short m_mode;
+    const unsigned short m_mode;
 
     State m_state;
     RefPtr<IDBTransactionCallbacks> m_callbacks;
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to