Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(39)

Unified Diff: Source/modules/indexeddb/IDBObjectStore.cpp

Issue 18580013: IndexedDB: Make DOMException messages more useful. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Message => ErrorMessage Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/modules/indexeddb/IDBObjectStore.cpp
diff --git a/Source/modules/indexeddb/IDBObjectStore.cpp b/Source/modules/indexeddb/IDBObjectStore.cpp
index a68b79d62cf5bbb6c9f4f163eb30c5a89a8963ec..7a6dbd66122226118bc15b71b6b17695e9c0ff16 100644
--- a/Source/modules/indexeddb/IDBObjectStore.cpp
+++ b/Source/modules/indexeddb/IDBObjectStore.cpp
@@ -74,11 +74,15 @@ PassRefPtr<IDBRequest> IDBObjectStore::get(ScriptExecutionContext* context, Pass
{
IDB_TRACE("IDBObjectStore::get");
if (isDeleted()) {
- es.throwDOMException(InvalidStateError);
+ es.throwDOMException(InvalidStateError, IDBDatabase::objectStoreDeletedErrorMessage);
return 0;
}
if (!keyRange) {
- es.throwDOMException(DataError);
+ es.throwDOMException(DataError, IDBDatabase::noKeyOrKeyRangeErrorMessage);
+ return 0;
+ }
+ if (m_transaction->isFinished()) {
+ es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionFinishedErrorMessage);
return 0;
}
if (!m_transaction->isActive()) {
@@ -145,7 +149,11 @@ PassRefPtr<IDBRequest> IDBObjectStore::put(IDBDatabaseBackendInterface::PutMode
{
RefPtr<IDBKey> key = prpKey;
if (isDeleted()) {
- es.throwDOMException(InvalidStateError);
+ es.throwDOMException(InvalidStateError, IDBDatabase::objectStoreDeletedErrorMessage);
+ return 0;
+ }
+ if (m_transaction->isFinished()) {
+ es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionFinishedErrorMessage);
return 0;
}
if (!m_transaction->isActive()) {
@@ -177,26 +185,26 @@ PassRefPtr<IDBRequest> IDBObjectStore::put(IDBDatabaseBackendInterface::PutMode
DOMRequestState requestState(context);
if (putMode != IDBDatabaseBackendInterface::CursorUpdate && usesInLineKeys && key) {
- es.throwDOMException(DataError);
+ es.throwDOMException(DataError, "The object store uses in-line keys and the key parameter was provided.");
return 0;
}
if (!usesInLineKeys && !hasKeyGenerator && !key) {
- es.throwDOMException(DataError);
+ es.throwDOMException(DataError, "The object store uses out-of-line keys and has no key generator and the key parameter was not provided.");
return 0;
}
if (usesInLineKeys) {
RefPtr<IDBKey> keyPathKey = createIDBKeyFromScriptValueAndKeyPath(&requestState, value, keyPath);
if (keyPathKey && !keyPathKey->isValid()) {
- es.throwDOMException(DataError);
+ es.throwDOMException(DataError, "Evaluating the object store's key path yielded a value that is not a valid key.");
return 0;
}
if (!hasKeyGenerator && !keyPathKey) {
- es.throwDOMException(DataError);
+ es.throwDOMException(DataError, "Evaluating the object store's key path did not yield a value.");
return 0;
}
if (hasKeyGenerator && !keyPathKey) {
if (!canInjectIDBKeyIntoScriptValue(&requestState, value, keyPath)) {
- es.throwDOMException(DataError);
+ es.throwDOMException(DataError, "A generated key could not be inserted into the value.");
return 0;
}
}
@@ -204,7 +212,7 @@ PassRefPtr<IDBRequest> IDBObjectStore::put(IDBDatabaseBackendInterface::PutMode
key = keyPathKey;
}
if (key && !key->isValid()) {
- es.throwDOMException(DataError);
+ es.throwDOMException(DataError, IDBDatabase::notValidKeyErrorMessage);
return 0;
}
@@ -229,7 +237,11 @@ PassRefPtr<IDBRequest> IDBObjectStore::deleteFunction(ScriptExecutionContext* co
{
IDB_TRACE("IDBObjectStore::delete");
if (isDeleted()) {
- es.throwDOMException(InvalidStateError);
+ es.throwDOMException(InvalidStateError, IDBDatabase::objectStoreDeletedErrorMessage);
+ return 0;
+ }
+ if (m_transaction->isFinished()) {
+ es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionFinishedErrorMessage);
return 0;
}
if (!m_transaction->isActive()) {
@@ -241,7 +253,7 @@ PassRefPtr<IDBRequest> IDBObjectStore::deleteFunction(ScriptExecutionContext* co
return 0;
}
if (!keyRange) {
- es.throwDOMException(DataError);
+ es.throwDOMException(DataError, IDBDatabase::noKeyOrKeyRangeErrorMessage);
return 0;
}
@@ -262,7 +274,11 @@ PassRefPtr<IDBRequest> IDBObjectStore::clear(ScriptExecutionContext* context, Ex
{
IDB_TRACE("IDBObjectStore::clear");
if (isDeleted()) {
- es.throwDOMException(InvalidStateError);
+ es.throwDOMException(InvalidStateError, IDBDatabase::objectStoreDeletedErrorMessage);
+ return 0;
+ }
+ if (m_transaction->isFinished()) {
+ es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionFinishedErrorMessage);
return 0;
}
if (!m_transaction->isActive()) {
@@ -363,8 +379,16 @@ PassRefPtr<IDBIndex> IDBObjectStore::createIndex(ScriptExecutionContext* context
PassRefPtr<IDBIndex> IDBObjectStore::createIndex(ScriptExecutionContext* context, const String& name, const IDBKeyPath& keyPath, bool unique, bool multiEntry, ExceptionState& es)
{
IDB_TRACE("IDBObjectStore::createIndex");
- if (!m_transaction->isVersionChange() || isDeleted()) {
- es.throwDOMException(InvalidStateError);
+ if (!m_transaction->isVersionChange()) {
+ es.throwDOMException(InvalidStateError, IDBDatabase::notVersionChangeTransactionErrorMessage);
+ return 0;
+ }
+ if (isDeleted()) {
+ es.throwDOMException(InvalidStateError, IDBDatabase::objectStoreDeletedErrorMessage);
+ return 0;
+ }
+ if (m_transaction->isFinished()) {
+ es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionFinishedErrorMessage);
return 0;
}
if (!m_transaction->isActive()) {
@@ -372,7 +396,7 @@ PassRefPtr<IDBIndex> IDBObjectStore::createIndex(ScriptExecutionContext* context
return 0;
}
if (!keyPath.isValid()) {
- es.throwDOMException(SyntaxError);
+ es.throwDOMException(SyntaxError, "The keyPath argument contains an invalid key path.");
return 0;
}
if (name.isNull()) {
@@ -380,12 +404,12 @@ PassRefPtr<IDBIndex> IDBObjectStore::createIndex(ScriptExecutionContext* context
return 0;
}
if (containsIndex(name)) {
- es.throwDOMException(ConstraintError);
+ es.throwDOMException(ConstraintError, "An index with the specified name already exists.");
return 0;
}
if (keyPath.type() == IDBKeyPath::ArrayType && multiEntry) {
- es.throwDOMException(InvalidAccessError);
+ es.throwDOMException(InvalidAccessError, "The keyPath argument was an array and the multiEntry option is true.");
return 0;
}
@@ -421,11 +445,11 @@ PassRefPtr<IDBIndex> IDBObjectStore::index(const String& name, ExceptionState& e
{
IDB_TRACE("IDBObjectStore::index");
if (isDeleted()) {
- es.throwDOMException(InvalidStateError);
+ es.throwDOMException(InvalidStateError, IDBDatabase::objectStoreDeletedErrorMessage);
return 0;
}
if (m_transaction->isFinished()) {
- es.throwDOMException(InvalidStateError);
+ es.throwDOMException(InvalidStateError, IDBDatabase::transactionFinishedErrorMessage);
return 0;
}
@@ -435,7 +459,7 @@ PassRefPtr<IDBIndex> IDBObjectStore::index(const String& name, ExceptionState& e
int64_t indexId = findIndexId(name);
if (indexId == IDBIndexMetadata::InvalidId) {
- es.throwDOMException(NotFoundError, IDBDatabase::notFoundErrorMessage);
+ es.throwDOMException(NotFoundError, IDBDatabase::noSuchIndexErrorMessage);
return 0;
}
@@ -457,8 +481,16 @@ PassRefPtr<IDBIndex> IDBObjectStore::index(const String& name, ExceptionState& e
void IDBObjectStore::deleteIndex(const String& name, ExceptionState& es)
{
IDB_TRACE("IDBObjectStore::deleteIndex");
- if (!m_transaction->isVersionChange() || isDeleted()) {
- es.throwDOMException(InvalidStateError);
+ if (!m_transaction->isVersionChange()) {
+ es.throwDOMException(InvalidStateError, IDBDatabase::notVersionChangeTransactionErrorMessage);
+ return;
+ }
+ if (isDeleted()) {
+ es.throwDOMException(InvalidStateError, IDBDatabase::objectStoreDeletedErrorMessage);
+ return;
+ }
+ if (m_transaction->isFinished()) {
+ es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionFinishedErrorMessage);
return;
}
if (!m_transaction->isActive()) {
@@ -467,7 +499,7 @@ void IDBObjectStore::deleteIndex(const String& name, ExceptionState& es)
}
int64_t indexId = findIndexId(name);
if (indexId == IDBIndexMetadata::InvalidId) {
- es.throwDOMException(NotFoundError, IDBDatabase::notFoundErrorMessage);
+ es.throwDOMException(NotFoundError, IDBDatabase::noSuchIndexErrorMessage);
return;
}
@@ -486,7 +518,11 @@ PassRefPtr<IDBRequest> IDBObjectStore::openCursor(ScriptExecutionContext* contex
{
IDB_TRACE("IDBObjectStore::openCursor");
if (isDeleted()) {
- es.throwDOMException(InvalidStateError);
+ es.throwDOMException(InvalidStateError, IDBDatabase::objectStoreDeletedErrorMessage);
+ return 0;
+ }
+ if (m_transaction->isFinished()) {
+ es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionFinishedErrorMessage);
return 0;
}
if (!m_transaction->isActive()) {
@@ -516,7 +552,11 @@ PassRefPtr<IDBRequest> IDBObjectStore::count(ScriptExecutionContext* context, Pa
{
IDB_TRACE("IDBObjectStore::count");
if (isDeleted()) {
- es.throwDOMException(InvalidStateError);
+ es.throwDOMException(InvalidStateError, IDBDatabase::objectStoreDeletedErrorMessage);
+ return 0;
+ }
+ if (m_transaction->isFinished()) {
+ es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionFinishedErrorMessage);
return 0;
}
if (!m_transaction->isActive()) {

Powered by Google App Engine
This is Rietveld 408576698