From f39f6fe5ffbb5d8a94bfdb204e81731e6be8cda6 Mon Sep 17 00:00:00 2001 From: Jonas Sicking Date: Mon, 12 Mar 2012 21:44:45 -0700 Subject: [PATCH] Bug 735094: Implement new string values (rather than numeric constants) for IndexedDB. r=bent --- dom/base/nsDOMClassInfo.cpp | 150 ++++++++++++++++++ dom/indexedDB/IDBCursor.cpp | 68 ++++++-- dom/indexedDB/IDBCursor.h | 35 ++-- dom/indexedDB/IDBDatabase.cpp | 18 +-- dom/indexedDB/IDBIndex.cpp | 74 ++++----- dom/indexedDB/IDBObjectStore.cpp | 41 +++-- dom/indexedDB/IDBRequest.cpp | 11 +- dom/indexedDB/IDBTransaction.cpp | 59 +++---- dom/indexedDB/IDBTransaction.h | 27 +++- dom/indexedDB/TransactionThreadPool.cpp | 12 +- dom/indexedDB/nsIIDBCursor.idl | 9 +- dom/indexedDB/nsIIDBDatabase.idl | 5 +- dom/indexedDB/nsIIDBIndex.idl | 8 +- dom/indexedDB/nsIIDBObjectStore.idl | 5 +- dom/indexedDB/nsIIDBRequest.idl | 7 +- dom/indexedDB/nsIIDBTransaction.idl | 14 +- dom/indexedDB/test/browser_quotaPrompt.html | 4 +- .../test/browser_quotaPromptDatabases.html | 2 - .../test/browser_quotaPromptDelete.html | 4 +- .../test/test_create_objectStore.html | 7 +- dom/indexedDB/test/test_deleteDatabase.html | 3 - .../test_deleteDatabase_interactions.html | 3 - .../test/test_readonly_transactions.html | 35 ++-- dom/indexedDB/test/unit/test_advance.js | 4 +- dom/indexedDB/test/unit/test_clear.js | 6 +- dom/indexedDB/test/unit/test_create_index.js | 7 +- .../test/unit/test_create_objectStore.js | 7 +- .../test/unit/test_cursor_mutation.js | 2 +- .../test_cursor_update_updates_indexes.js | 3 - dom/indexedDB/test/unit/test_cursors.js | 4 +- .../test/unit/test_index_empty_keyPath.js | 2 +- .../test/unit/test_index_object_cursors.js | 4 +- .../test/unit/test_index_update_delete.js | 6 +- dom/indexedDB/test/unit/test_indexes.js | 35 ++-- .../test/unit/test_indexes_bad_values.js | 1 - dom/indexedDB/test/unit/test_keys.js | 2 +- dom/indexedDB/test/unit/test_multientry.js | 2 +- .../test/unit/test_odd_result_order.js | 4 +- .../test/unit/test_optionalArguments.js | 2 +- .../unit/test_overlapping_transactions.js | 12 +- .../test/unit/test_request_readyState.js | 15 +- dom/indexedDB/test/unit/test_setVersion.js | 5 +- .../test/unit/test_setVersion_abort.js | 3 - .../test/unit/test_setVersion_events.js | 4 +- .../test/unit/test_transaction_abort.js | 42 ++--- .../unit/test_transaction_lifetimes_nested.js | 12 -- .../test/unit/test_transaction_ordering.js | 6 +- .../test/unit/test_writer_starvation.js | 11 +- 48 files changed, 450 insertions(+), 352 deletions(-) diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp index 63df3cd7666..2bfcc0729e9 100644 --- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -5692,6 +5692,138 @@ DefineInterfaceConstants(JSContext *cx, JSObject *obj, const nsIID *aIID) return NS_OK; } +// This code is temporary until we remove support for the constants defined +// on IDBCursor/IDBRequest/IDBTransaction + +struct IDBConstant +{ + const char* interface; + const char* name; + const char* value; + + static const char* IDBCursor; + static const char* IDBRequest; + static const char* IDBTransaction; +}; + +const char* IDBConstant::IDBCursor = "IDBCursor"; +const char* IDBConstant::IDBRequest = "IDBRequest"; +const char* IDBConstant::IDBTransaction = "IDBTransaction"; + +static const IDBConstant sIDBConstants[] = { + { IDBConstant::IDBCursor, "NEXT", "next" }, + { IDBConstant::IDBCursor, "NEXT_NO_DUPLICATE", "nextunique" }, + { IDBConstant::IDBCursor, "PREV", "prev" }, + { IDBConstant::IDBCursor, "PREV_NO_DUPLICATE", "prevunique" }, + { IDBConstant::IDBRequest, "LOADING", "pending" }, + { IDBConstant::IDBRequest, "DONE", "done" }, + { IDBConstant::IDBTransaction, "READ_ONLY", "readonly" }, + { IDBConstant::IDBTransaction, "READ_WRITE", "readwrite" }, + { IDBConstant::IDBTransaction, "VERSION_CHANGE", "versionchange" }, +}; + +static JSBool +IDBConstantGetter(JSContext *cx, JSObject *obj, jsid id, jsval* vp) +{ + MOZ_ASSERT(JSID_IS_INT(id)); + + int8_t index = JSID_TO_INT(id); + + MOZ_ASSERT((uint8_t)index < mozilla::ArrayLength(sIDBConstants)); + + const IDBConstant& c = sIDBConstants[index]; + + // Put a warning on the console + nsString warnText = + NS_LITERAL_STRING("The constant ") + + NS_ConvertASCIItoUTF16(c.interface) + + NS_LITERAL_STRING(".") + + NS_ConvertASCIItoUTF16(c.name) + + NS_LITERAL_STRING(" has been deprecated. Use the string value \"") + + NS_ConvertASCIItoUTF16(c.value) + + NS_LITERAL_STRING("\" instead."); + + PRUint64 windowID = 0; + nsIScriptContext* context = GetScriptContextFromJSContext(cx); + if (context) { + nsCOMPtr window = + do_QueryInterface(context->GetGlobalObject()); + if (window) { + window = window->GetCurrentInnerWindow(); + } + NS_WARN_IF_FALSE(window, "Missing a window, got a door?"); + if (window) { + windowID = window->WindowID(); + } + } + + nsCOMPtr errorObject = + do_CreateInstance(NS_SCRIPTERROR_CONTRACTID); + NS_WARN_IF_FALSE(errorObject, "Failed to create error object"); + if (errorObject) { + nsresult rv = errorObject->InitWithWindowID(warnText.get(), + nsnull, // file name + nsnull, // source line + 0, 0, // Line/col number + nsIScriptError::warningFlag, + "DOM Core", windowID); + NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Failed to init error object"); + + if (NS_SUCCEEDED(rv)) { + nsCOMPtr consoleServ = + do_GetService(NS_CONSOLESERVICE_CONTRACTID); + if (consoleServ) { + consoleServ->LogMessage(errorObject); + } + } + } + + // Redefine property to remove getter + NS_ConvertASCIItoUTF16 valStr(c.value); + jsval value; + if (!xpc::StringToJsval(cx, valStr, &value)) { + return JS_FALSE; + } + if (!::JS_DefineProperty(cx, obj, c.name, value, nsnull, nsnull, + JSPROP_ENUMERATE)) { + return JS_FALSE; + } + + // Return value + *vp = value; + return JS_TRUE; +} + +static nsresult +DefineIDBInterfaceConstants(JSContext *cx, JSObject *obj, const nsIID *aIID) +{ + const char* interface; + if (aIID->Equals(NS_GET_IID(nsIIDBCursor))) { + interface = IDBConstant::IDBCursor; + } + else if (aIID->Equals(NS_GET_IID(nsIIDBRequest))) { + interface = IDBConstant::IDBRequest; + } + else if (aIID->Equals(NS_GET_IID(nsIIDBTransaction))) { + interface = IDBConstant::IDBTransaction; + } + + for (int8_t i = 0; i < (int8_t)mozilla::ArrayLength(sIDBConstants); ++i) { + const IDBConstant& c = sIDBConstants[i]; + if (c.interface != interface) { + continue; + } + + if (!::JS_DefinePropertyWithTinyId(cx, obj, c.name, i, JSVAL_VOID, + IDBConstantGetter, nsnull, + JSPROP_ENUMERATE)) { + return NS_ERROR_UNEXPECTED; + } + } + + return NS_OK; +} + class nsDOMConstructor : public nsIDOMDOMConstructor { protected: @@ -6098,6 +6230,15 @@ nsDOMConstructor::ResolveInterfaceConstants(JSContext *cx, JSObject *obj) return NS_ERROR_FAILURE; } + // Special case a few IDB interfaces which for now are getting transitional + // constants. + if (class_iid->Equals(NS_GET_IID(nsIIDBCursor)) || + class_iid->Equals(NS_GET_IID(nsIIDBRequest)) || + class_iid->Equals(NS_GET_IID(nsIIDBTransaction))) { + rv = DefineIDBInterfaceConstants(cx, obj, class_iid); + NS_ENSURE_SUCCESS(rv, rv); + } + return NS_OK; } @@ -6241,6 +6382,15 @@ ResolvePrototype(nsIXPConnect *aXPConnect, nsGlobalWindow *aWin, JSContext *cx, return NS_ERROR_FAILURE; } + // Special case a few IDB interfaces which for now are getting transitional + // constants. + if (primary_iid->Equals(NS_GET_IID(nsIIDBCursor)) || + primary_iid->Equals(NS_GET_IID(nsIIDBRequest)) || + primary_iid->Equals(NS_GET_IID(nsIIDBTransaction))) { + rv = DefineIDBInterfaceConstants(cx, class_obj, primary_iid); + NS_ENSURE_SUCCESS(rv, rv); + } + nsCOMPtr iim(do_GetService(NS_INTERFACEINFOMANAGER_SERVICE_CONTRACTID)); NS_ENSURE_TRUE(iim, NS_ERROR_NOT_AVAILABLE); diff --git a/dom/indexedDB/IDBCursor.cpp b/dom/indexedDB/IDBCursor.cpp index 382150fd723..feb00dd2e4b 100644 --- a/dom/indexedDB/IDBCursor.cpp +++ b/dom/indexedDB/IDBCursor.cpp @@ -157,7 +157,7 @@ already_AddRefed IDBCursor::Create(IDBRequest* aRequest, IDBTransaction* aTransaction, IDBObjectStore* aObjectStore, - PRUint16 aDirection, + Direction aDirection, const Key& aRangeKey, const nsACString& aContinueQuery, const nsACString& aContinueToQuery, @@ -185,7 +185,7 @@ already_AddRefed IDBCursor::Create(IDBRequest* aRequest, IDBTransaction* aTransaction, IDBIndex* aIndex, - PRUint16 aDirection, + Direction aDirection, const Key& aRangeKey, const nsACString& aContinueQuery, const nsACString& aContinueToQuery, @@ -215,7 +215,7 @@ already_AddRefed IDBCursor::Create(IDBRequest* aRequest, IDBTransaction* aTransaction, IDBIndex* aIndex, - PRUint16 aDirection, + Direction aDirection, const Key& aRangeKey, const nsACString& aContinueQuery, const nsACString& aContinueToQuery, @@ -242,12 +242,35 @@ IDBCursor::Create(IDBRequest* aRequest, return cursor.forget(); } +// static +nsresult +IDBCursor::ParseDirection(const nsAString& aDirection, Direction* aResult) +{ + if (aDirection.EqualsLiteral("next")) { + *aResult = NEXT; + } + else if (aDirection.EqualsLiteral("nextunique")) { + *aResult = NEXT_UNIQUE; + } + else if (aDirection.EqualsLiteral("prev")) { + *aResult = PREV; + } + else if (aDirection.EqualsLiteral("prevunique")) { + *aResult = PREV_UNIQUE; + } + else { + return NS_ERROR_DOM_INDEXEDDB_NON_TRANSIENT_ERR; + } + + return NS_OK; +} + // static already_AddRefed IDBCursor::CreateCommon(IDBRequest* aRequest, IDBTransaction* aTransaction, IDBObjectStore* aObjectStore, - PRUint16 aDirection, + Direction aDirection, const Key& aRangeKey, const nsACString& aContinueQuery, const nsACString& aContinueToQuery) @@ -286,7 +309,7 @@ IDBCursor::CreateCommon(IDBRequest* aRequest, IDBCursor::IDBCursor() : mScriptOwner(nsnull), mType(OBJECTSTORE), - mDirection(nsIIDBCursor::NEXT), + mDirection(IDBCursor::NEXT), mCachedKey(JSVAL_VOID), mCachedPrimaryKey(JSVAL_VOID), mCachedValue(JSVAL_VOID), @@ -329,11 +352,11 @@ IDBCursor::ContinueInternal(const Key& aKey, #ifdef DEBUG { - PRUint16 readyState; - if (NS_FAILED(mRequest->GetReadyState(&readyState))) { + nsAutoString readyState; + if (NS_FAILED(mRequest->GetReadyState(readyState))) { NS_ERROR("This should never fail!"); } - NS_ASSERTION(readyState == nsIIDBRequest::DONE, "Should be DONE!"); + NS_ASSERTION(readyState.EqualsLiteral("done"), "Should be DONE!"); } #endif @@ -436,11 +459,24 @@ DOMCI_DATA(IDBCursor, IDBCursor) DOMCI_DATA(IDBCursorWithValue, IDBCursor) NS_IMETHODIMP -IDBCursor::GetDirection(PRUint16* aDirection) +IDBCursor::GetDirection(nsAString& aDirection) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); - *aDirection = mDirection; + switch(mDirection) { + case NEXT: + aDirection.AssignLiteral("next"); + break; + case NEXT_UNIQUE: + aDirection.AssignLiteral("nextunique"); + break; + case PREV: + aDirection.AssignLiteral("prev"); + break; + case PREV_UNIQUE: + aDirection.AssignLiteral("prevunique"); + } + return NS_OK; } @@ -562,15 +598,15 @@ IDBCursor::Continue(const jsval &aKey, if (!key.IsUnset()) { switch (mDirection) { - case nsIIDBCursor::NEXT: - case nsIIDBCursor::NEXT_NO_DUPLICATE: + case IDBCursor::NEXT: + case IDBCursor::NEXT_UNIQUE: if (key <= mKey) { return NS_ERROR_DOM_INDEXEDDB_DATA_ERR; } break; - case nsIIDBCursor::PREV: - case nsIIDBCursor::PREV_NO_DUPLICATE: + case IDBCursor::PREV: + case IDBCursor::PREV_UNIQUE: if (key >= mKey) { return NS_ERROR_DOM_INDEXEDDB_DATA_ERR; } @@ -853,8 +889,8 @@ ContinueIndexHelper::BindArgumentsToStatement(mozIStorageStatement* aStatement) // Bind object key if duplicates are allowed and we're not continuing to a // specific key. - if ((mCursor->mDirection == nsIIDBCursor::NEXT || - mCursor->mDirection == nsIIDBCursor::PREV) && + if ((mCursor->mDirection == IDBCursor::NEXT || + mCursor->mDirection == IDBCursor::PREV) && mCursor->mContinueToKey.IsUnset()) { NS_ASSERTION(!mCursor->mObjectKey.IsUnset(), "Bad key!"); diff --git a/dom/indexedDB/IDBCursor.h b/dom/indexedDB/IDBCursor.h index 24658eda0e0..dd768392525 100644 --- a/dom/indexedDB/IDBCursor.h +++ b/dom/indexedDB/IDBCursor.h @@ -77,13 +77,28 @@ public: NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(IDBCursor) + enum Type + { + OBJECTSTORE = 0, + INDEXKEY, + INDEXOBJECT + }; + + enum Direction + { + NEXT = 0, + NEXT_UNIQUE, + PREV, + PREV_UNIQUE + }; + // For OBJECTSTORE cursors. static already_AddRefed Create(IDBRequest* aRequest, IDBTransaction* aTransaction, IDBObjectStore* aObjectStore, - PRUint16 aDirection, + Direction aDirection, const Key& aRangeKey, const nsACString& aContinueQuery, const nsACString& aContinueToQuery, @@ -96,7 +111,7 @@ public: Create(IDBRequest* aRequest, IDBTransaction* aTransaction, IDBIndex* aIndex, - PRUint16 aDirection, + Direction aDirection, const Key& aRangeKey, const nsACString& aContinueQuery, const nsACString& aContinueToQuery, @@ -109,7 +124,7 @@ public: Create(IDBRequest* aRequest, IDBTransaction* aTransaction, IDBIndex* aIndex, - PRUint16 aDirection, + Direction aDirection, const Key& aRangeKey, const nsACString& aContinueQuery, const nsACString& aContinueToQuery, @@ -117,18 +132,14 @@ public: const Key& aObjectKey, StructuredCloneReadInfo& aCloneReadInfo); - enum Type - { - OBJECTSTORE = 0, - INDEXKEY, - INDEXOBJECT - }; - IDBTransaction* Transaction() { return mTransaction; } + static nsresult ParseDirection(const nsAString& aDirection, + Direction* aResult); + protected: IDBCursor(); ~IDBCursor(); @@ -138,7 +149,7 @@ protected: CreateCommon(IDBRequest* aRequest, IDBTransaction* aTransaction, IDBObjectStore* aObjectStore, - PRUint16 aDirection, + Direction aDirection, const Key& aRangeKey, const nsACString& aContinueQuery, const nsACString& aContinueToQuery); @@ -155,7 +166,7 @@ protected: JSObject* mScriptOwner; Type mType; - PRUint16 mDirection; + Direction mDirection; nsCString mContinueQuery; nsCString mContinueToQuery; diff --git a/dom/indexedDB/IDBDatabase.cpp b/dom/indexedDB/IDBDatabase.cpp index f9e0e2c2e8f..ffd0b5109a6 100644 --- a/dom/indexedDB/IDBDatabase.cpp +++ b/dom/indexedDB/IDBDatabase.cpp @@ -386,7 +386,7 @@ IDBDatabase::CreateObjectStore(const nsAString& aName, IDBTransaction* transaction = AsyncConnectionHelper::GetCurrentTransaction(); if (!transaction || - transaction->Mode() != nsIIDBTransaction::VERSION_CHANGE) { + transaction->GetMode() != IDBTransaction::VERSION_CHANGE) { return NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR; } @@ -506,7 +506,7 @@ IDBDatabase::DeleteObjectStore(const nsAString& aName) IDBTransaction* transaction = AsyncConnectionHelper::GetCurrentTransaction(); if (!transaction || - transaction->Mode() != nsIIDBTransaction::VERSION_CHANGE) { + transaction->GetMode() != IDBTransaction::VERSION_CHANGE) { return NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR; } @@ -528,7 +528,7 @@ IDBDatabase::DeleteObjectStore(const nsAString& aName) NS_IMETHODIMP IDBDatabase::Transaction(const jsval& aStoreNames, - PRUint16 aMode, + const nsAString& aMode, JSContext* aCx, PRUint8 aOptionalArgCount, nsIIDBTransaction** _retval) @@ -547,15 +547,15 @@ IDBDatabase::Transaction(const jsval& aStoreNames, return NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR; } + IDBTransaction::Mode transactionMode = IDBTransaction::READ_ONLY; if (aOptionalArgCount) { - if (aMode != nsIIDBTransaction::READ_WRITE && - aMode != nsIIDBTransaction::READ_ONLY) { + if (aMode.EqualsLiteral("readwrite")) { + transactionMode = IDBTransaction::READ_WRITE; + } + else if (!aMode.EqualsLiteral("readonly")) { return NS_ERROR_DOM_INDEXEDDB_NON_TRANSIENT_ERR; } } - else { - aMode = nsIIDBTransaction::READ_ONLY; - } nsresult rv; nsTArray storesToOpen; @@ -657,7 +657,7 @@ IDBDatabase::Transaction(const jsval& aStoreNames, } nsRefPtr transaction = - IDBTransaction::Create(this, storesToOpen, aMode, false); + IDBTransaction::Create(this, storesToOpen, transactionMode, false); NS_ENSURE_TRUE(transaction, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR); transaction.forget(_retval); diff --git a/dom/indexedDB/IDBIndex.cpp b/dom/indexedDB/IDBIndex.cpp index f2d3551e317..e4c7612df7e 100644 --- a/dom/indexedDB/IDBIndex.cpp +++ b/dom/indexedDB/IDBIndex.cpp @@ -186,7 +186,7 @@ public: IDBRequest* aRequest, IDBIndex* aIndex, IDBKeyRange* aKeyRange, - PRUint16 aDirection) + IDBCursor::Direction aDirection) : AsyncConnectionHelper(aTransaction, aRequest), mIndex(aIndex), mKeyRange(aKeyRange), mDirection(aDirection) { } @@ -206,7 +206,7 @@ private: // In-params. nsRefPtr mIndex; nsRefPtr mKeyRange; - const PRUint16 mDirection; + const IDBCursor::Direction mDirection; // Out-params. Key mKey; @@ -223,7 +223,7 @@ public: IDBRequest* aRequest, IDBIndex* aIndex, IDBKeyRange* aKeyRange, - PRUint16 aDirection) + IDBCursor::Direction aDirection) : AsyncConnectionHelper(aTransaction, aRequest), mIndex(aIndex), mKeyRange(aKeyRange), mDirection(aDirection) { } @@ -248,7 +248,7 @@ private: // In-params. nsRefPtr mIndex; nsRefPtr mKeyRange; - const PRUint16 mDirection; + const IDBCursor::Direction mDirection; // Out-params. Key mKey; @@ -582,7 +582,7 @@ IDBIndex::GetAllKeys(const jsval& aKey, NS_IMETHODIMP IDBIndex::OpenCursor(const jsval& aKey, - PRUint16 aDirection, + const nsAString& aDirection, JSContext* aCx, PRUint8 aOptionalArgCount, nsIIDBRequest** _retval) @@ -596,21 +596,16 @@ IDBIndex::OpenCursor(const jsval& aKey, nsresult rv; + IDBCursor::Direction direction = IDBCursor::NEXT; + nsRefPtr keyRange; if (aOptionalArgCount) { rv = IDBKeyRange::FromJSVal(aCx, aKey, getter_AddRefs(keyRange)); NS_ENSURE_SUCCESS(rv, rv); if (aOptionalArgCount >= 2) { - if (aDirection != nsIIDBCursor::NEXT && - aDirection != nsIIDBCursor::NEXT_NO_DUPLICATE && - aDirection != nsIIDBCursor::PREV && - aDirection != nsIIDBCursor::PREV_NO_DUPLICATE) { - return NS_ERROR_DOM_INDEXEDDB_NON_TRANSIENT_ERR; - } - } - else { - aDirection = nsIIDBCursor::NEXT; + rv = IDBCursor::ParseDirection(aDirection, &direction); + NS_ENSURE_SUCCESS(rv, rv); } } @@ -618,7 +613,7 @@ IDBIndex::OpenCursor(const jsval& aKey, NS_ENSURE_TRUE(request, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR); nsRefPtr helper = - new OpenCursorHelper(transaction, request, this, keyRange, aDirection); + new OpenCursorHelper(transaction, request, this, keyRange, direction); rv = helper->DispatchToTransactionPool(); NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR); @@ -629,7 +624,7 @@ IDBIndex::OpenCursor(const jsval& aKey, NS_IMETHODIMP IDBIndex::OpenKeyCursor(const jsval& aKey, - PRUint16 aDirection, + const nsAString& aDirection, JSContext* aCx, PRUint8 aOptionalArgCount, nsIIDBRequest** _retval) @@ -643,21 +638,16 @@ IDBIndex::OpenKeyCursor(const jsval& aKey, nsresult rv; + IDBCursor::Direction direction = IDBCursor::NEXT; + nsRefPtr keyRange; if (aOptionalArgCount) { rv = IDBKeyRange::FromJSVal(aCx, aKey, getter_AddRefs(keyRange)); NS_ENSURE_SUCCESS(rv, rv); if (aOptionalArgCount >= 2) { - if (aDirection != nsIIDBCursor::NEXT && - aDirection != nsIIDBCursor::NEXT_NO_DUPLICATE && - aDirection != nsIIDBCursor::PREV && - aDirection != nsIIDBCursor::PREV_NO_DUPLICATE) { - return NS_ERROR_DOM_INDEXEDDB_NON_TRANSIENT_ERR; - } - } - else { - aDirection = nsIIDBCursor::NEXT; + rv = IDBCursor::ParseDirection(aDirection, &direction); + NS_ENSURE_SUCCESS(rv, rv); } } @@ -665,7 +655,7 @@ IDBIndex::OpenKeyCursor(const jsval& aKey, NS_ENSURE_TRUE(request, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR); nsRefPtr helper = - new OpenKeyCursorHelper(transaction, request, this, keyRange, aDirection); + new OpenKeyCursorHelper(transaction, request, this, keyRange, direction); rv = helper->DispatchToTransactionPool(); NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR); @@ -1032,16 +1022,16 @@ OpenKeyCursorHelper::DoDatabaseWork(mozIStorageConnection* aConnection) nsCAutoString directionClause(" ORDER BY value "); switch (mDirection) { - case nsIIDBCursor::NEXT: - case nsIIDBCursor::NEXT_NO_DUPLICATE: + case IDBCursor::NEXT: + case IDBCursor::NEXT_UNIQUE: directionClause += NS_LITERAL_CSTRING("ASC, object_data_key ASC"); break; - case nsIIDBCursor::PREV: + case IDBCursor::PREV: directionClause += NS_LITERAL_CSTRING("DESC, object_data_key DESC"); break; - case nsIIDBCursor::PREV_NO_DUPLICATE: + case IDBCursor::PREV_UNIQUE: directionClause += NS_LITERAL_CSTRING("DESC, object_data_key ASC"); break; @@ -1092,7 +1082,7 @@ OpenKeyCursorHelper::DoDatabaseWork(mozIStorageConnection* aConnection) NS_NAMED_LITERAL_CSTRING(rangeKey, "range_key"); switch (mDirection) { - case nsIIDBCursor::NEXT: + case IDBCursor::NEXT: if (mKeyRange && !mKeyRange->Upper().IsUnset()) { AppendConditionClause(value, rangeKey, true, !mKeyRange->IsUpperOpen(), queryStart); @@ -1112,7 +1102,7 @@ OpenKeyCursorHelper::DoDatabaseWork(mozIStorageConnection* aConnection) NS_LITERAL_CSTRING(" LIMIT "); break; - case nsIIDBCursor::NEXT_NO_DUPLICATE: + case IDBCursor::NEXT_UNIQUE: if (mKeyRange && !mKeyRange->Upper().IsUnset()) { AppendConditionClause(value, rangeKey, true, !mKeyRange->IsUpperOpen(), queryStart); @@ -1128,7 +1118,7 @@ OpenKeyCursorHelper::DoDatabaseWork(mozIStorageConnection* aConnection) NS_LITERAL_CSTRING(" LIMIT "); break; - case nsIIDBCursor::PREV: + case IDBCursor::PREV: if (mKeyRange && !mKeyRange->Lower().IsUnset()) { AppendConditionClause(value, rangeKey, false, !mKeyRange->IsLowerOpen(), queryStart); @@ -1149,7 +1139,7 @@ OpenKeyCursorHelper::DoDatabaseWork(mozIStorageConnection* aConnection) NS_LITERAL_CSTRING(" LIMIT "); break; - case nsIIDBCursor::PREV_NO_DUPLICATE: + case IDBCursor::PREV_UNIQUE: if (mKeyRange && !mKeyRange->Lower().IsUnset()) { AppendConditionClause(value, rangeKey, false, !mKeyRange->IsLowerOpen(), queryStart); @@ -1213,18 +1203,18 @@ OpenCursorHelper::DoDatabaseWork(mozIStorageConnection* aConnection) nsCAutoString directionClause(" ORDER BY index_table.value "); switch (mDirection) { - case nsIIDBCursor::NEXT: - case nsIIDBCursor::NEXT_NO_DUPLICATE: + case IDBCursor::NEXT: + case IDBCursor::NEXT_UNIQUE: directionClause += NS_LITERAL_CSTRING("ASC, index_table.object_data_key ASC"); break; - case nsIIDBCursor::PREV: + case IDBCursor::PREV: directionClause += NS_LITERAL_CSTRING("DESC, index_table.object_data_key DESC"); break; - case nsIIDBCursor::PREV_NO_DUPLICATE: + case IDBCursor::PREV_UNIQUE: directionClause += NS_LITERAL_CSTRING("DESC, index_table.object_data_key ASC"); break; @@ -1292,7 +1282,7 @@ OpenCursorHelper::DoDatabaseWork(mozIStorageConnection* aConnection) NS_NAMED_LITERAL_CSTRING(limit, " LIMIT "); switch (mDirection) { - case nsIIDBCursor::NEXT: + case IDBCursor::NEXT: if (mKeyRange && !mKeyRange->Upper().IsUnset()) { AppendConditionClause(value, rangeKey, true, !mKeyRange->IsUpperOpen(), queryStart); @@ -1310,7 +1300,7 @@ OpenCursorHelper::DoDatabaseWork(mozIStorageConnection* aConnection) directionClause + limit; break; - case nsIIDBCursor::NEXT_NO_DUPLICATE: + case IDBCursor::NEXT_UNIQUE: if (mKeyRange && !mKeyRange->Upper().IsUnset()) { AppendConditionClause(value, rangeKey, true, !mKeyRange->IsUpperOpen(), queryStart); @@ -1326,7 +1316,7 @@ OpenCursorHelper::DoDatabaseWork(mozIStorageConnection* aConnection) directionClause + limit; break; - case nsIIDBCursor::PREV: + case IDBCursor::PREV: if (mKeyRange && !mKeyRange->Lower().IsUnset()) { AppendConditionClause(value, rangeKey, false, !mKeyRange->IsLowerOpen(), queryStart); @@ -1344,7 +1334,7 @@ OpenCursorHelper::DoDatabaseWork(mozIStorageConnection* aConnection) directionClause + limit; break; - case nsIIDBCursor::PREV_NO_DUPLICATE: + case IDBCursor::PREV_UNIQUE: if (mKeyRange && !mKeyRange->Lower().IsUnset()) { AppendConditionClause(value, rangeKey, false, !mKeyRange->IsLowerOpen(), queryStart); diff --git a/dom/indexedDB/IDBObjectStore.cpp b/dom/indexedDB/IDBObjectStore.cpp index b3704c7cf4b..aef8b75792e 100644 --- a/dom/indexedDB/IDBObjectStore.cpp +++ b/dom/indexedDB/IDBObjectStore.cpp @@ -198,7 +198,7 @@ public: IDBRequest* aRequest, IDBObjectStore* aObjectStore, IDBKeyRange* aKeyRange, - PRUint16 aDirection) + IDBCursor::Direction aDirection) : AsyncConnectionHelper(aTransaction, aRequest), mObjectStore(aObjectStore), mKeyRange(aKeyRange), mDirection(aDirection) { } @@ -224,7 +224,7 @@ private: // In-params. nsRefPtr mObjectStore; nsRefPtr mKeyRange; - const PRUint16 mDirection; + const IDBCursor::Direction mDirection; // Out-params. Key mKey; @@ -1637,7 +1637,7 @@ IDBObjectStore::Clear(nsIIDBRequest** _retval) NS_IMETHODIMP IDBObjectStore::OpenCursor(const jsval& aKey, - PRUint16 aDirection, + const nsAString& aDirection, JSContext* aCx, PRUint8 aOptionalArgCount, nsIIDBRequest** _retval) @@ -1650,21 +1650,16 @@ IDBObjectStore::OpenCursor(const jsval& aKey, nsresult rv; + IDBCursor::Direction direction = IDBCursor::NEXT; + nsRefPtr keyRange; if (aOptionalArgCount) { rv = IDBKeyRange::FromJSVal(aCx, aKey, getter_AddRefs(keyRange)); NS_ENSURE_SUCCESS(rv, rv); if (aOptionalArgCount >= 2) { - if (aDirection != nsIIDBCursor::NEXT && - aDirection != nsIIDBCursor::NEXT_NO_DUPLICATE && - aDirection != nsIIDBCursor::PREV && - aDirection != nsIIDBCursor::PREV_NO_DUPLICATE) { - return NS_ERROR_DOM_INDEXEDDB_NON_TRANSIENT_ERR; - } - } - else { - aDirection = nsIIDBCursor::NEXT; + rv = IDBCursor::ParseDirection(aDirection, &direction); + NS_ENSURE_SUCCESS(rv, rv); } } @@ -1672,7 +1667,7 @@ IDBObjectStore::OpenCursor(const jsval& aKey, NS_ENSURE_TRUE(request, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR); nsRefPtr helper = - new OpenCursorHelper(mTransaction, request, this, keyRange, aDirection); + new OpenCursorHelper(mTransaction, request, this, keyRange, direction); rv = helper->DispatchToTransactionPool(); NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR); @@ -1750,7 +1745,7 @@ IDBObjectStore::CreateIndex(const nsAString& aName, if (!transaction || transaction != mTransaction || - mTransaction->Mode() != nsIIDBTransaction::VERSION_CHANGE) { + mTransaction->GetMode() != IDBTransaction::VERSION_CHANGE) { return NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR; } @@ -1876,7 +1871,7 @@ IDBObjectStore::DeleteIndex(const nsAString& aName) if (!transaction || transaction != mTransaction || - mTransaction->Mode() != nsIIDBTransaction::VERSION_CHANGE) { + mTransaction->GetMode() != IDBTransaction::VERSION_CHANGE) { return NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR; } @@ -2285,13 +2280,13 @@ OpenCursorHelper::DoDatabaseWork(mozIStorageConnection* aConnection) nsCAutoString directionClause; switch (mDirection) { - case nsIIDBCursor::NEXT: - case nsIIDBCursor::NEXT_NO_DUPLICATE: + case IDBCursor::NEXT: + case IDBCursor::NEXT_UNIQUE: directionClause.AssignLiteral(" ORDER BY key_value ASC"); break; - case nsIIDBCursor::PREV: - case nsIIDBCursor::PREV_NO_DUPLICATE: + case IDBCursor::PREV: + case IDBCursor::PREV_UNIQUE: directionClause.AssignLiteral(" ORDER BY key_value DESC"); break; @@ -2344,8 +2339,8 @@ OpenCursorHelper::DoDatabaseWork(mozIStorageConnection* aConnection) NS_NAMED_LITERAL_CSTRING(rangeKey, "range_key"); switch (mDirection) { - case nsIIDBCursor::NEXT: - case nsIIDBCursor::NEXT_NO_DUPLICATE: + case IDBCursor::NEXT: + case IDBCursor::NEXT_UNIQUE: AppendConditionClause(keyValue, currentKey, false, false, keyRangeClause); AppendConditionClause(keyValue, currentKey, false, true, @@ -2360,8 +2355,8 @@ OpenCursorHelper::DoDatabaseWork(mozIStorageConnection* aConnection) } break; - case nsIIDBCursor::PREV: - case nsIIDBCursor::PREV_NO_DUPLICATE: + case IDBCursor::PREV: + case IDBCursor::PREV_UNIQUE: AppendConditionClause(keyValue, currentKey, true, false, keyRangeClause); AppendConditionClause(keyValue, currentKey, true, true, continueToKeyRangeClause); diff --git a/dom/indexedDB/IDBRequest.cpp b/dom/indexedDB/IDBRequest.cpp index dbd1580258a..80c02c2f111 100644 --- a/dom/indexedDB/IDBRequest.cpp +++ b/dom/indexedDB/IDBRequest.cpp @@ -190,13 +190,16 @@ IDBRequest::UnrootResultValInternal() } NS_IMETHODIMP -IDBRequest::GetReadyState(PRUint16* aReadyState) +IDBRequest::GetReadyState(nsAString& aReadyState) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); - *aReadyState = mHaveResultOrErrorCode ? - nsIIDBRequest::DONE : - nsIIDBRequest::LOADING; + if (mHaveResultOrErrorCode) { + aReadyState.AssignLiteral("done"); + } + else { + aReadyState.AssignLiteral("pending"); + } return NS_OK; } diff --git a/dom/indexedDB/IDBTransaction.cpp b/dom/indexedDB/IDBTransaction.cpp index 76793da7871..4db736cb995 100644 --- a/dom/indexedDB/IDBTransaction.cpp +++ b/dom/indexedDB/IDBTransaction.cpp @@ -110,7 +110,7 @@ StartTransactionRunnable gStartTransactionRunnable; already_AddRefed IDBTransaction::Create(IDBDatabase* aDatabase, nsTArray& aObjectStoreNames, - PRUint16 aMode, + Mode aMode, bool aDispatchDelayed) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); @@ -156,7 +156,7 @@ IDBTransaction::Create(IDBDatabase* aDatabase, transaction->mCreating = true; } - if (aMode != nsIIDBTransaction::VERSION_CHANGE) { + if (aMode != IDBTransaction::VERSION_CHANGE) { TransactionThreadPool* pool = TransactionThreadPool::GetOrCreate(); pool->Dispatch(transaction, &gStartTransactionRunnable, false, nsnull); } @@ -165,8 +165,8 @@ IDBTransaction::Create(IDBDatabase* aDatabase, } IDBTransaction::IDBTransaction() -: mReadyState(nsIIDBTransaction::INITIAL), - mMode(nsIIDBTransaction::READ_ONLY), +: mReadyState(IDBTransaction::INITIAL), + mMode(IDBTransaction::READ_ONLY), mPendingRequests(0), mCreatedRecursionDepth(0), mSavepointCount(0), @@ -196,9 +196,9 @@ IDBTransaction::OnNewRequest() { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); if (!mPendingRequests) { - NS_ASSERTION(mReadyState == nsIIDBTransaction::INITIAL, + NS_ASSERTION(mReadyState == IDBTransaction::INITIAL, "Reusing a transaction!"); - mReadyState = nsIIDBTransaction::LOADING; + mReadyState = IDBTransaction::LOADING; } ++mPendingRequests; } @@ -210,7 +210,7 @@ IDBTransaction::OnRequestFinished() NS_ASSERTION(mPendingRequests, "Mismatched calls!"); --mPendingRequests; if (!mPendingRequests) { - NS_ASSERTION(mAborted || mReadyState == nsIIDBTransaction::LOADING, + NS_ASSERTION(mAborted || mReadyState == IDBTransaction::LOADING, "Bad state!"); mReadyState = IDBTransaction::COMMITTING; CommitOrRollback(); @@ -220,7 +220,7 @@ IDBTransaction::OnRequestFinished() void IDBTransaction::RemoveObjectStore(const nsAString& aName) { - NS_ASSERTION(mMode == nsIIDBTransaction::VERSION_CHANGE, + NS_ASSERTION(mMode == IDBTransaction::VERSION_CHANGE, "Only remove object stores on VERSION_CHANGE transactions"); mDatabaseInfo->RemoveObjectStore(aName); @@ -343,7 +343,7 @@ IDBTransaction::GetOrCreateConnection(mozIStorageConnection** aResult) nsRefPtr function; nsCString beginTransaction; - if (mMode != nsIIDBTransaction::READ_ONLY) { + if (mMode != IDBTransaction::READ_ONLY) { function = new UpdateRefcountFunction(Database()->Manager()); NS_ENSURE_TRUE(function, NS_ERROR_OUT_OF_MEMORY); @@ -416,7 +416,7 @@ IDBTransaction::IsOpen() const NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); // If we haven't started anything then we're open. - if (mReadyState == nsIIDBTransaction::INITIAL) { + if (mReadyState == IDBTransaction::INITIAL) { NS_ASSERTION(AsyncConnectionHelper::GetCurrentTransaction() != this, "This should be some other transaction (or null)!"); return true; @@ -427,7 +427,7 @@ IDBTransaction::IsOpen() const // from the time we were created) then we are open. Otherwise check the // currently running transaction to see if it's the same. We only allow other // requests to be made if this transaction is currently running. - if (mReadyState == nsIIDBTransaction::LOADING) { + if (mReadyState == IDBTransaction::LOADING) { if (mCreating) { return true; } @@ -528,20 +528,21 @@ IDBTransaction::GetDb(nsIIDBDatabase** aDB) } NS_IMETHODIMP -IDBTransaction::GetReadyState(PRUint16* aReadyState) +IDBTransaction::GetMode(nsAString& aMode) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); - *aReadyState = mReadyState; - return NS_OK; -} + switch(mMode) { + case READ_ONLY: + aMode.AssignLiteral("readonly"); + break; + case READ_WRITE: + aMode.AssignLiteral("readwrite"); + break; + case VERSION_CHANGE: + aMode.AssignLiteral("versionchange"); + } -NS_IMETHODIMP -IDBTransaction::GetMode(PRUint16* aMode) -{ - NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); - - *aMode = mMode; return NS_OK; } @@ -586,7 +587,7 @@ IDBTransaction::ObjectStore(const nsAString& aName, ObjectStoreInfo* info = nsnull; - if (mMode == nsIIDBTransaction::VERSION_CHANGE || + if (mMode == IDBTransaction::VERSION_CHANGE || mObjectStoreNames.Contains(aName)) { info = mDatabaseInfo->GetObjectStore(aName); } @@ -614,12 +615,12 @@ IDBTransaction::Abort() return NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR; } - bool needToCommitOrRollback = mReadyState == nsIIDBTransaction::INITIAL; + bool needToCommitOrRollback = mReadyState == IDBTransaction::INITIAL; mAborted = true; - mReadyState = nsIIDBTransaction::DONE; + mReadyState = IDBTransaction::DONE; - if (Mode() == nsIIDBTransaction::VERSION_CHANGE) { + if (Mode() == IDBTransaction::VERSION_CHANGE) { // If a version change transaction is aborted, the db must be closed mDatabase->Close(); } @@ -676,8 +677,8 @@ IDBTransaction::AfterProcessNextEvent(nsIThreadInternal* aThread, mCreating = false; // Maybe set the readyState to DONE if there were no requests generated. - if (mReadyState == nsIIDBTransaction::INITIAL) { - mReadyState = nsIIDBTransaction::DONE; + if (mReadyState == IDBTransaction::INITIAL) { + mReadyState = IDBTransaction::DONE; if (NS_FAILED(CommitOrRollback())) { NS_WARNING("Failed to commit!"); @@ -724,7 +725,7 @@ CommitHelper::Run() if (NS_IsMainThread()) { NS_ASSERTION(mDoomedObjects.IsEmpty(), "Didn't release doomed objects!"); - mTransaction->mReadyState = nsIIDBTransaction::DONE; + mTransaction->mReadyState = IDBTransaction::DONE; // Release file infos on the main thread, so they will eventually get // destroyed on correct thread. @@ -736,7 +737,7 @@ CommitHelper::Run() nsCOMPtr event; if (mAborted) { - if (mTransaction->Mode() == nsIIDBTransaction::VERSION_CHANGE) { + if (mTransaction->GetMode() == IDBTransaction::VERSION_CHANGE) { // This will make the database take a snapshot of it's DatabaseInfo mTransaction->Database()->Close(); // Then remove the info from the hash as it contains invalid data. diff --git a/dom/indexedDB/IDBTransaction.h b/dom/indexedDB/IDBTransaction.h index 398e2073389..6856abfbcd7 100644 --- a/dom/indexedDB/IDBTransaction.h +++ b/dom/indexedDB/IDBTransaction.h @@ -93,10 +93,25 @@ public: NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(IDBTransaction, IDBWrapperCache) + enum Mode + { + READ_ONLY = 0, + READ_WRITE, + VERSION_CHANGE + }; + + enum ReadyState + { + INITIAL = 0, + LOADING, + COMMITTING, + DONE + }; + static already_AddRefed Create(IDBDatabase* aDatabase, nsTArray& aObjectStoreNames, - PRUint16 aMode, + Mode aMode, bool aDispatchDelayed); // nsIDOMEventTarget @@ -130,8 +145,7 @@ public: bool IsWriteAllowed() const { - return mMode == nsIIDBTransaction::READ_WRITE || - mMode == nsIIDBTransaction::VERSION_CHANGE; + return mMode == READ_WRITE || mMode == VERSION_CHANGE; } bool IsAborted() const @@ -139,7 +153,8 @@ public: return mAborted; } - PRUint16 Mode() + // 'Get' prefix is to avoid name collisions with the enum + Mode GetMode() { return mMode; } @@ -172,8 +187,8 @@ private: nsRefPtr mDatabase; nsRefPtr mDatabaseInfo; nsTArray mObjectStoreNames; - PRUint16 mReadyState; - PRUint16 mMode; + ReadyState mReadyState; + Mode mMode; PRUint32 mPendingRequests; PRUint32 mCreatedRecursionDepth; diff --git a/dom/indexedDB/TransactionThreadPool.cpp b/dom/indexedDB/TransactionThreadPool.cpp index 2c0e058cd0b..b9f6cfccd3d 100644 --- a/dom/indexedDB/TransactionThreadPool.cpp +++ b/dom/indexedDB/TransactionThreadPool.cpp @@ -275,14 +275,14 @@ TransactionThreadPool::FinishTransaction(IDBTransaction* aTransaction) const nsTArray& objectStores = transaction->mObjectStoreNames; bool dummy; - if (transaction->mMode == nsIIDBTransaction::READ_WRITE) { + if (transaction->mMode == IDBTransaction::READ_WRITE) { if (NS_FAILED(CheckOverlapAndMergeObjectStores(storesWriting, objectStores, true, &dummy))) { NS_WARNING("Out of memory!"); } } - else if (transaction->mMode == nsIIDBTransaction::READ_ONLY) { + else if (transaction->mMode == IDBTransaction::READ_ONLY) { if (NS_FAILED(CheckOverlapAndMergeObjectStores(storesReading, objectStores, true, &dummy))) { @@ -358,19 +358,19 @@ TransactionThreadPool::TransactionCanRun(IDBTransaction* aTransaction, nsresult rv = CheckOverlapAndMergeObjectStores(dbTransactionInfo->storesWriting, objectStoreNames, - mode == nsIIDBTransaction::READ_WRITE, + mode == IDBTransaction::READ_WRITE, &writeOverlap); NS_ENSURE_SUCCESS(rv, rv); bool readOverlap; rv = CheckOverlapAndMergeObjectStores(dbTransactionInfo->storesReading, objectStoreNames, - mode == nsIIDBTransaction::READ_ONLY, + mode == IDBTransaction::READ_ONLY, &readOverlap); NS_ENSURE_SUCCESS(rv, rv); if (writeOverlap || - (readOverlap && mode == nsIIDBTransaction::READ_WRITE)) { + (readOverlap && mode == IDBTransaction::READ_WRITE)) { *aCanRun = false; *aExistingQueue = nsnull; return NS_OK; @@ -441,7 +441,7 @@ TransactionThreadPool::Dispatch(IDBTransaction* aTransaction, const nsTArray& objectStoreNames = aTransaction->mObjectStoreNames; nsTArray& storesInUse = - aTransaction->mMode == nsIIDBTransaction::READ_WRITE ? + aTransaction->mMode == IDBTransaction::READ_WRITE ? dbTransactionInfo->storesWriting : dbTransactionInfo->storesReading; diff --git a/dom/indexedDB/nsIIDBCursor.idl b/dom/indexedDB/nsIIDBCursor.idl index 07802680725..1d744d9fbdc 100644 --- a/dom/indexedDB/nsIIDBCursor.idl +++ b/dom/indexedDB/nsIIDBCursor.idl @@ -46,14 +46,11 @@ interface nsIIDBRequest; * http://dev.w3.org/2006/webapi/WebSimpleDB/#idl-def-IDBCursor for more * information. */ -[scriptable, builtinclass, uuid(9d5ddd43-132d-418e-81e8-17d64a6467a2)] +[scriptable, builtinclass, uuid(01136b3a-d84c-487c-b929-f5d012346c44)] interface nsIIDBCursor : nsISupports { - const unsigned short NEXT = 0; - const unsigned short NEXT_NO_DUPLICATE = 1; - const unsigned short PREV = 2; - const unsigned short PREV_NO_DUPLICATE = 3; - readonly attribute unsigned short direction; + // "next", "nextunique", "prev" or "prevunique" + readonly attribute DOMString direction; readonly attribute nsISupports source; diff --git a/dom/indexedDB/nsIIDBDatabase.idl b/dom/indexedDB/nsIIDBDatabase.idl index 8a1d016b154..b9de76a82fe 100644 --- a/dom/indexedDB/nsIIDBDatabase.idl +++ b/dom/indexedDB/nsIIDBDatabase.idl @@ -57,7 +57,7 @@ interface nsIIDBObjectStoreParameters : nsISupports * http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#idl-def-IDBDatabase * for more information. */ -[scriptable, builtinclass, uuid(bb877dff-ab5b-4ebb-9b3c-a7fa97cd4b51)] +[scriptable, builtinclass, uuid(bedee48a-f47f-44f2-ba1e-d8fe595bbfee)] interface nsIIDBDatabase : nsISupports { readonly attribute DOMString name; @@ -75,10 +75,11 @@ interface nsIIDBDatabase : nsISupports void deleteObjectStore([Null(Stringify)] in DOMString name); + // mode can be either "readonly" or "readwrite" [optional_argc, implicit_jscontext] nsIIDBTransaction transaction(in jsval storeNames, // js array of strings - [optional /* READ_ONLY */] in unsigned short mode); + [optional /* "readonly" */] in DOMString mode); void close(); diff --git a/dom/indexedDB/nsIIDBIndex.idl b/dom/indexedDB/nsIIDBIndex.idl index ab88f138ce7..bf8ad347f20 100644 --- a/dom/indexedDB/nsIIDBIndex.idl +++ b/dom/indexedDB/nsIIDBIndex.idl @@ -47,7 +47,7 @@ interface nsIIDBRequest; * http://dev.w3.org/2006/webapi/WebSimpleDB/#idl-def-IDBIndex for more * information. */ -[scriptable, builtinclass, uuid(233ec586-7b34-4263-b27e-a4991b757597)] +[scriptable, builtinclass, uuid(a859747a-0f05-4dfb-8f42-05c61415d4e4)] interface nsIIDBIndex : nsISupports { readonly attribute DOMString name; @@ -81,15 +81,17 @@ interface nsIIDBIndex : nsISupports getAllKeys([optional /* null */] in jsval key, [optional /* unlimited */] in unsigned long limit); + // direction can be "next", "nextunique", "prev" or "prevunique" [implicit_jscontext, optional_argc] nsIIDBRequest openCursor([optional /* null */] in jsval key, - [optional /* nsIIDBCursor::NEXT */] in unsigned short direction); + [optional /* "next" */] in DOMString direction); + // direction can be "next", "nextunique", "prev" or "prevunique" [implicit_jscontext, optional_argc] nsIIDBRequest openKeyCursor([optional /* null */] in jsval key, - [optional /* nsIIDBCursor::NEXT */] in unsigned short direction); + [optional /* "next" */] in DOMString direction); // Accepts null, a key value, or a nsIIDBKeyRange object. [implicit_jscontext, optional_argc] diff --git a/dom/indexedDB/nsIIDBObjectStore.idl b/dom/indexedDB/nsIIDBObjectStore.idl index 1eb48b69b52..a7ae3ed3b17 100644 --- a/dom/indexedDB/nsIIDBObjectStore.idl +++ b/dom/indexedDB/nsIIDBObjectStore.idl @@ -57,7 +57,7 @@ interface nsIIDBIndexParameters : nsISupports * http://dev.w3.org/2006/webapi/WebSimpleDB/#idl-def-nsIIDBObjectStore * for more information. */ -[scriptable, builtinclass, uuid(e0d308ea-b804-4962-918a-28ec0aa4e42b)] +[scriptable, builtinclass, uuid(43157a3c-bed1-4ce7-98c0-11365b852560)] interface nsIIDBObjectStore : nsISupports { readonly attribute DOMString name; @@ -105,10 +105,11 @@ interface nsIIDBObjectStore : nsISupports // Success fires IDBTransactionEvent, result == IDBCursor or result == null if // no match. + // direction can be "next", "nextunique", "prev" or "prevunique" [implicit_jscontext, optional_argc] nsIIDBRequest openCursor([optional /* null */] in jsval range, - [optional /* NEXT */] in unsigned short direction); + [optional /* "next" */] in DOMString direction); [implicit_jscontext] nsIIDBIndex diff --git a/dom/indexedDB/nsIIDBRequest.idl b/dom/indexedDB/nsIIDBRequest.idl index 399b51bc929..5a3aa10f10e 100644 --- a/dom/indexedDB/nsIIDBRequest.idl +++ b/dom/indexedDB/nsIIDBRequest.idl @@ -48,12 +48,11 @@ interface nsIIDBTransaction; * http://dev.w3.org/2006/webapi/WebSimpleDB/#idl-def-IDBRequest for more * information. */ -[scriptable, builtinclass, uuid(a1e4a0ff-e0b2-431c-89cf-43b078189e27)] +[scriptable, builtinclass, uuid(fe30ca60-bb90-4d68-af2f-4735f9228a54)] interface nsIIDBRequest : nsISupports { - const unsigned short LOADING = 1; - const unsigned short DONE = 2; - readonly attribute unsigned short readyState; + // "pending" or "done" + readonly attribute DOMString readyState; readonly attribute nsISupports source; diff --git a/dom/indexedDB/nsIIDBTransaction.idl b/dom/indexedDB/nsIIDBTransaction.idl index 203495bc64e..c6627919749 100644 --- a/dom/indexedDB/nsIIDBTransaction.idl +++ b/dom/indexedDB/nsIIDBTransaction.idl @@ -50,21 +50,13 @@ interface nsIDOMDOMStringList; * http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#idl-def-IDBTransaction * for more information. */ -[scriptable, builtinclass, uuid(4f25832d-de40-4c0b-a176-358d94384b19)] +[scriptable, builtinclass, uuid(e4927c76-4f1f-4d7d-80ad-8186e1677da6)] interface nsIIDBTransaction : nsISupports { readonly attribute nsIIDBDatabase db; - const unsigned short INITIAL = 0; - const unsigned short LOADING = 1; - const unsigned short COMMITTING = 2; - const unsigned short DONE = 3; - readonly attribute unsigned short readyState; - - const unsigned short READ_ONLY = 0; - const unsigned short READ_WRITE = 1; - const unsigned short VERSION_CHANGE = 2; - readonly attribute unsigned short mode; + // "readonly", "readwrite" or "versionchange" + readonly attribute DOMString mode; readonly attribute nsIDOMDOMStringList objectStoreNames; diff --git a/dom/indexedDB/test/browser_quotaPrompt.html b/dom/indexedDB/test/browser_quotaPrompt.html index 15e991cee6c..dc9775c57ef 100644 --- a/dom/indexedDB/test/browser_quotaPrompt.html +++ b/dom/indexedDB/test/browser_quotaPrompt.html @@ -7,13 +7,11 @@ Indexed Database Test