2010-06-23 12:46:08 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2015-05-03 12:32:37 -07:00
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 04:12:37 -07: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 12:46:08 -07:00
|
|
|
|
2010-06-28 11:51:06 -07:00
|
|
|
#include "IDBIndex.h"
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
#include "FileInfo.h"
|
2010-06-28 11:51:06 -07:00
|
|
|
#include "IDBCursor.h"
|
2010-06-23 12:46:08 -07:00
|
|
|
#include "IDBEvents.h"
|
2011-11-03 08:57:30 -07:00
|
|
|
#include "IDBKeyRange.h"
|
2010-06-28 11:51:06 -07:00
|
|
|
#include "IDBObjectStore.h"
|
2014-09-26 16:21:57 -07:00
|
|
|
#include "IDBRequest.h"
|
2010-06-28 09:46:21 -07:00
|
|
|
#include "IDBTransaction.h"
|
2014-09-26 16:21:57 -07:00
|
|
|
#include "IndexedDatabase.h"
|
|
|
|
#include "IndexedDatabaseInlines.h"
|
|
|
|
#include "mozilla/ErrorResult.h"
|
|
|
|
#include "mozilla/dom/indexedDB/PBackgroundIDBSharedTypes.h"
|
2013-03-15 23:58:50 -07:00
|
|
|
#include "ProfilerHelpers.h"
|
2014-01-27 16:37:05 -08:00
|
|
|
#include "ReportInternalError.h"
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
// Include this last to avoid path problems on Windows.
|
|
|
|
#include "ActorsChild.h"
|
2012-06-01 10:21:12 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
namespace indexedDB {
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
already_AddRefed<IDBRequest>
|
|
|
|
GenerateRequest(IDBIndex* aIndex)
|
2012-06-01 10:21:12 -07:00
|
|
|
{
|
2014-09-26 16:21:57 -07:00
|
|
|
MOZ_ASSERT(aIndex);
|
|
|
|
aIndex->AssertIsOnOwningThread();
|
2012-06-01 10:21:12 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
IDBTransaction* transaction = aIndex->ObjectStore()->Transaction();
|
2012-06-01 10:21:12 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
nsRefPtr<IDBRequest> request =
|
|
|
|
IDBRequest::Create(aIndex, transaction->Database(), transaction);
|
|
|
|
MOZ_ASSERT(request);
|
2012-06-01 10:21:12 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
return request.forget();
|
|
|
|
}
|
2012-06-01 10:21:12 -07:00
|
|
|
|
2015-07-13 08:25:42 -07:00
|
|
|
} // namespace
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
IDBIndex::IDBIndex(IDBObjectStore* aObjectStore, const IndexMetadata* aMetadata)
|
|
|
|
: mObjectStore(aObjectStore)
|
2015-01-13 23:59:06 -08:00
|
|
|
, mCachedKeyPath(JS::UndefinedValue())
|
2014-09-26 16:21:57 -07:00
|
|
|
, mMetadata(aMetadata)
|
|
|
|
, mId(aMetadata->id())
|
|
|
|
, mRooted(false)
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
2014-09-26 16:21:57 -07:00
|
|
|
MOZ_ASSERT(aObjectStore);
|
|
|
|
aObjectStore->AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(aMetadata);
|
|
|
|
}
|
2014-09-17 16:36:01 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
IDBIndex::~IDBIndex()
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
2014-09-26 16:21:57 -07:00
|
|
|
AssertIsOnOwningThread();
|
2012-06-01 10:21:12 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
if (mRooted) {
|
2015-01-13 23:59:06 -08:00
|
|
|
mCachedKeyPath.setUndefined();
|
2014-09-26 16:21:57 -07:00
|
|
|
mozilla::DropJSObjects(this);
|
|
|
|
}
|
|
|
|
}
|
2014-09-17 16:36:01 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
already_AddRefed<IDBIndex>
|
|
|
|
IDBIndex::Create(IDBObjectStore* aObjectStore,
|
|
|
|
const IndexMetadata& aMetadata)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aObjectStore);
|
|
|
|
aObjectStore->AssertIsOnOwningThread();
|
2014-09-17 16:36:01 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
nsRefPtr<IDBIndex> index = new IDBIndex(aObjectStore, &aMetadata);
|
2014-09-17 16:36:01 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
return index.forget();
|
|
|
|
}
|
2014-09-17 16:36:01 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
#ifdef DEBUG
|
2014-09-17 16:36:01 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
void
|
|
|
|
IDBIndex::AssertIsOnOwningThread() const
|
2014-09-13 09:12:19 -07:00
|
|
|
{
|
2014-09-26 16:21:57 -07:00
|
|
|
MOZ_ASSERT(mObjectStore);
|
|
|
|
mObjectStore->AssertIsOnOwningThread();
|
|
|
|
}
|
2012-06-01 10:21:12 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
#endif // DEBUG
|
2012-06-01 10:21:12 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
void
|
|
|
|
IDBIndex::RefreshMetadata(bool aMayDelete)
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT_IF(mDeletedMetadata, mMetadata == mDeletedMetadata);
|
2012-06-01 10:21:12 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
const nsTArray<IndexMetadata>& indexes = mObjectStore->Spec().indexes();
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
bool found = false;
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
for (uint32_t count = indexes.Length(), index = 0;
|
|
|
|
index < count;
|
|
|
|
index++) {
|
|
|
|
const IndexMetadata& metadata = indexes[index];
|
2014-09-17 16:36:01 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
if (metadata.id() == Id()) {
|
|
|
|
mMetadata = &metadata;
|
2014-09-17 16:36:01 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
found = true;
|
|
|
|
break;
|
2011-01-26 17:53:02 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
MOZ_ASSERT_IF(!aMayDelete && !mDeletedMetadata, found);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
if (found) {
|
|
|
|
MOZ_ASSERT(mMetadata != mDeletedMetadata);
|
|
|
|
mDeletedMetadata = nullptr;
|
|
|
|
} else {
|
|
|
|
NoteDeletion();
|
2014-09-17 16:36:01 -07:00
|
|
|
}
|
2014-09-26 16:21:57 -07:00
|
|
|
}
|
2012-06-01 10:21:12 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
void
|
|
|
|
IDBIndex::NoteDeletion()
|
2014-09-13 09:12:19 -07:00
|
|
|
{
|
2014-09-26 16:21:57 -07:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mMetadata);
|
|
|
|
MOZ_ASSERT(Id() == mMetadata->id());
|
2012-06-01 10:21:12 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
if (mDeletedMetadata) {
|
|
|
|
MOZ_ASSERT(mMetadata == mDeletedMetadata);
|
|
|
|
return;
|
|
|
|
}
|
2014-09-17 16:36:01 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
mDeletedMetadata = new IndexMetadata(*mMetadata);
|
2014-09-17 16:36:01 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
mMetadata = mDeletedMetadata;
|
|
|
|
}
|
2014-09-17 16:36:01 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
const nsString&
|
|
|
|
IDBIndex::Name() const
|
2014-09-13 09:12:19 -07:00
|
|
|
{
|
2014-09-26 16:21:57 -07:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mMetadata);
|
2012-06-01 10:21:12 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
return mMetadata->name();
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
bool
|
|
|
|
IDBIndex::Unique() const
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
2014-09-26 16:21:57 -07:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mMetadata);
|
2013-07-31 08:48:40 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
return mMetadata->unique();
|
|
|
|
}
|
2014-09-17 16:36:01 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
bool
|
|
|
|
IDBIndex::MultiEntry() const
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mMetadata);
|
2014-09-17 16:36:01 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
return mMetadata->multiEntry();
|
|
|
|
}
|
2014-09-17 16:36:01 -07:00
|
|
|
|
2015-09-04 12:12:29 -07:00
|
|
|
bool
|
|
|
|
IDBIndex::LocaleAware() const
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mMetadata);
|
|
|
|
|
|
|
|
return mMetadata->locale().IsEmpty();
|
|
|
|
}
|
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
const KeyPath&
|
|
|
|
IDBIndex::GetKeyPath() const
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mMetadata);
|
2014-09-17 16:36:01 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
return mMetadata->keyPath();
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2015-09-04 12:12:29 -07:00
|
|
|
void
|
|
|
|
IDBIndex::GetLocale(nsString& aLocale) const
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mMetadata);
|
|
|
|
|
|
|
|
if (mMetadata->locale().IsEmpty()) {
|
|
|
|
SetDOMStringToNull(aLocale);
|
|
|
|
} else {
|
|
|
|
aLocale.AssignWithConversion(mMetadata->locale());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsCString&
|
|
|
|
IDBIndex::Locale() const
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mMetadata);
|
|
|
|
|
|
|
|
return mMetadata->locale();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
IDBIndex::IsAutoLocale() const
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mMetadata);
|
|
|
|
|
|
|
|
return mMetadata->autoLocale();
|
|
|
|
}
|
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
nsPIDOMWindow*
|
|
|
|
IDBIndex::GetParentObject() const
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
2014-09-26 16:21:57 -07:00
|
|
|
AssertIsOnOwningThread();
|
2012-06-22 14:00:53 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
return mObjectStore->GetParentObject();
|
2014-09-17 16:36:01 -07:00
|
|
|
}
|
2014-09-13 09:12:19 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
void
|
|
|
|
IDBIndex::GetKeyPath(JSContext* aCx,
|
|
|
|
JS::MutableHandle<JS::Value> aResult,
|
|
|
|
ErrorResult& aRv)
|
2014-09-17 16:36:01 -07:00
|
|
|
{
|
2014-09-26 16:21:57 -07:00
|
|
|
AssertIsOnOwningThread();
|
2014-09-13 09:12:19 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
if (!mCachedKeyPath.isUndefined()) {
|
|
|
|
MOZ_ASSERT(mRooted);
|
|
|
|
JS::ExposeValueToActiveJS(mCachedKeyPath);
|
|
|
|
aResult.set(mCachedKeyPath);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(!mRooted);
|
|
|
|
|
|
|
|
aRv = GetKeyPath().ToJSVal(aCx, mCachedKeyPath);
|
|
|
|
if (NS_WARN_IF(aRv.Failed())) {
|
|
|
|
return;
|
2012-06-22 14:00:53 -07:00
|
|
|
}
|
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
if (mCachedKeyPath.isGCThing()) {
|
|
|
|
mozilla::HoldJSObjects(this);
|
|
|
|
mRooted = true;
|
2012-06-01 10:21:12 -07:00
|
|
|
}
|
2014-09-26 16:21:57 -07:00
|
|
|
|
|
|
|
JS::ExposeValueToActiveJS(mCachedKeyPath);
|
|
|
|
aResult.set(mCachedKeyPath);
|
2012-06-01 10:21:12 -07:00
|
|
|
}
|
|
|
|
|
2013-07-31 08:48:40 -07:00
|
|
|
already_AddRefed<IDBRequest>
|
2014-09-26 16:21:57 -07:00
|
|
|
IDBIndex::GetInternal(bool aKeyOnly,
|
|
|
|
JSContext* aCx,
|
|
|
|
JS::Handle<JS::Value> aKey,
|
|
|
|
ErrorResult& aRv)
|
2012-06-01 10:21:12 -07:00
|
|
|
{
|
2014-09-26 16:21:57 -07:00
|
|
|
AssertIsOnOwningThread();
|
2012-06-01 10:21:12 -07:00
|
|
|
|
2015-06-20 09:08:23 -07:00
|
|
|
if (mDeletedMetadata) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
IDBTransaction* transaction = mObjectStore->Transaction();
|
|
|
|
if (!transaction->IsOpen()) {
|
2013-07-31 08:48:40 -07:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_TRANSACTION_INACTIVE_ERR);
|
|
|
|
return nullptr;
|
2012-06-01 10:21:12 -07:00
|
|
|
}
|
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
nsRefPtr<IDBKeyRange> keyRange;
|
|
|
|
aRv = IDBKeyRange::FromJSVal(aCx, aKey, getter_AddRefs(keyRange));
|
|
|
|
if (NS_WARN_IF(aRv.Failed())) {
|
2013-07-31 08:48:40 -07:00
|
|
|
return nullptr;
|
|
|
|
}
|
2012-06-01 10:21:12 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
if (!keyRange) {
|
|
|
|
// Must specify a key or keyRange for get() and getKey().
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_DATA_ERR);
|
2013-07-31 08:48:40 -07:00
|
|
|
return nullptr;
|
|
|
|
}
|
2012-06-01 10:21:12 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
const int64_t objectStoreId = mObjectStore->Id();
|
|
|
|
const int64_t indexId = Id();
|
2013-03-15 23:58:50 -07:00
|
|
|
|
2015-09-04 12:12:29 -07:00
|
|
|
SerializedKeyRange serializedKeyRange;
|
|
|
|
keyRange->ToSerialized(serializedKeyRange);
|
2012-06-01 10:21:12 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
RequestParams params;
|
2012-06-01 10:21:12 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
if (aKeyOnly) {
|
2015-09-04 12:12:29 -07:00
|
|
|
params = IndexGetKeyParams(objectStoreId, indexId, serializedKeyRange);
|
2014-09-26 16:21:57 -07:00
|
|
|
} else {
|
2015-09-04 12:12:29 -07:00
|
|
|
params = IndexGetParams(objectStoreId, indexId, serializedKeyRange);
|
2012-06-01 10:21:12 -07:00
|
|
|
}
|
|
|
|
|
2013-06-20 11:05:33 -07:00
|
|
|
nsRefPtr<IDBRequest> request = GenerateRequest(this);
|
2014-09-26 16:21:57 -07:00
|
|
|
MOZ_ASSERT(request);
|
|
|
|
|
2014-10-15 21:56:52 -07:00
|
|
|
if (aKeyOnly) {
|
|
|
|
IDB_LOG_MARK("IndexedDB %s: Child Transaction[%lld] Request[%llu]: "
|
|
|
|
"database(%s).transaction(%s).objectStore(%s).index(%s)."
|
|
|
|
"getKey(%s)",
|
|
|
|
"IndexedDB %s: C T[%lld] R[%llu]: IDBIndex.getKey()",
|
|
|
|
IDB_LOG_ID_STRING(),
|
|
|
|
transaction->LoggingSerialNumber(),
|
|
|
|
request->LoggingSerialNumber(),
|
|
|
|
IDB_LOG_STRINGIFY(transaction->Database()),
|
|
|
|
IDB_LOG_STRINGIFY(transaction),
|
|
|
|
IDB_LOG_STRINGIFY(mObjectStore),
|
|
|
|
IDB_LOG_STRINGIFY(this),
|
|
|
|
IDB_LOG_STRINGIFY(keyRange));
|
|
|
|
} else {
|
|
|
|
IDB_LOG_MARK("IndexedDB %s: Child Transaction[%lld] Request[%llu]: "
|
|
|
|
"database(%s).transaction(%s).objectStore(%s).index(%s)."
|
|
|
|
"get(%s)",
|
|
|
|
"IndexedDB %s: C T[%lld] R[%llu]: IDBIndex.get()",
|
|
|
|
IDB_LOG_ID_STRING(),
|
|
|
|
transaction->LoggingSerialNumber(),
|
|
|
|
request->LoggingSerialNumber(),
|
|
|
|
IDB_LOG_STRINGIFY(transaction->Database()),
|
|
|
|
IDB_LOG_STRINGIFY(transaction),
|
|
|
|
IDB_LOG_STRINGIFY(mObjectStore),
|
|
|
|
IDB_LOG_STRINGIFY(this),
|
|
|
|
IDB_LOG_STRINGIFY(keyRange));
|
|
|
|
}
|
|
|
|
|
2015-03-18 14:20:59 -07:00
|
|
|
transaction->StartRequest(request, params);
|
2014-09-26 16:21:57 -07:00
|
|
|
|
2013-07-31 08:48:40 -07:00
|
|
|
return request.forget();
|
2012-06-01 10:21:12 -07:00
|
|
|
}
|
|
|
|
|
2013-07-31 08:48:40 -07:00
|
|
|
already_AddRefed<IDBRequest>
|
2014-09-26 16:21:57 -07:00
|
|
|
IDBIndex::GetAllInternal(bool aKeysOnly,
|
|
|
|
JSContext* aCx,
|
|
|
|
JS::Handle<JS::Value> aKey,
|
|
|
|
const Optional<uint32_t>& aLimit,
|
2013-07-31 08:48:40 -07:00
|
|
|
ErrorResult& aRv)
|
2012-06-01 10:21:12 -07:00
|
|
|
{
|
2014-09-26 16:21:57 -07:00
|
|
|
AssertIsOnOwningThread();
|
2012-06-01 10:21:12 -07:00
|
|
|
|
2015-06-20 09:08:23 -07:00
|
|
|
if (mDeletedMetadata) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
IDBTransaction* transaction = mObjectStore->Transaction();
|
|
|
|
if (!transaction->IsOpen()) {
|
2013-07-31 08:48:40 -07:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_TRANSACTION_INACTIVE_ERR);
|
|
|
|
return nullptr;
|
2012-06-01 10:21:12 -07:00
|
|
|
}
|
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
nsRefPtr<IDBKeyRange> keyRange;
|
|
|
|
aRv = IDBKeyRange::FromJSVal(aCx, aKey, getter_AddRefs(keyRange));
|
|
|
|
if (NS_WARN_IF(aRv.Failed())) {
|
2013-07-31 08:48:40 -07:00
|
|
|
return nullptr;
|
|
|
|
}
|
2012-06-01 10:21:12 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
const int64_t objectStoreId = mObjectStore->Id();
|
|
|
|
const int64_t indexId = Id();
|
2012-06-01 10:21:12 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
OptionalKeyRange optionalKeyRange;
|
|
|
|
if (keyRange) {
|
|
|
|
SerializedKeyRange serializedKeyRange;
|
|
|
|
keyRange->ToSerialized(serializedKeyRange);
|
|
|
|
optionalKeyRange = serializedKeyRange;
|
|
|
|
} else {
|
|
|
|
optionalKeyRange = void_t();
|
2014-09-13 09:12:19 -07:00
|
|
|
}
|
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
const uint32_t limit = aLimit.WasPassed() ? aLimit.Value() : 0;
|
|
|
|
|
|
|
|
RequestParams params;
|
|
|
|
if (aKeysOnly) {
|
|
|
|
params = IndexGetAllKeysParams(objectStoreId, indexId, optionalKeyRange,
|
|
|
|
limit);
|
|
|
|
} else {
|
|
|
|
params = IndexGetAllParams(objectStoreId, indexId, optionalKeyRange, limit);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<IDBRequest> request = GenerateRequest(this);
|
|
|
|
MOZ_ASSERT(request);
|
|
|
|
|
|
|
|
if (aKeysOnly) {
|
2014-10-15 21:56:52 -07:00
|
|
|
IDB_LOG_MARK("IndexedDB %s: Child Transaction[%lld] Request[%llu]: "
|
|
|
|
"database(%s).transaction(%s).objectStore(%s).index(%s)."
|
|
|
|
"getAllKeys(%s, %s)",
|
|
|
|
"IndexedDB %s: C T[%lld] R[%llu]: IDBIndex.getAllKeys()",
|
|
|
|
IDB_LOG_ID_STRING(),
|
|
|
|
transaction->LoggingSerialNumber(),
|
|
|
|
request->LoggingSerialNumber(),
|
|
|
|
IDB_LOG_STRINGIFY(transaction->Database()),
|
|
|
|
IDB_LOG_STRINGIFY(transaction),
|
|
|
|
IDB_LOG_STRINGIFY(mObjectStore),
|
|
|
|
IDB_LOG_STRINGIFY(this),
|
|
|
|
IDB_LOG_STRINGIFY(keyRange),
|
|
|
|
IDB_LOG_STRINGIFY(aLimit));
|
2014-09-26 16:21:57 -07:00
|
|
|
} else {
|
2014-10-15 21:56:52 -07:00
|
|
|
IDB_LOG_MARK("IndexedDB %s: Child Transaction[%lld] Request[%llu]: "
|
|
|
|
"database(%s).transaction(%s).objectStore(%s).index(%s)."
|
|
|
|
"getAll(%s, %s)",
|
|
|
|
"IndexedDB %s: C T[%lld] R[%llu]: IDBIndex.getAll()",
|
|
|
|
IDB_LOG_ID_STRING(),
|
|
|
|
transaction->LoggingSerialNumber(),
|
|
|
|
request->LoggingSerialNumber(),
|
|
|
|
IDB_LOG_STRINGIFY(transaction->Database()),
|
|
|
|
IDB_LOG_STRINGIFY(transaction),
|
|
|
|
IDB_LOG_STRINGIFY(mObjectStore),
|
|
|
|
IDB_LOG_STRINGIFY(this),
|
|
|
|
IDB_LOG_STRINGIFY(keyRange),
|
|
|
|
IDB_LOG_STRINGIFY(aLimit));
|
2014-09-26 16:21:57 -07:00
|
|
|
}
|
2013-03-15 23:58:50 -07:00
|
|
|
|
2015-03-18 14:20:59 -07:00
|
|
|
transaction->StartRequest(request, params);
|
2014-10-15 21:56:52 -07:00
|
|
|
|
2013-07-31 08:48:40 -07:00
|
|
|
return request.forget();
|
2012-06-01 10:21:12 -07:00
|
|
|
}
|
|
|
|
|
2013-07-31 08:48:40 -07:00
|
|
|
already_AddRefed<IDBRequest>
|
2014-09-26 16:21:57 -07:00
|
|
|
IDBIndex::OpenCursorInternal(bool aKeysOnly,
|
|
|
|
JSContext* aCx,
|
|
|
|
JS::Handle<JS::Value> aRange,
|
|
|
|
IDBCursorDirection aDirection,
|
2013-07-31 08:48:40 -07:00
|
|
|
ErrorResult& aRv)
|
2012-06-01 10:21:12 -07:00
|
|
|
{
|
2014-09-26 16:21:57 -07:00
|
|
|
AssertIsOnOwningThread();
|
2012-06-01 10:21:12 -07:00
|
|
|
|
2015-06-20 09:08:23 -07:00
|
|
|
if (mDeletedMetadata) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
IDBTransaction* transaction = mObjectStore->Transaction();
|
|
|
|
if (!transaction->IsOpen()) {
|
2013-07-31 08:48:40 -07:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_TRANSACTION_INACTIVE_ERR);
|
2013-09-24 10:14:16 -07:00
|
|
|
return nullptr;
|
2012-06-01 10:21:12 -07:00
|
|
|
}
|
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
nsRefPtr<IDBKeyRange> keyRange;
|
|
|
|
aRv = IDBKeyRange::FromJSVal(aCx, aRange, getter_AddRefs(keyRange));
|
|
|
|
if (NS_WARN_IF(aRv.Failed())) {
|
2013-07-31 08:48:40 -07:00
|
|
|
return nullptr;
|
|
|
|
}
|
2012-06-01 10:21:12 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
int64_t objectStoreId = mObjectStore->Id();
|
|
|
|
int64_t indexId = Id();
|
2014-09-13 09:12:19 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
OptionalKeyRange optionalKeyRange;
|
|
|
|
|
|
|
|
if (keyRange) {
|
|
|
|
SerializedKeyRange serializedKeyRange;
|
|
|
|
keyRange->ToSerialized(serializedKeyRange);
|
|
|
|
|
|
|
|
optionalKeyRange = Move(serializedKeyRange);
|
|
|
|
} else {
|
|
|
|
optionalKeyRange = void_t();
|
2013-07-31 08:48:40 -07:00
|
|
|
}
|
2012-06-01 10:21:12 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
IDBCursor::Direction direction = IDBCursor::ConvertDirection(aDirection);
|
2013-03-15 23:58:50 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
OpenCursorParams params;
|
|
|
|
if (aKeysOnly) {
|
|
|
|
IndexOpenKeyCursorParams openParams;
|
|
|
|
openParams.objectStoreId() = objectStoreId;
|
|
|
|
openParams.indexId() = indexId;
|
|
|
|
openParams.optionalKeyRange() = Move(optionalKeyRange);
|
|
|
|
openParams.direction() = direction;
|
2012-06-01 10:21:12 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
params = Move(openParams);
|
|
|
|
} else {
|
|
|
|
IndexOpenCursorParams openParams;
|
|
|
|
openParams.objectStoreId() = objectStoreId;
|
|
|
|
openParams.indexId() = indexId;
|
|
|
|
openParams.optionalKeyRange() = Move(optionalKeyRange);
|
|
|
|
openParams.direction() = direction;
|
2012-06-01 10:21:12 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
params = Move(openParams);
|
2012-06-01 10:21:12 -07:00
|
|
|
}
|
|
|
|
|
2013-06-20 11:05:33 -07:00
|
|
|
nsRefPtr<IDBRequest> request = GenerateRequest(this);
|
2014-09-26 16:21:57 -07:00
|
|
|
MOZ_ASSERT(request);
|
2012-06-01 10:21:12 -07:00
|
|
|
|
2014-10-15 21:56:52 -07:00
|
|
|
if (aKeysOnly) {
|
|
|
|
IDB_LOG_MARK("IndexedDB %s: Child Transaction[%lld] Request[%llu]: "
|
|
|
|
"database(%s).transaction(%s).objectStore(%s).index(%s)."
|
|
|
|
"openKeyCursor(%s, %s)",
|
|
|
|
"IndexedDB %s: C T[%lld] R[%llu]: IDBIndex.openKeyCursor()",
|
|
|
|
IDB_LOG_ID_STRING(),
|
|
|
|
transaction->LoggingSerialNumber(),
|
|
|
|
request->LoggingSerialNumber(),
|
|
|
|
IDB_LOG_STRINGIFY(transaction->Database()),
|
|
|
|
IDB_LOG_STRINGIFY(transaction),
|
|
|
|
IDB_LOG_STRINGIFY(mObjectStore),
|
|
|
|
IDB_LOG_STRINGIFY(this),
|
|
|
|
IDB_LOG_STRINGIFY(keyRange),
|
|
|
|
IDB_LOG_STRINGIFY(direction));
|
|
|
|
} else {
|
|
|
|
IDB_LOG_MARK("IndexedDB %s: Child Transaction[%lld] Request[%llu]: "
|
|
|
|
"database(%s).transaction(%s).objectStore(%s).index(%s)."
|
|
|
|
"openCursor(%s, %s)",
|
|
|
|
"IndexedDB %s: C T[%lld] R[%llu]: "
|
|
|
|
"IDBObjectStore.openKeyCursor()",
|
|
|
|
IDB_LOG_ID_STRING(),
|
|
|
|
transaction->LoggingSerialNumber(),
|
|
|
|
request->LoggingSerialNumber(),
|
|
|
|
IDB_LOG_STRINGIFY(transaction->Database()),
|
|
|
|
IDB_LOG_STRINGIFY(transaction),
|
|
|
|
IDB_LOG_STRINGIFY(mObjectStore),
|
|
|
|
IDB_LOG_STRINGIFY(this),
|
|
|
|
IDB_LOG_STRINGIFY(keyRange),
|
|
|
|
IDB_LOG_STRINGIFY(direction));
|
|
|
|
}
|
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
BackgroundCursorChild* actor =
|
|
|
|
new BackgroundCursorChild(request, this, direction);
|
2012-06-01 10:21:12 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
mObjectStore->Transaction()->OpenCursor(actor, params);
|
2013-03-15 23:58:50 -07:00
|
|
|
|
2013-07-31 08:48:40 -07:00
|
|
|
return request.forget();
|
2012-06-01 10:21:12 -07:00
|
|
|
}
|
|
|
|
|
2013-07-31 08:48:40 -07:00
|
|
|
already_AddRefed<IDBRequest>
|
2014-09-26 16:21:57 -07:00
|
|
|
IDBIndex::Count(JSContext* aCx,
|
|
|
|
JS::Handle<JS::Value> aKey,
|
|
|
|
ErrorResult& aRv)
|
2012-06-01 10:21:12 -07:00
|
|
|
{
|
2014-09-26 16:21:57 -07:00
|
|
|
AssertIsOnOwningThread();
|
2012-06-01 10:21:12 -07:00
|
|
|
|
2015-06-20 09:08:23 -07:00
|
|
|
if (mDeletedMetadata) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
IDBTransaction* transaction = mObjectStore->Transaction();
|
|
|
|
if (!transaction->IsOpen()) {
|
2013-07-31 08:48:40 -07:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_TRANSACTION_INACTIVE_ERR);
|
|
|
|
return nullptr;
|
2012-06-01 10:21:12 -07:00
|
|
|
}
|
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
nsRefPtr<IDBKeyRange> keyRange;
|
|
|
|
aRv = IDBKeyRange::FromJSVal(aCx, aKey, getter_AddRefs(keyRange));
|
|
|
|
if (aRv.Failed()) {
|
2013-07-31 08:48:40 -07:00
|
|
|
return nullptr;
|
|
|
|
}
|
2012-06-01 10:21:12 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
IndexCountParams params;
|
|
|
|
params.objectStoreId() = mObjectStore->Id();
|
|
|
|
params.indexId() = Id();
|
2012-06-01 10:21:12 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
if (keyRange) {
|
|
|
|
SerializedKeyRange serializedKeyRange;
|
|
|
|
keyRange->ToSerialized(serializedKeyRange);
|
|
|
|
params.optionalKeyRange() = serializedKeyRange;
|
|
|
|
} else {
|
|
|
|
params.optionalKeyRange() = void_t();
|
2012-06-01 10:21:12 -07:00
|
|
|
}
|
|
|
|
|
2013-06-20 11:05:33 -07:00
|
|
|
nsRefPtr<IDBRequest> request = GenerateRequest(this);
|
2014-09-26 16:21:57 -07:00
|
|
|
MOZ_ASSERT(request);
|
2012-06-01 10:21:12 -07:00
|
|
|
|
2014-10-15 21:56:52 -07:00
|
|
|
IDB_LOG_MARK("IndexedDB %s: Child Transaction[%lld] Request[%llu]: "
|
|
|
|
"database(%s).transaction(%s).objectStore(%s).index(%s)."
|
|
|
|
"count(%s)",
|
|
|
|
"IndexedDB %s: C T[%lld] R[%llu]: IDBObjectStore.count()",
|
|
|
|
IDB_LOG_ID_STRING(),
|
|
|
|
transaction->LoggingSerialNumber(),
|
|
|
|
request->LoggingSerialNumber(),
|
|
|
|
IDB_LOG_STRINGIFY(transaction->Database()),
|
|
|
|
IDB_LOG_STRINGIFY(transaction),
|
|
|
|
IDB_LOG_STRINGIFY(mObjectStore),
|
|
|
|
IDB_LOG_STRINGIFY(this),
|
|
|
|
IDB_LOG_STRINGIFY(keyRange));
|
|
|
|
|
2015-03-18 14:20:59 -07:00
|
|
|
transaction->StartRequest(request, params);
|
2012-06-01 10:21:12 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
return request.forget();
|
2012-06-01 10:21:12 -07:00
|
|
|
}
|
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(IDBIndex)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(IDBIndex)
|
2014-09-17 16:36:01 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(IDBIndex)
|
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_END
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2013-08-01 18:29:05 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(IDBIndex)
|
|
|
|
|
2012-06-22 14:00:53 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(IDBIndex)
|
2013-07-31 08:48:40 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
|
2012-06-22 14:00:53 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_JSVAL_MEMBER_CALLBACK(mCachedKeyPath)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
|
|
|
|
2010-11-10 15:26:03 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(IDBIndex)
|
2012-06-22 14:00:53 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
|
2012-11-14 23:32:40 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mObjectStore)
|
2010-09-09 15:15:38 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-11-10 15:26:03 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(IDBIndex)
|
2013-07-31 08:48:40 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
|
|
|
|
|
2010-09-09 15:15:38 -07:00
|
|
|
// Don't unlink mObjectStore!
|
2012-06-22 14:00:53 -07:00
|
|
|
|
2015-01-13 23:59:06 -08:00
|
|
|
tmp->mCachedKeyPath.setUndefined();
|
2012-06-22 14:00:53 -07:00
|
|
|
|
|
|
|
if (tmp->mRooted) {
|
2013-08-16 13:10:17 -07:00
|
|
|
mozilla::DropJSObjects(tmp);
|
2012-06-22 14:00:53 -07:00
|
|
|
tmp->mRooted = false;
|
|
|
|
}
|
2010-09-09 15:15:38 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
2013-07-31 08:48:40 -07:00
|
|
|
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 07:13:33 -07:00
|
|
|
IDBIndex::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2010-06-23 12:46:08 -07: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 07:13:33 -07:00
|
|
|
return IDBIndexBinding::Wrap(aCx, this, aGivenProto);
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
} // namespace indexedDB
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|