From 171acc8c7e0d2c9a9b4f771407e58d7d66447bae Mon Sep 17 00:00:00 2001 From: Ben Turner Date: Wed, 2 Jun 2010 18:05:23 -0700 Subject: [PATCH] Future proof some key type checks --- dom/indexedDB/IDBObjectStoreRequest.cpp | 34 ++++++++++++++++--------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/dom/indexedDB/IDBObjectStoreRequest.cpp b/dom/indexedDB/IDBObjectStoreRequest.cpp index 9ee8c0ad7dc..4b8b129c450 100644 --- a/dom/indexedDB/IDBObjectStoreRequest.cpp +++ b/dom/indexedDB/IDBObjectStoreRequest.cpp @@ -1031,7 +1031,7 @@ AddHelper::GetSuccessResult(nsIWritableVariant* aResult) aResult->SetAsInt64(mKey.IntValue()); } else { - NS_NOTREACHED("Bad key!"); + NS_NOTREACHED("Unknown key type!"); } return OK; } @@ -1092,15 +1092,19 @@ GetHelper::DoDatabaseWork(mozIStorageConnection* aConnection) nsresult rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("osid"), mOSID); NS_ENSURE_SUCCESS(rv, nsIIDBDatabaseException::UNKNOWN_ERR); - NS_ASSERTION(!mKey.IsUnset(), "Must have a key here!"); + NS_ASSERTION(!mKey.IsUnset() && !mKey.IsNull(), "Must have a key here!"); NS_NAMED_LITERAL_CSTRING(id, "id"); - rv = mKey.IsNull() ? - stmt->BindNullByName(id) : - mKey.IsInt() ? - stmt->BindInt64ByName(id, mKey.IntValue()) : - stmt->BindStringByName(id, mKey.StringValue()); + if (mKey.IsInt()) { + rv = stmt->BindInt64ByName(id, mKey.IntValue()); + } + else if (mKey.IsString()) { + rv = stmt->BindStringByName(id, mKey.StringValue()); + } + else { + NS_NOTREACHED("Unknown key type!"); + } NS_ENSURE_SUCCESS(rv, nsIIDBDatabaseException::UNKNOWN_ERR); // Search for it! @@ -1143,13 +1147,19 @@ RemoveHelper::DoDatabaseWork(mozIStorageConnection* aConnection) nsresult rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("osid"), mOSID); NS_ENSURE_SUCCESS(rv, nsIIDBDatabaseException::UNKNOWN_ERR); + NS_ASSERTION(!mKey.IsUnset() && !mKey.IsNull(), "Must have a key here!"); + NS_NAMED_LITERAL_CSTRING(key_value, "key_value"); - rv = mKey.IsNull() ? - stmt->BindNullByName(key_value) : - mKey.IsInt() ? - stmt->BindInt64ByName(key_value, mKey.IntValue()) : - stmt->BindStringByName(key_value, mKey.StringValue()); + if (mKey.IsInt()) { + rv = stmt->BindInt64ByName(key_value, mKey.IntValue()); + } + else if (mKey.IsString()) { + rv = stmt->BindStringByName(key_value, mKey.StringValue()); + } + else { + NS_NOTREACHED("Unknown key type!"); + } NS_ENSURE_SUCCESS(rv, nsIIDBDatabaseException::UNKNOWN_ERR); // Search for it!