Bug 592801 - 'IndexedDB: IDBRequest rework, make everything an event target'. r=sicking.

This commit is contained in:
Ben Turner 2010-09-09 15:15:38 -07:00
parent d3b4b506dd
commit 5158899107
18 changed files with 348 additions and 304 deletions

View File

@ -146,17 +146,7 @@ NS_IMETHODIMP
AsyncConnectionHelper::Run()
{
if (NS_IsMainThread()) {
if (mRequest->mAborted) {
NS_ASSERTION(mRequest->mReadyState == nsIIDBRequest::DONE,
"Wrong state!");
mError = true;
mErrorCode = nsIIDBDatabaseException::UNKNOWN_ERR;
}
else {
NS_ASSERTION(mRequest->mReadyState == nsIIDBRequest::LOADING,
"Wrong state!");
mRequest->mReadyState = nsIIDBRequest::DONE;
}
mRequest->SetDone();
// Call OnError if the database had an error or if the OnSuccess handler
// has an error.
@ -268,10 +258,6 @@ AsyncConnectionHelper::Dispatch(nsIEventTarget* aDatabaseThread)
return rv;
}
NS_ASSERTION(mRequest->mReadyState == nsIIDBRequest::INITIAL,
"Wrong readyState!");
mRequest->mReadyState = nsIIDBRequest::LOADING;
rv = aDatabaseThread->Dispatch(this, NS_DISPATCH_NORMAL);
NS_ENSURE_SUCCESS(rv, rv);

View File

@ -115,6 +115,16 @@ private:
const bool mAutoIncrement;
};
inline
already_AddRefed<IDBRequest>
GenerateRequest(IDBCursor* aCursor)
{
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
IDBDatabase* database = aCursor->Transaction()->Database();
return IDBRequest::Create(static_cast<nsPIDOMEventTarget*>(aCursor),
database->ScriptContext(), database->Owner());
}
} // anonymous namespace
BEGIN_INDEXEDDB_NAMESPACE
@ -230,6 +240,10 @@ IDBCursor::CreateCommon(IDBRequest* aRequest,
NS_ASSERTION(aTransaction, "Null pointer!");
nsRefPtr<IDBCursor> cursor(new IDBCursor());
cursor->mScriptContext = aTransaction->Database()->ScriptContext();
cursor->mOwner = aTransaction->Database()->Owner();
cursor->mRequest = aRequest;
cursor->mTransaction = aTransaction;
cursor->mDirection = aDirection;
@ -256,16 +270,38 @@ IDBCursor::~IDBCursor()
if (mJSRuntime) {
js_RemoveRoot(mJSRuntime, &mCachedValue);
}
if (mListenerManager) {
mListenerManager->Disconnect();
}
}
NS_IMPL_ADDREF(IDBCursor)
NS_IMPL_RELEASE(IDBCursor)
NS_IMPL_CYCLE_COLLECTION_CLASS(IDBCursor)
NS_INTERFACE_MAP_BEGIN(IDBCursor)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, IDBRequest::Generator)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(IDBCursor,
nsDOMEventTargetHelper)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mObjectStore,
nsPIDOMEventTarget)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mIndex,
nsPIDOMEventTarget)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mTransaction,
nsPIDOMEventTarget)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mOnErrorListener)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(IDBCursor,
nsDOMEventTargetHelper)
// Don't unlink mObjectStore, mIndex, or mTransaction!
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mOnErrorListener)
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(IDBCursor)
NS_INTERFACE_MAP_ENTRY(nsIIDBCursor)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(IDBCursor)
NS_INTERFACE_MAP_END
NS_INTERFACE_MAP_END_INHERITING(nsDOMEventTargetHelper)
NS_IMPL_ADDREF_INHERITED(IDBCursor, nsDOMEventTargetHelper)
NS_IMPL_RELEASE_INHERITED(IDBCursor, nsDOMEventTargetHelper)
DOMCI_DATA(IDBCursor, IDBCursor)
@ -481,8 +517,7 @@ IDBCursor::Update(const jsval &aValue,
rv = json->EncodeFromJSVal(clone.jsval_addr(), aCx, jsonValue);
NS_ENSURE_SUCCESS(rv, rv);
nsRefPtr<IDBRequest> request =
GenerateWriteRequest(mTransaction->ScriptContext(), mTransaction->Owner());
nsRefPtr<IDBRequest> request = GenerateRequest(this);
NS_ENSURE_TRUE(request, NS_ERROR_FAILURE);
nsRefPtr<UpdateHelper> helper =
@ -516,8 +551,7 @@ IDBCursor::Remove(nsIIDBRequest** _retval)
const Key& key = mData[mDataIndex].key;
NS_ASSERTION(!key.IsUnset() && !key.IsNull(), "Bad key!");
nsRefPtr<IDBRequest> request =
GenerateWriteRequest(mTransaction->ScriptContext(), mTransaction->Owner());
nsRefPtr<IDBRequest> request = GenerateRequest(this);
NS_ENSURE_TRUE(request, NS_ERROR_FAILURE);
nsRefPtr<RemoveHelper> helper =
@ -750,7 +784,7 @@ ContinueRunnable::Run()
}
}
rv = variant->SetAsISupports(static_cast<IDBRequest::Generator*>(mCursor));
rv = variant->SetAsISupports(static_cast<nsPIDOMEventTarget*>(mCursor));
NS_ENSURE_SUCCESS(rv, rv);
}

View File

@ -40,16 +40,19 @@
#ifndef mozilla_dom_indexeddb_idbcursor_h__
#define mozilla_dom_indexeddb_idbcursor_h__
#include "mozilla/dom/indexedDB/IndexedDatabase.h"
#include "mozilla/dom/indexedDB/IDBObjectStore.h"
#include "nsIIDBCursor.h"
#include "nsDOMEventTargetHelper.h"
class nsIRunnable;
BEGIN_INDEXEDDB_NAMESPACE
class IDBIndex;
class IDBRequest;
class IDBObjectStore;
class IDBTransaction;
struct KeyValuePair
@ -66,15 +69,18 @@ struct KeyKeyPair
class ContinueRunnable;
class IDBCursor : public IDBRequest::Generator,
class IDBCursor : public nsDOMEventTargetHelper,
public nsIIDBCursor
{
friend class ContinueRunnable;
public:
NS_DECL_ISUPPORTS
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIIDBCURSOR
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(IDBCursor,
nsDOMEventTargetHelper)
static
already_AddRefed<IDBCursor>
Create(IDBRequest* aRequest,
@ -106,6 +112,11 @@ public:
INDEXOBJECT
};
IDBTransaction* Transaction()
{
return mTransaction;
}
protected:
IDBCursor();
~IDBCursor();
@ -134,6 +145,9 @@ protected:
Type mType;
nsTArray<KeyValuePair> mData;
nsTArray<KeyKeyPair> mKeyData;
// Only touched on the main thread.
nsRefPtr<nsDOMEventListenerWrapper> mOnErrorListener;
};
END_INDEXEDDB_NAMESPACE

