Issue #1693 - Use scoped enums for IDBTransaction.

Based on a patch from Mozilla bug 1598164.
Needed due to identifier collision between NSS and IDBTransaction.

Co-authored by: Simon Giesecke <simon.giesecke@gmail.com>
Co-authored by: Matt A. Tobin <email@mattatobin.com>
This commit is contained in:
Job Bautista 2023-03-03 20:07:55 +08:00 committed by roytam1
commit c920f32df3
25 changed files with 175 additions and 182 deletions

View file

@ -110,7 +110,7 @@ public:
MOZ_ASSERT(mLoggingInfo.nextVersionChangeTransactionSerialNumber() >
INT64_MIN);
if (aMode == IDBTransaction::VERSION_CHANGE) {
if (aMode == IDBTransaction::Mode::VersionChange) {
return mLoggingInfo.nextVersionChangeTransactionSerialNumber()--;
}

View file

@ -9005,7 +9005,7 @@ public:
MOZ_ASSERT(mLoggingInfo.nextVersionChangeTransactionSerialNumber() >
INT64_MIN);
if (aMode == IDBTransaction::VERSION_CHANGE) {
if (aMode == IDBTransaction::Mode::VersionChange) {
return mLoggingInfo.nextVersionChangeTransactionSerialNumber()--;
}
@ -11330,11 +11330,11 @@ AutoSavepoint::~AutoSavepoint()
if (mConnection) {
mConnection->AssertIsOnConnectionThread();
MOZ_ASSERT(mDEBUGTransaction);
MOZ_ASSERT(mDEBUGTransaction->GetMode() == IDBTransaction::READ_WRITE ||
MOZ_ASSERT(mDEBUGTransaction->GetMode() == IDBTransaction::Mode::ReadWrite ||
mDEBUGTransaction->GetMode() ==
IDBTransaction::READ_WRITE_FLUSH ||
mDEBUGTransaction->GetMode() == IDBTransaction::CLEANUP ||
mDEBUGTransaction->GetMode() == IDBTransaction::VERSION_CHANGE);
IDBTransaction::Mode::ReadWriteFlush ||
mDEBUGTransaction->GetMode() == IDBTransaction::Mode::Cleanup ||
mDEBUGTransaction->GetMode() == IDBTransaction::Mode::VersionChange);
if (NS_FAILED(mConnection->RollbackSavepoint())) {
NS_WARNING("Failed to rollback savepoint!");
@ -11347,10 +11347,10 @@ DatabaseConnection::
AutoSavepoint::Start(const TransactionBase* aTransaction)
{
MOZ_ASSERT(aTransaction);
MOZ_ASSERT(aTransaction->GetMode() == IDBTransaction::READ_WRITE ||
aTransaction->GetMode() == IDBTransaction::READ_WRITE_FLUSH ||
aTransaction->GetMode() == IDBTransaction::CLEANUP ||
aTransaction->GetMode() == IDBTransaction::VERSION_CHANGE);
MOZ_ASSERT(aTransaction->GetMode() == IDBTransaction::Mode::ReadWrite ||
aTransaction->GetMode() == IDBTransaction::Mode::ReadWriteFlush ||
aTransaction->GetMode() == IDBTransaction::Mode::Cleanup ||
aTransaction->GetMode() == IDBTransaction::Mode::VersionChange);
DatabaseConnection* connection = aTransaction->GetDatabase()->GetConnection();
MOZ_ASSERT(connection);
@ -14478,19 +14478,19 @@ Database::AllocPBackgroundIDBTransactionParent(
return nullptr;
}
if (NS_WARN_IF(aMode != IDBTransaction::READ_ONLY &&
aMode != IDBTransaction::READ_WRITE &&
aMode != IDBTransaction::READ_WRITE_FLUSH &&
aMode != IDBTransaction::CLEANUP)) {
if (NS_WARN_IF(aMode != IDBTransaction::Mode::ReadOnly &&
aMode != IDBTransaction::Mode::ReadWrite &&
aMode != IDBTransaction::Mode::ReadWriteFlush &&
aMode != IDBTransaction::Mode::Cleanup)) {
ASSERT_UNLESS_FUZZING();
return nullptr;
}
// If this is a readwrite transaction to a chrome database make sure the child
// has write access.
if (NS_WARN_IF((aMode == IDBTransaction::READ_WRITE ||
aMode == IDBTransaction::READ_WRITE_FLUSH ||
aMode == IDBTransaction::CLEANUP) &&
if (NS_WARN_IF((aMode == IDBTransaction::Mode::ReadWrite ||
aMode == IDBTransaction::Mode::ReadWriteFlush ||
aMode == IDBTransaction::Mode::Cleanup) &&
mPrincipalInfo.type() == PrincipalInfo::TSystemPrincipalInfo &&
!mChromeWriteAccessAllowed)) {
return nullptr;
@ -14553,10 +14553,10 @@ Database::RecvPBackgroundIDBTransactionConstructor(
AssertIsOnBackgroundThread();
MOZ_ASSERT(aActor);
MOZ_ASSERT(!aObjectStoreNames.IsEmpty());
MOZ_ASSERT(aMode == IDBTransaction::READ_ONLY ||
aMode == IDBTransaction::READ_WRITE ||
aMode == IDBTransaction::READ_WRITE_FLUSH ||
aMode == IDBTransaction::CLEANUP);
MOZ_ASSERT(aMode == IDBTransaction::Mode::ReadOnly ||
aMode == IDBTransaction::Mode::ReadWrite ||
aMode == IDBTransaction::Mode::ReadWriteFlush ||
aMode == IDBTransaction::Mode::Cleanup);
MOZ_ASSERT(!mClosed);
if (IsInvalidated()) {
@ -14578,7 +14578,7 @@ Database::RecvPBackgroundIDBTransactionConstructor(
mMetadata->mDatabaseId,
transaction->LoggingSerialNumber(),
aObjectStoreNames,
aMode != IDBTransaction::READ_ONLY);
aMode != IDBTransaction::Mode::ReadOnly);
transaction->SetActive(transactionId);
@ -14715,14 +14715,14 @@ StartTransactionOp::DoDatabaseWork(DatabaseConnection* aConnection)
Transaction()->SetActiveOnConnectionThread();
if (Transaction()->GetMode() == IDBTransaction::CLEANUP) {
if (Transaction()->GetMode() == IDBTransaction::Mode::Cleanup) {
nsresult rv = aConnection->DisableQuotaChecks();
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
}
if (Transaction()->GetMode() != IDBTransaction::READ_ONLY) {
if (Transaction()->GetMode() != IDBTransaction::Mode::ReadOnly) {
nsresult rv = aConnection->BeginWriteTransaction();
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
@ -15032,10 +15032,10 @@ TransactionBase::VerifyRequestParams(const RequestParams& aParams) const
}
case RequestParams::TObjectStoreDeleteParams: {
if (NS_WARN_IF(mMode != IDBTransaction::READ_WRITE &&
mMode != IDBTransaction::READ_WRITE_FLUSH &&
mMode != IDBTransaction::CLEANUP &&
mMode != IDBTransaction::VERSION_CHANGE)) {
if (NS_WARN_IF(mMode != IDBTransaction::Mode::ReadWrite &&
mMode != IDBTransaction::Mode::ReadWriteFlush &&
mMode != IDBTransaction::Mode::Cleanup &&
mMode != IDBTransaction::Mode::VersionChange)) {
ASSERT_UNLESS_FUZZING();
return false;
}
@ -15056,10 +15056,10 @@ TransactionBase::VerifyRequestParams(const RequestParams& aParams) const
}
case RequestParams::TObjectStoreClearParams: {
if (NS_WARN_IF(mMode != IDBTransaction::READ_WRITE &&
mMode != IDBTransaction::READ_WRITE_FLUSH &&
mMode != IDBTransaction::CLEANUP &&
mMode != IDBTransaction::VERSION_CHANGE)) {
if (NS_WARN_IF(mMode != IDBTransaction::Mode::ReadWrite &&
mMode != IDBTransaction::Mode::ReadWriteFlush &&
mMode != IDBTransaction::Mode::Cleanup &&
mMode != IDBTransaction::Mode::VersionChange)) {
ASSERT_UNLESS_FUZZING();
return false;
}
@ -15243,9 +15243,9 @@ TransactionBase::VerifyRequestParams(const ObjectStoreAddPutParams& aParams)
{
AssertIsOnBackgroundThread();
if (NS_WARN_IF(mMode != IDBTransaction::READ_WRITE &&
mMode != IDBTransaction::READ_WRITE_FLUSH &&
mMode != IDBTransaction::VERSION_CHANGE)) {
if (NS_WARN_IF(mMode != IDBTransaction::Mode::ReadWrite &&
mMode != IDBTransaction::Mode::ReadWriteFlush &&
mMode != IDBTransaction::Mode::VersionChange)) {
ASSERT_UNLESS_FUZZING();
return false;
}
@ -15864,7 +15864,7 @@ NormalTransaction::DeallocPBackgroundIDBCursorParent(
VersionChangeTransaction::VersionChangeTransaction(
OpenDatabaseOp* aOpenDatabaseOp)
: TransactionBase(aOpenDatabaseOp->mDatabase,
IDBTransaction::VERSION_CHANGE)
IDBTransaction::Mode::VersionChange)
, mOpenDatabaseOp(aOpenDatabaseOp)
, mActorWasAlive(false)
{
@ -22234,7 +22234,7 @@ OpenDatabaseOp::DispatchToWorkThread()
MOZ_ASSERT(mState == State::WaitingForTransactionsToComplete);
MOZ_ASSERT(mVersionChangeTransaction);
MOZ_ASSERT(mVersionChangeTransaction->GetMode() ==
IDBTransaction::VERSION_CHANGE);
IDBTransaction::Mode::VersionChange);
MOZ_ASSERT(mMaybeBlockedDatabases.IsEmpty());
if (NS_WARN_IF(QuotaClient::IsShuttingDownOnBackgroundThread()) ||
@ -23739,10 +23739,10 @@ CommitOp::WriteAutoIncrementCounts()
{
MOZ_ASSERT(mTransaction);
mTransaction->AssertIsOnConnectionThread();
MOZ_ASSERT(mTransaction->GetMode() == IDBTransaction::READ_WRITE ||
mTransaction->GetMode() == IDBTransaction::READ_WRITE_FLUSH ||
mTransaction->GetMode() == IDBTransaction::CLEANUP ||
mTransaction->GetMode() == IDBTransaction::VERSION_CHANGE);
MOZ_ASSERT(mTransaction->GetMode() == IDBTransaction::Mode::ReadWrite ||
mTransaction->GetMode() == IDBTransaction::Mode::ReadWriteFlush ||
mTransaction->GetMode() == IDBTransaction::Mode::Cleanup ||
mTransaction->GetMode() == IDBTransaction::Mode::VersionChange);
const nsTArray<RefPtr<FullObjectStoreMetadata>>& metadataArray =
mTransaction->mModifiedAutoIncrementObjectStoreMetadataArray;
@ -23807,10 +23807,10 @@ CommitOp::CommitOrRollbackAutoIncrementCounts()
{
MOZ_ASSERT(mTransaction);
mTransaction->AssertIsOnConnectionThread();
MOZ_ASSERT(mTransaction->GetMode() == IDBTransaction::READ_WRITE ||
mTransaction->GetMode() == IDBTransaction::READ_WRITE_FLUSH ||
mTransaction->GetMode() == IDBTransaction::CLEANUP ||
mTransaction->GetMode() == IDBTransaction::VERSION_CHANGE);
MOZ_ASSERT(mTransaction->GetMode() == IDBTransaction::Mode::ReadWrite ||
mTransaction->GetMode() == IDBTransaction::Mode::ReadWriteFlush ||
mTransaction->GetMode() == IDBTransaction::Mode::Cleanup ||
mTransaction->GetMode() == IDBTransaction::Mode::VersionChange);
nsTArray<RefPtr<FullObjectStoreMetadata>>& metadataArray =
mTransaction->mModifiedAutoIncrementObjectStoreMetadataArray;
@ -23841,7 +23841,7 @@ CommitOp::AssertForeignKeyConsistency(DatabaseConnection* aConnection)
MOZ_ASSERT(aConnection);
MOZ_ASSERT(mTransaction);
mTransaction->AssertIsOnConnectionThread();
MOZ_ASSERT(mTransaction->GetMode() != IDBTransaction::READ_ONLY);
MOZ_ASSERT(mTransaction->GetMode() != IDBTransaction::Mode::ReadOnly);
DatabaseConnection::CachedStatement pragmaStmt;
MOZ_ALWAYS_SUCCEEDS(
@ -23891,7 +23891,7 @@ CommitOp::Run()
mTransaction->LoggingSerialNumber(),
mLoggingSerialNumber);
if (mTransaction->GetMode() != IDBTransaction::READ_ONLY &&
if (mTransaction->GetMode() != IDBTransaction::Mode::ReadOnly &&
mTransaction->mHasBeenActiveOnConnectionThread) {
Database* database = mTransaction->GetDatabase();
MOZ_ASSERT(database);
@ -23920,7 +23920,7 @@ CommitOp::Run()
NS_WARNING_ASSERTION(NS_SUCCEEDED(mResultCode), "Commit failed!");
if (NS_SUCCEEDED(mResultCode) &&
mTransaction->GetMode() == IDBTransaction::READ_WRITE_FLUSH) {
mTransaction->GetMode() == IDBTransaction::Mode::ReadWriteFlush) {
mResultCode = connection->Checkpoint();
}
@ -23943,7 +23943,7 @@ CommitOp::Run()
connection->FinishWriteTransaction();
if (mTransaction->GetMode() == IDBTransaction::CLEANUP) {
if (mTransaction->GetMode() == IDBTransaction::Mode::Cleanup) {
connection->DoIdleProcessing(/* aNeedsCheckpoint */ true);
connection->EnableQuotaChecks();
@ -25789,7 +25789,7 @@ NormalTransactionOp::ObjectStoreHasIndexes(NormalTransactionOp* aOp,
MOZ_ASSERT(aHasIndexes);
bool hasIndexes;
if (aOp->Transaction()->GetMode() == IDBTransaction::VERSION_CHANGE &&
if (aOp->Transaction()->GetMode() == IDBTransaction::Mode::VersionChange &&
aMayHaveIndexes) {
// If this is a version change transaction then mObjectStoreMayHaveIndexes
// could be wrong (e.g. if a unique index failed to be created due to a

View file

@ -685,7 +685,7 @@ IDBCursor::Update(JSContext* aCx, JS::Handle<JS::Value> aValue,
return nullptr;
}
if (mTransaction->GetMode() == IDBTransaction::CLEANUP ||
if (mTransaction->GetMode() == IDBTransaction::Mode::Cleanup ||
IsSourceDeleted() ||
!mHaveValue ||
mType == Type_ObjectStoreKey ||

View file

@ -425,7 +425,7 @@ IDBDatabase::CreateObjectStore(
IDBTransaction* transaction = IDBTransaction::GetCurrent();
if (!transaction ||
transaction->Database() != this ||
transaction->GetMode() != IDBTransaction::VERSION_CHANGE) {
transaction->GetMode() != IDBTransaction::Mode::VersionChange) {
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR);
return nullptr;
}
@ -503,7 +503,7 @@ IDBDatabase::DeleteObjectStore(const nsAString& aName, ErrorResult& aRv)
IDBTransaction* transaction = IDBTransaction::GetCurrent();
if (!transaction ||
transaction->Database() != this ||
transaction->GetMode() != IDBTransaction::VERSION_CHANGE) {
transaction->GetMode() != IDBTransaction::Mode::VersionChange) {
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR);
return;
}
@ -666,21 +666,21 @@ IDBDatabase::Transaction(JSContext* aCx,
IDBTransaction::Mode mode;
switch (aMode) {
case IDBTransactionMode::Readonly:
mode = IDBTransaction::READ_ONLY;
mode = IDBTransaction::Mode::ReadOnly;
break;
case IDBTransactionMode::Readwrite:
if (mQuotaExceeded) {
mode = IDBTransaction::CLEANUP;
mode = IDBTransaction::Mode::Cleanup;
mQuotaExceeded = false;
} else {
mode = IDBTransaction::READ_WRITE;
mode = IDBTransaction::Mode::ReadWrite;
}
break;
case IDBTransactionMode::Readwriteflush:
mode = IDBTransaction::READ_WRITE_FLUSH;
mode = IDBTransaction::Mode::ReadWriteFlush;
break;
case IDBTransactionMode::Cleanup:
mode = IDBTransaction::CLEANUP;
mode = IDBTransaction::Mode::Cleanup;
mQuotaExceeded = false;
break;
case IDBTransactionMode::Versionchange:
@ -715,7 +715,7 @@ IDBDatabase::Transaction(JSContext* aCx,
transaction->SetBackgroundActor(actor);
if (mode == IDBTransaction::CLEANUP) {
if (mode == IDBTransaction::Mode::Cleanup) {
ExpireFileActors(/* aExpireAll */ true);
}
@ -859,14 +859,14 @@ IDBDatabase::AbortTransactions(bool aShouldWarn)
if (aShouldWarn) {
switch (transaction->GetMode()) {
// We ignore transactions that could not have written any data.
case IDBTransaction::READ_ONLY:
case IDBTransaction::Mode::ReadOnly:
break;
// We warn for any transactions that could have written data.
case IDBTransaction::READ_WRITE:
case IDBTransaction::READ_WRITE_FLUSH:
case IDBTransaction::CLEANUP:
case IDBTransaction::VERSION_CHANGE:
case IDBTransaction::Mode::ReadWrite:
case IDBTransaction::Mode::ReadWriteFlush:
case IDBTransaction::Mode::Cleanup:
case IDBTransaction::Mode::VersionChange:
transactionsThatNeedWarning.AppendElement(transaction);
break;

View file

@ -158,7 +158,7 @@ IDBIndex::SetName(const nsAString& aName, ErrorResult& aRv)
IDBTransaction* transaction = mObjectStore->Transaction();
if (transaction->GetMode() != IDBTransaction::VERSION_CHANGE ||
if (transaction->GetMode() != IDBTransaction::Mode::VersionChange ||
mDeletedMetadata) {
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
return;

View file

@ -1407,7 +1407,7 @@ IDBObjectStore::AddOrPut(JSContext* aCx,
MOZ_ASSERT(aCx);
MOZ_ASSERT_IF(aFromCursor, aOverwrite);
if (mTransaction->GetMode() == IDBTransaction::CLEANUP ||
if (mTransaction->GetMode() == IDBTransaction::Mode::Cleanup ||
mDeletedSpec) {
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR);
return nullptr;
@ -1991,7 +1991,7 @@ IDBObjectStore::CreateIndex(const nsAString& aName,
{
AssertIsOnOwningThread();
if (mTransaction->GetMode() != IDBTransaction::VERSION_CHANGE ||
if (mTransaction->GetMode() != IDBTransaction::Mode::VersionChange ||
mDeletedSpec) {
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR);
return nullptr;
@ -2101,7 +2101,7 @@ IDBObjectStore::DeleteIndex(const nsAString& aName, ErrorResult& aRv)
{
AssertIsOnOwningThread();
if (mTransaction->GetMode() != IDBTransaction::VERSION_CHANGE ||
if (mTransaction->GetMode() != IDBTransaction::Mode::VersionChange ||
mDeletedSpec) {
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR);
return;
@ -2424,7 +2424,7 @@ IDBObjectStore::SetName(const nsAString& aName, ErrorResult& aRv)
{
AssertIsOnOwningThread();
if (mTransaction->GetMode() != IDBTransaction::VERSION_CHANGE ||
if (mTransaction->GetMode() != IDBTransaction::Mode::VersionChange ||
mDeletedSpec) {
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
return;

View file

@ -82,7 +82,7 @@ IDBTransaction::IDBTransaction(IDBDatabase* aDatabase,
, mPendingRequestCount(0)
, mLineNo(0)
, mColumn(0)
, mReadyState(IDBTransaction::INITIAL)
, mReadyState(IDBTransaction::ReadyState::Initial)
, mMode(aMode)
, mCreating(false)
, mRegistered(false)
@ -134,10 +134,10 @@ IDBTransaction::~IDBTransaction()
MOZ_ASSERT(!mPendingRequestCount);
MOZ_ASSERT(!mCreating);
MOZ_ASSERT(mSentCommitOrAbort);
MOZ_ASSERT_IF(mMode == VERSION_CHANGE &&
MOZ_ASSERT_IF(mMode == Mode::VersionChange &&
mBackgroundActor.mVersionChangeBackgroundActor,
mFiredCompleteOrAbort);
MOZ_ASSERT_IF(mMode != VERSION_CHANGE &&
MOZ_ASSERT_IF(mMode != Mode::VersionChange &&
mBackgroundActor.mNormalBackgroundActor,
mFiredCompleteOrAbort);
@ -148,7 +148,7 @@ IDBTransaction::~IDBTransaction()
#endif
}
if (mMode == VERSION_CHANGE) {
if (mMode == Mode::VersionChange) {
if (auto* actor = mBackgroundActor.mVersionChangeBackgroundActor) {
actor->SendDeleteMeInternal(/* aFailedConstructor */ false);
@ -184,7 +184,7 @@ IDBTransaction::CreateVersionChange(
RefPtr<IDBTransaction> transaction =
new IDBTransaction(aDatabase,
emptyObjectStoreNames,
VERSION_CHANGE);
Mode::VersionChange);
aOpenRequest->GetCallerLocation(transaction->mFilename,
&transaction->mLineNo, &transaction->mColumn);
@ -213,10 +213,10 @@ IDBTransaction::Create(JSContext* aCx, IDBDatabase* aDatabase,
MOZ_ASSERT(aDatabase);
aDatabase->AssertIsOnOwningThread();
MOZ_ASSERT(!aObjectStoreNames.IsEmpty());
MOZ_ASSERT(aMode == READ_ONLY ||
aMode == READ_WRITE ||
aMode == READ_WRITE_FLUSH ||
aMode == CLEANUP);
MOZ_ASSERT(aMode == Mode::ReadOnly ||
aMode == Mode::ReadWrite ||
aMode == Mode::ReadWriteFlush ||
aMode == Mode::Cleanup);
RefPtr<IDBTransaction> transaction =
new IDBTransaction(aDatabase, aObjectStoreNames, aMode);
@ -281,7 +281,7 @@ IDBTransaction::SetBackgroundActor(indexedDB::BackgroundTransactionChild* aBackg
AssertIsOnOwningThread();
MOZ_ASSERT(aBackgroundActor);
MOZ_ASSERT(!mBackgroundActor.mNormalBackgroundActor);
MOZ_ASSERT(mMode != VERSION_CHANGE);
MOZ_ASSERT(mMode != Mode::VersionChange);
mBackgroundActor.mNormalBackgroundActor = aBackgroundActor;
}
@ -295,7 +295,7 @@ IDBTransaction::StartRequest(IDBRequest* aRequest, const RequestParams& aParams)
BackgroundRequestChild* actor = new BackgroundRequestChild(aRequest);
if (mMode == VERSION_CHANGE) {
if (mMode == Mode::VersionChange) {
MOZ_ASSERT(mBackgroundActor.mVersionChangeBackgroundActor);
mBackgroundActor.mVersionChangeBackgroundActor->
@ -321,7 +321,7 @@ IDBTransaction::OpenCursor(BackgroundCursorChild* aBackgroundActor,
MOZ_ASSERT(aBackgroundActor);
MOZ_ASSERT(aParams.type() != OpenCursorParams::T__None);
if (mMode == VERSION_CHANGE) {
if (mMode == Mode::VersionChange) {
MOZ_ASSERT(mBackgroundActor.mVersionChangeBackgroundActor);
mBackgroundActor.mVersionChangeBackgroundActor->
@ -361,8 +361,8 @@ IDBTransaction::OnNewRequest()
AssertIsOnOwningThread();
if (!mPendingRequestCount) {
MOZ_ASSERT(INITIAL == mReadyState);
mReadyState = LOADING;
MOZ_ASSERT(ReadyState::Initial == mReadyState);
mReadyState = ReadyState::Loading;
}
++mPendingRequestCount;
@ -377,7 +377,7 @@ IDBTransaction::OnRequestFinished(bool aActorDestroyedNormally)
--mPendingRequestCount;
if (!mPendingRequestCount) {
mReadyState = COMMITTING;
mReadyState = ReadyState::Committing;
if (aActorDestroyedNormally) {
if (NS_SUCCEEDED(mAbortCode)) {
@ -421,7 +421,7 @@ IDBTransaction::SendCommit()
LoggingSerialNumber(),
requestSerialNumber);
if (mMode == VERSION_CHANGE) {
if (mMode == Mode::VersionChange) {
MOZ_ASSERT(mBackgroundActor.mVersionChangeBackgroundActor);
mBackgroundActor.mVersionChangeBackgroundActor->SendCommit();
} else {
@ -454,7 +454,7 @@ IDBTransaction::SendAbort(nsresult aResultCode)
requestSerialNumber,
aResultCode);
if (mMode == VERSION_CHANGE) {
if (mMode == Mode::VersionChange) {
MOZ_ASSERT(mBackgroundActor.mVersionChangeBackgroundActor);
mBackgroundActor.mVersionChangeBackgroundActor->SendAbort(aResultCode);
} else {
@ -473,7 +473,7 @@ IDBTransaction::IsOpen() const
AssertIsOnOwningThread();
// If we haven't started anything then we're open.
if (mReadyState == IDBTransaction::INITIAL) {
if (mReadyState == IDBTransaction::ReadyState::Initial) {
return true;
}
@ -482,7 +482,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 == IDBTransaction::LOADING &&
if (mReadyState == IDBTransaction::ReadyState::Loading &&
(mCreating || GetCurrent() == this)) {
return true;
}
@ -508,7 +508,7 @@ IDBTransaction::CreateObjectStore(const ObjectStoreSpec& aSpec)
{
AssertIsOnOwningThread();
MOZ_ASSERT(aSpec.metadata().id());
MOZ_ASSERT(VERSION_CHANGE == mMode);
MOZ_ASSERT(Mode::VersionChange == mMode);
MOZ_ASSERT(mBackgroundActor.mVersionChangeBackgroundActor);
MOZ_ASSERT(IsOpen());
@ -540,7 +540,7 @@ IDBTransaction::DeleteObjectStore(int64_t aObjectStoreId)
{
AssertIsOnOwningThread();
MOZ_ASSERT(aObjectStoreId);
MOZ_ASSERT(VERSION_CHANGE == mMode);
MOZ_ASSERT(Mode::VersionChange == mMode);
MOZ_ASSERT(mBackgroundActor.mVersionChangeBackgroundActor);
MOZ_ASSERT(IsOpen());
@ -571,7 +571,7 @@ IDBTransaction::RenameObjectStore(int64_t aObjectStoreId,
{
AssertIsOnOwningThread();
MOZ_ASSERT(aObjectStoreId);
MOZ_ASSERT(VERSION_CHANGE == mMode);
MOZ_ASSERT(Mode::VersionChange == mMode);
MOZ_ASSERT(mBackgroundActor.mVersionChangeBackgroundActor);
MOZ_ASSERT(IsOpen());
@ -586,7 +586,7 @@ IDBTransaction::CreateIndex(IDBObjectStore* aObjectStore,
AssertIsOnOwningThread();
MOZ_ASSERT(aObjectStore);
MOZ_ASSERT(aMetadata.id());
MOZ_ASSERT(VERSION_CHANGE == mMode);
MOZ_ASSERT(Mode::VersionChange == mMode);
MOZ_ASSERT(mBackgroundActor.mVersionChangeBackgroundActor);
MOZ_ASSERT(IsOpen());
@ -601,7 +601,7 @@ IDBTransaction::DeleteIndex(IDBObjectStore* aObjectStore,
AssertIsOnOwningThread();
MOZ_ASSERT(aObjectStore);
MOZ_ASSERT(aIndexId);
MOZ_ASSERT(VERSION_CHANGE == mMode);
MOZ_ASSERT(Mode::VersionChange == mMode);
MOZ_ASSERT(mBackgroundActor.mVersionChangeBackgroundActor);
MOZ_ASSERT(IsOpen());
@ -617,7 +617,7 @@ IDBTransaction::RenameIndex(IDBObjectStore* aObjectStore,
AssertIsOnOwningThread();
MOZ_ASSERT(aObjectStore);
MOZ_ASSERT(aIndexId);
MOZ_ASSERT(VERSION_CHANGE == mMode);
MOZ_ASSERT(Mode::VersionChange == mMode);
MOZ_ASSERT(mBackgroundActor.mVersionChangeBackgroundActor);
MOZ_ASSERT(IsOpen());
@ -637,12 +637,12 @@ IDBTransaction::AbortInternal(nsresult aAbortCode,
RefPtr<DOMError> error = aError;
const bool isVersionChange = mMode == VERSION_CHANGE;
const bool isVersionChange = mMode == Mode::VersionChange;
const bool isInvalidated = mDatabase->IsInvalidated();
bool needToSendAbort = mReadyState == INITIAL;
bool needToSendAbort = mReadyState == ReadyState::Initial;
mAbortCode = aAbortCode;
mReadyState = DONE;
mReadyState = ReadyState::Done;
mError = error.forget();
if (isVersionChange) {
@ -775,7 +775,7 @@ IDBTransaction::FireCompleteOrAbortEvents(nsresult aResult)
AssertIsOnOwningThread();
MOZ_ASSERT(!mFiredCompleteOrAbort);
mReadyState = DONE;
mReadyState = ReadyState::Done;
#ifdef DEBUG
mFiredCompleteOrAbort = true;
@ -834,7 +834,7 @@ int64_t
IDBTransaction::NextObjectStoreId()
{
AssertIsOnOwningThread();
MOZ_ASSERT(VERSION_CHANGE == mMode);
MOZ_ASSERT(Mode::VersionChange == mMode);
return mNextObjectStoreId++;
}
@ -843,7 +843,7 @@ int64_t
IDBTransaction::NextIndexId()
{
AssertIsOnOwningThread();
MOZ_ASSERT(VERSION_CHANGE == mMode);
MOZ_ASSERT(Mode::VersionChange == mMode);
return mNextIndexId++;
}
@ -862,22 +862,22 @@ IDBTransaction::GetMode(ErrorResult& aRv) const
AssertIsOnOwningThread();
switch (mMode) {
case READ_ONLY:
case Mode::ReadOnly:
return IDBTransactionMode::Readonly;
case READ_WRITE:
case Mode::ReadWrite:
return IDBTransactionMode::Readwrite;
case READ_WRITE_FLUSH:
case Mode::ReadWriteFlush:
return IDBTransactionMode::Readwriteflush;
case CLEANUP:
case Mode::Cleanup:
return IDBTransactionMode::Cleanup;
case VERSION_CHANGE:
case Mode::VersionChange:
return IDBTransactionMode::Versionchange;
case MODE_INVALID:
case Mode::Invalid:
default:
MOZ_CRASH("Bad mode!");
}
@ -896,7 +896,7 @@ IDBTransaction::ObjectStoreNames() const
{
AssertIsOnOwningThread();
if (mMode == IDBTransaction::VERSION_CHANGE) {
if (mMode == IDBTransaction::Mode::VersionChange) {
return mDatabase->ObjectStoreNames();
}
@ -917,7 +917,7 @@ IDBTransaction::ObjectStore(const nsAString& aName, ErrorResult& aRv)
const ObjectStoreSpec* spec = nullptr;
if (IDBTransaction::VERSION_CHANGE == mMode ||
if (IDBTransaction::Mode::VersionChange == mMode ||
mObjectStoreNames.Contains(aName)) {
const nsTArray<ObjectStoreSpec>& objectStores =
mDatabase->Spec()->objectStores();
@ -1014,8 +1014,8 @@ IDBTransaction::Run()
mCreating = false;
// Maybe commit if there were no requests generated.
if (mReadyState == IDBTransaction::INITIAL) {
mReadyState = DONE;
if (mReadyState == IDBTransaction::ReadyState::Initial) {
mReadyState = ReadyState::Done;
SendCommit();
}

View file

@ -53,25 +53,18 @@ class IDBTransaction final
friend class WorkerHolder;
public:
enum Mode
{
READ_ONLY = 0,
READ_WRITE,
READ_WRITE_FLUSH,
CLEANUP,
VERSION_CHANGE,
enum struct Mode {
ReadOnly = 0,
ReadWrite,
ReadWriteFlush,
Cleanup,
VersionChange,
// Only needed for IPC serialization helper, should never be used in code.
MODE_INVALID
Invalid
};
enum ReadyState
{
INITIAL = 0,
LOADING,
COMMITTING,
DONE
};
enum struct ReadyState { Initial = 0, Loading, Inactive, Committing, Done };
private:
RefPtr<IDBDatabase> mDatabase;
@ -81,7 +74,7 @@ private:
nsTArray<RefPtr<IDBObjectStore>> mDeletedObjectStores;
nsAutoPtr<WorkerHolder> mWorkerHolder;
// Tagged with mMode. If mMode is VERSION_CHANGE then mBackgroundActor will be
// Tagged with mMode. If mMode is Mode::VersionChange then mBackgroundActor will be
// a BackgroundVersionChangeTransactionChild. Otherwise it will be a
// BackgroundTransactionChild.
union {
@ -91,7 +84,7 @@ private:
const int64_t mLoggingSerialNumber;
// Only used for VERSION_CHANGE transactions.
// Only used for Mode::VersionChange transactions.
int64_t mNextObjectStoreId;
int64_t mNextIndexId;
@ -146,7 +139,7 @@ public:
{
AssertIsOnOwningThread();
if (mMode == VERSION_CHANGE) {
if (mMode == Mode::VersionChange) {
mBackgroundActor.mVersionChangeBackgroundActor = nullptr;
} else {
mBackgroundActor.mNormalBackgroundActor = nullptr;
@ -171,7 +164,7 @@ public:
{
AssertIsOnOwningThread();
return mReadyState == COMMITTING || mReadyState == DONE;
return mReadyState == ReadyState::Committing || mReadyState == ReadyState::Done;
}
bool
@ -179,17 +172,17 @@ public:
{
AssertIsOnOwningThread();
return mReadyState == DONE;
return mReadyState == ReadyState::Done;
}
bool
IsWriteAllowed() const
{
AssertIsOnOwningThread();
return mMode == READ_WRITE ||
mMode == READ_WRITE_FLUSH ||
mMode == CLEANUP ||
mMode == VERSION_CHANGE;
return mMode == Mode::ReadWrite ||
mMode == Mode::ReadWriteFlush ||
mMode == Mode::Cleanup ||
mMode == Mode::VersionChange;
}
bool
@ -295,11 +288,11 @@ public:
void
FireCompleteOrAbortEvents(nsresult aResult);
// Only for VERSION_CHANGE transactions.
// Only for Mode::VersionChange transactions.
int64_t
NextObjectStoreId();
// Only for VERSION_CHANGE transactions.
// Only for Mode::VersionChange transactions.
int64_t
NextIndexId();

View file

@ -119,19 +119,19 @@ public:
Append(kCommaSpace);
switch (aTransaction->GetMode()) {
case IDBTransaction::READ_ONLY:
case IDBTransaction::Mode::ReadOnly:
AppendLiteral("\"readonly\"");
break;
case IDBTransaction::READ_WRITE:
case IDBTransaction::Mode::ReadWrite:
AppendLiteral("\"readwrite\"");
break;
case IDBTransaction::READ_WRITE_FLUSH:
case IDBTransaction::Mode::ReadWriteFlush:
AppendLiteral("\"readwriteflush\"");
break;
case IDBTransaction::CLEANUP:
case IDBTransaction::Mode::Cleanup:
AppendLiteral("\"cleanup\"");
break;
case IDBTransaction::VERSION_CHANGE:
case IDBTransaction::Mode::VersionChange:
AppendLiteral("\"versionchange\"");
break;
default:

View file

@ -86,8 +86,8 @@ template <>
struct ParamTraits<mozilla::dom::IDBTransaction::Mode> :
public ContiguousEnumSerializer<
mozilla::dom::IDBTransaction::Mode,
mozilla::dom::IDBTransaction::READ_ONLY,
mozilla::dom::IDBTransaction::MODE_INVALID>
mozilla::dom::IDBTransaction::Mode::ReadOnly,
mozilla::dom::IDBTransaction::Mode::Invalid>
{ };
} // namespace IPC

View file

@ -12,7 +12,7 @@
<script type="text/javascript;version=1.7">
function testSteps()
{
const READ_WRITE = "readwrite";
const Mode::ReadWrite = "readwrite";
const databaseInfo = [
{ name: window.location.pathname + "1" },
@ -72,7 +72,7 @@
for (let i = 1; i < databases.length; i++) {
let db = databases[i];
let objectStore = db.transaction([objectStoreName], READ_WRITE)
let objectStore = db.transaction([objectStoreName], Mode::ReadWrite)
.objectStore(objectStoreName);
request = objectStore.add(refResult, 2);

View file

@ -12,7 +12,7 @@
<script type="text/javascript;version=1.7">
function testSteps()
{
const READ_WRITE = "readwrite";
const Mode::ReadWrite = "readwrite";
const name = window.location.pathname;
@ -48,7 +48,7 @@
is(event.type, "success", "Got correct event type");
let trans = db.transaction([objectStoreName], READ_WRITE);
let trans = db.transaction([objectStoreName], Mode::ReadWrite);
trans.objectStore(objectStoreName).delete(fileData1.key);
trans.oncomplete = grabEventAndContinueHandler;
event = yield undefined;
@ -80,7 +80,7 @@
let db = event.target.result;
db.onerror = errorHandler;
trans = db.transaction([objectStoreName], READ_WRITE);
trans = db.transaction([objectStoreName], Mode::ReadWrite);
objectStore = trans.objectStore(objectStoreName);
request = objectStore.get(fileData2.key);
@ -100,7 +100,7 @@
is(getFileDBRefCount(name, 2), 0, "Correct db ref count");
trans = db.transaction([objectStoreName], READ_WRITE);
trans = db.transaction([objectStoreName], Mode::ReadWrite);
objectStore = trans.objectStore(objectStoreName);
objectStore.delete(fileData3.key);

View file

@ -12,7 +12,7 @@
<script type="text/javascript;version=1.7">
function testSteps()
{
const READ_WRITE = "readwrite";
const Mode::ReadWrite = "readwrite";
const name = window.location.pathname;
@ -67,7 +67,7 @@
is(usage, startUsage + fileData1.obj.file.size + fileData2.obj.file.size,
"Correct file usage");
let trans = db.transaction([objectStoreName], READ_WRITE);
let trans = db.transaction([objectStoreName], Mode::ReadWrite);
trans.objectStore(objectStoreName).delete(fileData1.key);
trans.oncomplete = grabEventAndContinueHandler;
event = yield undefined;

View file

@ -21,7 +21,7 @@
*/
function testSteps()
{
const READ_WRITE = "readwrite";
const Mode::ReadWrite = "readwrite";
const databaseInfo = [
{ name: window.location.pathname + "1", source: true },
@ -106,7 +106,7 @@
for (let i = 1; i < databases.length; i++) {
let db = databases[i];
let trans = db.transaction([objectStoreName], READ_WRITE);
let trans = db.transaction([objectStoreName], Mode::ReadWrite);
let objectStore = trans.objectStore(objectStoreName);
request = objectStore.add(fileBackedFile, 2);

View file

@ -12,7 +12,7 @@
<script type="text/javascript;version=1.7">
function testSteps()
{
const READ_WRITE = "readwrite";
const Mode::ReadWrite = "readwrite";
const name = window.location.pathname;

View file

@ -12,7 +12,7 @@
<script type="text/javascript;version=1.7">
function testSteps()
{
const READ_WRITE = "readwrite";
const Mode::ReadWrite = "readwrite";
const name = window.location.pathname;
@ -42,7 +42,7 @@
is(event.type, "success", "Got correct event type");
let objectStore = db.transaction([objectStoreName], READ_WRITE)
let objectStore = db.transaction([objectStoreName], Mode::ReadWrite)
.objectStore(objectStoreName);
request = objectStore.add(blobData.blob, blobData.key);
request.onsuccess = grabEventAndContinueHandler;
@ -65,7 +65,7 @@
verifyBlob(event.target.result, blobData.blob, 1);
yield undefined;
objectStore = db.transaction([objectStoreName], READ_WRITE)
objectStore = db.transaction([objectStoreName], Mode::ReadWrite)
.objectStore(objectStoreName);
request = objectStore.add(fileData.file, fileData.key);
request.onsuccess = grabEventAndContinueHandler;

View file

@ -12,7 +12,7 @@
<script type="text/javascript;version=1.7">
function testSteps()
{
const READ_WRITE = "readwrite";
const Mode::ReadWrite = "readwrite";
const name = window.location.pathname;
@ -40,7 +40,7 @@
is(event.type, "success", "Got correct event type");
let trans = db.transaction([objectStoreName], READ_WRITE);
let trans = db.transaction([objectStoreName], Mode::ReadWrite);
objectStore = trans.objectStore(objectStoreName);
objectStore.delete(fileData.key);
@ -50,7 +50,7 @@
is(getFileDBRefCount(name, 1), 0, "Correct db ref count");
trans = db.transaction([objectStoreName], READ_WRITE);
trans = db.transaction([objectStoreName], Mode::ReadWrite);
objectStore = trans.objectStore(objectStoreName);
request = objectStore.add(fileData.file, fileData.key);
@ -81,7 +81,7 @@
let db = event.target.result;
db.onerror = errorHandler;
let trans = db.transaction([objectStoreName], READ_WRITE);
let trans = db.transaction([objectStoreName], Mode::ReadWrite);
objectStore = trans.objectStore(objectStoreName);
request = objectStore.get(fileData.key);
@ -98,7 +98,7 @@
is(getFileDBRefCount(name, 1), 0, "Correct db ref count");
trans = db.transaction([objectStoreName], READ_WRITE);
trans = db.transaction([objectStoreName], Mode::ReadWrite);
objectStore = trans.objectStore(objectStoreName);
request = objectStore.add(result, fileData.key);

View file

@ -12,7 +12,7 @@
<script type="text/javascript;version=1.7">
function testSteps()
{
const READ_WRITE = "readwrite";
const Mode::ReadWrite = "readwrite";
const name = window.location.pathname;
@ -38,7 +38,7 @@
is(event.type, "success", "Got correct event type");
let trans = db.transaction([objectStoreName], READ_WRITE);
let trans = db.transaction([objectStoreName], Mode::ReadWrite);
objectStore = trans.objectStore(objectStoreName);
request = objectStore.add(fileData.file, fileData.key);
@ -58,7 +58,7 @@
is(getFileDBRefCount(name, 1), 0, "Correct db ref count");
trans = db.transaction([objectStoreName], READ_WRITE);
trans = db.transaction([objectStoreName], Mode::ReadWrite);
objectStore = trans.objectStore(objectStoreName);
request = objectStore.add(result, fileData.key);

View file

@ -12,7 +12,7 @@
<script type="text/javascript;version=1.7">
function testSteps()
{
const READ_WRITE = "readwrite";
const Mode::ReadWrite = "readwrite";
const name = window.location.pathname;
@ -67,7 +67,7 @@
for (let i = 1; i < objectStoreInfo.length; i++) {
let info = objectStoreInfo[i];
let objectStore = db.transaction([info.name], READ_WRITE)
let objectStore = db.transaction([info.name], Mode::ReadWrite)
.objectStore(info.name);
request = objectStore.add(refResult, 2);

View file

@ -12,7 +12,7 @@
<script type="text/javascript;version=1.7">
function testSteps()
{
const READ_WRITE = "readwrite";
const Mode::ReadWrite = "readwrite";
const name = window.location.pathname;
@ -38,7 +38,7 @@
is(event.type, "success", "Got correct event type");
let trans = db.transaction([objectStoreName], READ_WRITE);
let trans = db.transaction([objectStoreName], Mode::ReadWrite);
objectStore = trans.objectStore(objectStoreName);
request = objectStore.add(fileData.file, fileData.key);

View file

@ -12,7 +12,7 @@
<script type="text/javascript;version=1.7">
function testSteps()
{
const READ_WRITE = "readwrite";
const Mode::ReadWrite = "readwrite";
const databaseInfo = [
{ name: window.location.pathname + "1" },
@ -56,7 +56,7 @@
is(mutableFile.name, "random.bin", "Correct name");
is(mutableFile.type, "binary/random", "Correct type");
let trans = db1.transaction([objectStoreName], READ_WRITE);
let trans = db1.transaction([objectStoreName], Mode::ReadWrite);
let objectStore = trans.objectStore(objectStoreName);
request = objectStore.add(mutableFile, 42);
@ -74,7 +74,7 @@
let db2 = databases[1];
trans = db2.transaction([objectStoreName], READ_WRITE);
trans = db2.transaction([objectStoreName], Mode::ReadWrite);
objectStore = trans.objectStore(objectStoreName);
try {

View file

@ -12,7 +12,7 @@
<script type="text/javascript;version=1.7">
function testSteps()
{
const READ_WRITE = "readwrite";
const Mode::ReadWrite = "readwrite";
const name = window.location.pathname;
@ -58,7 +58,7 @@
let file = event.target.result;
let trans = db.transaction([objectStoreName], READ_WRITE);
let trans = db.transaction([objectStoreName], Mode::ReadWrite);
objectStore = trans.objectStore(objectStoreName);
request = objectStore.add(file, 42);

View file

@ -55,10 +55,10 @@ function testSteps()
try {
db.transaction("foo").objectStore("foo").clear();
ok(false, "clear should throw on READ_ONLY transactions");
ok(false, "clear should throw on Mode::ReadOnly transactions");
}
catch (e) {
ok(true, "clear should throw on READ_ONLY transactions");
ok(true, "clear should throw on Mode::ReadOnly transactions");
}
request = db.transaction("foo", "readwriteflush")

View file

@ -28,7 +28,7 @@ function testSteps()
is(db.version, 1, "Database has correct version");
db.onupgradeneeded = function() {
ok(false, "our ongoing VERSION_CHANGE transaction should exclude any others!");
ok(false, "our ongoing Mode::VersionChange transaction should exclude any others!");
}
db.createObjectStore("foo");

View file

@ -258,7 +258,7 @@ function testSteps()
abortEventCount = 0;
let expectedAbortEventCount = 0;
// During INITIAL
// During ReadyState::Initial
transaction = db.transaction("foo");
transaction.abort();
try {
@ -269,7 +269,7 @@ function testSteps()
ok(true, "second abort should throw an error");
}
// During LOADING
// During ReadyState::Loading
transaction = db.transaction("foo");
transaction.objectStore("foo").get(1).onerror = abortErrorHandler;
expectedAbortEventCount++;
@ -282,7 +282,7 @@ function testSteps()
ok(true, "second abort should throw an error");
}
// During LOADING from callback
// During ReadyState::Loading from callback
transaction = db.transaction("foo");
transaction.objectStore("foo").get(1).onsuccess = grabEventAndContinueHandler;
event = yield undefined;
@ -297,7 +297,7 @@ function testSteps()
ok(true, "second abort should throw an error");
}
// During LOADING from error callback
// During ReadyState::Loading from error callback
transaction = db.transaction("foo", "readwrite");
transaction.objectStore("foo").add({}, 1).onerror = function(event) {
event.preventDefault();
@ -327,7 +327,7 @@ function testSteps()
};
yield undefined;
// During COMMITTING
// During ReadyState::Committing
transaction = db.transaction("foo", "readwrite");
transaction.objectStore("foo").put({hello: "world"}, 1).onsuccess = function(event) {
continueToNextStep();