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

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

Issue 18580013: IndexedDB: Make DOMException messages more useful. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Disambiguate TransactionInactiveError 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/IDBDatabase.cpp
diff --git a/Source/modules/indexeddb/IDBDatabase.cpp b/Source/modules/indexeddb/IDBDatabase.cpp
index 186bf64ba4e5b84aed26c334b82f17a9b06f43aa..237e62404f3007cac5c0f01b5e857271033e892a 100644
--- a/Source/modules/indexeddb/IDBDatabase.cpp
+++ b/Source/modules/indexeddb/IDBDatabase.cpp
@@ -48,7 +48,18 @@
namespace WebCore {
-const char IDBDatabase::notFoundErrorMessage[] = "An operation failed because the requested database object could not be found.";
+const char IDBDatabase::indexDeletedMessage[] = "The index or its object store has been deleted.";
+const char IDBDatabase::isKeyCursorMessage[] = "The cursor is a key cursor.";
+const char IDBDatabase::noKeyOrKeyRangeMessage[] = "No key or key range specified.";
+const char IDBDatabase::noSuchIndexMessage[] = "The specified index was not be found.";
arv (Not doing code reviews) 2013/07/12 17:43:08 Bad grammar of message
jsbell 2013/07/12 17:53:14 Done.
+const char IDBDatabase::noSuchObjectStoreMessage[] = "The specified object store was not found.";
+const char IDBDatabase::notGotValueMessage[] = "The cursor is being iterated or has iterated past its end.";
+const char IDBDatabase::notValidKeyMessage[] = "The parameter is not a valid key.";
+const char IDBDatabase::notVersionChangeTransactionMessage[] = "The database is not running a version change transaction.";
+const char IDBDatabase::objectStoreDeletedMessage[] = "The object store has been deleted.";
+const char IDBDatabase::requestNotFinishedMessage[] = "The request has not finished.";
+const char IDBDatabase::sourceDeletedMessage[] = "The cursor's source or effective object store has been deleted.";
+const char IDBDatabase::transactionFinishedMessage[] = "The transaction has finished.";
PassRefPtr<IDBDatabase> IDBDatabase::create(ScriptExecutionContext* context, PassRefPtr<IDBDatabaseBackendInterface> database, PassRefPtr<IDBDatabaseCallbacks> callbacks)
{
@@ -176,7 +187,11 @@ PassRefPtr<IDBObjectStore> IDBDatabase::createObjectStore(const String& name, co
IDB_TRACE("IDBDatabase::createObjectStore");
HistogramSupport::histogramEnumeration("WebCore.IndexedDB.FrontEndAPICalls", IDBCreateObjectStoreCall, IDBMethodsMax);
if (!m_versionChangeTransaction) {
- es.throwDOMException(InvalidStateError);
+ es.throwDOMException(InvalidStateError, IDBDatabase::notVersionChangeTransactionMessage);
+ return 0;
+ }
+ if (m_versionChangeTransaction->isFinished()) {
+ es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionFinishedMessage);
return 0;
}
if (!m_versionChangeTransaction->isActive()) {
@@ -185,17 +200,17 @@ PassRefPtr<IDBObjectStore> IDBDatabase::createObjectStore(const String& name, co
}
if (containsObjectStore(name)) {
- es.throwDOMException(ConstraintError);
+ es.throwDOMException(ConstraintError, "An object store with the specified name already exists.");
return 0;
}
if (!keyPath.isNull() && !keyPath.isValid()) {
- es.throwDOMException(SyntaxError);
+ es.throwDOMException(SyntaxError, "The keyPath option is not a valid key path.");
return 0;
}
if (autoIncrement && ((keyPath.type() == IDBKeyPath::StringType && keyPath.string().isEmpty()) || keyPath.type() == IDBKeyPath::ArrayType)) {
- es.throwDOMException(InvalidAccessError);
+ es.throwDOMException(InvalidAccessError, "The autoIncrement option was set but the keyPath option was not a non-empty string.");
arv (Not doing code reviews) 2013/07/12 17:43:08 Double negation. Maybe? but the keyPath option wa
jsbell 2013/07/12 17:53:14 Went with "but the keyPath option was empty or an
return 0;
}
@@ -216,7 +231,11 @@ void IDBDatabase::deleteObjectStore(const String& name, ExceptionState& es)
IDB_TRACE("IDBDatabase::deleteObjectStore");
HistogramSupport::histogramEnumeration("WebCore.IndexedDB.FrontEndAPICalls", IDBDeleteObjectStoreCall, IDBMethodsMax);
if (!m_versionChangeTransaction) {
- es.throwDOMException(InvalidStateError);
+ es.throwDOMException(InvalidStateError, IDBDatabase::notVersionChangeTransactionMessage);
+ return;
+ }
+ if (m_versionChangeTransaction->isFinished()) {
+ es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionFinishedMessage);
return;
}
if (!m_versionChangeTransaction->isActive()) {
@@ -226,7 +245,7 @@ void IDBDatabase::deleteObjectStore(const String& name, ExceptionState& es)
int64_t objectStoreId = findObjectStoreId(name);
if (objectStoreId == IDBObjectStoreMetadata::InvalidId) {
- es.throwDOMException(NotFoundError, IDBDatabase::notFoundErrorMessage);
+ es.throwDOMException(NotFoundError, "The specified object store was not found.");
return;
}
@@ -240,7 +259,7 @@ PassRefPtr<IDBTransaction> IDBDatabase::transaction(ScriptExecutionContext* cont
IDB_TRACE("IDBDatabase::transaction");
HistogramSupport::histogramEnumeration("WebCore.IndexedDB.FrontEndAPICalls", IDBTransactionCall, IDBMethodsMax);
if (!scope.size()) {
- es.throwDOMException(InvalidAccessError);
+ es.throwDOMException(InvalidAccessError, "The storeNames parameter was empty.");
return 0;
}
@@ -248,8 +267,13 @@ PassRefPtr<IDBTransaction> IDBDatabase::transaction(ScriptExecutionContext* cont
if (es.hadException())
return 0;
- if (m_versionChangeTransaction || m_closePending) {
- es.throwDOMException(InvalidStateError);
+ if (m_versionChangeTransaction) {
+ es.throwDOMException(InvalidStateError, "A version change transaction is running.");
+ return 0;
+ }
+
+ if (m_closePending) {
+ es.throwDOMException(InvalidStateError, "The database connection is closing.");
return 0;
}
@@ -257,7 +281,7 @@ PassRefPtr<IDBTransaction> IDBDatabase::transaction(ScriptExecutionContext* cont
for (size_t i = 0; i < scope.size(); ++i) {
int64_t objectStoreId = findObjectStoreId(scope[i]);
if (objectStoreId == IDBObjectStoreMetadata::InvalidId) {
- es.throwDOMException(NotFoundError, IDBDatabase::notFoundErrorMessage);
+ es.throwDOMException(NotFoundError, "One of the specified object stores was not found.");
return 0;
}
objectStoreIds.append(objectStoreId);

Powered by Google App Engine
This is Rietveld 408576698