View File

@ -60,14 +60,6 @@ namespace {
const PRUint32 kDefaultDatabaseTimeoutSeconds = 30;
inline
nsISupports*
isupports_cast(IDBDatabase* aClassPtr)
{
return static_cast<nsISupports*>(
static_cast<IDBRequest::Generator*>(aClassPtr));
}
class SetVersionHelper : public AsyncConnectionHelper
{
public:
@ -206,25 +198,42 @@ ConvertVariantToStringArray(nsIVariant* aVariant,
return NS_OK;
}
inline
already_AddRefed<IDBRequest>
GenerateRequest(IDBDatabase* aDatabase)
{
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
return IDBRequest::Create(static_cast<nsPIDOMEventTarget*>(aDatabase),
aDatabase->ScriptContext(), aDatabase->Owner());
}
} // anonymous namespace
// static
already_AddRefed<IDBDatabase>
IDBDatabase::Create(DatabaseInfo* aDatabaseInfo,
IDBDatabase::Create(nsIScriptContext* aScriptContext,
nsPIDOMWindow* aOwner,
DatabaseInfo* aDatabaseInfo,
LazyIdleThread* aThread,
nsCOMPtr<mozIStorageConnection>& aConnection)
nsCOMPtr<mozIStorageConnection>& aConnection,
const nsACString& aASCIIOrigin)
{
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
NS_ASSERTION(aDatabaseInfo, "Null pointer!");
NS_ASSERTION(aThread, "Null pointer!");
NS_ASSERTION(aConnection, "Null pointer!");
NS_ASSERTION(!aASCIIOrigin.IsEmpty(), "Empty origin!");
nsRefPtr<IDBDatabase> db(new IDBDatabase());
db->mScriptContext = aScriptContext;
db->mOwner = aOwner;
db->mDatabaseId = aDatabaseInfo->id;
db->mName = aDatabaseInfo->name;
db->mDescription = aDatabaseInfo->description;
db->mFilePath = aDatabaseInfo->filePath;
db->mASCIIOrigin = aASCIIOrigin;
aThread->SetWeakIdleObserver(db);
db->mConnectionThread = aThread;
@ -259,6 +268,10 @@ IDBDatabase::~IDBDatabase()
DatabaseInfo::Remove(mDatabaseId);
}
}
if (mListenerManager) {
mListenerManager->Disconnect();
}
}
nsresult
@ -291,15 +304,26 @@ IDBDatabase::CloseConnection()
}
}
NS_IMPL_ADDREF(IDBDatabase)
NS_IMPL_RELEASE(IDBDatabase)
NS_IMPL_CYCLE_COLLECTION_CLASS(IDBDatabase)
NS_INTERFACE_MAP_BEGIN(IDBDatabase)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, IDBRequest::Generator)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(IDBDatabase,
nsDOMEventTargetHelper)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mOnErrorListener)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(IDBDatabase,
nsDOMEventTargetHelper)
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mOnErrorListener)
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(IDBDatabase)
NS_INTERFACE_MAP_ENTRY(nsIIDBDatabase)
NS_INTERFACE_MAP_ENTRY(nsIObserver)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(IDBDatabase)
NS_INTERFACE_MAP_END
NS_INTERFACE_MAP_END_INHERITING(nsDOMEventTargetHelper)
NS_IMPL_ADDREF_INHERITED(IDBDatabase, nsDOMEventTargetHelper)
NS_IMPL_RELEASE_INHERITED(IDBDatabase, nsDOMEventTargetHelper)
DOMCI_DATA(IDBDatabase, IDBDatabase)
@ -397,12 +421,10 @@ IDBDatabase::CreateObjectStore(const nsAString& aName,
}
nsRefPtr<IDBTransaction> transaction =
IDBTransaction::Create(aCx, this, objectStores,
nsIIDBTransaction::READ_WRITE,
IDBTransaction::Create(this, objectStores, nsIIDBTransaction::READ_WRITE,
kDefaultDatabaseTimeoutSeconds);
nsRefPtr<IDBRequest> request =
GenerateWriteRequest(transaction->ScriptContext(), transaction->Owner());
nsRefPtr<IDBRequest> request = GenerateRequest(this);
NS_ENSURE_TRUE(request, NS_ERROR_FAILURE);
nsRefPtr<CreateObjectStoreHelper> helper =
@ -443,13 +465,11 @@ IDBDatabase::RemoveObjectStore(const nsAString& aName,
}
nsRefPtr<IDBTransaction> transaction =
IDBTransaction::Create(aCx, this, storesToOpen,
nsIIDBTransaction::READ_WRITE,
IDBTransaction::Create(this, storesToOpen, nsIIDBTransaction::READ_WRITE,
kDefaultDatabaseTimeoutSeconds);
NS_ENSURE_TRUE(transaction, NS_ERROR_FAILURE);
nsRefPtr<IDBRequest> request =
GenerateWriteRequest(transaction->ScriptContext(), transaction->Owner());
nsRefPtr<IDBRequest> request = GenerateRequest(this);
NS_ENSURE_TRUE(request, NS_ERROR_FAILURE);
nsRefPtr<RemoveObjectStoreHelper> helper =
@ -477,12 +497,11 @@ IDBDatabase::SetVersion(const nsAString& aVersion,
// Lock the whole database
nsTArray<nsString> storesToOpen;
nsRefPtr<IDBTransaction> transaction =
IDBTransaction::Create(aCx, this, storesToOpen, IDBTransaction::FULL_LOCK,
IDBTransaction::Create(this, storesToOpen, IDBTransaction::FULL_LOCK,
kDefaultDatabaseTimeoutSeconds);
NS_ENSURE_TRUE(transaction, NS_ERROR_FAILURE);
nsRefPtr<IDBRequest> request =
GenerateWriteRequest(transaction->ScriptContext(), transaction->Owner());
nsRefPtr<IDBRequest> request = GenerateRequest(this);
NS_ENSURE_TRUE(request, NS_ERROR_FAILURE);
nsRefPtr<SetVersionHelper> helper =
@ -623,7 +642,7 @@ IDBDatabase::Transaction(nsIVariant* aStoreNames,
}
nsRefPtr<IDBTransaction> transaction =
IDBTransaction::Create(aCx, this, storesToOpen, aMode,
IDBTransaction::Create(this, storesToOpen, aMode,
kDefaultDatabaseTimeoutSeconds);
NS_ENSURE_TRUE(transaction, NS_ERROR_FAILURE);
@ -672,7 +691,7 @@ IDBDatabase::ObjectStore(const nsAString& aName,
}
nsRefPtr<IDBTransaction> transaction =
IDBTransaction::Create(aCx, this, storesToOpen, aMode,
IDBTransaction::Create(this, storesToOpen, aMode,
kDefaultDatabaseTimeoutSeconds);
NS_ENSURE_TRUE(transaction, NS_ERROR_FAILURE);

View File

@ -40,69 +40,98 @@
#ifndef mozilla_dom_indexeddb_idbdatabase_h__
#define mozilla_dom_indexeddb_idbdatabase_h__
#include "mozilla/dom/indexedDB/IDBRequest.h"
#include "mozilla/dom/indexedDB/IndexedDatabase.h"
#include "mozilla/dom/indexedDB/LazyIdleThread.h"
#include "mozIStorageConnection.h"
#include "nsIIDBDatabase.h"
#include "nsIObserver.h"
#include "nsCycleCollectionParticipant.h"
#include "nsDOMEventTargetHelper.h"
#include "nsDOMLists.h"
class mozIStorageConnection;
class nsIScriptContext;
class nsPIDOMWindow;
BEGIN_INDEXEDDB_NAMESPACE
class AsyncConnectionHelper;
struct DatabaseInfo;
class IDBTransaction;
class IDBDatabase : public IDBRequest::Generator,
class IDBDatabase : public nsDOMEventTargetHelper,
public nsIIDBDatabase,
public nsIObserver
{
friend class AsyncConnectionHelper;
public:
NS_DECL_ISUPPORTS
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIIDBDATABASE
NS_DECL_NSIOBSERVER
static already_AddRefed<IDBDatabase>
Create(DatabaseInfo* aDatabaseInfo,
LazyIdleThread* aThread,
nsCOMPtr<mozIStorageConnection>& aConnection);
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(IDBDatabase,
nsDOMEventTargetHelper)
nsIThread* ConnectionThread() {
static already_AddRefed<IDBDatabase>
Create(nsIScriptContext* aScriptContext,
nsPIDOMWindow* aOwner,
DatabaseInfo* aDatabaseInfo,
LazyIdleThread* aThread,
nsCOMPtr<mozIStorageConnection>& aConnection,
const nsACString& aASCIIOrigin);
nsIThread* ConnectionThread()
{
return mConnectionThread;
}
void CloseConnection();
PRUint32 Id() {
PRUint32 Id()
{
return mDatabaseId;
}
const nsString& FilePath() {
const nsString& FilePath()
{
return mFilePath;
}
protected:
nsIScriptContext* ScriptContext()
{
NS_ASSERTION(mScriptContext, "This should never be null!");
return mScriptContext;
}
nsPIDOMWindow* Owner()
{
NS_ASSERTION(mOwner, "This should never be null!");
return mOwner;
}
private:
IDBDatabase();
~IDBDatabase();
// Only meant to be called on mStorageThread!
nsresult GetOrCreateConnection(mozIStorageConnection** aConnection);
private:
PRUint32 mDatabaseId;
nsString mName;
nsString mDescription;
nsString mFilePath;
nsCString mASCIIOrigin;
nsRefPtr<LazyIdleThread> mConnectionThread;
// Only touched on mStorageThread! These must be destroyed in the
// FireCloseConnectionRunnable method.
nsCOMPtr<mozIStorageConnection> mConnection;
// Only touched on the main thread.
nsRefPtr<nsDOMEventListenerWrapper> mOnErrorListener;
};
END_INDEXEDDB_NAMESPACE

View File

@ -224,7 +224,7 @@ IDBErrorEvent::Create(IDBRequest* aRequest,
{
nsRefPtr<IDBErrorEvent> event(new IDBErrorEvent());
event->mSource = aRequest->GetGenerator();
event->mSource = aRequest->Source();
event->mCode = aCode;
GetMessageForErrorCode(aCode, event->mMessage);
@ -298,7 +298,7 @@ IDBSuccessEvent::Create(IDBRequest* aRequest,
{
nsRefPtr<IDBSuccessEvent> event(new IDBSuccessEvent());
event->mSource = aRequest->GetGenerator();
event->mSource = aRequest->Source();
event->mResult = aResult;
event->mTransaction = aTransaction;
@ -376,7 +376,7 @@ nsresult
GetSuccessEvent::Init(IDBRequest* aRequest,
IDBTransaction* aTransaction)
{
mSource = aRequest->GetGenerator();
mSource = aRequest->Source();
mTransaction = aTransaction;
nsresult rv = InitEvent(NS_LITERAL_STRING(SUCCESS_EVT_STR), PR_FALSE,

View File

@ -509,7 +509,7 @@ NS_IMPL_ADDREF(IDBFactory)
NS_IMPL_RELEASE(IDBFactory)
NS_INTERFACE_MAP_BEGIN(IDBFactory)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, IDBRequest::Generator)
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_ENTRY(nsIIDBFactory)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(IDBFactory)
NS_INTERFACE_MAP_END
@ -554,7 +554,7 @@ IDBFactory::Open(const nsAString& aName,
}
NS_ENSURE_STATE(innerWindow);
nsRefPtr<IDBRequest> request = GenerateRequest(context, innerWindow);
nsRefPtr<IDBRequest> request = IDBRequest::Create(this, context, innerWindow);
NS_ENSURE_TRUE(request, NS_ERROR_FAILURE);
nsRefPtr<LazyIdleThread> thread(new LazyIdleThread(kDefaultThreadTimeoutMS,
@ -895,11 +895,13 @@ OpenDatabaseHelper::GetSuccessResult(nsIWritableVariant* aResult)
}
}
nsRefPtr<IDBDatabase> db = IDBDatabase::Create(dbInfo, mThread, mConnection);
nsRefPtr<IDBDatabase> db =
IDBDatabase::Create(mRequest->ScriptContext(), mRequest->Owner(), dbInfo,
mThread, mConnection, mASCIIOrigin);
NS_ASSERTION(db, "This can't fail!");
NS_ASSERTION(!mConnection, "Should have swapped out!");
aResult->SetAsISupports(static_cast<IDBRequest::Generator*>(db));
aResult->SetAsISupports(static_cast<nsPIDOMEventTarget*>(db));
return OK;
}

View File

@ -40,15 +40,14 @@
#ifndef mozilla_dom_indexeddb_idbfactory_h__
#define mozilla_dom_indexeddb_idbfactory_h__
#include "mozilla/dom/indexedDB/IDBRequest.h"
#include "mozilla/dom/indexedDB/IndexedDatabase.h"
#include "mozIStorageConnection.h"
#include "nsIIDBFactory.h"
BEGIN_INDEXEDDB_NAMESPACE
class IDBFactory : public IDBRequest::Generator,
public nsIIDBFactory
class IDBFactory : public nsIIDBFactory
{
public:
NS_DECL_ISUPPORTS
@ -62,9 +61,9 @@ public:
already_AddRefed<mozIStorageConnection>
GetConnection(const nsAString& aDatabaseFilePath);
protected:
// Only called by Create().
private:
IDBFactory() { }
~IDBFactory() { }
};
END_INDEXEDDB_NAMESPACE

View File

@ -223,6 +223,16 @@ private:
nsTArray<KeyValuePair> mData;
};
inline
already_AddRefed<IDBRequest>
GenerateRequest(IDBIndex* aIndex)
{
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
IDBDatabase* database = aIndex->ObjectStore()->Transaction()->Database();
return IDBRequest::Create(static_cast<nsPIDOMEventTarget*>(aIndex),
database->ScriptContext(), database->Owner());
}
} // anonymous namespace
// static
@ -234,8 +244,13 @@ IDBIndex::Create(IDBObjectStore* aObjectStore,
NS_ASSERTION(aObjectStore, "Null pointer!");
NS_ASSERTION(aIndexInfo, "Null pointer!");
IDBDatabase* database = aObjectStore->Transaction()->Database();
nsRefPtr<IDBIndex> index = new IDBIndex();
index->mScriptContext = database->ScriptContext();
index->mOwner = database->Owner();
index->mObjectStore = aObjectStore;
index->mId = aIndexInfo->id;
index->mName = aIndexInfo->name;
@ -257,16 +272,34 @@ IDBIndex::IDBIndex()
IDBIndex::~IDBIndex()
{
NS_PRECONDITION(NS_IsMainThread(), "Wrong thread!");
if (mListenerManager) {
mListenerManager->Disconnect();
}
}
NS_IMPL_ADDREF(IDBIndex)
NS_IMPL_RELEASE(IDBIndex)
NS_IMPL_CYCLE_COLLECTION_CLASS(IDBIndex)
NS_INTERFACE_MAP_BEGIN(IDBIndex)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, IDBRequest::Generator)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(IDBIndex,
nsDOMEventTargetHelper)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mObjectStore,
nsPIDOMEventTarget)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mOnErrorListener)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(IDBIndex,
nsDOMEventTargetHelper)
// Don't unlink mObjectStore!
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mOnErrorListener)
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(IDBIndex)
NS_INTERFACE_MAP_ENTRY(nsIIDBIndex)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(IDBIndex)
NS_INTERFACE_MAP_END
NS_INTERFACE_MAP_END_INHERITING(nsDOMEventTargetHelper)
NS_IMPL_ADDREF_INHERITED(IDBIndex, nsDOMEventTargetHelper)
NS_IMPL_RELEASE_INHERITED(IDBIndex, nsDOMEventTargetHelper)
DOMCI_DATA(IDBIndex, IDBIndex)
@ -321,8 +354,7 @@ IDBIndex::Get(nsIVariant* aKey,
IDBTransaction* transaction = mObjectStore->Transaction();
nsRefPtr<IDBRequest> request =
GenerateRequest(transaction->ScriptContext(), transaction->Owner());
nsRefPtr<IDBRequest> request = GenerateRequest(this);
NS_ENSURE_TRUE(request, NS_ERROR_FAILURE);
nsRefPtr<GetHelper> helper =
@ -350,8 +382,7 @@ IDBIndex::GetObject(nsIVariant* aKey,
IDBTransaction* transaction = mObjectStore->Transaction();
nsRefPtr<IDBRequest> request =
GenerateRequest(transaction->ScriptContext(), transaction->Owner());
nsRefPtr<IDBRequest> request = GenerateRequest(this);
NS_ENSURE_TRUE(request, NS_ERROR_FAILURE);
nsRefPtr<GetObjectHelper> helper =
@ -386,8 +417,7 @@ IDBIndex::GetAll(nsIVariant* aKey,
IDBTransaction* transaction = mObjectStore->Transaction();
nsRefPtr<IDBRequest> request =
GenerateRequest(transaction->ScriptContext(), transaction->Owner());
nsRefPtr<IDBRequest> request = GenerateRequest(this);
NS_ENSURE_TRUE(request, NS_ERROR_FAILURE);
nsRefPtr<GetAllHelper> helper =
@ -422,8 +452,7 @@ IDBIndex::GetAllObjects(nsIVariant* aKey,
IDBTransaction* transaction = mObjectStore->Transaction();
nsRefPtr<IDBRequest> request =
GenerateRequest(transaction->ScriptContext(), transaction->Owner());
nsRefPtr<IDBRequest> request = GenerateRequest(this);
NS_ENSURE_TRUE(request, NS_ERROR_FAILURE);
nsRefPtr<GetAllObjectsHelper> helper =
@ -490,8 +519,7 @@ IDBIndex::OpenCursor(nsIIDBKeyRange* aKeyRange,
IDBTransaction* transaction = mObjectStore->Transaction();
nsRefPtr<IDBRequest> request =
GenerateRequest(transaction->ScriptContext(), transaction->Owner());
nsRefPtr<IDBRequest> request = GenerateRequest(this);
NS_ENSURE_TRUE(request, NS_ERROR_FAILURE);
nsRefPtr<OpenCursorHelper> helper =
@ -560,8 +588,7 @@ IDBIndex::OpenObjectCursor(nsIIDBKeyRange* aKeyRange,
IDBTransaction* transaction = mObjectStore->Transaction();
nsRefPtr<IDBRequest> request =
GenerateRequest(transaction->ScriptContext(), transaction->Owner());
nsRefPtr<IDBRequest> request = GenerateRequest(this);
NS_ENSURE_TRUE(request, NS_ERROR_FAILURE);
nsRefPtr<OpenObjectCursorHelper> helper =
@ -1156,7 +1183,7 @@ OpenCursorHelper::GetSuccessResult(nsIWritableVariant* aResult)
IDBCursor::Create(mRequest, mTransaction, mIndex, mDirection, mData);
NS_ENSURE_TRUE(cursor, nsIIDBDatabaseException::UNKNOWN_ERR);
aResult->SetAsISupports(static_cast<IDBRequest::Generator*>(cursor));
aResult->SetAsISupports(static_cast<nsPIDOMEventTarget*>(cursor));
mIndex = nsnull;
@ -1361,7 +1388,7 @@ OpenObjectCursorHelper::GetSuccessResult(nsIWritableVariant* aResult)
IDBCursor::Create(mRequest, mTransaction, mIndex, mDirection, mData);
NS_ENSURE_TRUE(cursor, nsIIDBDatabaseException::UNKNOWN_ERR);
aResult->SetAsISupports(static_cast<IDBRequest::Generator*>(cursor));
aResult->SetAsISupports(static_cast<nsPIDOMEventTarget*>(cursor));
mIndex = nsnull;

View File

@ -40,22 +40,27 @@
#ifndef mozilla_dom_indexeddb_idbindex_h__
#define mozilla_dom_indexeddb_idbindex_h__
#include "mozilla/dom/indexedDB/IDBRequest.h"
#include "mozilla/dom/indexedDB/IndexedDatabase.h"
#include "nsIIDBIndex.h"
#include "nsDOMEventTargetHelper.h"
BEGIN_INDEXEDDB_NAMESPACE
class IDBObjectStore;
struct IndexInfo;
class IDBIndex : public IDBRequest::Generator,
class IDBIndex : public nsDOMEventTargetHelper,
public nsIIDBIndex
{
public:
NS_DECL_ISUPPORTS
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIIDBINDEX
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(IDBIndex,
nsDOMEventTargetHelper)
static already_AddRefed<IDBIndex>
Create(IDBObjectStore* aObjectStore,
const IndexInfo* aIndexInfo);
@ -65,11 +70,10 @@ public:
return mObjectStore;
}
protected:
private:
IDBIndex();
~IDBIndex();
private:
nsRefPtr<IDBObjectStore> mObjectStore;
PRInt64 mId;
@ -77,6 +81,9 @@ private:
nsString mKeyPath;
bool mUnique;
bool mAutoIncrement;
// Only touched on the main thread.
nsRefPtr<nsDOMEventListenerWrapper> mOnErrorListener;
};
END_INDEXEDDB_NAMESPACE

View File

@ -305,12 +305,21 @@ GetKeyFromObject(JSContext* aCx,
return NS_OK;
}
inline
already_AddRefed<IDBRequest>
GenerateRequest(IDBObjectStore* aObjectStore)
{
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
IDBDatabase* database = aObjectStore->Transaction()->Database();
return IDBRequest::Create(static_cast<nsPIDOMEventTarget*>(aObjectStore),
database->ScriptContext(), database->Owner());
}
} // anonymous namespace
// static
already_AddRefed<IDBObjectStore>
IDBObjectStore::Create(IDBDatabase* aDatabase,
IDBTransaction* aTransaction,
IDBObjectStore::Create(IDBTransaction* aTransaction,
const ObjectStoreInfo* aStoreInfo,
PRUint16 aMode)
{
@ -318,7 +327,9 @@ IDBObjectStore::Create(IDBDatabase* aDatabase,
nsRefPtr<IDBObjectStore> objectStore = new IDBObjectStore();
objectStore->mDatabase = aDatabase;
objectStore->mScriptContext = aTransaction->Database()->ScriptContext();
objectStore->mOwner = aTransaction->Database()->Owner();
objectStore->mTransaction = aTransaction;
objectStore->mName = aStoreInfo->name;
objectStore->mId = aStoreInfo->id;
@ -732,6 +743,10 @@ IDBObjectStore::IDBObjectStore()
IDBObjectStore::~IDBObjectStore()
{
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
if (mListenerManager) {
mListenerManager->Disconnect();
}
}
nsresult
@ -789,14 +804,28 @@ IDBObjectStore::GetAddInfo(JSContext* aCx,
return NS_OK;
}
NS_IMPL_ADDREF(IDBObjectStore)
NS_IMPL_RELEASE(IDBObjectStore)
NS_IMPL_CYCLE_COLLECTION_CLASS(IDBObjectStore)
NS_INTERFACE_MAP_BEGIN(IDBObjectStore)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, IDBRequest::Generator)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(IDBObjectStore,
nsDOMEventTargetHelper)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mTransaction,
nsPIDOMEventTarget)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mOnErrorListener)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(IDBObjectStore,
nsDOMEventTargetHelper)
// Don't unlink mTransaction!
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mOnErrorListener)
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(IDBObjectStore)
NS_INTERFACE_MAP_ENTRY(nsIIDBObjectStore)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(IDBObjectStore)
NS_INTERFACE_MAP_END
NS_INTERFACE_MAP_END_INHERITING(nsDOMEventTargetHelper)
NS_IMPL_ADDREF_INHERITED(IDBObjectStore, nsDOMEventTargetHelper)
NS_IMPL_RELEASE_INHERITED(IDBObjectStore, nsDOMEventTargetHelper)
DOMCI_DATA(IDBObjectStore, IDBObjectStore)
@ -856,8 +885,7 @@ IDBObjectStore::Get(nsIVariant* aKey,
return NS_ERROR_ILLEGAL_VALUE;
}
nsRefPtr<IDBRequest> request =
GenerateRequest(mTransaction->ScriptContext(), mTransaction->Owner());
nsRefPtr<IDBRequest> request = GenerateRequest(this);
NS_ENSURE_TRUE(request, NS_ERROR_FAILURE);
nsRefPtr<GetHelper> helper =
@ -907,8 +935,7 @@ IDBObjectStore::GetAll(nsIIDBKeyRange* aKeyRange,
NS_ENSURE_SUCCESS(rv, rv);
}
nsRefPtr<IDBRequest> request =
GenerateRequest(mTransaction->ScriptContext(), mTransaction->Owner());
nsRefPtr<IDBRequest> request = GenerateRequest(this);
NS_ENSURE_TRUE(request, NS_ERROR_FAILURE);
nsRefPtr<GetAllHelper> helper =
@ -963,8 +990,7 @@ IDBObjectStore::Add(const jsval &aValue,
return NS_ERROR_ILLEGAL_VALUE;
}
nsRefPtr<IDBRequest> request =
GenerateWriteRequest(mTransaction->ScriptContext(), mTransaction->Owner());
nsRefPtr<IDBRequest> request = GenerateRequest(this);
NS_ENSURE_TRUE(request, NS_ERROR_FAILURE);
nsRefPtr<AddHelper> helper =
@ -1009,8 +1035,7 @@ IDBObjectStore::Put(const jsval &aValue,
return NS_ERROR_ILLEGAL_VALUE;
}
nsRefPtr<IDBRequest> request =
GenerateWriteRequest(mTransaction->ScriptContext(), mTransaction->Owner());
nsRefPtr<IDBRequest> request = GenerateRequest(this);
NS_ENSURE_TRUE(request, NS_ERROR_FAILURE);
nsRefPtr<AddHelper> helper =
@ -1047,8 +1072,7 @@ IDBObjectStore::Remove(nsIVariant* aKey,
return NS_ERROR_ILLEGAL_VALUE;
}
nsRefPtr<IDBRequest> request =
GenerateWriteRequest(mTransaction->ScriptContext(), mTransaction->Owner());
nsRefPtr<IDBRequest> request = GenerateRequest(this);
NS_ENSURE_TRUE(request, NS_ERROR_FAILURE);
nsRefPtr<RemoveHelper> helper =
@ -1073,8 +1097,7 @@ IDBObjectStore::Clear(nsIIDBRequest** _retval)
return NS_ERROR_OBJECT_IS_IMMUTABLE;
}
nsRefPtr<IDBRequest> request =
GenerateWriteRequest(mTransaction->ScriptContext(), mTransaction->Owner());
nsRefPtr<IDBRequest> request = GenerateRequest(this);
NS_ENSURE_TRUE(request, NS_ERROR_FAILURE);
nsRefPtr<ClearHelper> helper =
@ -1139,8 +1162,7 @@ IDBObjectStore::OpenCursor(nsIIDBKeyRange* aKeyRange,
return NS_ERROR_NOT_IMPLEMENTED;
}
nsRefPtr<IDBRequest> request =
GenerateRequest(mTransaction->ScriptContext(), mTransaction->Owner());
nsRefPtr<IDBRequest> request = GenerateRequest(this);
NS_ENSURE_TRUE(request, NS_ERROR_FAILURE);
nsRefPtr<OpenCursorHelper> helper =
@ -1191,8 +1213,7 @@ IDBObjectStore::CreateIndex(const nsAString& aName,
return NS_ERROR_UNEXPECTED;
}
nsRefPtr<IDBRequest> request =
GenerateWriteRequest(mTransaction->ScriptContext(), mTransaction->Owner());
nsRefPtr<IDBRequest> request = GenerateRequest(this);
NS_ENSURE_TRUE(request, NS_ERROR_FAILURE);
nsRefPtr<CreateIndexHelper> helper =
@ -1271,8 +1292,7 @@ IDBObjectStore::RemoveIndex(const nsAString& aName,
return NS_ERROR_NOT_AVAILABLE;
}
nsRefPtr<IDBRequest> request =
GenerateWriteRequest(mTransaction->ScriptContext(), mTransaction->Owner());
nsRefPtr<IDBRequest> request = GenerateRequest(this);
NS_ENSURE_TRUE(request, NS_ERROR_FAILURE);
nsRefPtr<RemoveIndexHelper> helper =
@ -1860,7 +1880,7 @@ OpenCursorHelper::GetSuccessResult(nsIWritableVariant* aResult)
mObjectStore = nsnull;
aResult->SetAsISupports(static_cast<IDBRequest::Generator*>(cursor));
aResult->SetAsISupports(static_cast<nsPIDOMEventTarget*>(cursor));
return OK;
}

View File

@ -40,13 +40,12 @@
#ifndef mozilla_dom_indexeddb_idbobjectstore_h__
#define mozilla_dom_indexeddb_idbobjectstore_h__
#include "mozilla/dom/indexedDB/IDBRequest.h"
#include "mozilla/dom/indexedDB/IDBDatabase.h"
#include "mozilla/dom/indexedDB/IndexedDatabase.h"
#include "mozilla/dom/indexedDB/IDBTransaction.h"
#include "nsIIDBObjectStore.h"
struct JSContext;
#include "nsDOMEventTargetHelper.h"
BEGIN_INDEXEDDB_NAMESPACE
@ -210,16 +209,18 @@ private:
PRInt64 mInt;
};
class IDBObjectStore : public IDBRequest::Generator,
class IDBObjectStore : public nsDOMEventTargetHelper,
public nsIIDBObjectStore
{
public:
NS_DECL_ISUPPORTS
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIIDBOBJECTSTORE
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(IDBObjectStore,
nsDOMEventTargetHelper)
static already_AddRefed<IDBObjectStore>
Create(IDBDatabase* aDatabase,
IDBTransaction* aTransaction,
Create(IDBTransaction* aTransaction,
const ObjectStoreInfo* aInfo,
PRUint16 aMode);
@ -306,7 +307,6 @@ protected:
nsTArray<IndexUpdateInfo>& aUpdateInfoArray);
private:
nsRefPtr<IDBDatabase> mDatabase;
nsRefPtr<IDBTransaction> mTransaction;
PRInt64 mId;
@ -315,6 +315,9 @@ private:
PRBool mAutoIncrement;
PRUint32 mDatabaseId;
PRUint16 mMode;
// Only touched on the main thread.
nsRefPtr<nsDOMEventListenerWrapper> mOnErrorListener;
};
END_INDEXEDDB_NAMESPACE

View File

@ -54,10 +54,11 @@
USING_INDEXEDDB_NAMESPACE
// static
already_AddRefed<IDBRequest>
IDBRequest::Generator::GenerateRequestInternal(nsIScriptContext* aScriptContext,
nsPIDOMWindow* aOwner,
PRBool aWriteRequest)
IDBRequest::Create(nsISupports* aSource,
nsIScriptContext* aScriptContext,
nsPIDOMWindow* aOwner)
{
if (!aScriptContext || !aOwner) {
NS_ERROR("Null context and owner!");
@ -66,46 +67,13 @@ IDBRequest::Generator::GenerateRequestInternal(nsIScriptContext* aScriptContext,
nsRefPtr<IDBRequest> request(new IDBRequest());
request->mGenerator = this;
request->mWriteRequest = aWriteRequest;
request->mSource = aSource;
request->mScriptContext = aScriptContext;
request->mOwner = aOwner;
if (!mLiveRequests.AppendElement(request)) {
NS_ERROR("Append failed!");
return nsnull;
}
return request.forget();
}
IDBRequest::~IDBRequest()
{
mGenerator->NoteDyingRequest(this);
if (mListenerManager) {
mListenerManager->Disconnect();
}
}
NS_IMETHODIMP
IDBRequest::Abort()
{
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
if (mAborted || mReadyState != nsIIDBRequest::LOADING) {
return NS_OK;
}
if (mWriteRequest) {
return NS_ERROR_NOT_AVAILABLE;
}
mAborted = PR_TRUE;
mReadyState = nsIIDBRequest::DONE;
return NS_OK;
}
NS_IMETHODIMP
IDBRequest::GetReadyState(PRUint16* aReadyState)
{

View File

@ -44,7 +44,6 @@
#include "mozilla/dom/indexedDB/IndexedDatabase.h"
#include "nsIIDBRequest.h"
#include "nsIVariant.h"
#include "nsDOMEventTargetHelper.h"
#include "nsCycleCollectionParticipant.h"
@ -54,87 +53,62 @@ class nsPIDOMWindow;
BEGIN_INDEXEDDB_NAMESPACE
class AsyncConnectionHelper;
class IDBFactory;
class IDBDatabase;
class IDBRequest : public nsDOMEventTargetHelper,
public nsIIDBRequest
{
friend class AsyncConnectionHelper;
public:
class Generator : public nsISupports
{
protected:
friend class IDBRequest;
Generator() { }
virtual ~Generator() {
NS_ASSERTION(mLiveRequests.IsEmpty(), "Huh?!");
}
already_AddRefed<IDBRequest>
GenerateRequest(nsIScriptContext* aScriptContext,
nsPIDOMWindow* aOwner) {
return GenerateRequestInternal(aScriptContext, aOwner, PR_FALSE);
}
already_AddRefed<IDBRequest>
GenerateWriteRequest(nsIScriptContext* aScriptContext,
nsPIDOMWindow* aOwner) {
return GenerateRequestInternal(aScriptContext, aOwner, PR_TRUE);
}
void NoteDyingRequest(IDBRequest* aRequest) {
NS_ASSERTION(mLiveRequests.Contains(aRequest), "Unknown request!");
mLiveRequests.RemoveElement(aRequest);
}
private:
already_AddRefed<IDBRequest>
GenerateRequestInternal(nsIScriptContext* aScriptContext,
nsPIDOMWindow* aOwner,
PRBool aWriteRequest);
// XXXbent Assuming infallible nsTArray here, make sure it lands!
nsAutoTArray<IDBRequest*, 1> mLiveRequests;
};
friend class IDBRequestGenerator;
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIIDBREQUEST
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(IDBRequest,
nsDOMEventTargetHelper)
already_AddRefed<nsISupports> GetGenerator()
static
already_AddRefed<IDBRequest> Create(nsISupports* aSource,
nsIScriptContext* aScriptContext,
nsPIDOMWindow* aOwner);
already_AddRefed<nsISupports> Source()
{
nsCOMPtr<nsISupports> generator(mGenerator);
return generator.forget();
nsCOMPtr<nsISupports> source(mSource);
return source.forget();
}
private:
// Only called by IDBRequestGenerator::Generate().
IDBRequest()
: mReadyState(nsIIDBRequest::INITIAL),
mAborted(PR_FALSE),
mWriteRequest(PR_FALSE)
{ }
void SetDone()
{
NS_ASSERTION(mReadyState != nsIIDBRequest::DONE, "Already set!");
mReadyState = nsIIDBRequest::DONE;
}
nsRefPtr<Generator> mGenerator;
nsIScriptContext* ScriptContext()
{
NS_ASSERTION(mScriptContext, "This should never be null!");
return mScriptContext;
}
nsPIDOMWindow* Owner()
{
NS_ASSERTION(mOwner, "This should never be null!");
return mOwner;
}
protected:
// Called by Release().
~IDBRequest();
IDBRequest()
: mReadyState(nsIIDBRequest::LOADING)
{ }
~IDBRequest()
{
if (mListenerManager) {
mListenerManager->Disconnect();
}
}
nsCOMPtr<nsISupports> mSource;
nsRefPtr<nsDOMEventListenerWrapper> mOnSuccessListener;
nsRefPtr<nsDOMEventListenerWrapper> mOnErrorListener;
PRUint16 mReadyState;
PRPackedBool mAborted;
PRPackedBool mWriteRequest;
};
END_INDEXEDDB_NAMESPACE

View File

@ -75,8 +75,7 @@ DoomCachedStatements(const nsACString& aQuery,
// static
already_AddRefed<IDBTransaction>
IDBTransaction::Create(JSContext* aCx,
IDBDatabase* aDatabase,
IDBTransaction::Create(IDBDatabase* aDatabase,
nsTArray<nsString>& aObjectStoreNames,
PRUint16 aMode,
PRUint32 aTimeout)
@ -85,6 +84,9 @@ IDBTransaction::Create(JSContext* aCx,
nsRefPtr<IDBTransaction> transaction = new IDBTransaction();
transaction->mScriptContext = aDatabase->ScriptContext();
transaction->mOwner = aDatabase->Owner();
transaction->mDatabase = aDatabase;
transaction->mMode = aMode;
transaction->mTimeout = aTimeout;
@ -99,21 +101,6 @@ IDBTransaction::Create(JSContext* aCx,
return nsnull;
}
nsIScriptContext* context = GetScriptContextFromJSContext(aCx);
if (context) {
transaction->mScriptContext = context;
nsCOMPtr<nsPIDOMWindow> window =
do_QueryInterface(context->GetGlobalObject());
if (window) {
transaction->mOwner = window->GetCurrentInnerWindow();
}
}
if (!transaction->mOwner) {
NS_ERROR("Couldn't get script context and owner!");
return nsnull;
}
return transaction.forget();
}
@ -551,16 +538,21 @@ NS_IMPL_CYCLE_COLLECTION_CLASS(IDBTransaction)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(IDBTransaction,
nsDOMEventTargetHelper)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mDatabase,
nsPIDOMEventTarget)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mOnCompleteListener)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mOnAbortListener)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mOnTimeoutListener)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mOnErrorListener)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(IDBTransaction,
nsDOMEventTargetHelper)
// Don't unlink mDatabase!
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mOnCompleteListener)
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mOnAbortListener)
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mOnTimeoutListener)
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mOnErrorListener)
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(IDBTransaction)
@ -666,7 +658,7 @@ IDBTransaction::ObjectStore(const nsAString& aName,
}
nsRefPtr<IDBObjectStore> objectStore =
IDBObjectStore::Create(mDatabase, this, info, mMode);
IDBObjectStore::Create(this, info, mMode);
NS_ENSURE_TRUE(objectStore, NS_ERROR_FAILURE);
objectStore.forget(_retval);
@ -739,6 +731,14 @@ IDBTransaction::SetOntimeout(nsIDOMEventListener* aOntimeout)
mOnTimeoutListener, aOntimeout);
}
CommitHelper::CommitHelper(IDBTransaction* aTransaction)
: mTransaction(aTransaction),
mAborted(!!aTransaction->mAborted),
mHasInitialSavepoint(!!aTransaction->mHasInitialSavepoint)
{
mConnection.swap(aTransaction->mConnection);
}
NS_IMPL_THREADSAFE_ISUPPORTS1(CommitHelper, nsIRunnable)
NS_IMETHODIMP

View File

@ -40,7 +40,7 @@
#ifndef mozilla_dom_indexeddb_idbtransaction_h__
#define mozilla_dom_indexeddb_idbtransaction_h__
#include "mozilla/dom/indexedDB/IDBRequest.h"
#include "mozilla/dom/indexedDB/IndexedDatabase.h"
#include "mozilla/dom/indexedDB/IDBDatabase.h"
#include "nsIIDBTransaction.h"
@ -53,9 +53,8 @@
#include "nsHashKeys.h"
#include "nsInterfaceHashtable.h"
class nsIScriptContext;
class mozIStorageStatement;
class nsIThread;
class nsPIDOMWindow;
BEGIN_INDEXEDDB_NAMESPACE
@ -65,7 +64,6 @@ struct ObjectStoreInfo;
class TransactionThreadPool;
class IDBTransaction : public nsDOMEventTargetHelper,
public IDBRequest::Generator,
public nsIIDBTransaction
{
friend class AsyncConnectionHelper;
@ -80,8 +78,7 @@ public:
nsDOMEventTargetHelper)
static already_AddRefed<IDBTransaction>
Create(JSContext* aCx,
IDBDatabase* aDatabase,
Create(IDBDatabase* aDatabase,
nsTArray<nsString>& aObjectStoreNames,
PRUint16 aMode,
PRUint32 aTimeout);
@ -147,14 +144,10 @@ public:
enum { FULL_LOCK = nsIIDBTransaction::SNAPSHOT_READ + 1 };
nsIScriptContext* ScriptContext()
IDBDatabase* Database()
{
return mScriptContext;
}
nsPIDOMWindow* Owner()
{
return mOwner;
NS_ASSERTION(mDatabase, "This should never be null!");
return mDatabase;
}
private:
@ -177,6 +170,7 @@ private:
nsRefPtr<nsDOMEventListenerWrapper> mOnCompleteListener;
nsRefPtr<nsDOMEventListenerWrapper> mOnAbortListener;
nsRefPtr<nsDOMEventListenerWrapper> mOnTimeoutListener;
nsRefPtr<nsDOMEventListenerWrapper> mOnErrorListener;
nsInterfaceHashtable<nsCStringHashKey, mozIStorageStatement>
mCachedStatements;
@ -197,13 +191,7 @@ public:
NS_DECL_ISUPPORTS
NS_DECL_NSIRUNNABLE
CommitHelper(IDBTransaction* aTransaction)
: mTransaction(aTransaction),
mAborted(!!aTransaction->mAborted),
mHasInitialSavepoint(!!aTransaction->mHasInitialSavepoint)
{
mConnection.swap(aTransaction->mConnection);
}
CommitHelper(IDBTransaction* aTransaction);
template<class T>
bool AddDoomedObject(nsCOMPtr<T>& aCOMPtr)

View File

@ -47,13 +47,9 @@ interface nsIDOMEventListener;
* http://dev.w3.org/2006/webapi/WebSimpleDB/#idl-def-IDBRequest for more
* information.
*/
[scriptable, uuid(2cff021d-e80e-48a7-bb45-00172df02c1c)]
[scriptable, uuid(162f308f-a3eb-447c-95ee-d96bf3f78c64)]
interface nsIIDBRequest : nsISupports
{
void
abort();
const unsigned short INITIAL = 0;
const unsigned short LOADING = 1;
const unsigned short DONE = 2;
readonly attribute unsigned short readyState;

View File

@ -53,14 +53,6 @@
request = objectStore.add({}, key);
is(request.readyState, LOADING, "Correct readyState");
try {
request.abort();
ok(false, "Can't abort a writing request");
}
catch (e) {
ok(true, "Can't abort a writing request");
}
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
event = yield;
@ -68,20 +60,6 @@
is(request.readyState, DONE, "Correct readyState");
is(event.result, key, "Correct key");
request = objectStore.get(key);
request.onerror = function(event) {
ok(true, "reading request was aborted");
is(request.readyState, DONE, "Correct readyState");
testGenerator.next();
};
request.onsuccess = unexpectedSuccessHandler;
is(request.readyState, LOADING, "Correct readyState");
request.abort();
is(request.readyState, DONE, "Correct readyState");
yield;
request = objectStore.get(key);
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;