2010-06-23 23:46:08 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2015-05-03 22:32:37 +03:00
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-06-28 20:46:21 +04:00
|
|
|
#include "IDBTransaction.h"
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
#include "BackgroundChildImpl.h"
|
|
|
|
#include "IDBDatabase.h"
|
|
|
|
#include "IDBEvents.h"
|
|
|
|
#include "IDBObjectStore.h"
|
|
|
|
#include "IDBRequest.h"
|
|
|
|
#include "mozilla/ErrorResult.h"
|
2014-09-18 03:36:01 +04:00
|
|
|
#include "mozilla/EventDispatcher.h"
|
2019-03-29 21:05:11 +03:00
|
|
|
#include "mozilla/HoldDropJSObjects.h"
|
2017-08-06 20:47:00 +03:00
|
|
|
#include "mozilla/dom/DOMException.h"
|
2014-09-27 03:21:57 +04:00
|
|
|
#include "mozilla/dom/DOMStringList.h"
|
2018-06-18 23:37:21 +03:00
|
|
|
#include "mozilla/dom/WorkerRef.h"
|
2018-01-31 10:25:30 +03:00
|
|
|
#include "mozilla/dom/WorkerPrivate.h"
|
2014-09-27 03:21:57 +04:00
|
|
|
#include "mozilla/ipc/BackgroundChild.h"
|
2018-06-18 23:37:21 +03:00
|
|
|
#include "mozilla/ScopeExit.h"
|
2010-08-27 00:57:25 +04:00
|
|
|
#include "nsPIDOMWindow.h"
|
2017-06-07 13:36:20 +03:00
|
|
|
#include "nsQueryObject.h"
|
2014-09-27 03:21:57 +04:00
|
|
|
#include "nsServiceManagerUtils.h"
|
|
|
|
#include "nsTHashtable.h"
|
2013-03-16 10:58:50 +04:00
|
|
|
#include "ProfilerHelpers.h"
|
2014-01-28 04:37:05 +04:00
|
|
|
#include "ReportInternalError.h"
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
// Include this last to avoid path problems on Windows.
|
|
|
|
#include "ActorsChild.h"
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2019-11-11 11:24:53 +03:00
|
|
|
namespace {
|
2019-11-11 11:25:05 +03:00
|
|
|
using namespace mozilla::dom::indexedDB;
|
|
|
|
using namespace mozilla::ipc;
|
|
|
|
|
2019-11-11 11:24:53 +03:00
|
|
|
// TODO: Move this to xpcom/ds.
|
|
|
|
template <typename T, typename Range, typename Transformation>
|
|
|
|
nsTHashtable<T> TransformToHashtable(const Range& aRange,
|
|
|
|
const Transformation& aTransformation) {
|
|
|
|
// TODO: Determining the size of the range is not syntactically necessary (and
|
|
|
|
// requires random access iterators if expressed this way). It is a
|
|
|
|
// performance optimization. We could resort to std::distance to support any
|
|
|
|
// iterator category, but this would lead to a double iteration of the range
|
|
|
|
// in case of non-random-access iterators. It is hard to determine in general
|
|
|
|
// if double iteration or reallocation is worse.
|
|
|
|
auto res = nsTHashtable<T>(aRange.cend() - aRange.cbegin());
|
|
|
|
// TOOD: std::transform could be used if nsTHashtable had an insert_iterator,
|
|
|
|
// and this would also allow a more generic version not depending on
|
|
|
|
// nsTHashtable at all.
|
|
|
|
for (const auto& item : aRange) {
|
|
|
|
res.PutEntry(aTransformation(item));
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
2019-11-11 11:25:05 +03:00
|
|
|
|
|
|
|
ThreadLocal* GetIndexedDBThreadLocal() {
|
|
|
|
BackgroundChildImpl::ThreadLocal* const threadLocal =
|
|
|
|
BackgroundChildImpl::GetThreadLocalForCurrentThread();
|
|
|
|
MOZ_ASSERT(threadLocal);
|
|
|
|
|
|
|
|
ThreadLocal* idbThreadLocal = threadLocal->mIndexedDBThreadLocal;
|
|
|
|
MOZ_ASSERT(idbThreadLocal);
|
|
|
|
|
|
|
|
return idbThreadLocal;
|
|
|
|
}
|
2019-11-11 11:24:53 +03:00
|
|
|
} // namespace
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2016-02-17 00:46:08 +03:00
|
|
|
using namespace mozilla::dom::indexedDB;
|
2014-10-16 08:56:52 +04:00
|
|
|
using namespace mozilla::ipc;
|
|
|
|
|
2019-11-11 11:24:32 +03:00
|
|
|
bool IDBTransaction::HasTransactionChild() const {
|
2019-11-27 13:54:57 +03:00
|
|
|
return (mMode == Mode::VersionChange
|
2019-11-11 11:24:32 +03:00
|
|
|
? static_cast<void*>(
|
|
|
|
mBackgroundActor.mVersionChangeBackgroundActor)
|
|
|
|
: mBackgroundActor.mNormalBackgroundActor) != nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Func>
|
|
|
|
auto IDBTransaction::DoWithTransactionChild(const Func& aFunc) const {
|
|
|
|
MOZ_ASSERT(HasTransactionChild());
|
2019-11-27 13:54:57 +03:00
|
|
|
return mMode == Mode::VersionChange
|
2019-11-11 11:24:32 +03:00
|
|
|
? aFunc(*mBackgroundActor.mVersionChangeBackgroundActor)
|
|
|
|
: aFunc(*mBackgroundActor.mNormalBackgroundActor);
|
|
|
|
}
|
|
|
|
|
2019-11-11 11:24:25 +03:00
|
|
|
IDBTransaction::IDBTransaction(IDBDatabase* const aDatabase,
|
2014-09-27 03:21:57 +04:00
|
|
|
const nsTArray<nsString>& aObjectStoreNames,
|
2019-11-11 11:24:25 +03:00
|
|
|
const Mode aMode, nsString aFilename,
|
2019-11-28 18:05:28 +03:00
|
|
|
const uint32_t aLineNo, const uint32_t aColumn,
|
|
|
|
CreatedFromFactoryFunction /*aDummy*/)
|
2019-03-29 21:05:11 +03:00
|
|
|
: DOMEventTargetHelper(aDatabase),
|
2014-09-27 03:21:57 +04:00
|
|
|
mDatabase(aDatabase),
|
|
|
|
mObjectStoreNames(aObjectStoreNames),
|
2019-11-11 11:25:05 +03:00
|
|
|
mLoggingSerialNumber(GetIndexedDBThreadLocal()->NextTransactionSN(aMode)),
|
2014-09-27 03:21:57 +04:00
|
|
|
mNextObjectStoreId(0),
|
|
|
|
mNextIndexId(0),
|
|
|
|
mAbortCode(NS_OK),
|
|
|
|
mPendingRequestCount(0),
|
2019-11-11 11:24:25 +03:00
|
|
|
mFilename(std::move(aFilename)),
|
|
|
|
mLineNo(aLineNo),
|
|
|
|
mColumn(aColumn),
|
2014-09-27 03:21:57 +04:00
|
|
|
mMode(aMode),
|
2020-01-14 16:22:26 +03:00
|
|
|
mCreating(false),
|
2014-12-17 09:26:15 +03:00
|
|
|
mRegistered(false),
|
2019-12-03 18:32:18 +03:00
|
|
|
mNotedActiveTransaction(false) {
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(aDatabase);
|
|
|
|
aDatabase->AssertIsOnOwningThread();
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2019-11-11 11:25:20 +03:00
|
|
|
// This also nulls mBackgroundActor.mVersionChangeBackgroundActor, so this is
|
2019-11-27 13:54:57 +03:00
|
|
|
// valid also for mMode == Mode::VersionChange.
|
2014-09-27 03:21:57 +04:00
|
|
|
mBackgroundActor.mNormalBackgroundActor = nullptr;
|
2011-11-18 19:21:04 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (!aObjectStoreNames.IsEmpty()) {
|
|
|
|
// Make sure the array is properly sorted.
|
2019-11-11 11:24:53 +03:00
|
|
|
MOZ_ASSERT(
|
|
|
|
std::is_sorted(aObjectStoreNames.cbegin(), aObjectStoreNames.cend()));
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
// Make sure there are no duplicates in our objectStore names.
|
2019-11-11 11:24:53 +03:00
|
|
|
MOZ_ASSERT(aObjectStoreNames.cend() ==
|
|
|
|
std::adjacent_find(aObjectStoreNames.cbegin(),
|
|
|
|
aObjectStoreNames.cend()));
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
|
|
|
#endif
|
2019-03-29 21:05:11 +03:00
|
|
|
|
|
|
|
mozilla::HoldJSObjects(this);
|
2011-11-18 19:21:04 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
IDBTransaction::~IDBTransaction() {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(!mPendingRequestCount);
|
2020-01-14 16:22:26 +03:00
|
|
|
MOZ_ASSERT(!mCreating);
|
2017-06-16 14:06:36 +03:00
|
|
|
MOZ_ASSERT(!mNotedActiveTransaction);
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(mSentCommitOrAbort);
|
2019-11-11 11:24:32 +03:00
|
|
|
MOZ_ASSERT_IF(HasTransactionChild(), mFiredCompleteOrAbort);
|
2011-11-18 19:21:04 +04:00
|
|
|
|
2014-12-17 09:26:15 +03:00
|
|
|
if (mRegistered) {
|
|
|
|
mDatabase->UnregisterTransaction(this);
|
|
|
|
#ifdef DEBUG
|
|
|
|
mRegistered = false;
|
|
|
|
#endif
|
|
|
|
}
|
2011-11-18 19:21:04 +04:00
|
|
|
|
2019-11-11 11:24:32 +03:00
|
|
|
if (HasTransactionChild()) {
|
2019-11-27 13:54:57 +03:00
|
|
|
if (mMode == Mode::VersionChange) {
|
2019-11-11 11:24:32 +03:00
|
|
|
mBackgroundActor.mVersionChangeBackgroundActor->SendDeleteMeInternal(
|
|
|
|
/* aFailedConstructor */ false);
|
|
|
|
} else {
|
|
|
|
mBackgroundActor.mNormalBackgroundActor->SendDeleteMeInternal();
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
|
|
|
}
|
2019-11-11 11:24:32 +03:00
|
|
|
MOZ_ASSERT(!HasTransactionChild(),
|
|
|
|
"SendDeleteMeInternal should have cleared!");
|
2019-03-29 21:05:11 +03:00
|
|
|
|
|
|
|
ReleaseWrapper(this);
|
|
|
|
mozilla::DropJSObjects(this);
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
2010-06-23 23:46:08 +04:00
|
|
|
|
|
|
|
// static
|
2019-11-28 18:05:28 +03:00
|
|
|
RefPtr<IDBTransaction> IDBTransaction::CreateVersionChange(
|
2019-11-11 11:24:25 +03:00
|
|
|
IDBDatabase* const aDatabase,
|
|
|
|
BackgroundVersionChangeTransactionChild* const aActor,
|
|
|
|
IDBOpenDBRequest* const aOpenRequest, const int64_t aNextObjectStoreId,
|
|
|
|
const int64_t aNextIndexId) {
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(aDatabase);
|
|
|
|
aDatabase->AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(aActor);
|
2014-11-14 05:20:38 +03:00
|
|
|
MOZ_ASSERT(aOpenRequest);
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(aNextObjectStoreId > 0);
|
|
|
|
MOZ_ASSERT(aNextIndexId > 0);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2019-11-28 18:05:28 +03:00
|
|
|
const nsTArray<nsString> emptyObjectStoreNames;
|
2014-05-30 00:07:35 +04:00
|
|
|
|
2019-11-11 11:24:25 +03:00
|
|
|
nsString filename;
|
|
|
|
uint32_t lineNo, column;
|
|
|
|
aOpenRequest->GetCallerLocation(filename, &lineNo, &column);
|
2019-11-28 18:05:28 +03:00
|
|
|
auto transaction = MakeRefPtr<IDBTransaction>(
|
|
|
|
aDatabase, emptyObjectStoreNames, Mode::VersionChange,
|
|
|
|
std::move(filename), lineNo, column, CreatedFromFactoryFunction{});
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2017-06-16 14:06:36 +03:00
|
|
|
transaction->NoteActiveTransaction();
|
|
|
|
|
2014-12-17 09:26:15 +03:00
|
|
|
transaction->mBackgroundActor.mVersionChangeBackgroundActor = aActor;
|
|
|
|
transaction->mNextObjectStoreId = aNextObjectStoreId;
|
|
|
|
transaction->mNextIndexId = aNextIndexId;
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
aDatabase->RegisterTransaction(transaction);
|
2014-12-17 09:26:15 +03:00
|
|
|
transaction->mRegistered = true;
|
2010-11-19 01:19:19 +03:00
|
|
|
|
2019-11-28 18:05:28 +03:00
|
|
|
return transaction;
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
2019-11-28 18:05:28 +03:00
|
|
|
RefPtr<IDBTransaction> IDBTransaction::Create(
|
2019-11-11 11:24:25 +03:00
|
|
|
JSContext* const aCx, IDBDatabase* const aDatabase,
|
|
|
|
const nsTArray<nsString>& aObjectStoreNames, const Mode aMode) {
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(aDatabase);
|
|
|
|
aDatabase->AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(!aObjectStoreNames.IsEmpty());
|
2019-11-27 13:54:57 +03:00
|
|
|
MOZ_ASSERT(aMode == Mode::ReadOnly || aMode == Mode::ReadWrite ||
|
|
|
|
aMode == Mode::ReadWriteFlush || aMode == Mode::Cleanup);
|
2010-11-19 01:19:19 +03:00
|
|
|
|
2019-11-11 11:24:25 +03:00
|
|
|
nsString filename;
|
|
|
|
uint32_t lineNo, column;
|
|
|
|
IDBRequest::CaptureCaller(aCx, filename, &lineNo, &column);
|
2019-11-28 18:05:28 +03:00
|
|
|
auto transaction = MakeRefPtr<IDBTransaction>(
|
|
|
|
aDatabase, aObjectStoreNames, aMode, std::move(filename), lineNo, column,
|
|
|
|
CreatedFromFactoryFunction{});
|
2010-11-16 00:49:49 +03:00
|
|
|
|
2014-12-17 09:26:15 +03:00
|
|
|
if (!NS_IsMainThread()) {
|
2019-11-11 11:24:25 +03:00
|
|
|
WorkerPrivate* const workerPrivate = GetCurrentThreadWorkerPrivate();
|
2014-12-17 09:26:15 +03:00
|
|
|
MOZ_ASSERT(workerPrivate);
|
|
|
|
|
|
|
|
workerPrivate->AssertIsOnWorkerThread();
|
|
|
|
|
2018-06-18 23:37:21 +03:00
|
|
|
RefPtr<StrongWorkerRef> workerRef = StrongWorkerRef::Create(
|
|
|
|
workerPrivate, "IDBTransaction", [transaction]() {
|
|
|
|
transaction->AssertIsOnOwningThread();
|
2019-11-28 19:00:29 +03:00
|
|
|
if (!transaction->IsCommittingOrFinished()) {
|
2018-06-18 23:37:21 +03:00
|
|
|
IDB_REPORT_INTERNAL_ERR();
|
|
|
|
transaction->AbortInternal(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR,
|
|
|
|
nullptr);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (NS_WARN_IF(!workerRef)) {
|
2017-09-29 09:48:47 +03:00
|
|
|
// Silence the destructor assertion if we never made this object live.
|
|
|
|
#ifdef DEBUG
|
2019-12-03 18:32:18 +03:00
|
|
|
transaction->mSentCommitOrAbort.Flip();
|
2017-09-29 09:48:47 +03:00
|
|
|
#endif
|
2017-09-20 11:53:14 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-06-18 23:37:21 +03:00
|
|
|
transaction->mWorkerRef = std::move(workerRef);
|
2014-12-17 09:26:15 +03:00
|
|
|
}
|
2014-09-27 03:21:57 +04:00
|
|
|
|
2017-09-20 11:53:14 +03:00
|
|
|
nsCOMPtr<nsIRunnable> runnable = do_QueryObject(transaction);
|
2017-11-17 06:01:27 +03:00
|
|
|
nsContentUtils::AddPendingIDBTransaction(runnable.forget());
|
2017-09-20 11:53:14 +03:00
|
|
|
|
2020-01-14 16:22:26 +03:00
|
|
|
transaction->mCreating = true;
|
|
|
|
|
2017-09-20 11:53:14 +03:00
|
|
|
aDatabase->RegisterTransaction(transaction);
|
|
|
|
transaction->mRegistered = true;
|
|
|
|
|
2019-11-28 18:05:28 +03:00
|
|
|
return transaction;
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
// static
|
|
|
|
IDBTransaction* IDBTransaction::GetCurrent() {
|
|
|
|
using namespace mozilla::ipc;
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(BackgroundChild::GetForCurrentThread());
|
2014-09-13 20:12:19 +04:00
|
|
|
|
2019-11-11 11:25:05 +03:00
|
|
|
return GetIndexedDBThreadLocal()->GetCurrentTransaction();
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
|
|
|
|
void IDBTransaction::AssertIsOnOwningThread() const {
|
|
|
|
MOZ_ASSERT(mDatabase);
|
|
|
|
mDatabase->AssertIsOnOwningThread();
|
2012-11-10 07:29:07 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
#endif // DEBUG
|
|
|
|
|
2016-02-17 00:46:08 +03:00
|
|
|
void IDBTransaction::SetBackgroundActor(
|
2019-11-11 11:24:25 +03:00
|
|
|
indexedDB::BackgroundTransactionChild* const aBackgroundActor) {
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(aBackgroundActor);
|
|
|
|
MOZ_ASSERT(!mBackgroundActor.mNormalBackgroundActor);
|
2019-11-27 13:54:57 +03:00
|
|
|
MOZ_ASSERT(mMode != Mode::VersionChange);
|
2014-09-27 03:21:57 +04:00
|
|
|
|
2017-06-16 14:06:36 +03:00
|
|
|
NoteActiveTransaction();
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
mBackgroundActor.mNormalBackgroundActor = aBackgroundActor;
|
2014-09-18 03:36:01 +04:00
|
|
|
}
|
2011-12-17 04:40:47 +04:00
|
|
|
|
2015-03-19 00:20:59 +03:00
|
|
|
BackgroundRequestChild* IDBTransaction::StartRequest(
|
2019-11-11 11:24:25 +03:00
|
|
|
IDBRequest* const aRequest, const RequestParams& aParams) {
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
2015-03-19 00:20:59 +03:00
|
|
|
MOZ_ASSERT(aRequest);
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(aParams.type() != RequestParams::T__None);
|
2011-12-17 04:40:47 +04:00
|
|
|
|
2019-11-11 11:24:25 +03:00
|
|
|
BackgroundRequestChild* const actor = new BackgroundRequestChild(aRequest);
|
2019-11-08 17:28:53 +03:00
|
|
|
|
2019-11-11 11:24:32 +03:00
|
|
|
DoWithTransactionChild([actor, &aParams](auto& transactionChild) {
|
|
|
|
transactionChild.SendPBackgroundIDBRequestConstructor(actor, aParams);
|
|
|
|
});
|
2015-03-19 00:20:59 +03:00
|
|
|
|
2017-02-10 10:13:45 +03:00
|
|
|
MOZ_ASSERT(actor->GetActorEventTarget(),
|
|
|
|
"The event target shall be inherited from its manager actor.");
|
|
|
|
|
2015-03-19 00:20:59 +03:00
|
|
|
// Balanced in BackgroundRequestChild::Recv__delete__().
|
|
|
|
OnNewRequest();
|
|
|
|
|
|
|
|
return actor;
|
2011-12-04 21:39:01 +04:00
|
|
|
}
|
|
|
|
|
2020-01-10 18:23:52 +03:00
|
|
|
void IDBTransaction::OpenCursor(
|
|
|
|
PBackgroundIDBCursorChild* const aBackgroundActor,
|
|
|
|
const OpenCursorParams& aParams) {
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(aBackgroundActor);
|
|
|
|
MOZ_ASSERT(aParams.type() != OpenCursorParams::T__None);
|
2011-10-20 20:10:56 +04:00
|
|
|
|
2019-11-11 11:24:32 +03:00
|
|
|
DoWithTransactionChild([aBackgroundActor, &aParams](auto& actor) {
|
|
|
|
actor.SendPBackgroundIDBCursorConstructor(aBackgroundActor, aParams);
|
|
|
|
});
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2017-02-10 10:13:45 +03:00
|
|
|
MOZ_ASSERT(aBackgroundActor->GetActorEventTarget(),
|
|
|
|
"The event target shall be inherited from its manager actor.");
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
// Balanced in BackgroundCursorChild::RecvResponse().
|
|
|
|
OnNewRequest();
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2019-11-11 11:24:25 +03:00
|
|
|
void IDBTransaction::RefreshSpec(const bool aMayDelete) {
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
2014-01-31 22:53:37 +04:00
|
|
|
|
2019-11-11 11:24:53 +03:00
|
|
|
for (auto& objectStore : mObjectStores) {
|
|
|
|
objectStore->RefreshSpec(aMayDelete);
|
2014-09-13 20:12:19 +04:00
|
|
|
}
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2019-11-11 11:24:53 +03:00
|
|
|
for (auto& objectStore : mDeletedObjectStores) {
|
|
|
|
objectStore->RefreshSpec(false);
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void IDBTransaction::OnNewRequest() {
|
|
|
|
AssertIsOnOwningThread();
|
2010-10-19 21:58:52 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
if (!mPendingRequestCount) {
|
2019-11-28 19:00:29 +03:00
|
|
|
MOZ_ASSERT(ReadyState::Active == mReadyState);
|
2019-12-03 18:32:18 +03:00
|
|
|
mStarted.Flip();
|
2014-01-31 22:53:37 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
++mPendingRequestCount;
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2019-11-11 11:24:25 +03:00
|
|
|
void IDBTransaction::OnRequestFinished(
|
|
|
|
const bool aRequestCompletedSuccessfully) {
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
2020-01-14 16:22:26 +03:00
|
|
|
MOZ_ASSERT(mReadyState == ReadyState::Inactive ||
|
|
|
|
mReadyState == ReadyState::Finished);
|
2019-11-28 19:00:29 +03:00
|
|
|
MOZ_ASSERT_IF(mReadyState == ReadyState::Finished, !NS_SUCCEEDED(mAbortCode));
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(mPendingRequestCount);
|
2014-01-31 22:53:37 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
--mPendingRequestCount;
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2016-05-31 13:08:20 +03:00
|
|
|
if (!mPendingRequestCount) {
|
2019-12-04 15:59:09 +03:00
|
|
|
if (mReadyState == ReadyState::Inactive) {
|
2019-11-28 19:00:29 +03:00
|
|
|
mReadyState = ReadyState::Committing;
|
|
|
|
}
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2019-11-05 17:40:37 +03:00
|
|
|
if (aRequestCompletedSuccessfully) {
|
2015-03-19 00:20:59 +03:00
|
|
|
if (NS_SUCCEEDED(mAbortCode)) {
|
2020-01-14 16:22:26 +03:00
|
|
|
SendCommit();
|
2015-03-19 00:20:59 +03:00
|
|
|
} else {
|
|
|
|
SendAbort(mAbortCode);
|
|
|
|
}
|
2014-09-27 03:21:57 +04:00
|
|
|
} else {
|
2015-03-19 00:20:59 +03:00
|
|
|
// Don't try to send any more messages to the parent if the request actor
|
|
|
|
// was killed.
|
2020-01-14 16:22:26 +03:00
|
|
|
#ifdef DEBUG
|
2019-12-03 18:32:18 +03:00
|
|
|
mSentCommitOrAbort.Flip();
|
2020-01-14 16:22:26 +03:00
|
|
|
#endif
|
2019-09-27 13:11:45 +03:00
|
|
|
IDB_LOG_MARK_CHILD_TRANSACTION(
|
2015-03-19 00:20:59 +03:00
|
|
|
"Request actor was killed, transaction will be aborted",
|
2019-09-27 13:11:45 +03:00
|
|
|
"IDBTransaction abort", LoggingSerialNumber());
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
2014-01-31 22:53:37 +04:00
|
|
|
}
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2020-01-14 16:22:26 +03:00
|
|
|
void IDBTransaction::SendCommit() {
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(NS_SUCCEEDED(mAbortCode));
|
2019-11-28 19:00:29 +03:00
|
|
|
MOZ_ASSERT(IsCommittingOrFinished());
|
2020-01-14 16:22:26 +03:00
|
|
|
MOZ_ASSERT(!mPendingRequestCount);
|
2014-10-16 08:56:52 +04:00
|
|
|
|
|
|
|
// Don't do this in the macro because we always need to increment the serial
|
|
|
|
// number to keep in sync with the parent.
|
|
|
|
const uint64_t requestSerialNumber = IDBRequest::NextSerialNumber();
|
|
|
|
|
2019-09-27 13:11:45 +03:00
|
|
|
IDB_LOG_MARK_CHILD_TRANSACTION_REQUEST(
|
2020-01-14 16:22:26 +03:00
|
|
|
"All requests complete, committing transaction", "IDBTransaction commit",
|
|
|
|
LoggingSerialNumber(), requestSerialNumber);
|
2013-03-16 10:58:50 +04:00
|
|
|
|
2019-11-11 11:24:32 +03:00
|
|
|
DoWithTransactionChild([](auto& actor) { actor.SendCommit(); });
|
2010-09-10 23:12:11 +04:00
|
|
|
|
2020-01-14 16:22:26 +03:00
|
|
|
#ifdef DEBUG
|
2019-12-03 18:32:18 +03:00
|
|
|
mSentCommitOrAbort.Flip();
|
2020-01-14 16:22:26 +03:00
|
|
|
#endif
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2019-11-11 11:24:25 +03:00
|
|
|
void IDBTransaction::SendAbort(const nsresult aResultCode) {
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(NS_FAILED(aResultCode));
|
2019-11-28 19:00:29 +03:00
|
|
|
MOZ_ASSERT(IsCommittingOrFinished());
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2014-10-16 08:56:52 +04:00
|
|
|
// Don't do this in the macro because we always need to increment the serial
|
|
|
|
// number to keep in sync with the parent.
|
|
|
|
const uint64_t requestSerialNumber = IDBRequest::NextSerialNumber();
|
|
|
|
|
2019-09-27 13:11:45 +03:00
|
|
|
IDB_LOG_MARK_CHILD_TRANSACTION_REQUEST(
|
|
|
|
"Aborting transaction with result 0x%x", "IDBTransaction abort (0x%x)",
|
|
|
|
LoggingSerialNumber(), requestSerialNumber, aResultCode);
|
2014-10-16 08:56:52 +04:00
|
|
|
|
2019-11-11 11:24:32 +03:00
|
|
|
DoWithTransactionChild(
|
|
|
|
[aResultCode](auto& actor) { actor.SendAbort(aResultCode); });
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2020-01-14 16:22:26 +03:00
|
|
|
#ifdef DEBUG
|
2019-12-03 18:32:18 +03:00
|
|
|
mSentCommitOrAbort.Flip();
|
2020-01-14 16:22:26 +03:00
|
|
|
#endif
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2017-06-16 14:06:36 +03:00
|
|
|
void IDBTransaction::NoteActiveTransaction() {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(!mNotedActiveTransaction);
|
|
|
|
|
|
|
|
mDatabase->NoteActiveTransaction();
|
|
|
|
mNotedActiveTransaction = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IDBTransaction::MaybeNoteInactiveTransaction() {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
if (mNotedActiveTransaction) {
|
|
|
|
mDatabase->NoteInactiveTransaction();
|
|
|
|
mNotedActiveTransaction = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-28 19:00:29 +03:00
|
|
|
bool IDBTransaction::CanAcceptRequests() const {
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
2010-11-16 00:49:49 +03:00
|
|
|
|
2020-01-14 16:22:26 +03:00
|
|
|
// If we haven't started anything then we can accept requests.
|
|
|
|
// If we've already started then we need to check to see if we still have the
|
|
|
|
// mCreating flag set. If we do (i.e. we haven't returned to the event loop
|
|
|
|
// from the time we were created) then we can accept requests. 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.
|
|
|
|
return mReadyState == ReadyState::Active &&
|
|
|
|
(!mStarted || mCreating || GetCurrent() == this);
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2019-12-04 15:59:09 +03:00
|
|
|
IDBTransaction::AutoRestoreState<IDBTransaction::ReadyState::Inactive,
|
|
|
|
IDBTransaction::ReadyState::Active>
|
|
|
|
IDBTransaction::TemporarilyTransitionToActive() {
|
|
|
|
return AutoRestoreState<ReadyState::Inactive, ReadyState::Active>{*this};
|
|
|
|
}
|
|
|
|
|
|
|
|
IDBTransaction::AutoRestoreState<IDBTransaction::ReadyState::Active,
|
|
|
|
IDBTransaction::ReadyState::Inactive>
|
|
|
|
IDBTransaction::TemporarilyTransitionToInactive() {
|
|
|
|
return AutoRestoreState<ReadyState::Active, ReadyState::Inactive>{*this};
|
|
|
|
}
|
|
|
|
|
2019-11-11 11:24:25 +03:00
|
|
|
void IDBTransaction::GetCallerLocation(nsAString& aFilename,
|
|
|
|
uint32_t* const aLineNo,
|
|
|
|
uint32_t* const aColumn) const {
|
2014-11-14 05:20:38 +03:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(aLineNo);
|
2015-09-02 04:01:02 +03:00
|
|
|
MOZ_ASSERT(aColumn);
|
2014-11-14 05:20:38 +03:00
|
|
|
|
|
|
|
aFilename = mFilename;
|
|
|
|
*aLineNo = mLineNo;
|
2015-09-02 04:01:02 +03:00
|
|
|
*aColumn = mColumn;
|
2014-11-14 05:20:38 +03:00
|
|
|
}
|
|
|
|
|
2019-11-28 18:05:28 +03:00
|
|
|
RefPtr<IDBObjectStore> IDBTransaction::CreateObjectStore(
|
2014-09-27 03:21:57 +04:00
|
|
|
const ObjectStoreSpec& aSpec) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(aSpec.metadata().id());
|
2019-11-27 13:54:57 +03:00
|
|
|
MOZ_ASSERT(Mode::VersionChange == mMode);
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(mBackgroundActor.mVersionChangeBackgroundActor);
|
2019-11-28 19:00:29 +03:00
|
|
|
MOZ_ASSERT(CanAcceptRequests());
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2019-11-08 17:28:53 +03:00
|
|
|
{
|
2019-11-11 11:24:53 +03:00
|
|
|
// TODO: Bind name outside of lambda capture as a workaround for GCC 7 bug
|
|
|
|
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66735.
|
|
|
|
const auto& name = aSpec.metadata().name();
|
|
|
|
// TODO: Use #ifdef and local variable as a workaround for Bug 1583449.
|
|
|
|
const bool objectStoreNameDoesNotYetExist =
|
|
|
|
std::all_of(mObjectStores.cbegin(), mObjectStores.cend(),
|
|
|
|
[&name](const auto& objectStore) {
|
|
|
|
return objectStore->Name() != name;
|
|
|
|
});
|
|
|
|
MOZ_ASSERT(objectStoreNameDoesNotYetExist);
|
2019-11-08 17:28:53 +03:00
|
|
|
}
|
2014-09-27 03:21:57 +04:00
|
|
|
#endif
|
2010-11-11 02:25:40 +03:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ALWAYS_TRUE(
|
|
|
|
mBackgroundActor.mVersionChangeBackgroundActor->SendCreateObjectStore(
|
|
|
|
aSpec.metadata()));
|
2010-11-11 02:25:40 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<IDBObjectStore> objectStore = IDBObjectStore::Create(this, aSpec);
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(objectStore);
|
2010-11-11 02:25:40 +03:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
mObjectStores.AppendElement(objectStore);
|
|
|
|
|
2019-11-28 18:05:28 +03:00
|
|
|
return objectStore;
|
2010-11-11 02:25:40 +03:00
|
|
|
}
|
|
|
|
|
2019-11-11 11:24:25 +03:00
|
|
|
void IDBTransaction::DeleteObjectStore(const int64_t aObjectStoreId) {
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(aObjectStoreId);
|
2019-11-27 13:54:57 +03:00
|
|
|
MOZ_ASSERT(Mode::VersionChange == mMode);
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(mBackgroundActor.mVersionChangeBackgroundActor);
|
2019-11-28 19:00:29 +03:00
|
|
|
MOZ_ASSERT(CanAcceptRequests());
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
MOZ_ALWAYS_TRUE(
|
|
|
|
mBackgroundActor.mVersionChangeBackgroundActor->SendDeleteObjectStore(
|
|
|
|
aObjectStoreId));
|
|
|
|
|
2019-11-11 11:24:53 +03:00
|
|
|
const auto foundIt =
|
|
|
|
std::find_if(mObjectStores.begin(), mObjectStores.end(),
|
|
|
|
[aObjectStoreId](const auto& objectStore) {
|
|
|
|
return objectStore->Id() == aObjectStoreId;
|
|
|
|
});
|
|
|
|
if (foundIt != mObjectStores.end()) {
|
|
|
|
auto& objectStore = *foundIt;
|
|
|
|
objectStore->NoteDeletion();
|
2019-11-08 17:28:53 +03:00
|
|
|
|
2019-11-11 11:24:53 +03:00
|
|
|
RefPtr<IDBObjectStore>* deletedObjectStore =
|
|
|
|
mDeletedObjectStores.AppendElement();
|
|
|
|
deletedObjectStore->swap(objectStore);
|
2014-09-27 03:21:57 +04:00
|
|
|
|
2019-11-11 11:24:53 +03:00
|
|
|
mObjectStores.RemoveElementAt(foundIt);
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
2012-06-03 20:33:52 +04:00
|
|
|
}
|
|
|
|
|
2019-11-11 11:24:25 +03:00
|
|
|
void IDBTransaction::RenameObjectStore(const int64_t aObjectStoreId,
|
2016-03-30 06:04:56 +03:00
|
|
|
const nsAString& aName) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(aObjectStoreId);
|
2019-11-27 13:54:57 +03:00
|
|
|
MOZ_ASSERT(Mode::VersionChange == mMode);
|
2016-03-30 06:04:56 +03:00
|
|
|
MOZ_ASSERT(mBackgroundActor.mVersionChangeBackgroundActor);
|
2019-11-28 19:00:29 +03:00
|
|
|
MOZ_ASSERT(CanAcceptRequests());
|
2016-03-30 06:04:56 +03:00
|
|
|
|
|
|
|
MOZ_ALWAYS_TRUE(
|
|
|
|
mBackgroundActor.mVersionChangeBackgroundActor->SendRenameObjectStore(
|
|
|
|
aObjectStoreId, nsString(aName)));
|
|
|
|
}
|
|
|
|
|
2019-11-11 11:24:25 +03:00
|
|
|
void IDBTransaction::CreateIndex(IDBObjectStore* const aObjectStore,
|
2016-02-17 00:46:08 +03:00
|
|
|
const indexedDB::IndexMetadata& aMetadata) {
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(aObjectStore);
|
|
|
|
MOZ_ASSERT(aMetadata.id());
|
2019-11-27 13:54:57 +03:00
|
|
|
MOZ_ASSERT(Mode::VersionChange == mMode);
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(mBackgroundActor.mVersionChangeBackgroundActor);
|
2019-11-28 19:00:29 +03:00
|
|
|
MOZ_ASSERT(CanAcceptRequests());
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
MOZ_ALWAYS_TRUE(
|
|
|
|
mBackgroundActor.mVersionChangeBackgroundActor->SendCreateIndex(
|
|
|
|
aObjectStore->Id(), aMetadata));
|
2011-12-16 11:34:24 +04:00
|
|
|
}
|
|
|
|
|
2019-11-11 11:24:25 +03:00
|
|
|
void IDBTransaction::DeleteIndex(IDBObjectStore* const aObjectStore,
|
|
|
|
const int64_t aIndexId) {
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(aObjectStore);
|
|
|
|
MOZ_ASSERT(aIndexId);
|
2019-11-27 13:54:57 +03:00
|
|
|
MOZ_ASSERT(Mode::VersionChange == mMode);
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(mBackgroundActor.mVersionChangeBackgroundActor);
|
2019-11-28 19:00:29 +03:00
|
|
|
MOZ_ASSERT(CanAcceptRequests());
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
MOZ_ALWAYS_TRUE(
|
|
|
|
mBackgroundActor.mVersionChangeBackgroundActor->SendDeleteIndex(
|
|
|
|
aObjectStore->Id(), aIndexId));
|
2011-12-16 11:34:24 +04:00
|
|
|
}
|
|
|
|
|
2019-11-11 11:24:25 +03:00
|
|
|
void IDBTransaction::RenameIndex(IDBObjectStore* const aObjectStore,
|
|
|
|
const int64_t aIndexId,
|
2016-03-30 06:04:56 +03:00
|
|
|
const nsAString& aName) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(aObjectStore);
|
|
|
|
MOZ_ASSERT(aIndexId);
|
2019-11-27 13:54:57 +03:00
|
|
|
MOZ_ASSERT(Mode::VersionChange == mMode);
|
2016-03-30 06:04:56 +03:00
|
|
|
MOZ_ASSERT(mBackgroundActor.mVersionChangeBackgroundActor);
|
2019-11-28 19:00:29 +03:00
|
|
|
MOZ_ASSERT(CanAcceptRequests());
|
2016-03-30 06:04:56 +03:00
|
|
|
|
|
|
|
MOZ_ALWAYS_TRUE(
|
|
|
|
mBackgroundActor.mVersionChangeBackgroundActor->SendRenameIndex(
|
|
|
|
aObjectStore->Id(), aIndexId, nsString(aName)));
|
|
|
|
}
|
|
|
|
|
2019-11-11 11:24:25 +03:00
|
|
|
void IDBTransaction::AbortInternal(const nsresult aAbortCode,
|
2019-11-28 18:05:28 +03:00
|
|
|
RefPtr<DOMException> aError) {
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(NS_FAILED(aAbortCode));
|
2019-11-28 19:00:29 +03:00
|
|
|
MOZ_ASSERT(!IsCommittingOrFinished());
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2019-11-27 13:54:57 +03:00
|
|
|
const bool isVersionChange = mMode == Mode::VersionChange;
|
2019-12-04 15:59:09 +03:00
|
|
|
const bool needToSendAbort = mReadyState == ReadyState::Inactive && !mStarted;
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2012-06-01 21:21:12 +04:00
|
|
|
mAbortCode = aAbortCode;
|
2019-11-28 19:00:29 +03:00
|
|
|
mReadyState = ReadyState::Finished;
|
2019-11-28 18:05:28 +03:00
|
|
|
mError = std::move(aError);
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
if (isVersionChange) {
|
2012-06-29 20:48:34 +04:00
|
|
|
// If a version change transaction is aborted, we must revert the world
|
2014-09-27 03:21:57 +04:00
|
|
|
// back to its previous state unless we're being invalidated after the
|
|
|
|
// transaction already completed.
|
2019-11-11 11:24:45 +03:00
|
|
|
if (!mDatabase->IsInvalidated()) {
|
2014-09-27 03:21:57 +04:00
|
|
|
mDatabase->RevertToPreviousState();
|
|
|
|
}
|
2012-06-29 20:48:34 +04:00
|
|
|
|
2016-09-13 01:38:43 +03:00
|
|
|
// We do the reversion only for the mObjectStores/mDeletedObjectStores but
|
|
|
|
// not for the mIndexes/mDeletedIndexes of each IDBObjectStore because it's
|
|
|
|
// time-consuming(O(m*n)) and mIndexes/mDeletedIndexes won't be used anymore
|
|
|
|
// in IDBObjectStore::(Create|Delete)Index() and IDBObjectStore::Index() in
|
2019-11-28 19:00:29 +03:00
|
|
|
// which all the executions are returned earlier by
|
|
|
|
// !transaction->CanAcceptRequests().
|
2016-09-13 01:38:43 +03:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
const nsTArray<ObjectStoreSpec>& specArray =
|
|
|
|
mDatabase->Spec()->objectStores();
|
2012-06-29 20:48:34 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
if (specArray.IsEmpty()) {
|
2019-11-11 11:24:45 +03:00
|
|
|
// This case is specially handled as a performance optimization, it is
|
|
|
|
// equivalent to the else block.
|
2014-09-27 03:21:57 +04:00
|
|
|
mObjectStores.Clear();
|
|
|
|
} else {
|
2019-11-11 11:24:53 +03:00
|
|
|
const auto validIds = TransformToHashtable<nsUint64HashKey>(
|
|
|
|
specArray, [](const auto& spec) {
|
|
|
|
const int64_t objectStoreId = spec.metadata().id();
|
|
|
|
MOZ_ASSERT(objectStoreId);
|
|
|
|
return static_cast<uint64_t>(objectStoreId);
|
|
|
|
});
|
|
|
|
|
|
|
|
mObjectStores.RemoveElementsAt(
|
|
|
|
std::remove_if(mObjectStores.begin(), mObjectStores.end(),
|
|
|
|
[&validIds](const auto& objectStore) {
|
|
|
|
return !validIds.Contains(
|
|
|
|
uint64_t(objectStore->Id()));
|
|
|
|
}),
|
|
|
|
mObjectStores.end());
|
|
|
|
|
2019-11-27 13:54:57 +03:00
|
|
|
std::copy_if(std::make_move_iterator(mDeletedObjectStores.begin()),
|
|
|
|
std::make_move_iterator(mDeletedObjectStores.end()),
|
|
|
|
MakeBackInserter(mObjectStores),
|
|
|
|
[&validIds](const auto& deletedObjectStore) {
|
|
|
|
const int64_t objectStoreId = deletedObjectStore->Id();
|
|
|
|
MOZ_ASSERT(objectStoreId);
|
|
|
|
return validIds.Contains(uint64_t(objectStoreId));
|
|
|
|
});
|
2012-06-29 20:48:34 +04:00
|
|
|
}
|
2019-11-11 11:24:53 +03:00
|
|
|
mDeletedObjectStores.Clear();
|
2012-06-01 21:21:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Fire the abort event if there are no outstanding requests. Otherwise the
|
|
|
|
// abort event will be fired when all outstanding requests finish.
|
2014-09-27 03:21:57 +04:00
|
|
|
if (needToSendAbort) {
|
|
|
|
SendAbort(aAbortCode);
|
2012-06-01 21:21:12 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
if (isVersionChange) {
|
|
|
|
mDatabase->Close();
|
|
|
|
}
|
2012-06-01 21:21:12 +04:00
|
|
|
}
|
|
|
|
|
2019-11-11 11:24:25 +03:00
|
|
|
void IDBTransaction::Abort(IDBRequest* const aRequest) {
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(aRequest);
|
2012-06-25 23:15:17 +04:00
|
|
|
|
2019-11-28 19:00:29 +03:00
|
|
|
if (IsCommittingOrFinished()) {
|
2015-06-26 01:22:59 +03:00
|
|
|
// Already started (and maybe finished) the commit or abort so there is
|
|
|
|
// nothing to do here.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-05-18 21:52:06 +04:00
|
|
|
ErrorResult rv;
|
2017-08-06 20:47:00 +03:00
|
|
|
RefPtr<DOMException> error = aRequest->GetError(rv);
|
2012-06-29 20:48:34 +04:00
|
|
|
|
2019-11-28 18:05:28 +03:00
|
|
|
// TODO: Do we deliberately ignore rv here? Isn't there a static analysis that
|
|
|
|
// prevents that?
|
|
|
|
|
|
|
|
AbortInternal(aRequest->GetErrorCode(), std::move(error));
|
2012-06-29 20:48:34 +04:00
|
|
|
}
|
|
|
|
|
2019-11-11 11:24:25 +03:00
|
|
|
void IDBTransaction::Abort(const nsresult aErrorCode) {
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
2012-06-25 23:15:17 +04:00
|
|
|
|
2019-11-28 19:00:29 +03:00
|
|
|
if (IsCommittingOrFinished()) {
|
2015-06-26 01:22:59 +03:00
|
|
|
// Already started (and maybe finished) the commit or abort so there is
|
|
|
|
// nothing to do here.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-11-28 18:05:28 +03:00
|
|
|
AbortInternal(aErrorCode, DOMException::Create(aErrorCode));
|
2012-06-25 23:15:17 +04:00
|
|
|
}
|
|
|
|
|
2019-12-04 15:59:09 +03:00
|
|
|
// Specified by https://w3c.github.io/IndexedDB/#dom-idbtransaction-abort.
|
2014-09-27 03:21:57 +04:00
|
|
|
void IDBTransaction::Abort(ErrorResult& aRv) {
|
|
|
|
AssertIsOnOwningThread();
|
2011-10-20 20:10:56 +04:00
|
|
|
|
2019-11-28 19:00:29 +03:00
|
|
|
if (IsCommittingOrFinished()) {
|
2014-09-27 03:21:57 +04:00
|
|
|
aRv = NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR;
|
|
|
|
return;
|
2014-09-18 03:36:01 +04:00
|
|
|
}
|
2011-12-17 04:40:47 +04:00
|
|
|
|
2019-12-04 15:59:09 +03:00
|
|
|
mReadyState = ReadyState::Inactive;
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
AbortInternal(NS_ERROR_DOM_INDEXEDDB_ABORT_ERR, nullptr);
|
2011-12-16 11:34:24 +04:00
|
|
|
|
2019-12-03 18:32:18 +03:00
|
|
|
mAbortedByScript.Flip();
|
2011-12-16 11:34:24 +04:00
|
|
|
}
|
|
|
|
|
2019-12-10 13:24:18 +03:00
|
|
|
// Specified by https://w3c.github.io/IndexedDB/#dom-idbtransaction-commit.
|
|
|
|
void IDBTransaction::Commit(ErrorResult& aRv) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
2020-01-14 16:22:26 +03:00
|
|
|
if (IsCommittingOrFinished()) {
|
|
|
|
aRv = NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR;
|
2019-12-10 13:24:18 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-01-14 16:22:26 +03:00
|
|
|
// TODO
|
|
|
|
aRv = NS_ERROR_NOT_IMPLEMENTED;
|
2019-12-10 13:24:18 +03:00
|
|
|
}
|
|
|
|
|
2019-11-11 11:24:25 +03:00
|
|
|
void IDBTransaction::FireCompleteOrAbortEvents(const nsresult aResult) {
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(!mFiredCompleteOrAbort);
|
2012-08-24 22:51:33 +04:00
|
|
|
|
2019-11-28 19:00:29 +03:00
|
|
|
mReadyState = ReadyState::Finished;
|
2014-09-18 03:36:01 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2019-12-03 18:32:18 +03:00
|
|
|
mFiredCompleteOrAbort.Flip();
|
2014-09-18 03:36:01 +04:00
|
|
|
#endif
|
|
|
|
|
2018-06-18 23:37:21 +03:00
|
|
|
// Make sure we drop the WorkerRef when this function completes.
|
2019-11-11 11:24:25 +03:00
|
|
|
const auto scopeExit = MakeScopeExit([&] { mWorkerRef = nullptr; });
|
2014-12-17 09:26:15 +03:00
|
|
|
|
2018-04-05 20:42:41 +03:00
|
|
|
RefPtr<Event> event;
|
2014-09-27 03:21:57 +04:00
|
|
|
if (NS_SUCCEEDED(aResult)) {
|
|
|
|
event = CreateGenericEvent(this, nsDependentString(kCompleteEventType),
|
|
|
|
eDoesNotBubble, eNotCancelable);
|
2014-12-17 09:26:15 +03:00
|
|
|
MOZ_ASSERT(event);
|
2019-07-26 16:29:04 +03:00
|
|
|
|
|
|
|
// If we hit this assertion, it probably means transaction object on the
|
|
|
|
// parent process doesn't propagate error properly.
|
|
|
|
MOZ_ASSERT(NS_SUCCEEDED(mAbortCode));
|
2014-09-27 03:21:57 +04:00
|
|
|
} else {
|
2016-04-21 07:53:30 +03:00
|
|
|
if (aResult == NS_ERROR_DOM_INDEXEDDB_QUOTA_ERR) {
|
|
|
|
mDatabase->SetQuotaExceeded();
|
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
if (!mError && !mAbortedByScript) {
|
2017-08-06 20:47:00 +03:00
|
|
|
mError = DOMException::Create(aResult);
|
2014-09-18 03:36:01 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
event = CreateGenericEvent(this, nsDependentString(kAbortEventType),
|
|
|
|
eDoesBubble, eNotCancelable);
|
2014-12-17 09:26:15 +03:00
|
|
|
MOZ_ASSERT(event);
|
2019-07-26 16:29:04 +03:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(mAbortCode)) {
|
|
|
|
mAbortCode = aResult;
|
|
|
|
}
|
2014-09-18 03:36:01 +04:00
|
|
|
}
|
|
|
|
|
2014-10-16 08:56:52 +04:00
|
|
|
if (NS_SUCCEEDED(mAbortCode)) {
|
2019-09-27 13:11:45 +03:00
|
|
|
IDB_LOG_MARK_CHILD_TRANSACTION("Firing 'complete' event",
|
|
|
|
"IDBTransaction 'complete' event",
|
|
|
|
mLoggingSerialNumber);
|
2014-10-16 08:56:52 +04:00
|
|
|
} else {
|
2019-09-27 13:11:45 +03:00
|
|
|
IDB_LOG_MARK_CHILD_TRANSACTION("Firing 'abort' event with error 0x%x",
|
|
|
|
"IDBTransaction 'abort' event (0x%x)",
|
|
|
|
mLoggingSerialNumber, mAbortCode);
|
2014-10-16 08:56:52 +04:00
|
|
|
}
|
|
|
|
|
2018-04-05 20:42:41 +03:00
|
|
|
IgnoredErrorResult rv;
|
|
|
|
DispatchEvent(*event, rv);
|
|
|
|
if (rv.Failed()) {
|
2014-09-27 03:21:57 +04:00
|
|
|
NS_WARNING("DispatchEvent failed!");
|
2014-09-13 20:12:19 +04:00
|
|
|
}
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2017-06-16 14:06:36 +03:00
|
|
|
// Normally, we note inactive transaction here instead of
|
|
|
|
// IDBTransaction::ClearBackgroundActor() because here is the earliest place
|
|
|
|
// to know that it becomes non-blocking to allow the scheduler to start the
|
|
|
|
// preemption as soon as it can.
|
|
|
|
// Note: If the IDBTransaction object is held by the script,
|
|
|
|
// ClearBackgroundActor() will be done in ~IDBTransaction() until garbage
|
|
|
|
// collected after its window is closed which prevents us to preempt its
|
|
|
|
// window immediately after committed.
|
|
|
|
MaybeNoteInactiveTransaction();
|
2012-08-24 22:51:33 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
int64_t IDBTransaction::NextObjectStoreId() {
|
|
|
|
AssertIsOnOwningThread();
|
2019-11-27 13:54:57 +03:00
|
|
|
MOZ_ASSERT(Mode::VersionChange == mMode);
|
2012-08-24 22:51:33 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
return mNextObjectStoreId++;
|
2012-08-24 22:51:33 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
int64_t IDBTransaction::NextIndexId() {
|
|
|
|
AssertIsOnOwningThread();
|
2019-11-27 13:54:57 +03:00
|
|
|
MOZ_ASSERT(Mode::VersionChange == mMode);
|
2012-08-24 22:51:33 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
return mNextIndexId++;
|
2014-09-18 03:36:01 +04:00
|
|
|
}
|
2011-12-16 11:34:24 +04:00
|
|
|
|
2019-11-05 17:40:37 +03:00
|
|
|
void IDBTransaction::InvalidateCursorCaches() {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
for (auto* const cursor : mCursors) {
|
|
|
|
cursor->InvalidateCachedResponses();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void IDBTransaction::RegisterCursor(IDBCursor* const aCursor) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
mCursors.AppendElement(aCursor);
|
|
|
|
}
|
|
|
|
|
|
|
|
void IDBTransaction::UnregisterCursor(IDBCursor* const aCursor) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
DebugOnly<bool> removed = mCursors.RemoveElement(aCursor);
|
|
|
|
MOZ_ASSERT(removed);
|
|
|
|
}
|
|
|
|
|
2019-03-29 21:05:11 +03:00
|
|
|
nsIGlobalObject* IDBTransaction::GetParentObject() const {
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
return mDatabase->GetParentObject();
|
2014-09-13 20:12:19 +04:00
|
|
|
}
|
2011-12-16 11:34:24 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
IDBTransactionMode IDBTransaction::GetMode(ErrorResult& aRv) const {
|
|
|
|
AssertIsOnOwningThread();
|
2011-12-16 11:34:24 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
switch (mMode) {
|
2019-11-27 13:54:57 +03:00
|
|
|
case Mode::ReadOnly:
|
2014-09-27 03:21:57 +04:00
|
|
|
return IDBTransactionMode::Readonly;
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2019-11-27 13:54:57 +03:00
|
|
|
case Mode::ReadWrite:
|
2014-09-27 03:21:57 +04:00
|
|
|
return IDBTransactionMode::Readwrite;
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2019-11-27 13:54:57 +03:00
|
|
|
case Mode::ReadWriteFlush:
|
2015-01-26 09:30:09 +03:00
|
|
|
return IDBTransactionMode::Readwriteflush;
|
|
|
|
|
2019-11-27 13:54:57 +03:00
|
|
|
case Mode::Cleanup:
|
2016-03-15 09:00:37 +03:00
|
|
|
return IDBTransactionMode::Cleanup;
|
|
|
|
|
2019-11-27 13:54:57 +03:00
|
|
|
case Mode::VersionChange:
|
2014-09-27 03:21:57 +04:00
|
|
|
return IDBTransactionMode::Versionchange;
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2019-11-27 13:54:57 +03:00
|
|
|
case Mode::Invalid:
|
2014-09-27 03:21:57 +04:00
|
|
|
default:
|
|
|
|
MOZ_CRASH("Bad mode!");
|
|
|
|
}
|
2014-09-18 03:36:01 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
DOMException* IDBTransaction::GetError() const {
|
|
|
|
AssertIsOnOwningThread();
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
return mError;
|
2014-09-18 03:36:01 +04:00
|
|
|
}
|
|
|
|
|
2019-11-28 18:05:28 +03:00
|
|
|
RefPtr<DOMStringList> IDBTransaction::ObjectStoreNames() const {
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2019-11-27 13:54:57 +03:00
|
|
|
if (mMode == Mode::VersionChange) {
|
2014-09-27 03:21:57 +04:00
|
|
|
return mDatabase->ObjectStoreNames();
|
2014-09-13 20:12:19 +04:00
|
|
|
}
|
2011-12-16 11:34:24 +04:00
|
|
|
|
2019-11-28 18:05:28 +03:00
|
|
|
auto list = MakeRefPtr<DOMStringList>();
|
2014-09-27 03:21:57 +04:00
|
|
|
list->StringArray() = mObjectStoreNames;
|
2019-11-28 18:05:28 +03:00
|
|
|
return list;
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2019-11-28 18:05:28 +03:00
|
|
|
RefPtr<IDBObjectStore> IDBTransaction::ObjectStore(const nsAString& aName,
|
|
|
|
ErrorResult& aRv) {
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2019-11-28 19:00:29 +03:00
|
|
|
if (IsCommittingOrFinished()) {
|
2019-11-20 13:23:47 +03:00
|
|
|
aRv.ThrowDOMException(
|
|
|
|
NS_ERROR_DOM_INVALID_STATE_ERR,
|
|
|
|
NS_LITERAL_CSTRING("Transaction is already committing or done."));
|
2014-09-27 03:21:57 +04:00
|
|
|
return nullptr;
|
|
|
|
}
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
const ObjectStoreSpec* spec = nullptr;
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2019-11-27 13:54:57 +03:00
|
|
|
if (IDBTransaction::Mode::VersionChange == mMode ||
|
2014-09-27 03:21:57 +04:00
|
|
|
mObjectStoreNames.Contains(aName)) {
|
|
|
|
const nsTArray<ObjectStoreSpec>& objectStores =
|
|
|
|
mDatabase->Spec()->objectStores();
|
|
|
|
|
2019-11-11 11:24:53 +03:00
|
|
|
const auto foundIt =
|
|
|
|
std::find_if(objectStores.cbegin(), objectStores.cend(),
|
|
|
|
[&aName](const auto& objectStore) {
|
|
|
|
return objectStore.metadata().name() == aName;
|
|
|
|
});
|
|
|
|
if (foundIt != objectStores.cend()) {
|
|
|
|
spec = &*foundIt;
|
2011-12-16 11:34:24 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
if (!spec) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_NOT_FOUND_ERR);
|
|
|
|
return nullptr;
|
2012-08-24 22:51:33 +04:00
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<IDBObjectStore> objectStore;
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2019-11-11 11:24:53 +03:00
|
|
|
const auto foundIt = std::find_if(
|
|
|
|
mObjectStores.cbegin(), mObjectStores.cend(),
|
|
|
|
[desiredId = spec->metadata().id()](const auto& existingObjectStore) {
|
|
|
|
return existingObjectStore->Id() == desiredId;
|
|
|
|
});
|
|
|
|
if (foundIt != mObjectStores.cend()) {
|
|
|
|
objectStore = *foundIt;
|
|
|
|
} else {
|
2014-09-27 03:21:57 +04:00
|
|
|
objectStore = IDBObjectStore::Create(this, *spec);
|
|
|
|
MOZ_ASSERT(objectStore);
|
2011-12-16 11:34:24 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
mObjectStores.AppendElement(objectStore);
|
2014-09-18 03:36:01 +04:00
|
|
|
}
|
2014-01-31 22:53:37 +04:00
|
|
|
|
2019-11-28 18:05:28 +03:00
|
|
|
return objectStore;
|
2014-09-18 03:36:01 +04:00
|
|
|
}
|
2014-01-31 22:53:37 +04:00
|
|
|
|
2019-03-29 21:05:11 +03:00
|
|
|
NS_IMPL_ADDREF_INHERITED(IDBTransaction, DOMEventTargetHelper)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(IDBTransaction, DOMEventTargetHelper)
|
2014-09-13 20:12:19 +04:00
|
|
|
|
2017-08-30 02:02:48 +03:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(IDBTransaction)
|
2014-09-27 03:21:57 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIRunnable)
|
2019-03-29 21:05:11 +03:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(IDBTransaction)
|
2011-12-16 11:34:24 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(IDBTransaction,
|
2019-03-29 21:05:11 +03:00
|
|
|
DOMEventTargetHelper)
|
2014-09-27 03:21:57 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDatabase)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mError)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mObjectStores)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDeletedObjectStores)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
2011-12-16 11:34:24 +04:00
|
|
|
|
2019-03-29 21:05:11 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(IDBTransaction,
|
|
|
|
DOMEventTargetHelper)
|
2014-09-27 03:21:57 +04:00
|
|
|
// Don't unlink mDatabase!
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mError)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mObjectStores)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mDeletedObjectStores)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
2019-11-11 11:24:25 +03:00
|
|
|
JSObject* IDBTransaction::WrapObject(JSContext* const aCx,
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
2011-12-16 11:34:24 +04:00
|
|
|
|
2019-11-11 11:24:25 +03:00
|
|
|
return IDBTransaction_Binding::Wrap(aCx, this, std::move(aGivenProto));
|
2014-09-13 20:12:19 +04:00
|
|
|
}
|
2012-08-24 22:51:33 +04:00
|
|
|
|
2016-10-21 05:11:07 +03:00
|
|
|
void IDBTransaction::GetEventTargetParent(EventChainPreVisitor& aVisitor) {
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
aVisitor.mCanHandle = true;
|
2017-12-18 19:07:36 +03:00
|
|
|
aVisitor.SetParentTarget(mDatabase, false);
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
IDBTransaction::Run() {
|
|
|
|
AssertIsOnOwningThread();
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2020-01-14 16:22:26 +03:00
|
|
|
// We're back at the event loop, no longer newborn.
|
|
|
|
mCreating = false;
|
2020-01-14 14:14:52 +03:00
|
|
|
|
2020-01-14 16:22:26 +03:00
|
|
|
MOZ_ASSERT_IF(mReadyState == ReadyState::Finished, IsAborted());
|
2019-12-04 15:59:09 +03:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
// Maybe commit if there were no requests generated.
|
2020-01-14 16:22:26 +03:00
|
|
|
if (!mStarted && mReadyState != ReadyState::Finished) {
|
|
|
|
MOZ_ASSERT(mReadyState == ReadyState::Inactive ||
|
|
|
|
mReadyState == ReadyState::Active);
|
2019-11-28 19:00:29 +03:00
|
|
|
mReadyState = ReadyState::Finished;
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2020-01-14 16:22:26 +03:00
|
|
|
SendCommit();
|
2011-12-16 11:34:24 +04:00
|
|
|
}
|
2020-01-14 16:22:26 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
2011-12-16 11:34:24 +04:00
|
|
|
}
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|