2010-06-23 19:46:08 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2015-05-03 19:32:37 +00:00
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 11:12:37 +00: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 19:46:08 +00:00
|
|
|
|
2010-06-28 16:46:21 +00:00
|
|
|
#include "IDBTransaction.h"
|
2010-06-23 19:46:08 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
#include "BackgroundChildImpl.h"
|
|
|
|
#include "IDBDatabase.h"
|
|
|
|
#include "IDBEvents.h"
|
|
|
|
#include "IDBObjectStore.h"
|
|
|
|
#include "IDBRequest.h"
|
|
|
|
#include "mozilla/ErrorResult.h"
|
2014-09-17 23:36:01 +00:00
|
|
|
#include "mozilla/EventDispatcher.h"
|
2014-09-26 23:21:57 +00:00
|
|
|
#include "mozilla/dom/DOMError.h"
|
|
|
|
#include "mozilla/dom/DOMStringList.h"
|
|
|
|
#include "mozilla/ipc/BackgroundChild.h"
|
2016-06-07 20:10:18 +00:00
|
|
|
#include "nsAutoPtr.h"
|
2010-08-26 20:57:25 +00:00
|
|
|
#include "nsPIDOMWindow.h"
|
2014-09-26 23:21:57 +00:00
|
|
|
#include "nsServiceManagerUtils.h"
|
|
|
|
#include "nsTHashtable.h"
|
2013-03-16 06:58:50 +00:00
|
|
|
#include "ProfilerHelpers.h"
|
2014-01-28 00:37:05 +00:00
|
|
|
#include "ReportInternalError.h"
|
2016-06-23 08:53:14 +00:00
|
|
|
#include "WorkerHolder.h"
|
2014-12-17 06:26:15 +00:00
|
|
|
#include "WorkerPrivate.h"
|
2012-06-01 17:21:12 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
// Include this last to avoid path problems on Windows.
|
|
|
|
#include "ActorsChild.h"
|
2010-06-23 19:46:08 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2010-06-23 19:46:08 +00:00
|
|
|
|
2016-02-16 21:46:08 +00:00
|
|
|
using namespace mozilla::dom::indexedDB;
|
2014-12-17 06:26:15 +00:00
|
|
|
using namespace mozilla::dom::workers;
|
2014-10-16 04:56:52 +00:00
|
|
|
using namespace mozilla::ipc;
|
|
|
|
|
2016-06-23 08:53:14 +00:00
|
|
|
class IDBTransaction::WorkerHolder final
|
|
|
|
: public mozilla::dom::workers::WorkerHolder
|
2014-12-17 06:26:15 +00:00
|
|
|
{
|
|
|
|
WorkerPrivate* mWorkerPrivate;
|
|
|
|
|
|
|
|
// The IDBTransaction owns this object so we only need a weak reference back
|
|
|
|
// to it.
|
|
|
|
IDBTransaction* mTransaction;
|
|
|
|
|
|
|
|
public:
|
2016-06-23 08:53:14 +00:00
|
|
|
WorkerHolder(WorkerPrivate* aWorkerPrivate, IDBTransaction* aTransaction)
|
2014-12-17 06:26:15 +00:00
|
|
|
: mWorkerPrivate(aWorkerPrivate)
|
|
|
|
, mTransaction(aTransaction)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aWorkerPrivate);
|
|
|
|
MOZ_ASSERT(aTransaction);
|
|
|
|
aWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
|
aTransaction->AssertIsOnOwningThread();
|
|
|
|
|
2016-06-23 08:53:14 +00:00
|
|
|
MOZ_COUNT_CTOR(IDBTransaction::WorkerHolder);
|
2014-12-17 06:26:15 +00:00
|
|
|
}
|
|
|
|
|
2016-06-23 08:53:14 +00:00
|
|
|
~WorkerHolder()
|
2014-12-17 06:26:15 +00:00
|
|
|
{
|
|
|
|
mWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
|
|
2016-06-23 08:53:14 +00:00
|
|
|
MOZ_COUNT_DTOR(IDBTransaction::WorkerHolder);
|
2014-12-17 06:26:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
virtual bool
|
2016-03-28 17:28:14 +00:00
|
|
|
Notify(Status aStatus) override;
|
2014-12-17 06:26:15 +00:00
|
|
|
};
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
IDBTransaction::IDBTransaction(IDBDatabase* aDatabase,
|
|
|
|
const nsTArray<nsString>& aObjectStoreNames,
|
|
|
|
Mode aMode)
|
|
|
|
: IDBWrapperCache(aDatabase)
|
|
|
|
, mDatabase(aDatabase)
|
|
|
|
, mObjectStoreNames(aObjectStoreNames)
|
2014-10-16 04:56:52 +00:00
|
|
|
, mLoggingSerialNumber(0)
|
2014-09-26 23:21:57 +00:00
|
|
|
, mNextObjectStoreId(0)
|
|
|
|
, mNextIndexId(0)
|
|
|
|
, mAbortCode(NS_OK)
|
|
|
|
, mPendingRequestCount(0)
|
2014-11-14 02:20:38 +00:00
|
|
|
, mLineNo(0)
|
2015-09-02 01:01:02 +00:00
|
|
|
, mColumn(0)
|
2014-09-26 23:21:57 +00:00
|
|
|
, mReadyState(IDBTransaction::INITIAL)
|
|
|
|
, mMode(aMode)
|
|
|
|
, mCreating(false)
|
2014-12-17 06:26:15 +00:00
|
|
|
, mRegistered(false)
|
2014-09-26 23:21:57 +00:00
|
|
|
, mAbortedByScript(false)
|
|
|
|
#ifdef DEBUG
|
|
|
|
, mSentCommitOrAbort(false)
|
|
|
|
, mFiredCompleteOrAbort(false)
|
|
|
|
#endif
|
2010-06-23 19:46:08 +00:00
|
|
|
{
|
2014-09-26 23:21:57 +00:00
|
|
|
MOZ_ASSERT(aDatabase);
|
|
|
|
aDatabase->AssertIsOnOwningThread();
|
2010-06-23 19:46:08 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
mBackgroundActor.mNormalBackgroundActor = nullptr;
|
2011-11-18 15:21:04 +00:00
|
|
|
|
2014-10-16 04:56:52 +00:00
|
|
|
BackgroundChildImpl::ThreadLocal* threadLocal =
|
|
|
|
BackgroundChildImpl::GetThreadLocalForCurrentThread();
|
|
|
|
MOZ_ASSERT(threadLocal);
|
2014-09-26 23:21:57 +00:00
|
|
|
|
2014-10-16 04:56:52 +00:00
|
|
|
ThreadLocal* idbThreadLocal = threadLocal->mIndexedDBThreadLocal;
|
|
|
|
MOZ_ASSERT(idbThreadLocal);
|
|
|
|
|
|
|
|
const_cast<int64_t&>(mLoggingSerialNumber) =
|
|
|
|
idbThreadLocal->NextTransactionSN(aMode);
|
2011-11-18 15:21:04 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (!aObjectStoreNames.IsEmpty()) {
|
|
|
|
nsTArray<nsString> sortedNames(aObjectStoreNames);
|
|
|
|
sortedNames.Sort();
|
|
|
|
|
|
|
|
const uint32_t count = sortedNames.Length();
|
|
|
|
MOZ_ASSERT(count == aObjectStoreNames.Length());
|
|
|
|
|
|
|
|
// Make sure the array is properly sorted.
|
|
|
|
for (uint32_t index = 0; index < count; index++) {
|
|
|
|
MOZ_ASSERT(aObjectStoreNames[index] == sortedNames[index]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure there are no duplicates in our objectStore names.
|
|
|
|
for (uint32_t index = 0; index < count - 1; index++) {
|
|
|
|
MOZ_ASSERT(sortedNames[index] != sortedNames[index + 1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2011-11-18 15:21:04 +00:00
|
|
|
}
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
IDBTransaction::~IDBTransaction()
|
2011-11-18 15:21:04 +00:00
|
|
|
{
|
2014-09-26 23:21:57 +00:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(!mPendingRequestCount);
|
|
|
|
MOZ_ASSERT(!mCreating);
|
|
|
|
MOZ_ASSERT(mSentCommitOrAbort);
|
|
|
|
MOZ_ASSERT_IF(mMode == VERSION_CHANGE &&
|
|
|
|
mBackgroundActor.mVersionChangeBackgroundActor,
|
|
|
|
mFiredCompleteOrAbort);
|
|
|
|
MOZ_ASSERT_IF(mMode != VERSION_CHANGE &&
|
|
|
|
mBackgroundActor.mNormalBackgroundActor,
|
|
|
|
mFiredCompleteOrAbort);
|
2011-11-18 15:21:04 +00:00
|
|
|
|
2014-12-17 06:26:15 +00:00
|
|
|
if (mRegistered) {
|
|
|
|
mDatabase->UnregisterTransaction(this);
|
|
|
|
#ifdef DEBUG
|
|
|
|
mRegistered = false;
|
|
|
|
#endif
|
|
|
|
}
|
2011-11-18 15:21:04 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
if (mMode == VERSION_CHANGE) {
|
2014-10-16 04:56:52 +00:00
|
|
|
if (auto* actor = mBackgroundActor.mVersionChangeBackgroundActor) {
|
2014-12-17 06:26:15 +00:00
|
|
|
actor->SendDeleteMeInternal(/* aFailedConstructor */ false);
|
2014-10-16 04:56:52 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
MOZ_ASSERT(!mBackgroundActor.mVersionChangeBackgroundActor,
|
|
|
|
"SendDeleteMeInternal should have cleared!");
|
|
|
|
}
|
2014-10-16 04:56:52 +00:00
|
|
|
} else if (auto* actor = mBackgroundActor.mNormalBackgroundActor) {
|
|
|
|
actor->SendDeleteMeInternal();
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
MOZ_ASSERT(!mBackgroundActor.mNormalBackgroundActor,
|
|
|
|
"SendDeleteMeInternal should have cleared!");
|
|
|
|
}
|
|
|
|
}
|
2010-06-23 19:46:08 +00:00
|
|
|
|
|
|
|
// static
|
2010-06-28 16:46:21 +00:00
|
|
|
already_AddRefed<IDBTransaction>
|
2014-09-26 23:21:57 +00:00
|
|
|
IDBTransaction::CreateVersionChange(
|
|
|
|
IDBDatabase* aDatabase,
|
|
|
|
BackgroundVersionChangeTransactionChild* aActor,
|
2014-11-14 02:20:38 +00:00
|
|
|
IDBOpenDBRequest* aOpenRequest,
|
2014-09-26 23:21:57 +00:00
|
|
|
int64_t aNextObjectStoreId,
|
|
|
|
int64_t aNextIndexId)
|
2010-06-23 19:46:08 +00:00
|
|
|
{
|
2014-09-26 23:21:57 +00:00
|
|
|
MOZ_ASSERT(aDatabase);
|
|
|
|
aDatabase->AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(aActor);
|
2014-11-14 02:20:38 +00:00
|
|
|
MOZ_ASSERT(aOpenRequest);
|
2014-09-26 23:21:57 +00:00
|
|
|
MOZ_ASSERT(aNextObjectStoreId > 0);
|
|
|
|
MOZ_ASSERT(aNextIndexId > 0);
|
2010-06-23 19:46:08 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
nsTArray<nsString> emptyObjectStoreNames;
|
2014-05-29 20:07:35 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<IDBTransaction> transaction =
|
2015-01-26 06:30:09 +00:00
|
|
|
new IDBTransaction(aDatabase,
|
|
|
|
emptyObjectStoreNames,
|
|
|
|
VERSION_CHANGE);
|
2014-11-14 02:20:38 +00:00
|
|
|
aOpenRequest->GetCallerLocation(transaction->mFilename,
|
2015-09-02 01:01:02 +00:00
|
|
|
&transaction->mLineNo, &transaction->mColumn);
|
2012-06-01 17:21:12 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
transaction->SetScriptOwner(aDatabase->GetScriptOwner());
|
2012-06-01 17:21:12 +00:00
|
|
|
|
Bug 1179909: Refactor stable state handling. r=smaug
This is motivated by three separate but related problems:
1. Our concept of recursion depth is broken for things that run from AfterProcessNextEvent observers (e.g. Promises). We decrement the recursionDepth counter before firing observers, so a Promise callback running at the lowest event loop depth has a recursion depth of 0 (whereas a regular nsIRunnable would be 1). This is a problem because it's impossible to distinguish a Promise running after a sync XHR's onreadystatechange handler from a top-level event (since the former runs with depth 2 - 1 = 1, and the latter runs with just 1).
2. The nsIThreadObserver mechanism that is used by a lot of code to run "after" the current event is a poor fit for anything that runs script. First, the order the observers fire in is the order they were added, not anything fixed by spec. Additionally, running script can cause the event loop to spin, which is a big source of pain here (bholley has some nasty bug caused by this).
3. We run Promises from different points in the code for workers and main thread. The latter runs from XPConnect's nsIThreadObserver callbacks, while the former runs from a hardcoded call to run Promises in the worker event loop. What workers do is particularly problematic because it means we can't get the right recursion depth no matter what we do to nsThread.
The solve this, this patch does the following:
1. Consolidate some handling of microtasks and all handling of stable state from appshell and WorkerPrivate into CycleCollectedJSRuntime.
2. Make the recursionDepth counter only available to CycleCollectedJSRuntime (and its consumers) and remove it from the nsIThreadInternal and nsIThreadObserver APIs.
3. Adjust the recursionDepth counter so that microtasks run with the recursionDepth of the task they are associated with.
4. Introduce the concept of metastable state to replace appshell's RunBeforeNextEvent. Metastable state is reached after every microtask or task is completed. This provides the semantics that bent and I want for IndexedDB, where transactions autocommit at the end of a microtask and do not "spill" from one microtask into a subsequent microtask. This differs from appshell's RunBeforeNextEvent in two ways:
a) It fires between microtasks, which was the motivation for starting this.
b) It no longer ensures that we're at the same event loop depth in the native event queue. bent decided we don't care about this.
5. Reorder stable state to happen after microtasks such as Promises, per HTML. Right now we call the regular thread observers, including appshell, before the main thread observer (XPConnect), so stable state tasks happen before microtasks.
2015-08-11 13:10:46 +00:00
|
|
|
nsCOMPtr<nsIRunnable> runnable = do_QueryObject(transaction);
|
|
|
|
nsContentUtils::RunInMetastableState(runnable.forget());
|
2014-09-13 16:12:19 +00:00
|
|
|
|
2014-12-17 06:26:15 +00:00
|
|
|
transaction->mBackgroundActor.mVersionChangeBackgroundActor = aActor;
|
|
|
|
transaction->mNextObjectStoreId = aNextObjectStoreId;
|
|
|
|
transaction->mNextIndexId = aNextIndexId;
|
2014-09-26 23:21:57 +00:00
|
|
|
transaction->mCreating = true;
|
2010-06-23 19:46:08 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
aDatabase->RegisterTransaction(transaction);
|
2014-12-17 06:26:15 +00:00
|
|
|
transaction->mRegistered = true;
|
2010-11-18 22:19:19 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
return transaction.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
already_AddRefed<IDBTransaction>
|
2016-03-23 15:02:57 +00:00
|
|
|
IDBTransaction::Create(JSContext* aCx, IDBDatabase* aDatabase,
|
2014-09-26 23:21:57 +00:00
|
|
|
const nsTArray<nsString>& aObjectStoreNames,
|
|
|
|
Mode aMode)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aDatabase);
|
|
|
|
aDatabase->AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(!aObjectStoreNames.IsEmpty());
|
2015-01-26 06:30:09 +00:00
|
|
|
MOZ_ASSERT(aMode == READ_ONLY ||
|
|
|
|
aMode == READ_WRITE ||
|
2016-03-15 06:00:37 +00:00
|
|
|
aMode == READ_WRITE_FLUSH ||
|
|
|
|
aMode == CLEANUP);
|
2010-11-18 22:19:19 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<IDBTransaction> transaction =
|
2014-09-26 23:21:57 +00:00
|
|
|
new IDBTransaction(aDatabase, aObjectStoreNames, aMode);
|
2016-03-23 15:02:57 +00:00
|
|
|
IDBRequest::CaptureCaller(aCx, transaction->mFilename, &transaction->mLineNo,
|
2015-09-02 01:01:02 +00:00
|
|
|
&transaction->mColumn);
|
2010-11-15 21:49:49 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
transaction->SetScriptOwner(aDatabase->GetScriptOwner());
|
2011-11-18 15:21:04 +00:00
|
|
|
|
Bug 1179909: Refactor stable state handling. r=smaug
This is motivated by three separate but related problems:
1. Our concept of recursion depth is broken for things that run from AfterProcessNextEvent observers (e.g. Promises). We decrement the recursionDepth counter before firing observers, so a Promise callback running at the lowest event loop depth has a recursion depth of 0 (whereas a regular nsIRunnable would be 1). This is a problem because it's impossible to distinguish a Promise running after a sync XHR's onreadystatechange handler from a top-level event (since the former runs with depth 2 - 1 = 1, and the latter runs with just 1).
2. The nsIThreadObserver mechanism that is used by a lot of code to run "after" the current event is a poor fit for anything that runs script. First, the order the observers fire in is the order they were added, not anything fixed by spec. Additionally, running script can cause the event loop to spin, which is a big source of pain here (bholley has some nasty bug caused by this).
3. We run Promises from different points in the code for workers and main thread. The latter runs from XPConnect's nsIThreadObserver callbacks, while the former runs from a hardcoded call to run Promises in the worker event loop. What workers do is particularly problematic because it means we can't get the right recursion depth no matter what we do to nsThread.
The solve this, this patch does the following:
1. Consolidate some handling of microtasks and all handling of stable state from appshell and WorkerPrivate into CycleCollectedJSRuntime.
2. Make the recursionDepth counter only available to CycleCollectedJSRuntime (and its consumers) and remove it from the nsIThreadInternal and nsIThreadObserver APIs.
3. Adjust the recursionDepth counter so that microtasks run with the recursionDepth of the task they are associated with.
4. Introduce the concept of metastable state to replace appshell's RunBeforeNextEvent. Metastable state is reached after every microtask or task is completed. This provides the semantics that bent and I want for IndexedDB, where transactions autocommit at the end of a microtask and do not "spill" from one microtask into a subsequent microtask. This differs from appshell's RunBeforeNextEvent in two ways:
a) It fires between microtasks, which was the motivation for starting this.
b) It no longer ensures that we're at the same event loop depth in the native event queue. bent decided we don't care about this.
5. Reorder stable state to happen after microtasks such as Promises, per HTML. Right now we call the regular thread observers, including appshell, before the main thread observer (XPConnect), so stable state tasks happen before microtasks.
2015-08-11 13:10:46 +00:00
|
|
|
nsCOMPtr<nsIRunnable> runnable = do_QueryObject(transaction);
|
|
|
|
nsContentUtils::RunInMetastableState(runnable.forget());
|
2014-09-13 16:12:19 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
transaction->mCreating = true;
|
|
|
|
|
|
|
|
aDatabase->RegisterTransaction(transaction);
|
2014-12-17 06:26:15 +00:00
|
|
|
transaction->mRegistered = true;
|
|
|
|
|
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
|
|
|
|
MOZ_ASSERT(workerPrivate);
|
|
|
|
|
|
|
|
workerPrivate->AssertIsOnWorkerThread();
|
|
|
|
|
2016-06-23 08:53:14 +00:00
|
|
|
transaction->mWorkerHolder = new WorkerHolder(workerPrivate, transaction);
|
|
|
|
MOZ_ALWAYS_TRUE(transaction->mWorkerHolder->HoldWorker(workerPrivate));
|
2014-12-17 06:26:15 +00:00
|
|
|
}
|
2014-09-26 23:21:57 +00:00
|
|
|
|
2010-06-23 19:46:08 +00:00
|
|
|
return transaction.forget();
|
|
|
|
}
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
// static
|
|
|
|
IDBTransaction*
|
|
|
|
IDBTransaction::GetCurrent()
|
2010-06-23 19:46:08 +00:00
|
|
|
{
|
2014-09-26 23:21:57 +00:00
|
|
|
using namespace mozilla::ipc;
|
2010-06-23 19:46:08 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
MOZ_ASSERT(BackgroundChild::GetForCurrentThread());
|
2014-09-13 16:12:19 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
BackgroundChildImpl::ThreadLocal* threadLocal =
|
|
|
|
BackgroundChildImpl::GetThreadLocalForCurrentThread();
|
|
|
|
MOZ_ASSERT(threadLocal);
|
|
|
|
|
2014-10-16 04:56:52 +00:00
|
|
|
ThreadLocal* idbThreadLocal = threadLocal->mIndexedDBThreadLocal;
|
|
|
|
MOZ_ASSERT(idbThreadLocal);
|
|
|
|
|
|
|
|
return idbThreadLocal->GetCurrentTransaction();
|
2010-06-23 19:46:08 +00:00
|
|
|
}
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
|
2012-11-10 03:29:07 +00:00
|
|
|
void
|
2014-09-26 23:21:57 +00:00
|
|
|
IDBTransaction::AssertIsOnOwningThread() const
|
2012-11-10 03:29:07 +00:00
|
|
|
{
|
2014-09-26 23:21:57 +00:00
|
|
|
MOZ_ASSERT(mDatabase);
|
|
|
|
mDatabase->AssertIsOnOwningThread();
|
2012-11-10 03:29:07 +00:00
|
|
|
}
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
#endif // DEBUG
|
|
|
|
|
2011-12-04 17:39:01 +00:00
|
|
|
void
|
2016-02-16 21:46:08 +00:00
|
|
|
IDBTransaction::SetBackgroundActor(indexedDB::BackgroundTransactionChild* aBackgroundActor)
|
2011-12-04 17:39:01 +00:00
|
|
|
{
|
2014-09-26 23:21:57 +00:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(aBackgroundActor);
|
|
|
|
MOZ_ASSERT(!mBackgroundActor.mNormalBackgroundActor);
|
|
|
|
MOZ_ASSERT(mMode != VERSION_CHANGE);
|
|
|
|
|
|
|
|
mBackgroundActor.mNormalBackgroundActor = aBackgroundActor;
|
2014-09-17 23:36:01 +00:00
|
|
|
}
|
2011-12-17 00:40:47 +00:00
|
|
|
|
2015-03-18 21:20:59 +00:00
|
|
|
BackgroundRequestChild*
|
|
|
|
IDBTransaction::StartRequest(IDBRequest* aRequest, const RequestParams& aParams)
|
2014-09-17 23:36:01 +00:00
|
|
|
{
|
2014-09-26 23:21:57 +00:00
|
|
|
AssertIsOnOwningThread();
|
2015-03-18 21:20:59 +00:00
|
|
|
MOZ_ASSERT(aRequest);
|
2014-09-26 23:21:57 +00:00
|
|
|
MOZ_ASSERT(aParams.type() != RequestParams::T__None);
|
2011-12-17 00:40:47 +00:00
|
|
|
|
2015-03-18 21:20:59 +00:00
|
|
|
BackgroundRequestChild* actor = new BackgroundRequestChild(aRequest);
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
if (mMode == VERSION_CHANGE) {
|
|
|
|
MOZ_ASSERT(mBackgroundActor.mVersionChangeBackgroundActor);
|
2014-09-13 16:12:19 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
mBackgroundActor.mVersionChangeBackgroundActor->
|
2015-03-18 21:20:59 +00:00
|
|
|
SendPBackgroundIDBRequestConstructor(actor, aParams);
|
2014-09-26 23:21:57 +00:00
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(mBackgroundActor.mNormalBackgroundActor);
|
|
|
|
|
|
|
|
mBackgroundActor.mNormalBackgroundActor->
|
2015-03-18 21:20:59 +00:00
|
|
|
SendPBackgroundIDBRequestConstructor(actor, aParams);
|
2011-12-04 17:39:01 +00:00
|
|
|
}
|
2015-03-18 21:20:59 +00:00
|
|
|
|
|
|
|
// Balanced in BackgroundRequestChild::Recv__delete__().
|
|
|
|
OnNewRequest();
|
|
|
|
|
|
|
|
return actor;
|
2011-12-04 17:39:01 +00:00
|
|
|
}
|
|
|
|
|
2011-10-20 16:10:56 +00:00
|
|
|
void
|
2014-09-26 23:21:57 +00:00
|
|
|
IDBTransaction::OpenCursor(BackgroundCursorChild* aBackgroundActor,
|
|
|
|
const OpenCursorParams& aParams)
|
2011-10-20 16:10:56 +00:00
|
|
|
{
|
2014-09-26 23:21:57 +00:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(aBackgroundActor);
|
|
|
|
MOZ_ASSERT(aParams.type() != OpenCursorParams::T__None);
|
2011-10-20 16:10:56 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
if (mMode == VERSION_CHANGE) {
|
|
|
|
MOZ_ASSERT(mBackgroundActor.mVersionChangeBackgroundActor);
|
2010-10-20 00:46:37 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
mBackgroundActor.mVersionChangeBackgroundActor->
|
|
|
|
SendPBackgroundIDBCursorConstructor(aBackgroundActor, aParams);
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(mBackgroundActor.mNormalBackgroundActor);
|
2012-06-20 01:50:39 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
mBackgroundActor.mNormalBackgroundActor->
|
|
|
|
SendPBackgroundIDBCursorConstructor(aBackgroundActor, aParams);
|
2012-06-01 17:21:12 +00:00
|
|
|
}
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
// Balanced in BackgroundCursorChild::RecvResponse().
|
|
|
|
OnNewRequest();
|
2010-06-23 19:46:08 +00:00
|
|
|
}
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
void
|
|
|
|
IDBTransaction::RefreshSpec(bool aMayDelete)
|
2010-06-23 19:46:08 +00:00
|
|
|
{
|
2014-09-26 23:21:57 +00:00
|
|
|
AssertIsOnOwningThread();
|
2014-01-31 18:53:37 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
for (uint32_t count = mObjectStores.Length(), index = 0;
|
|
|
|
index < count;
|
|
|
|
index++) {
|
|
|
|
mObjectStores[index]->RefreshSpec(aMayDelete);
|
2014-09-13 16:12:19 +00:00
|
|
|
}
|
2014-09-17 23:36:01 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
for (uint32_t count = mDeletedObjectStores.Length(), index = 0;
|
|
|
|
index < count;
|
|
|
|
index++) {
|
|
|
|
mDeletedObjectStores[index]->RefreshSpec(false);
|
|
|
|
}
|
2010-06-23 19:46:08 +00:00
|
|
|
}
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
void
|
|
|
|
IDBTransaction::OnNewRequest()
|
2010-06-23 19:46:08 +00:00
|
|
|
{
|
2014-09-26 23:21:57 +00:00
|
|
|
AssertIsOnOwningThread();
|
2010-10-19 17:58:52 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
if (!mPendingRequestCount) {
|
|
|
|
MOZ_ASSERT(INITIAL == mReadyState);
|
|
|
|
mReadyState = LOADING;
|
2014-01-31 18:53:37 +00:00
|
|
|
}
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
++mPendingRequestCount;
|
2010-06-23 19:46:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-03-18 21:20:59 +00:00
|
|
|
IDBTransaction::OnRequestFinished(bool aActorDestroyedNormally)
|
2010-06-23 19:46:08 +00:00
|
|
|
{
|
2014-09-26 23:21:57 +00:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mPendingRequestCount);
|
2014-01-31 18:53:37 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
--mPendingRequestCount;
|
2014-09-17 23:36:01 +00:00
|
|
|
|
2016-05-31 10:08:20 +00:00
|
|
|
if (!mPendingRequestCount) {
|
2014-09-26 23:21:57 +00:00
|
|
|
mReadyState = COMMITTING;
|
2014-09-17 23:36:01 +00:00
|
|
|
|
2015-03-18 21:20:59 +00:00
|
|
|
if (aActorDestroyedNormally) {
|
|
|
|
if (NS_SUCCEEDED(mAbortCode)) {
|
|
|
|
SendCommit();
|
|
|
|
} else {
|
|
|
|
SendAbort(mAbortCode);
|
|
|
|
}
|
2014-09-26 23:21:57 +00:00
|
|
|
} else {
|
2015-03-18 21:20:59 +00:00
|
|
|
// Don't try to send any more messages to the parent if the request actor
|
|
|
|
// was killed.
|
|
|
|
#ifdef DEBUG
|
|
|
|
MOZ_ASSERT(!mSentCommitOrAbort);
|
|
|
|
mSentCommitOrAbort = true;
|
|
|
|
#endif
|
|
|
|
IDB_LOG_MARK("IndexedDB %s: Child Transaction[%lld]: "
|
|
|
|
"Request actor was killed, transaction will be aborted",
|
|
|
|
"IndexedDB %s: C T[%lld]: IDBTransaction abort",
|
|
|
|
IDB_LOG_ID_STRING(),
|
|
|
|
LoggingSerialNumber());
|
2014-09-26 23:21:57 +00:00
|
|
|
}
|
2014-01-31 18:53:37 +00:00
|
|
|
}
|
2010-06-23 19:46:08 +00:00
|
|
|
}
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
void
|
|
|
|
IDBTransaction::SendCommit()
|
2010-06-23 19:46:08 +00:00
|
|
|
{
|
2014-09-26 23:21:57 +00:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(NS_SUCCEEDED(mAbortCode));
|
2015-06-25 22:22:59 +00:00
|
|
|
MOZ_ASSERT(IsCommittingOrDone());
|
2014-09-26 23:21:57 +00:00
|
|
|
MOZ_ASSERT(!mSentCommitOrAbort);
|
2014-10-16 04:56:52 +00:00
|
|
|
MOZ_ASSERT(!mPendingRequestCount);
|
|
|
|
|
|
|
|
// 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();
|
|
|
|
|
|
|
|
IDB_LOG_MARK("IndexedDB %s: Child Transaction[%lld] Request[%llu]: "
|
|
|
|
"All requests complete, committing transaction",
|
|
|
|
"IndexedDB %s: C T[%lld] R[%llu]: IDBTransaction commit",
|
|
|
|
IDB_LOG_ID_STRING(),
|
|
|
|
LoggingSerialNumber(),
|
|
|
|
requestSerialNumber);
|
2013-03-16 06:58:50 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
if (mMode == VERSION_CHANGE) {
|
|
|
|
MOZ_ASSERT(mBackgroundActor.mVersionChangeBackgroundActor);
|
|
|
|
mBackgroundActor.mVersionChangeBackgroundActor->SendCommit();
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(mBackgroundActor.mNormalBackgroundActor);
|
|
|
|
mBackgroundActor.mNormalBackgroundActor->SendCommit();
|
2010-09-10 19:12:11 +00:00
|
|
|
}
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
mSentCommitOrAbort = true;
|
|
|
|
#endif
|
2010-06-23 19:46:08 +00:00
|
|
|
}
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
void
|
|
|
|
IDBTransaction::SendAbort(nsresult aResultCode)
|
2010-06-23 19:46:08 +00:00
|
|
|
{
|
2014-09-26 23:21:57 +00:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(NS_FAILED(aResultCode));
|
2015-06-25 22:22:59 +00:00
|
|
|
MOZ_ASSERT(IsCommittingOrDone());
|
2014-09-26 23:21:57 +00:00
|
|
|
MOZ_ASSERT(!mSentCommitOrAbort);
|
2010-06-23 19:46:08 +00:00
|
|
|
|
2014-10-16 04:56:52 +00: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();
|
|
|
|
|
|
|
|
IDB_LOG_MARK("IndexedDB %s: Child Transaction[%lld] Request[%llu]: "
|
|
|
|
"Aborting transaction with result 0x%x",
|
|
|
|
"IndexedDB %s: C T[%lld] R[%llu]: IDBTransaction abort (0x%x)",
|
|
|
|
IDB_LOG_ID_STRING(),
|
|
|
|
LoggingSerialNumber(),
|
|
|
|
requestSerialNumber,
|
|
|
|
aResultCode);
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
if (mMode == VERSION_CHANGE) {
|
|
|
|
MOZ_ASSERT(mBackgroundActor.mVersionChangeBackgroundActor);
|
|
|
|
mBackgroundActor.mVersionChangeBackgroundActor->SendAbort(aResultCode);
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(mBackgroundActor.mNormalBackgroundActor);
|
|
|
|
mBackgroundActor.mNormalBackgroundActor->SendAbort(aResultCode);
|
|
|
|
}
|
2010-06-23 19:46:08 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2014-09-26 23:21:57 +00:00
|
|
|
mSentCommitOrAbort = true;
|
2010-06-23 19:46:08 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2010-12-15 21:21:17 +00:00
|
|
|
IDBTransaction::IsOpen() const
|
2010-06-23 19:46:08 +00:00
|
|
|
{
|
2014-09-26 23:21:57 +00:00
|
|
|
AssertIsOnOwningThread();
|
2010-11-15 21:49:49 +00:00
|
|
|
|
|
|
|
// If we haven't started anything then we're open.
|
2012-03-13 04:44:45 +00:00
|
|
|
if (mReadyState == IDBTransaction::INITIAL) {
|
2010-11-15 21:49:49 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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 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.
|
2014-09-26 23:21:57 +00:00
|
|
|
if (mReadyState == IDBTransaction::LOADING &&
|
|
|
|
(mCreating || GetCurrent() == this)) {
|
|
|
|
return true;
|
2010-11-15 21:49:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2010-06-23 19:46:08 +00:00
|
|
|
}
|
|
|
|
|
2014-11-14 02:20:38 +00:00
|
|
|
void
|
2015-09-02 01:01:02 +00:00
|
|
|
IDBTransaction::GetCallerLocation(nsAString& aFilename, uint32_t* aLineNo,
|
|
|
|
uint32_t* aColumn) const
|
2014-11-14 02:20:38 +00:00
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(aLineNo);
|
2015-09-02 01:01:02 +00:00
|
|
|
MOZ_ASSERT(aColumn);
|
2014-11-14 02:20:38 +00:00
|
|
|
|
|
|
|
aFilename = mFilename;
|
|
|
|
*aLineNo = mLineNo;
|
2015-09-02 01:01:02 +00:00
|
|
|
*aColumn = mColumn;
|
2014-11-14 02:20:38 +00:00
|
|
|
}
|
|
|
|
|
2010-11-10 23:25:40 +00:00
|
|
|
already_AddRefed<IDBObjectStore>
|
2014-09-26 23:21:57 +00:00
|
|
|
IDBTransaction::CreateObjectStore(const ObjectStoreSpec& aSpec)
|
2010-11-10 23:25:40 +00:00
|
|
|
{
|
2014-09-26 23:21:57 +00:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(aSpec.metadata().id());
|
|
|
|
MOZ_ASSERT(VERSION_CHANGE == mMode);
|
|
|
|
MOZ_ASSERT(mBackgroundActor.mVersionChangeBackgroundActor);
|
|
|
|
MOZ_ASSERT(IsOpen());
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
{
|
|
|
|
const nsString& name = aSpec.metadata().name();
|
|
|
|
|
|
|
|
for (uint32_t count = mObjectStores.Length(), index = 0;
|
|
|
|
index < count;
|
|
|
|
index++) {
|
|
|
|
MOZ_ASSERT(mObjectStores[index]->Name() != name);
|
2010-11-10 23:25:40 +00:00
|
|
|
}
|
|
|
|
}
|
2014-09-26 23:21:57 +00:00
|
|
|
#endif
|
2010-11-10 23:25:40 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
MOZ_ALWAYS_TRUE(mBackgroundActor.mVersionChangeBackgroundActor->
|
|
|
|
SendCreateObjectStore(aSpec.metadata()));
|
2010-11-10 23:25:40 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<IDBObjectStore> objectStore = IDBObjectStore::Create(this, aSpec);
|
2014-09-26 23:21:57 +00:00
|
|
|
MOZ_ASSERT(objectStore);
|
2010-11-10 23:25:40 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
mObjectStores.AppendElement(objectStore);
|
|
|
|
|
|
|
|
return objectStore.forget();
|
2010-11-10 23:25:40 +00:00
|
|
|
}
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
void
|
|
|
|
IDBTransaction::DeleteObjectStore(int64_t aObjectStoreId)
|
2012-06-03 16:33:52 +00:00
|
|
|
{
|
2014-09-26 23:21:57 +00:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(aObjectStoreId);
|
|
|
|
MOZ_ASSERT(VERSION_CHANGE == mMode);
|
|
|
|
MOZ_ASSERT(mBackgroundActor.mVersionChangeBackgroundActor);
|
|
|
|
MOZ_ASSERT(IsOpen());
|
|
|
|
|
|
|
|
MOZ_ALWAYS_TRUE(mBackgroundActor.mVersionChangeBackgroundActor->
|
|
|
|
SendDeleteObjectStore(aObjectStoreId));
|
|
|
|
|
|
|
|
for (uint32_t count = mObjectStores.Length(), index = 0;
|
|
|
|
index < count;
|
|
|
|
index++) {
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<IDBObjectStore>& objectStore = mObjectStores[index];
|
2014-09-26 23:21:57 +00:00
|
|
|
|
|
|
|
if (objectStore->Id() == aObjectStoreId) {
|
|
|
|
objectStore->NoteDeletion();
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<IDBObjectStore>* deletedObjectStore =
|
2014-09-26 23:21:57 +00:00
|
|
|
mDeletedObjectStores.AppendElement();
|
|
|
|
deletedObjectStore->swap(mObjectStores[index]);
|
|
|
|
|
|
|
|
mObjectStores.RemoveElementAt(index);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-06-03 16:33:52 +00:00
|
|
|
}
|
|
|
|
|
2016-03-30 03:04:56 +00:00
|
|
|
void
|
|
|
|
IDBTransaction::RenameObjectStore(int64_t aObjectStoreId,
|
|
|
|
const nsAString& aName)
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(aObjectStoreId);
|
|
|
|
MOZ_ASSERT(VERSION_CHANGE == mMode);
|
|
|
|
MOZ_ASSERT(mBackgroundActor.mVersionChangeBackgroundActor);
|
|
|
|
MOZ_ASSERT(IsOpen());
|
|
|
|
|
|
|
|
MOZ_ALWAYS_TRUE(mBackgroundActor.mVersionChangeBackgroundActor->
|
|
|
|
SendRenameObjectStore(aObjectStoreId, nsString(aName)));
|
|
|
|
}
|
|
|
|
|
2011-12-16 07:34:24 +00:00
|
|
|
void
|
2014-09-26 23:21:57 +00:00
|
|
|
IDBTransaction::CreateIndex(IDBObjectStore* aObjectStore,
|
2016-02-16 21:46:08 +00:00
|
|
|
const indexedDB::IndexMetadata& aMetadata)
|
2011-12-16 07:34:24 +00:00
|
|
|
{
|
2014-09-26 23:21:57 +00:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(aObjectStore);
|
|
|
|
MOZ_ASSERT(aMetadata.id());
|
|
|
|
MOZ_ASSERT(VERSION_CHANGE == mMode);
|
|
|
|
MOZ_ASSERT(mBackgroundActor.mVersionChangeBackgroundActor);
|
|
|
|
MOZ_ASSERT(IsOpen());
|
|
|
|
|
|
|
|
MOZ_ALWAYS_TRUE(mBackgroundActor.mVersionChangeBackgroundActor->
|
|
|
|
SendCreateIndex(aObjectStore->Id(), aMetadata));
|
2011-12-16 07:34:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-09-26 23:21:57 +00:00
|
|
|
IDBTransaction::DeleteIndex(IDBObjectStore* aObjectStore,
|
|
|
|
int64_t aIndexId)
|
2011-12-16 07:34:24 +00:00
|
|
|
{
|
2014-09-26 23:21:57 +00:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(aObjectStore);
|
|
|
|
MOZ_ASSERT(aIndexId);
|
|
|
|
MOZ_ASSERT(VERSION_CHANGE == mMode);
|
|
|
|
MOZ_ASSERT(mBackgroundActor.mVersionChangeBackgroundActor);
|
|
|
|
MOZ_ASSERT(IsOpen());
|
|
|
|
|
|
|
|
MOZ_ALWAYS_TRUE(mBackgroundActor.mVersionChangeBackgroundActor->
|
|
|
|
SendDeleteIndex(aObjectStore->Id(), aIndexId));
|
2011-12-16 07:34:24 +00:00
|
|
|
}
|
|
|
|
|
2016-03-30 03:04:56 +00:00
|
|
|
void
|
|
|
|
IDBTransaction::RenameIndex(IDBObjectStore* aObjectStore,
|
|
|
|
int64_t aIndexId,
|
|
|
|
const nsAString& aName)
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(aObjectStore);
|
|
|
|
MOZ_ASSERT(aIndexId);
|
|
|
|
MOZ_ASSERT(VERSION_CHANGE == mMode);
|
|
|
|
MOZ_ASSERT(mBackgroundActor.mVersionChangeBackgroundActor);
|
|
|
|
MOZ_ASSERT(IsOpen());
|
|
|
|
|
|
|
|
MOZ_ALWAYS_TRUE(mBackgroundActor.mVersionChangeBackgroundActor->
|
|
|
|
SendRenameIndex(aObjectStore->Id(),
|
|
|
|
aIndexId,
|
|
|
|
nsString(aName)));
|
|
|
|
}
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
void
|
2012-06-29 16:48:34 +00:00
|
|
|
IDBTransaction::AbortInternal(nsresult aAbortCode,
|
2013-05-18 17:52:06 +00:00
|
|
|
already_AddRefed<DOMError> aError)
|
2012-06-01 17:21:12 +00:00
|
|
|
{
|
2014-09-26 23:21:57 +00:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(NS_FAILED(aAbortCode));
|
2015-06-25 22:22:59 +00:00
|
|
|
MOZ_ASSERT(!IsCommittingOrDone());
|
2012-06-01 17:21:12 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<DOMError> error = aError;
|
2012-06-29 16:48:34 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
const bool isVersionChange = mMode == VERSION_CHANGE;
|
|
|
|
const bool isInvalidated = mDatabase->IsInvalidated();
|
|
|
|
bool needToSendAbort = mReadyState == INITIAL && !isInvalidated;
|
2014-09-17 23:36:01 +00:00
|
|
|
|
2012-06-01 17:21:12 +00:00
|
|
|
mAbortCode = aAbortCode;
|
2014-09-26 23:21:57 +00:00
|
|
|
mReadyState = DONE;
|
2012-06-29 16:48:34 +00:00
|
|
|
mError = error.forget();
|
2012-06-01 17:21:12 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
if (isVersionChange) {
|
2012-06-29 16:48:34 +00:00
|
|
|
// If a version change transaction is aborted, we must revert the world
|
2014-09-26 23:21:57 +00:00
|
|
|
// back to its previous state unless we're being invalidated after the
|
|
|
|
// transaction already completed.
|
|
|
|
if (!isInvalidated) {
|
|
|
|
mDatabase->RevertToPreviousState();
|
|
|
|
}
|
2012-06-29 16:48:34 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
const nsTArray<ObjectStoreSpec>& specArray =
|
|
|
|
mDatabase->Spec()->objectStores();
|
2012-06-29 16:48:34 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
if (specArray.IsEmpty()) {
|
|
|
|
mObjectStores.Clear();
|
|
|
|
mDeletedObjectStores.Clear();
|
|
|
|
} else {
|
|
|
|
nsTHashtable<nsUint64HashKey> validIds(specArray.Length());
|
2012-06-29 16:48:34 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
for (uint32_t specCount = specArray.Length(), specIndex = 0;
|
|
|
|
specIndex < specCount;
|
|
|
|
specIndex++) {
|
|
|
|
const int64_t objectStoreId = specArray[specIndex].metadata().id();
|
|
|
|
MOZ_ASSERT(objectStoreId);
|
2012-06-29 16:48:34 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
validIds.PutEntry(uint64_t(objectStoreId));
|
|
|
|
}
|
2014-09-17 23:36:01 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
for (uint32_t objCount = mObjectStores.Length(), objIndex = 0;
|
|
|
|
objIndex < objCount;
|
|
|
|
/* incremented conditionally */) {
|
|
|
|
const int64_t objectStoreId = mObjectStores[objIndex]->Id();
|
|
|
|
MOZ_ASSERT(objectStoreId);
|
|
|
|
|
|
|
|
if (validIds.Contains(uint64_t(objectStoreId))) {
|
|
|
|
objIndex++;
|
|
|
|
} else {
|
|
|
|
mObjectStores.RemoveElementAt(objIndex);
|
|
|
|
objCount--;
|
|
|
|
}
|
2014-09-13 16:12:19 +00:00
|
|
|
}
|
2014-09-17 23:36:01 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
if (!mDeletedObjectStores.IsEmpty()) {
|
|
|
|
for (uint32_t objCount = mDeletedObjectStores.Length(), objIndex = 0;
|
|
|
|
objIndex < objCount;
|
|
|
|
objIndex++) {
|
|
|
|
const int64_t objectStoreId = mDeletedObjectStores[objIndex]->Id();
|
|
|
|
MOZ_ASSERT(objectStoreId);
|
|
|
|
|
|
|
|
if (validIds.Contains(uint64_t(objectStoreId))) {
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<IDBObjectStore>* objectStore =
|
2014-09-26 23:21:57 +00:00
|
|
|
mObjectStores.AppendElement();
|
|
|
|
objectStore->swap(mDeletedObjectStores[objIndex]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mDeletedObjectStores.Clear();
|
|
|
|
}
|
2012-06-29 16:48:34 +00:00
|
|
|
}
|
2012-06-01 17:21:12 +00: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-26 23:21:57 +00:00
|
|
|
if (needToSendAbort) {
|
|
|
|
SendAbort(aAbortCode);
|
2012-06-01 17:21:12 +00:00
|
|
|
}
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
if (isVersionChange) {
|
|
|
|
mDatabase->Close();
|
|
|
|
}
|
2012-06-01 17:21:12 +00:00
|
|
|
}
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
void
|
2012-06-25 19:15:17 +00:00
|
|
|
IDBTransaction::Abort(IDBRequest* aRequest)
|
|
|
|
{
|
2014-09-26 23:21:57 +00:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(aRequest);
|
2012-06-25 19:15:17 +00:00
|
|
|
|
2015-06-25 22:22:59 +00:00
|
|
|
if (IsCommittingOrDone()) {
|
|
|
|
// Already started (and maybe finished) the commit or abort so there is
|
|
|
|
// nothing to do here.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-05-18 17:52:06 +00:00
|
|
|
ErrorResult rv;
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<DOMError> error = aRequest->GetError(rv);
|
2012-06-29 16:48:34 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
AbortInternal(aRequest->GetErrorCode(), error.forget());
|
2012-06-29 16:48:34 +00:00
|
|
|
}
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
void
|
2012-06-29 16:48:34 +00:00
|
|
|
IDBTransaction::Abort(nsresult aErrorCode)
|
|
|
|
{
|
2014-09-26 23:21:57 +00:00
|
|
|
AssertIsOnOwningThread();
|
2012-06-25 19:15:17 +00:00
|
|
|
|
2015-06-25 22:22:59 +00:00
|
|
|
if (IsCommittingOrDone()) {
|
|
|
|
// Already started (and maybe finished) the commit or abort so there is
|
|
|
|
// nothing to do here.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<DOMError> error = new DOMError(GetOwner(), aErrorCode);
|
2014-09-26 23:21:57 +00:00
|
|
|
AbortInternal(aErrorCode, error.forget());
|
2012-06-25 19:15:17 +00:00
|
|
|
}
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
void
|
|
|
|
IDBTransaction::Abort(ErrorResult& aRv)
|
2014-09-17 23:36:01 +00:00
|
|
|
{
|
2014-09-26 23:21:57 +00:00
|
|
|
AssertIsOnOwningThread();
|
2011-10-20 16:10:56 +00:00
|
|
|
|
2015-06-25 22:22:59 +00:00
|
|
|
if (IsCommittingOrDone()) {
|
2014-09-26 23:21:57 +00:00
|
|
|
aRv = NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR;
|
|
|
|
return;
|
2014-09-17 23:36:01 +00:00
|
|
|
}
|
2011-12-17 00:40:47 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
AbortInternal(NS_ERROR_DOM_INDEXEDDB_ABORT_ERR, nullptr);
|
2011-12-16 07:34:24 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
MOZ_ASSERT(!mAbortedByScript);
|
|
|
|
mAbortedByScript = true;
|
2011-12-16 07:34:24 +00:00
|
|
|
}
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
void
|
|
|
|
IDBTransaction::FireCompleteOrAbortEvents(nsresult aResult)
|
2012-08-24 18:51:33 +00:00
|
|
|
{
|
2014-09-26 23:21:57 +00:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(!mFiredCompleteOrAbort);
|
2012-08-24 18:51:33 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
mReadyState = DONE;
|
2014-09-17 23:36:01 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2014-09-26 23:21:57 +00:00
|
|
|
mFiredCompleteOrAbort = true;
|
2014-09-17 23:36:01 +00:00
|
|
|
#endif
|
|
|
|
|
2016-06-23 08:53:14 +00:00
|
|
|
// Make sure we drop the WorkerHolder when this function completes.
|
|
|
|
nsAutoPtr<WorkerHolder> workerHolder = Move(mWorkerHolder);
|
2014-12-17 06:26:15 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
nsCOMPtr<nsIDOMEvent> event;
|
|
|
|
if (NS_SUCCEEDED(aResult)) {
|
|
|
|
event = CreateGenericEvent(this,
|
|
|
|
nsDependentString(kCompleteEventType),
|
|
|
|
eDoesNotBubble,
|
|
|
|
eNotCancelable);
|
2014-12-17 06:26:15 +00:00
|
|
|
MOZ_ASSERT(event);
|
2014-09-26 23:21:57 +00:00
|
|
|
} else {
|
2016-04-21 04:53:30 +00:00
|
|
|
if (aResult == NS_ERROR_DOM_INDEXEDDB_QUOTA_ERR) {
|
|
|
|
mDatabase->SetQuotaExceeded();
|
|
|
|
}
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
if (!mError && !mAbortedByScript) {
|
|
|
|
mError = new DOMError(GetOwner(), aResult);
|
2014-09-17 23:36:01 +00:00
|
|
|
}
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
event = CreateGenericEvent(this,
|
|
|
|
nsDependentString(kAbortEventType),
|
|
|
|
eDoesBubble,
|
|
|
|
eNotCancelable);
|
2014-12-17 06:26:15 +00:00
|
|
|
MOZ_ASSERT(event);
|
2014-09-17 23:36:01 +00:00
|
|
|
}
|
|
|
|
|
2014-10-16 04:56:52 +00:00
|
|
|
if (NS_SUCCEEDED(mAbortCode)) {
|
|
|
|
IDB_LOG_MARK("IndexedDB %s: Child Transaction[%lld]: "
|
|
|
|
"Firing 'complete' event",
|
|
|
|
"IndexedDB %s: C T[%lld]: IDBTransaction 'complete' event",
|
|
|
|
IDB_LOG_ID_STRING(),
|
|
|
|
mLoggingSerialNumber);
|
|
|
|
} else {
|
|
|
|
IDB_LOG_MARK("IndexedDB %s: Child Transaction[%lld]: "
|
|
|
|
"Firing 'abort' event with error 0x%x",
|
|
|
|
"IndexedDB %s: C T[%lld]: IDBTransaction 'abort' event (0x%x)",
|
|
|
|
IDB_LOG_ID_STRING(),
|
|
|
|
mLoggingSerialNumber,
|
|
|
|
mAbortCode);
|
|
|
|
}
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
bool dummy;
|
|
|
|
if (NS_FAILED(DispatchEvent(event, &dummy))) {
|
|
|
|
NS_WARNING("DispatchEvent failed!");
|
2014-09-13 16:12:19 +00:00
|
|
|
}
|
2014-09-17 23:36:01 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
mDatabase->DelayedMaybeExpireFileActors();
|
2012-08-24 18:51:33 +00:00
|
|
|
}
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
int64_t
|
|
|
|
IDBTransaction::NextObjectStoreId()
|
2012-08-24 18:51:33 +00:00
|
|
|
{
|
2014-09-26 23:21:57 +00:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(VERSION_CHANGE == mMode);
|
2012-08-24 18:51:33 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
return mNextObjectStoreId++;
|
2012-08-24 18:51:33 +00:00
|
|
|
}
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
int64_t
|
|
|
|
IDBTransaction::NextIndexId()
|
2012-08-24 18:51:33 +00:00
|
|
|
{
|
2014-09-26 23:21:57 +00:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(VERSION_CHANGE == mMode);
|
2012-08-24 18:51:33 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
return mNextIndexId++;
|
2014-09-17 23:36:01 +00:00
|
|
|
}
|
2011-12-16 07:34:24 +00:00
|
|
|
|
2016-01-30 17:05:36 +00:00
|
|
|
nsPIDOMWindowInner*
|
2014-09-26 23:21:57 +00:00
|
|
|
IDBTransaction::GetParentObject() const
|
2014-09-17 23:36:01 +00:00
|
|
|
{
|
2014-09-26 23:21:57 +00:00
|
|
|
AssertIsOnOwningThread();
|
2014-09-17 23:36:01 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
return mDatabase->GetParentObject();
|
2014-09-13 16:12:19 +00:00
|
|
|
}
|
2011-12-16 07:34:24 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
IDBTransactionMode
|
|
|
|
IDBTransaction::GetMode(ErrorResult& aRv) const
|
2014-09-13 16:12:19 +00:00
|
|
|
{
|
2014-09-26 23:21:57 +00:00
|
|
|
AssertIsOnOwningThread();
|
2011-12-16 07:34:24 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
switch (mMode) {
|
|
|
|
case READ_ONLY:
|
|
|
|
return IDBTransactionMode::Readonly;
|
2014-09-17 23:36:01 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
case READ_WRITE:
|
|
|
|
return IDBTransactionMode::Readwrite;
|
2014-09-17 23:36:01 +00:00
|
|
|
|
2015-01-26 06:30:09 +00:00
|
|
|
case READ_WRITE_FLUSH:
|
|
|
|
return IDBTransactionMode::Readwriteflush;
|
|
|
|
|
2016-03-15 06:00:37 +00:00
|
|
|
case CLEANUP:
|
|
|
|
return IDBTransactionMode::Cleanup;
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
case VERSION_CHANGE:
|
|
|
|
return IDBTransactionMode::Versionchange;
|
2014-09-17 23:36:01 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
case MODE_INVALID:
|
|
|
|
default:
|
|
|
|
MOZ_CRASH("Bad mode!");
|
|
|
|
}
|
2014-09-17 23:36:01 +00:00
|
|
|
}
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
DOMError*
|
|
|
|
IDBTransaction::GetError() const
|
2014-09-17 23:36:01 +00:00
|
|
|
{
|
2014-09-26 23:21:57 +00:00
|
|
|
AssertIsOnOwningThread();
|
2014-09-17 23:36:01 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
return mError;
|
2014-09-17 23:36:01 +00:00
|
|
|
}
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
already_AddRefed<DOMStringList>
|
2015-08-25 20:30:18 +00:00
|
|
|
IDBTransaction::ObjectStoreNames() const
|
2014-09-17 23:36:01 +00:00
|
|
|
{
|
2014-09-26 23:21:57 +00:00
|
|
|
AssertIsOnOwningThread();
|
2014-09-17 23:36:01 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
if (mMode == IDBTransaction::VERSION_CHANGE) {
|
|
|
|
return mDatabase->ObjectStoreNames();
|
2014-09-13 16:12:19 +00:00
|
|
|
}
|
2011-12-16 07:34:24 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<DOMStringList> list = new DOMStringList();
|
2014-09-26 23:21:57 +00:00
|
|
|
list->StringArray() = mObjectStoreNames;
|
|
|
|
return list.forget();
|
|
|
|
}
|
2014-09-17 23:36:01 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
already_AddRefed<IDBObjectStore>
|
|
|
|
IDBTransaction::ObjectStore(const nsAString& aName, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
2014-09-17 23:36:01 +00:00
|
|
|
|
2015-06-25 22:22:59 +00:00
|
|
|
if (IsCommittingOrDone()) {
|
2014-09-26 23:21:57 +00:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-09-17 23:36:01 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
const ObjectStoreSpec* spec = nullptr;
|
2014-09-17 23:36:01 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
if (IDBTransaction::VERSION_CHANGE == mMode ||
|
|
|
|
mObjectStoreNames.Contains(aName)) {
|
|
|
|
const nsTArray<ObjectStoreSpec>& objectStores =
|
|
|
|
mDatabase->Spec()->objectStores();
|
|
|
|
|
|
|
|
for (uint32_t count = objectStores.Length(), index = 0;
|
|
|
|
index < count;
|
|
|
|
index++) {
|
|
|
|
const ObjectStoreSpec& objectStore = objectStores[index];
|
|
|
|
if (objectStore.metadata().name() == aName) {
|
|
|
|
spec = &objectStore;
|
2014-09-17 23:36:01 +00:00
|
|
|
break;
|
2014-09-26 23:21:57 +00:00
|
|
|
}
|
2011-12-16 07:34:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
if (!spec) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_NOT_FOUND_ERR);
|
|
|
|
return nullptr;
|
2012-08-24 18:51:33 +00:00
|
|
|
}
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
const int64_t desiredId = spec->metadata().id();
|
2011-12-16 07:34:24 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<IDBObjectStore> objectStore;
|
2014-09-17 23:36:01 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
for (uint32_t count = mObjectStores.Length(), index = 0;
|
|
|
|
index < count;
|
|
|
|
index++) {
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<IDBObjectStore>& existingObjectStore = mObjectStores[index];
|
2014-09-17 23:36:01 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
if (existingObjectStore->Id() == desiredId) {
|
|
|
|
objectStore = existingObjectStore;
|
|
|
|
break;
|
2014-09-17 23:36:01 +00:00
|
|
|
}
|
2011-12-16 07:34:24 +00:00
|
|
|
}
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
if (!objectStore) {
|
|
|
|
objectStore = IDBObjectStore::Create(this, *spec);
|
|
|
|
MOZ_ASSERT(objectStore);
|
2011-12-16 07:34:24 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
mObjectStores.AppendElement(objectStore);
|
2014-09-17 23:36:01 +00:00
|
|
|
}
|
2014-01-31 18:53:37 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
return objectStore.forget();
|
2014-09-17 23:36:01 +00:00
|
|
|
}
|
2014-01-31 18:53:37 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
NS_IMPL_ADDREF_INHERITED(IDBTransaction, IDBWrapperCache)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(IDBTransaction, IDBWrapperCache)
|
2014-09-13 16:12:19 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(IDBTransaction)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIRunnable)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(IDBWrapperCache)
|
2014-09-17 23:36:01 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(IDBTransaction)
|
2011-12-16 07:34:24 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(IDBTransaction,
|
|
|
|
IDBWrapperCache)
|
|
|
|
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 07:34:24 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(IDBTransaction, IDBWrapperCache)
|
|
|
|
// 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
|
|
|
|
|
|
|
|
JSObject*
|
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 14:13:33 +00:00
|
|
|
IDBTransaction::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2011-12-16 07:34:24 +00:00
|
|
|
{
|
2014-09-26 23:21:57 +00:00
|
|
|
AssertIsOnOwningThread();
|
2011-12-16 07:34:24 +00:00
|
|
|
|
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 14:13:33 +00:00
|
|
|
return IDBTransactionBinding::Wrap(aCx, this, aGivenProto);
|
2014-09-13 16:12:19 +00:00
|
|
|
}
|
2012-08-24 18:51:33 +00:00
|
|
|
|
2014-09-17 23:36:01 +00:00
|
|
|
nsresult
|
2014-09-26 23:21:57 +00:00
|
|
|
IDBTransaction::PreHandleEvent(EventChainPreVisitor& aVisitor)
|
2014-09-13 16:12:19 +00:00
|
|
|
{
|
2014-09-26 23:21:57 +00:00
|
|
|
AssertIsOnOwningThread();
|
2014-09-17 23:36:01 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
aVisitor.mCanHandle = true;
|
|
|
|
aVisitor.mParentTarget = mDatabase;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2014-09-17 23:36:01 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
IDBTransaction::Run()
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
2014-09-17 23:36:01 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
// We're back at the event loop, no longer newborn.
|
|
|
|
mCreating = false;
|
2014-09-17 23:36:01 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
// Maybe commit if there were no requests generated.
|
|
|
|
if (mReadyState == IDBTransaction::INITIAL) {
|
|
|
|
mReadyState = DONE;
|
2014-09-17 23:36:01 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
SendCommit();
|
2011-12-16 07:34:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2014-09-26 23:21:57 +00:00
|
|
|
|
2014-12-17 06:26:15 +00:00
|
|
|
bool
|
|
|
|
IDBTransaction::
|
2016-06-23 08:53:14 +00:00
|
|
|
WorkerHolder::Notify(Status aStatus)
|
2014-12-17 06:26:15 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(mWorkerPrivate);
|
|
|
|
mWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
|
MOZ_ASSERT(aStatus > Running);
|
|
|
|
|
|
|
|
if (mTransaction && aStatus > Terminating) {
|
|
|
|
mTransaction->AssertIsOnOwningThread();
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<IDBTransaction> transaction = Move(mTransaction);
|
2014-12-17 06:26:15 +00:00
|
|
|
|
2015-06-25 22:22:59 +00:00
|
|
|
if (!transaction->IsCommittingOrDone()) {
|
|
|
|
IDB_REPORT_INTERNAL_ERR();
|
|
|
|
transaction->AbortInternal(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR, nullptr);
|
|
|
|
}
|
2014-12-17 06:26:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|