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 22:51:06 +04:00
|
|
|
#include "IDBIndex.h"
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
#include "FileInfo.h"
|
2010-06-28 22:51:06 +04:00
|
|
|
#include "IDBCursor.h"
|
2010-06-23 23:46:08 +04:00
|
|
|
#include "IDBEvents.h"
|
2011-11-03 19:57:30 +04:00
|
|
|
#include "IDBKeyRange.h"
|
2010-06-28 22:51:06 +04:00
|
|
|
#include "IDBObjectStore.h"
|
2014-09-27 03:21:57 +04:00
|
|
|
#include "IDBRequest.h"
|
2010-06-28 20:46:21 +04:00
|
|
|
#include "IDBTransaction.h"
|
2014-09-27 03:21:57 +04:00
|
|
|
#include "IndexedDatabase.h"
|
|
|
|
#include "IndexedDatabaseInlines.h"
|
|
|
|
#include "mozilla/ErrorResult.h"
|
|
|
|
#include "mozilla/dom/indexedDB/PBackgroundIDBSharedTypes.h"
|
2013-03-16 10:58:50 +04:00
|
|
|
#include "ProfilerHelpers.h"
|
2014-01-28 04:37:05 +04:00
|
|
|
#include "ReportInternalError.h"
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
// Include this last to avoid path problems on Windows.
|
|
|
|
#include "ActorsChild.h"
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2017-06-07 13:36:20 +03:00
|
|
|
using namespace mozilla::dom::indexedDB;
|
|
|
|
|
2010-06-23 23:46:08 +04:00
|
|
|
namespace {
|
|
|
|
|
2016-03-23 18:02:57 +03:00
|
|
|
already_AddRefed<IDBRequest> GenerateRequest(JSContext* aCx, IDBIndex* aIndex) {
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(aIndex);
|
|
|
|
aIndex->AssertIsOnOwningThread();
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2019-10-03 10:56:45 +03:00
|
|
|
IDBTransaction* const transaction = aIndex->ObjectStore()->Transaction();
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<IDBRequest> request =
|
2016-03-23 18:02:57 +03:00
|
|
|
IDBRequest::Create(aCx, aIndex, transaction->Database(), transaction);
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(request);
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
return request.forget();
|
|
|
|
}
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
IDBIndex::IDBIndex(IDBObjectStore* aObjectStore, const IndexMetadata* aMetadata)
|
|
|
|
: mObjectStore(aObjectStore),
|
2015-01-14 10:59:06 +03:00
|
|
|
mCachedKeyPath(JS::UndefinedValue()),
|
2014-09-27 03:21:57 +04:00
|
|
|
mMetadata(aMetadata),
|
|
|
|
mId(aMetadata->id()),
|
|
|
|
mRooted(false) {
|
|
|
|
MOZ_ASSERT(aObjectStore);
|
|
|
|
aObjectStore->AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(aMetadata);
|
|
|
|
}
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
IDBIndex::~IDBIndex() {
|
|
|
|
AssertIsOnOwningThread();
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
if (mRooted) {
|
2015-01-14 10:59:06 +03:00
|
|
|
mCachedKeyPath.setUndefined();
|
2014-09-27 03:21:57 +04:00
|
|
|
mozilla::DropJSObjects(this);
|
|
|
|
}
|
|
|
|
}
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
already_AddRefed<IDBIndex> IDBIndex::Create(IDBObjectStore* aObjectStore,
|
|
|
|
const IndexMetadata& aMetadata) {
|
|
|
|
MOZ_ASSERT(aObjectStore);
|
|
|
|
aObjectStore->AssertIsOnOwningThread();
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<IDBIndex> index = new IDBIndex(aObjectStore, &aMetadata);
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
return index.forget();
|
|
|
|
}
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
#ifdef DEBUG
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void IDBIndex::AssertIsOnOwningThread() const {
|
|
|
|
MOZ_ASSERT(mObjectStore);
|
|
|
|
mObjectStore->AssertIsOnOwningThread();
|
|
|
|
}
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
#endif // DEBUG
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void IDBIndex::RefreshMetadata(bool aMayDelete) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT_IF(mDeletedMetadata, mMetadata == mDeletedMetadata);
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
const nsTArray<IndexMetadata>& indexes = mObjectStore->Spec().indexes();
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
bool found = false;
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
for (uint32_t count = indexes.Length(), index = 0; index < count; index++) {
|
|
|
|
const IndexMetadata& metadata = indexes[index];
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
if (metadata.id() == Id()) {
|
|
|
|
mMetadata = &metadata;
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
found = true;
|
|
|
|
break;
|
2011-01-27 04:53:02 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT_IF(!aMayDelete && !mDeletedMetadata, found);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
if (found) {
|
|
|
|
MOZ_ASSERT(mMetadata != mDeletedMetadata);
|
|
|
|
mDeletedMetadata = nullptr;
|
|
|
|
} else {
|
|
|
|
NoteDeletion();
|
2014-09-18 03:36:01 +04:00
|
|
|
}
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void IDBIndex::NoteDeletion() {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mMetadata);
|
|
|
|
MOZ_ASSERT(Id() == mMetadata->id());
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
if (mDeletedMetadata) {
|
|
|
|
MOZ_ASSERT(mMetadata == mDeletedMetadata);
|
|
|
|
return;
|
|
|
|
}
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
mDeletedMetadata = new IndexMetadata(*mMetadata);
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
mMetadata = mDeletedMetadata;
|
|
|
|
}
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
const nsString& IDBIndex::Name() const {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mMetadata);
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
return mMetadata->name();
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2016-03-30 06:04:56 +03:00
|
|
|
void IDBIndex::SetName(const nsAString& aName, ErrorResult& aRv) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
2019-10-03 10:56:45 +03:00
|
|
|
IDBTransaction* const transaction = mObjectStore->Transaction();
|
2016-03-30 06:04:56 +03:00
|
|
|
|
|
|
|
if (transaction->GetMode() != IDBTransaction::VERSION_CHANGE ||
|
|
|
|
mDeletedMetadata) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!transaction->IsOpen()) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_TRANSACTION_INACTIVE_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aName == mMetadata->name()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cache logging string of this index before renaming.
|
|
|
|
const LoggingString loggingOldIndex(this);
|
|
|
|
|
|
|
|
const int64_t indexId = Id();
|
|
|
|
|
|
|
|
nsresult rv =
|
|
|
|
transaction->Database()->RenameIndex(mObjectStore->Id(), indexId, aName);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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(
|
2016-03-30 06:04:56 +03:00
|
|
|
"database(%s).transaction(%s).objectStore(%s).index(%s)."
|
|
|
|
"rename(%s)",
|
2019-09-27 13:11:45 +03:00
|
|
|
"IDBIndex.rename()", transaction->LoggingSerialNumber(),
|
|
|
|
requestSerialNumber, IDB_LOG_STRINGIFY(transaction->Database()),
|
2016-03-30 06:04:56 +03:00
|
|
|
IDB_LOG_STRINGIFY(transaction), IDB_LOG_STRINGIFY(mObjectStore),
|
|
|
|
loggingOldIndex.get(), IDB_LOG_STRINGIFY(this));
|
|
|
|
|
|
|
|
transaction->RenameIndex(mObjectStore, indexId, aName);
|
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
bool IDBIndex::Unique() const {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mMetadata);
|
2013-07-31 19:48:40 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
return mMetadata->unique();
|
|
|
|
}
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
bool IDBIndex::MultiEntry() const {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mMetadata);
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
return mMetadata->multiEntry();
|
|
|
|
}
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2015-09-04 22:12:29 +03:00
|
|
|
bool IDBIndex::LocaleAware() const {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mMetadata);
|
|
|
|
|
|
|
|
return mMetadata->locale().IsEmpty();
|
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
const indexedDB::KeyPath& IDBIndex::GetKeyPath() const {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mMetadata);
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
return mMetadata->keyPath();
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2015-09-04 22:12:29 +03:00
|
|
|
void IDBIndex::GetLocale(nsString& aLocale) const {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mMetadata);
|
|
|
|
|
|
|
|
if (mMetadata->locale().IsEmpty()) {
|
|
|
|
SetDOMStringToNull(aLocale);
|
|
|
|
} else {
|
2017-07-24 20:23:52 +03:00
|
|
|
CopyASCIItoUTF16(mMetadata->locale(), aLocale);
|
2015-09-04 22:12:29 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsCString& IDBIndex::Locale() const {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mMetadata);
|
|
|
|
|
|
|
|
return mMetadata->locale();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IDBIndex::IsAutoLocale() const {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mMetadata);
|
|
|
|
|
|
|
|
return mMetadata->autoLocale();
|
|
|
|
}
|
|
|
|
|
2019-03-29 21:05:11 +03:00
|
|
|
nsIGlobalObject* IDBIndex::GetParentObject() const {
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
2012-06-23 01:00:53 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
return mObjectStore->GetParentObject();
|
2014-09-18 03:36:01 +04:00
|
|
|
}
|
2014-09-13 20:12:19 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void IDBIndex::GetKeyPath(JSContext* aCx, JS::MutableHandle<JS::Value> aResult,
|
|
|
|
ErrorResult& aRv) {
|
|
|
|
AssertIsOnOwningThread();
|
2014-09-13 20:12:19 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
if (!mCachedKeyPath.isUndefined()) {
|
|
|
|
MOZ_ASSERT(mRooted);
|
|
|
|
aResult.set(mCachedKeyPath);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(!mRooted);
|
|
|
|
|
|
|
|
aRv = GetKeyPath().ToJSVal(aCx, mCachedKeyPath);
|
|
|
|
if (NS_WARN_IF(aRv.Failed())) {
|
|
|
|
return;
|
2012-06-23 01:00:53 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
if (mCachedKeyPath.isGCThing()) {
|
|
|
|
mozilla::HoldJSObjects(this);
|
|
|
|
mRooted = true;
|
2012-06-01 21:21:12 +04:00
|
|
|
}
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
aResult.set(mCachedKeyPath);
|
2012-06-01 21:21:12 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
already_AddRefed<IDBRequest> IDBIndex::GetInternal(bool aKeyOnly,
|
|
|
|
JSContext* aCx,
|
|
|
|
JS::Handle<JS::Value> aKey,
|
|
|
|
ErrorResult& aRv) {
|
|
|
|
AssertIsOnOwningThread();
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2015-06-20 19:08:23 +03:00
|
|
|
if (mDeletedMetadata) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2012-06-01 21:21:12 +04:00
|
|
|
IDBTransaction* transaction = mObjectStore->Transaction();
|
|
|
|
if (!transaction->IsOpen()) {
|
2013-07-31 19:48:40 +04:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_TRANSACTION_INACTIVE_ERR);
|
|
|
|
return nullptr;
|
2012-06-01 21:21:12 +04:00
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<IDBKeyRange> keyRange;
|
2019-04-26 19:53:59 +03:00
|
|
|
IDBKeyRange::FromJSVal(aCx, aKey, getter_AddRefs(keyRange), aRv);
|
2014-09-27 03:21:57 +04:00
|
|
|
if (NS_WARN_IF(aRv.Failed())) {
|
2013-07-31 19:48:40 +04:00
|
|
|
return nullptr;
|
|
|
|
}
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
if (!keyRange) {
|
|
|
|
// Must specify a key or keyRange for get() and getKey().
|
2018-08-15 16:35:58 +03:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_KEY_ERR);
|
2013-07-31 19:48:40 +04:00
|
|
|
return nullptr;
|
|
|
|
}
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
const int64_t objectStoreId = mObjectStore->Id();
|
|
|
|
const int64_t indexId = Id();
|
2013-03-16 10:58:50 +04:00
|
|
|
|
2015-09-04 22:12:29 +03:00
|
|
|
SerializedKeyRange serializedKeyRange;
|
|
|
|
keyRange->ToSerialized(serializedKeyRange);
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
RequestParams params;
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
if (aKeyOnly) {
|
2015-09-04 22:12:29 +03:00
|
|
|
params = IndexGetKeyParams(objectStoreId, indexId, serializedKeyRange);
|
2014-09-27 03:21:57 +04:00
|
|
|
} else {
|
2015-09-04 22:12:29 +03:00
|
|
|
params = IndexGetParams(objectStoreId, indexId, serializedKeyRange);
|
2012-06-01 21:21:12 +04:00
|
|
|
}
|
|
|
|
|
2016-03-23 18:02:57 +03:00
|
|
|
RefPtr<IDBRequest> request = GenerateRequest(aCx, this);
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(request);
|
|
|
|
|
2014-10-16 08:56:52 +04:00
|
|
|
if (aKeyOnly) {
|
2019-09-27 13:11:45 +03:00
|
|
|
IDB_LOG_MARK_CHILD_TRANSACTION_REQUEST(
|
2014-10-16 08:56:52 +04:00
|
|
|
"database(%s).transaction(%s).objectStore(%s).index(%s)."
|
|
|
|
"getKey(%s)",
|
2019-09-27 13:11:45 +03:00
|
|
|
"IDBIndex.getKey()", transaction->LoggingSerialNumber(),
|
2014-10-16 08:56:52 +04:00
|
|
|
request->LoggingSerialNumber(),
|
|
|
|
IDB_LOG_STRINGIFY(transaction->Database()),
|
|
|
|
IDB_LOG_STRINGIFY(transaction), IDB_LOG_STRINGIFY(mObjectStore),
|
|
|
|
IDB_LOG_STRINGIFY(this), IDB_LOG_STRINGIFY(keyRange));
|
|
|
|
} else {
|
2019-09-27 13:11:45 +03:00
|
|
|
IDB_LOG_MARK_CHILD_TRANSACTION_REQUEST(
|
2014-10-16 08:56:52 +04:00
|
|
|
"database(%s).transaction(%s).objectStore(%s).index(%s)."
|
|
|
|
"get(%s)",
|
2019-09-27 13:11:45 +03:00
|
|
|
"IDBIndex.get()", transaction->LoggingSerialNumber(),
|
|
|
|
request->LoggingSerialNumber(),
|
2014-10-16 08:56:52 +04:00
|
|
|
IDB_LOG_STRINGIFY(transaction->Database()),
|
|
|
|
IDB_LOG_STRINGIFY(transaction), IDB_LOG_STRINGIFY(mObjectStore),
|
|
|
|
IDB_LOG_STRINGIFY(this), IDB_LOG_STRINGIFY(keyRange));
|
|
|
|
}
|
|
|
|
|
2015-03-19 00:20:59 +03:00
|
|
|
transaction->StartRequest(request, params);
|
2014-09-27 03:21:57 +04:00
|
|
|
|
2013-07-31 19:48:40 +04:00
|
|
|
return request.forget();
|
2012-06-01 21:21:12 +04:00
|
|
|
}
|
|
|
|
|
2013-07-31 19:48:40 +04:00
|
|
|
already_AddRefed<IDBRequest> IDBIndex::GetAllInternal(
|
2014-09-27 03:21:57 +04:00
|
|
|
bool aKeysOnly, JSContext* aCx, JS::Handle<JS::Value> aKey,
|
|
|
|
const Optional<uint32_t>& aLimit, ErrorResult& aRv) {
|
|
|
|
AssertIsOnOwningThread();
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2015-06-20 19:08:23 +03:00
|
|
|
if (mDeletedMetadata) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2012-06-01 21:21:12 +04:00
|
|
|
IDBTransaction* transaction = mObjectStore->Transaction();
|
|
|
|
if (!transaction->IsOpen()) {
|
2013-07-31 19:48:40 +04:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_TRANSACTION_INACTIVE_ERR);
|
|
|
|
return nullptr;
|
2012-06-01 21:21:12 +04:00
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<IDBKeyRange> keyRange;
|
2019-04-26 19:53:59 +03:00
|
|
|
IDBKeyRange::FromJSVal(aCx, aKey, getter_AddRefs(keyRange), aRv);
|
2014-09-27 03:21:57 +04:00
|
|
|
if (NS_WARN_IF(aRv.Failed())) {
|
2013-07-31 19:48:40 +04:00
|
|
|
return nullptr;
|
|
|
|
}
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
const int64_t objectStoreId = mObjectStore->Id();
|
|
|
|
const int64_t indexId = Id();
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2019-03-15 20:39:59 +03:00
|
|
|
Maybe<SerializedKeyRange> optionalKeyRange;
|
2014-09-27 03:21:57 +04:00
|
|
|
if (keyRange) {
|
|
|
|
SerializedKeyRange serializedKeyRange;
|
|
|
|
keyRange->ToSerialized(serializedKeyRange);
|
2019-03-15 20:39:59 +03:00
|
|
|
optionalKeyRange.emplace(serializedKeyRange);
|
2014-09-13 20:12:19 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
const uint32_t limit = aLimit.WasPassed() ? aLimit.Value() : 0;
|
|
|
|
|
2019-10-03 10:56:45 +03:00
|
|
|
const auto& params =
|
|
|
|
aKeysOnly ? RequestParams{IndexGetAllKeysParams(objectStoreId, indexId,
|
|
|
|
optionalKeyRange, limit)}
|
|
|
|
: RequestParams{IndexGetAllParams(objectStoreId, indexId,
|
|
|
|
optionalKeyRange, limit)};
|
2014-09-27 03:21:57 +04:00
|
|
|
|
2016-03-23 18:02:57 +03:00
|
|
|
RefPtr<IDBRequest> request = GenerateRequest(aCx, this);
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(request);
|
|
|
|
|
|
|
|
if (aKeysOnly) {
|
2019-09-27 13:11:45 +03:00
|
|
|
IDB_LOG_MARK_CHILD_TRANSACTION_REQUEST(
|
2014-10-16 08:56:52 +04:00
|
|
|
"database(%s).transaction(%s).objectStore(%s).index(%s)."
|
|
|
|
"getAllKeys(%s, %s)",
|
2019-09-27 13:11:45 +03:00
|
|
|
"IDBIndex.getAllKeys()", transaction->LoggingSerialNumber(),
|
2014-10-16 08:56:52 +04:00
|
|
|
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-27 03:21:57 +04:00
|
|
|
} else {
|
2019-09-27 13:11:45 +03:00
|
|
|
IDB_LOG_MARK_CHILD_TRANSACTION_REQUEST(
|
2014-10-16 08:56:52 +04:00
|
|
|
"database(%s).transaction(%s).objectStore(%s).index(%s)."
|
|
|
|
"getAll(%s, %s)",
|
2019-09-27 13:11:45 +03:00
|
|
|
"IDBIndex.getAll()", transaction->LoggingSerialNumber(),
|
2014-10-16 08:56:52 +04:00
|
|
|
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-27 03:21:57 +04:00
|
|
|
}
|
2013-03-16 10:58:50 +04:00
|
|
|
|
2015-03-19 00:20:59 +03:00
|
|
|
transaction->StartRequest(request, params);
|
2014-10-16 08:56:52 +04:00
|
|
|
|
2013-07-31 19:48:40 +04:00
|
|
|
return request.forget();
|
2012-06-01 21:21:12 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
already_AddRefed<IDBRequest> IDBIndex::OpenCursorInternal(
|
|
|
|
bool aKeysOnly, JSContext* aCx, JS::Handle<JS::Value> aRange,
|
|
|
|
IDBCursorDirection aDirection, ErrorResult& aRv) {
|
|
|
|
AssertIsOnOwningThread();
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2015-06-20 19:08:23 +03:00
|
|
|
if (mDeletedMetadata) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2012-06-01 21:21:12 +04:00
|
|
|
IDBTransaction* transaction = mObjectStore->Transaction();
|
|
|
|
if (!transaction->IsOpen()) {
|
2013-07-31 19:48:40 +04:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_TRANSACTION_INACTIVE_ERR);
|
2013-09-24 21:14:16 +04:00
|
|
|
return nullptr;
|
2012-06-01 21:21:12 +04:00
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<IDBKeyRange> keyRange;
|
2019-04-26 19:53:59 +03:00
|
|
|
IDBKeyRange::FromJSVal(aCx, aRange, getter_AddRefs(keyRange), aRv);
|
2014-09-27 03:21:57 +04:00
|
|
|
if (NS_WARN_IF(aRv.Failed())) {
|
2013-07-31 19:48:40 +04:00
|
|
|
return nullptr;
|
|
|
|
}
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2019-10-03 10:56:45 +03:00
|
|
|
const int64_t objectStoreId = mObjectStore->Id();
|
|
|
|
const int64_t indexId = Id();
|
2014-09-13 20:12:19 +04:00
|
|
|
|
2019-03-15 20:39:59 +03:00
|
|
|
Maybe<SerializedKeyRange> optionalKeyRange;
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
if (keyRange) {
|
|
|
|
SerializedKeyRange serializedKeyRange;
|
|
|
|
keyRange->ToSerialized(serializedKeyRange);
|
|
|
|
|
2019-03-15 20:39:59 +03:00
|
|
|
optionalKeyRange.emplace(std::move(serializedKeyRange));
|
2013-07-31 19:48:40 +04:00
|
|
|
}
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2019-10-03 10:56:45 +03:00
|
|
|
const IDBCursor::Direction direction =
|
|
|
|
IDBCursor::ConvertDirection(aDirection);
|
2013-03-16 10:58:50 +04:00
|
|
|
|
2019-09-11 14:51:24 +03:00
|
|
|
const CommonIndexOpenCursorParams commonIndexParams = {
|
|
|
|
{objectStoreId, std::move(optionalKeyRange), direction}, indexId};
|
|
|
|
|
|
|
|
const auto params =
|
|
|
|
aKeysOnly ? OpenCursorParams{IndexOpenKeyCursorParams{commonIndexParams}}
|
|
|
|
: OpenCursorParams{IndexOpenCursorParams{commonIndexParams}};
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2016-03-23 18:02:57 +03:00
|
|
|
RefPtr<IDBRequest> request = GenerateRequest(aCx, this);
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(request);
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2014-10-16 08:56:52 +04:00
|
|
|
if (aKeysOnly) {
|
2019-09-27 13:11:45 +03:00
|
|
|
IDB_LOG_MARK_CHILD_TRANSACTION_REQUEST(
|
2014-10-16 08:56:52 +04:00
|
|
|
"database(%s).transaction(%s).objectStore(%s).index(%s)."
|
|
|
|
"openKeyCursor(%s, %s)",
|
2019-09-27 13:11:45 +03:00
|
|
|
"IDBIndex.openKeyCursor()", transaction->LoggingSerialNumber(),
|
2014-10-16 08:56:52 +04:00
|
|
|
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 {
|
2019-09-27 13:11:45 +03:00
|
|
|
IDB_LOG_MARK_CHILD_TRANSACTION_REQUEST(
|
2014-10-16 08:56:52 +04:00
|
|
|
"database(%s).transaction(%s).objectStore(%s).index(%s)."
|
|
|
|
"openCursor(%s, %s)",
|
2019-11-05 17:34:22 +03:00
|
|
|
"IDBObjectStore.openCursor()", transaction->LoggingSerialNumber(),
|
2014-10-16 08:56:52 +04:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2019-10-03 10:56:45 +03:00
|
|
|
BackgroundCursorChild* const actor =
|
2014-09-27 03:21:57 +04:00
|
|
|
new BackgroundCursorChild(request, this, direction);
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
mObjectStore->Transaction()->OpenCursor(actor, params);
|
2013-03-16 10:58:50 +04:00
|
|
|
|
2013-07-31 19:48:40 +04:00
|
|
|
return request.forget();
|
2012-06-01 21:21:12 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
already_AddRefed<IDBRequest> IDBIndex::Count(JSContext* aCx,
|
|
|
|
JS::Handle<JS::Value> aKey,
|
|
|
|
ErrorResult& aRv) {
|
|
|
|
AssertIsOnOwningThread();
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2015-06-20 19:08:23 +03:00
|
|
|
if (mDeletedMetadata) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-10-03 10:56:45 +03:00
|
|
|
IDBTransaction* const transaction = mObjectStore->Transaction();
|
2012-06-01 21:21:12 +04:00
|
|
|
if (!transaction->IsOpen()) {
|
2013-07-31 19:48:40 +04:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_TRANSACTION_INACTIVE_ERR);
|
|
|
|
return nullptr;
|
2012-06-01 21:21:12 +04:00
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<IDBKeyRange> keyRange;
|
2019-04-26 19:53:59 +03:00
|
|
|
IDBKeyRange::FromJSVal(aCx, aKey, getter_AddRefs(keyRange), aRv);
|
2014-09-27 03:21:57 +04:00
|
|
|
if (aRv.Failed()) {
|
2013-07-31 19:48:40 +04:00
|
|
|
return nullptr;
|
|
|
|
}
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
IndexCountParams params;
|
|
|
|
params.objectStoreId() = mObjectStore->Id();
|
|
|
|
params.indexId() = Id();
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
if (keyRange) {
|
|
|
|
SerializedKeyRange serializedKeyRange;
|
|
|
|
keyRange->ToSerialized(serializedKeyRange);
|
2019-03-15 20:39:59 +03:00
|
|
|
params.optionalKeyRange().emplace(serializedKeyRange);
|
2012-06-01 21:21:12 +04:00
|
|
|
}
|
|
|
|
|
2016-03-23 18:02:57 +03:00
|
|
|
RefPtr<IDBRequest> request = GenerateRequest(aCx, this);
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(request);
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2019-09-27 13:11:45 +03:00
|
|
|
IDB_LOG_MARK_CHILD_TRANSACTION_REQUEST(
|
2014-10-16 08:56:52 +04:00
|
|
|
"database(%s).transaction(%s).objectStore(%s).index(%s)."
|
|
|
|
"count(%s)",
|
2019-11-05 17:34:22 +03:00
|
|
|
"IDBObjectStore.count()", transaction->LoggingSerialNumber(),
|
2014-10-16 08:56:52 +04:00
|
|
|
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-19 00:20:59 +03:00
|
|
|
transaction->StartRequest(request, params);
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
return request.forget();
|
2012-06-01 21:21:12 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(IDBIndex)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(IDBIndex)
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04: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 23:46:08 +04:00
|
|
|
|
2013-08-02 05:29:05 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(IDBIndex)
|
|
|
|
|
2012-06-23 01:00:53 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(IDBIndex)
|
2013-07-31 19:48:40 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
|
2016-02-22 21:11:02 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mCachedKeyPath)
|
2012-06-23 01:00:53 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
|
|
|
|
2010-11-11 02:26:03 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(IDBIndex)
|
2012-11-15 11:32:40 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mObjectStore)
|
2010-09-10 02:15:38 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-11-11 02:26:03 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(IDBIndex)
|
2013-07-31 19:48:40 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
|
|
|
|
|
2010-09-10 02:15:38 +04:00
|
|
|
// Don't unlink mObjectStore!
|
2012-06-23 01:00:53 +04:00
|
|
|
|
2015-01-14 10:59:06 +03:00
|
|
|
tmp->mCachedKeyPath.setUndefined();
|
2012-06-23 01:00:53 +04:00
|
|
|
|
|
|
|
if (tmp->mRooted) {
|
2013-08-17 00:10:17 +04:00
|
|
|
mozilla::DropJSObjects(tmp);
|
2012-06-23 01:00:53 +04:00
|
|
|
tmp->mRooted = false;
|
|
|
|
}
|
2010-09-10 02:15:38 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
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
|
|
|
JSObject* IDBIndex::WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
2018-06-26 00:20:54 +03:00
|
|
|
return IDBIndex_Binding::Wrap(aCx, this, aGivenProto);
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|