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 "IDBCursor.h"
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
#include "IDBDatabase.h"
|
2010-06-28 22:51:06 +04:00
|
|
|
#include "IDBIndex.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-18 03:36:01 +04:00
|
|
|
#include "IndexedDatabaseInlines.h"
|
2014-09-27 03:21:57 +04:00
|
|
|
#include "mozilla/ErrorResult.h"
|
2014-09-18 03:36:01 +04:00
|
|
|
#include "mozilla/dom/UnionTypes.h"
|
2014-09-27 03:21:57 +04:00
|
|
|
#include "mozilla/dom/indexedDB/PBackgroundIDBSharedTypes.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "ProfilerHelpers.h"
|
|
|
|
#include "ReportInternalError.h"
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
// Include this last to avoid path problems on Windows.
|
|
|
|
#include "ActorsChild.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2016-02-17 00:46:08 +03:00
|
|
|
|
|
|
|
using namespace indexedDB;
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
IDBCursor::IDBCursor(Type aType, BackgroundCursorChild* aBackgroundActor,
|
2019-10-03 10:56:32 +03:00
|
|
|
Key aKey)
|
2014-11-08 03:42:53 +03:00
|
|
|
: mBackgroundActor(aBackgroundActor),
|
|
|
|
mRequest(aBackgroundActor->GetRequest()),
|
|
|
|
mSourceObjectStore(aBackgroundActor->GetObjectStore()),
|
|
|
|
mSourceIndex(aBackgroundActor->GetIndex()),
|
|
|
|
mTransaction(mRequest->GetTransaction()),
|
2015-01-14 10:59:06 +03:00
|
|
|
mCachedKey(JS::UndefinedValue()),
|
|
|
|
mCachedPrimaryKey(JS::UndefinedValue()),
|
|
|
|
mCachedValue(JS::UndefinedValue()),
|
2019-10-03 10:56:32 +03:00
|
|
|
mKey(std::move(aKey)),
|
2014-09-27 03:21:57 +04:00
|
|
|
mType(aType),
|
2014-11-08 03:42:53 +03:00
|
|
|
mDirection(aBackgroundActor->GetDirection()),
|
2014-09-27 03:21:57 +04:00
|
|
|
mHaveCachedKey(false),
|
|
|
|
mHaveCachedPrimaryKey(false),
|
|
|
|
mHaveCachedValue(false),
|
|
|
|
mRooted(false),
|
|
|
|
mContinueCalled(false),
|
|
|
|
mHaveValue(true) {
|
|
|
|
MOZ_ASSERT(aBackgroundActor);
|
2014-11-08 03:42:53 +03:00
|
|
|
aBackgroundActor->AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mRequest);
|
|
|
|
MOZ_ASSERT_IF(aType == Type_ObjectStore || aType == Type_ObjectStoreKey,
|
|
|
|
mSourceObjectStore);
|
|
|
|
MOZ_ASSERT_IF(aType == Type_Index || aType == Type_IndexKey, mSourceIndex);
|
|
|
|
MOZ_ASSERT(mTransaction);
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(!aKey.IsUnset());
|
|
|
|
}
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2015-09-04 22:12:29 +03:00
|
|
|
bool IDBCursor::IsLocaleAware() const {
|
|
|
|
return mSourceIndex && !mSourceIndex->Locale().IsEmpty();
|
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
IDBCursor::~IDBCursor() {
|
|
|
|
AssertIsOnOwningThread();
|
2011-01-27 04:53:02 +03:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
DropJSObjects();
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
if (mBackgroundActor) {
|
|
|
|
mBackgroundActor->SendDeleteMeInternal();
|
|
|
|
MOZ_ASSERT(!mBackgroundActor, "SendDeleteMeInternal should have cleared!");
|
2014-09-18 03:36:01 +04:00
|
|
|
}
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
2010-06-23 23:46:08 +04:00
|
|
|
|
|
|
|
// static
|
2010-06-28 22:51:06 +04:00
|
|
|
already_AddRefed<IDBCursor> IDBCursor::Create(
|
2019-10-03 10:56:32 +03:00
|
|
|
BackgroundCursorChild* aBackgroundActor, Key aKey,
|
2014-09-27 03:21:57 +04:00
|
|
|
StructuredCloneReadInfo&& aCloneInfo) {
|
|
|
|
MOZ_ASSERT(aBackgroundActor);
|
2014-11-08 03:42:53 +03:00
|
|
|
aBackgroundActor->AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(aBackgroundActor->GetObjectStore());
|
|
|
|
MOZ_ASSERT(!aBackgroundActor->GetIndex());
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(!aKey.IsUnset());
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<IDBCursor> cursor =
|
2019-10-03 10:56:32 +03:00
|
|
|
new IDBCursor(Type_ObjectStore, aBackgroundActor, std::move(aKey));
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2018-05-30 22:15:35 +03:00
|
|
|
cursor->mCloneInfo = std::move(aCloneInfo);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
|
|
|
return cursor.forget();
|
|
|
|
}
|
|
|
|
|
2013-09-26 03:11:47 +04:00
|
|
|
// static
|
|
|
|
already_AddRefed<IDBCursor> IDBCursor::Create(
|
2019-10-03 10:56:32 +03:00
|
|
|
BackgroundCursorChild* aBackgroundActor, Key aKey) {
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(aBackgroundActor);
|
2014-11-08 03:42:53 +03:00
|
|
|
aBackgroundActor->AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(aBackgroundActor->GetObjectStore());
|
|
|
|
MOZ_ASSERT(!aBackgroundActor->GetIndex());
|
2013-09-26 03:11:47 +04:00
|
|
|
MOZ_ASSERT(!aKey.IsUnset());
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<IDBCursor> cursor =
|
2019-10-03 10:56:32 +03:00
|
|
|
new IDBCursor(Type_ObjectStoreKey, aBackgroundActor, std::move(aKey));
|
2013-09-26 03:11:47 +04:00
|
|
|
|
|
|
|
return cursor.forget();
|
|
|
|
}
|
|
|
|
|
2010-06-23 23:46:08 +04:00
|
|
|
// static
|
2010-06-28 22:51:06 +04:00
|
|
|
already_AddRefed<IDBCursor> IDBCursor::Create(
|
2019-10-03 10:56:32 +03:00
|
|
|
BackgroundCursorChild* aBackgroundActor, Key aKey, Key aSortKey,
|
|
|
|
Key aPrimaryKey, StructuredCloneReadInfo&& aCloneInfo) {
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(aBackgroundActor);
|
2014-11-08 03:42:53 +03:00
|
|
|
aBackgroundActor->AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(aBackgroundActor->GetIndex());
|
|
|
|
MOZ_ASSERT(!aBackgroundActor->GetObjectStore());
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(!aKey.IsUnset());
|
|
|
|
MOZ_ASSERT(!aPrimaryKey.IsUnset());
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2019-10-03 10:56:32 +03:00
|
|
|
RefPtr<IDBCursor> cursor =
|
|
|
|
new IDBCursor(Type_Index, aBackgroundActor, std::move(aKey));
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2018-05-30 22:15:35 +03:00
|
|
|
cursor->mSortKey = std::move(aSortKey);
|
|
|
|
cursor->mPrimaryKey = std::move(aPrimaryKey);
|
|
|
|
cursor->mCloneInfo = std::move(aCloneInfo);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
|
|
|
return cursor.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
2010-06-28 22:51:06 +04:00
|
|
|
already_AddRefed<IDBCursor> IDBCursor::Create(
|
2019-10-03 10:56:32 +03:00
|
|
|
BackgroundCursorChild* aBackgroundActor, Key aKey, Key aSortKey,
|
|
|
|
Key aPrimaryKey) {
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(aBackgroundActor);
|
2014-11-08 03:42:53 +03:00
|
|
|
aBackgroundActor->AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(aBackgroundActor->GetIndex());
|
|
|
|
MOZ_ASSERT(!aBackgroundActor->GetObjectStore());
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(!aKey.IsUnset());
|
|
|
|
MOZ_ASSERT(!aPrimaryKey.IsUnset());
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<IDBCursor> cursor =
|
2019-10-03 10:56:32 +03:00
|
|
|
new IDBCursor(Type_IndexKey, aBackgroundActor, std::move(aKey));
|
2014-09-27 03:21:57 +04:00
|
|
|
|
2018-05-30 22:15:35 +03:00
|
|
|
cursor->mSortKey = std::move(aSortKey);
|
|
|
|
cursor->mPrimaryKey = std::move(aPrimaryKey);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
|
|
|
return cursor.forget();
|
|
|
|
}
|
|
|
|
|
2013-07-31 19:48:36 +04:00
|
|
|
// static
|
2014-09-27 03:21:57 +04:00
|
|
|
auto IDBCursor::ConvertDirection(IDBCursorDirection aDirection) -> Direction {
|
2013-07-31 19:48:36 +04:00
|
|
|
switch (aDirection) {
|
|
|
|
case mozilla::dom::IDBCursorDirection::Next:
|
|
|
|
return NEXT;
|
|
|
|
|
|
|
|
case mozilla::dom::IDBCursorDirection::Nextunique:
|
|
|
|
return NEXT_UNIQUE;
|
|
|
|
|
|
|
|
case mozilla::dom::IDBCursorDirection::Prev:
|
|
|
|
return PREV;
|
|
|
|
|
|
|
|
case mozilla::dom::IDBCursorDirection::Prevunique:
|
|
|
|
return PREV_UNIQUE;
|
|
|
|
|
|
|
|
default:
|
2014-04-20 11:36:40 +04:00
|
|
|
MOZ_CRASH("Unknown direction!");
|
2013-07-31 19:48:36 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
#ifdef DEBUG
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void IDBCursor::AssertIsOnOwningThread() const {
|
|
|
|
MOZ_ASSERT(mTransaction);
|
|
|
|
mTransaction->AssertIsOnOwningThread();
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
#endif // DEBUG
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2012-11-28 05:37:57 +04:00
|
|
|
void IDBCursor::DropJSObjects() {
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
Reset();
|
|
|
|
|
2012-11-28 05:37:57 +04:00
|
|
|
if (!mRooted) {
|
|
|
|
return;
|
|
|
|
}
|
2014-09-27 03:21:57 +04:00
|
|
|
|
2012-11-28 05:37:57 +04:00
|
|
|
mRooted = false;
|
2014-09-27 03:21:57 +04:00
|
|
|
|
2013-08-17 00:10:17 +04:00
|
|
|
mozilla::DropJSObjects(this);
|
2012-11-28 05:37:57 +04:00
|
|
|
}
|
|
|
|
|
2015-07-02 20:47:53 +03:00
|
|
|
bool IDBCursor::IsSourceDeleted() const {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mTransaction);
|
|
|
|
MOZ_ASSERT(mTransaction->IsOpen());
|
|
|
|
|
|
|
|
IDBObjectStore* sourceObjectStore;
|
|
|
|
if (mType == Type_Index || mType == Type_IndexKey) {
|
|
|
|
MOZ_ASSERT(mSourceIndex);
|
|
|
|
|
|
|
|
if (mSourceIndex->IsDeleted()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
sourceObjectStore = mSourceIndex->ObjectStore();
|
|
|
|
MOZ_ASSERT(sourceObjectStore);
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(mSourceObjectStore);
|
|
|
|
sourceObjectStore = mSourceObjectStore;
|
|
|
|
}
|
|
|
|
|
|
|
|
return sourceObjectStore->IsDeleted();
|
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void IDBCursor::Reset() {
|
|
|
|
AssertIsOnOwningThread();
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
mCachedKey.setUndefined();
|
|
|
|
mCachedPrimaryKey.setUndefined();
|
|
|
|
mCachedValue.setUndefined();
|
|
|
|
IDBObjectStore::ClearCloneReadInfo(mCloneInfo);
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
mHaveCachedKey = false;
|
|
|
|
mHaveCachedPrimaryKey = false;
|
|
|
|
mHaveCachedValue = false;
|
|
|
|
mHaveValue = false;
|
|
|
|
mContinueCalled = false;
|
2011-11-08 03:37:19 +04:00
|
|
|
}
|
|
|
|
|
2019-03-29 21:05:11 +03:00
|
|
|
nsIGlobalObject* IDBCursor::GetParentObject() const {
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mTransaction);
|
2013-09-26 03:11:47 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
return mTransaction->GetParentObject();
|
2013-08-01 02:28:13 +04:00
|
|
|
}
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2013-08-01 02:28:13 +04:00
|
|
|
IDBCursorDirection IDBCursor::GetDirection() const {
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2012-03-14 00:25:05 +04:00
|
|
|
switch (mDirection) {
|
2012-03-13 08:44:45 +04:00
|
|
|
case NEXT:
|
2014-09-27 03:21:57 +04:00
|
|
|
return IDBCursorDirection::Next;
|
2013-08-01 02:28:13 +04:00
|
|
|
|
2012-03-13 08:44:45 +04:00
|
|
|
case NEXT_UNIQUE:
|
2014-09-27 03:21:57 +04:00
|
|
|
return IDBCursorDirection::Nextunique;
|
2013-08-01 02:28:13 +04:00
|
|
|
|
2012-03-13 08:44:45 +04:00
|
|
|
case PREV:
|
2014-09-27 03:21:57 +04:00
|
|
|
return IDBCursorDirection::Prev;
|
2013-08-01 02:28:13 +04:00
|
|
|
|
2012-03-13 08:44:45 +04:00
|
|
|
case PREV_UNIQUE:
|
2014-09-27 03:21:57 +04:00
|
|
|
return IDBCursorDirection::Prevunique;
|
2012-06-01 21:21:12 +04:00
|
|
|
|
|
|
|
default:
|
2014-04-20 11:36:40 +04:00
|
|
|
MOZ_CRASH("Bad direction!");
|
2012-03-13 08:44:45 +04:00
|
|
|
}
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2013-09-17 19:16:02 +04:00
|
|
|
void IDBCursor::GetSource(OwningIDBObjectStoreOrIDBIndex& aSource) const {
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
2013-09-26 03:11:47 +04:00
|
|
|
|
2013-09-26 03:11:47 +04:00
|
|
|
switch (mType) {
|
2014-09-27 03:21:57 +04:00
|
|
|
case Type_ObjectStore:
|
|
|
|
case Type_ObjectStoreKey:
|
|
|
|
MOZ_ASSERT(mSourceObjectStore);
|
|
|
|
aSource.SetAsIDBObjectStore() = mSourceObjectStore;
|
|
|
|
return;
|
|
|
|
|
|
|
|
case Type_Index:
|
|
|
|
case Type_IndexKey:
|
|
|
|
MOZ_ASSERT(mSourceIndex);
|
|
|
|
aSource.SetAsIDBIndex() = mSourceIndex;
|
|
|
|
return;
|
2013-09-26 03:11:47 +04:00
|
|
|
|
|
|
|
default:
|
2014-04-20 11:36:40 +04:00
|
|
|
MOZ_ASSERT_UNREACHABLE("Bad type!");
|
2013-08-01 02:28:13 +04:00
|
|
|
}
|
2010-12-10 05:14:09 +03:00
|
|
|
}
|
|
|
|
|
2014-06-12 00:26:52 +04:00
|
|
|
void IDBCursor::GetKey(JSContext* aCx, JS::MutableHandle<JS::Value> aResult,
|
|
|
|
ErrorResult& aRv) {
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
2013-09-26 03:11:47 +04:00
|
|
|
MOZ_ASSERT(!mKey.IsUnset() || !mHaveValue);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2011-11-03 19:57:30 +04:00
|
|
|
if (!mHaveValue) {
|
2014-06-12 00:26:52 +04:00
|
|
|
aResult.setUndefined();
|
|
|
|
return;
|
2011-11-03 19:57:30 +04:00
|
|
|
}
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2011-11-03 19:57:30 +04:00
|
|
|
if (!mHaveCachedKey) {
|
|
|
|
if (!mRooted) {
|
2013-08-17 00:10:17 +04:00
|
|
|
mozilla::HoldJSObjects(this);
|
2011-11-03 19:57:30 +04:00
|
|
|
mRooted = true;
|
2011-11-03 05:57:48 +04:00
|
|
|
}
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2013-08-01 02:28:13 +04:00
|
|
|
aRv = mKey.ToJSVal(aCx, mCachedKey);
|
2014-06-12 00:26:52 +04:00
|
|
|
if (NS_WARN_IF(aRv.Failed())) {
|
|
|
|
return;
|
|
|
|
}
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2011-11-03 19:57:30 +04:00
|
|
|
mHaveCachedKey = true;
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2014-06-12 00:26:52 +04:00
|
|
|
aResult.set(mCachedKey);
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2014-06-12 00:26:52 +04:00
|
|
|
void IDBCursor::GetPrimaryKey(JSContext* aCx,
|
|
|
|
JS::MutableHandle<JS::Value> aResult,
|
|
|
|
ErrorResult& aRv) {
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2011-01-07 09:21:36 +03:00
|
|
|
if (!mHaveValue) {
|
2014-06-12 00:26:52 +04:00
|
|
|
aResult.setUndefined();
|
|
|
|
return;
|
2011-01-07 09:21:36 +03:00
|
|
|
}
|
|
|
|
|
2011-02-11 10:47:00 +03:00
|
|
|
if (!mHaveCachedPrimaryKey) {
|
|
|
|
if (!mRooted) {
|
2013-08-17 00:10:17 +04:00
|
|
|
mozilla::HoldJSObjects(this);
|
2011-02-11 10:47:00 +03:00
|
|
|
mRooted = true;
|
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
const Key& key = (mType == Type_ObjectStore || mType == Type_ObjectStoreKey)
|
|
|
|
? mKey
|
|
|
|
: mPrimaryKey;
|
|
|
|
|
2013-09-26 03:11:47 +04:00
|
|
|
MOZ_ASSERT(!key.IsUnset());
|
2011-11-03 19:57:30 +04:00
|
|
|
|
2013-08-01 02:28:13 +04:00
|
|
|
aRv = key.ToJSVal(aCx, mCachedPrimaryKey);
|
2014-06-12 00:26:52 +04:00
|
|
|
if (NS_WARN_IF(aRv.Failed())) {
|
|
|
|
return;
|
|
|
|
}
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2011-02-11 10:47:00 +03:00
|
|
|
mHaveCachedPrimaryKey = true;
|
|
|
|
}
|
|
|
|
|
2014-06-12 00:26:52 +04:00
|
|
|
aResult.set(mCachedPrimaryKey);
|
2011-02-11 10:47:00 +03:00
|
|
|
}
|
|
|
|
|
2014-06-12 00:26:52 +04:00
|
|
|
void IDBCursor::GetValue(JSContext* aCx, JS::MutableHandle<JS::Value> aResult,
|
|
|
|
ErrorResult& aRv) {
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mType == Type_ObjectStore || mType == Type_Index);
|
2011-02-11 10:47:00 +03:00
|
|
|
|
|
|
|
if (!mHaveValue) {
|
2014-06-12 00:26:52 +04:00
|
|
|
aResult.setUndefined();
|
|
|
|
return;
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!mHaveCachedValue) {
|
2011-02-11 10:47:00 +03:00
|
|
|
if (!mRooted) {
|
2013-08-17 00:10:17 +04:00
|
|
|
mozilla::HoldJSObjects(this);
|
2011-02-11 10:47:00 +03:00
|
|
|
mRooted = true;
|
2010-09-14 02:32:56 +04:00
|
|
|
}
|
|
|
|
|
2013-05-02 13:12:47 +04:00
|
|
|
JS::Rooted<JS::Value> val(aCx);
|
2014-09-27 03:21:57 +04:00
|
|
|
if (NS_WARN_IF(!IDBObjectStore::DeserializeValue(aCx, mCloneInfo, &val))) {
|
2013-08-01 02:28:13 +04:00
|
|
|
aRv.Throw(NS_ERROR_DOM_DATA_CLONE_ERR);
|
2014-06-12 00:26:52 +04:00
|
|
|
return;
|
2010-12-21 19:02:04 +03:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
IDBObjectStore::ClearCloneReadInfo(mCloneInfo);
|
2012-06-01 21:21:12 +04:00
|
|
|
|
|
|
|
mCachedValue = val;
|
2010-06-23 23:46:08 +04:00
|
|
|
mHaveCachedValue = true;
|
|
|
|
}
|
|
|
|
|
2014-06-12 00:26:52 +04:00
|
|
|
aResult.set(mCachedValue);
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2013-08-01 02:28:13 +04:00
|
|
|
void IDBCursor::Continue(JSContext* aCx, JS::Handle<JS::Value> aKey,
|
|
|
|
ErrorResult& aRv) {
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
if (!mTransaction->IsOpen()) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_TRANSACTION_INACTIVE_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-07-02 20:47:53 +03:00
|
|
|
if (IsSourceDeleted() || !mHaveValue || mContinueCalled) {
|
2014-09-27 03:21:57 +04:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR);
|
|
|
|
return;
|
|
|
|
}
|
2010-06-23 23:46:08 +04:00
|
|
|
|
|
|
|
Key key;
|
2019-07-29 12:05:44 +03:00
|
|
|
auto result = key.SetFromJSVal(aCx, aKey, aRv);
|
|
|
|
if (!result.Is(Ok, aRv)) {
|
|
|
|
if (result.Is(Invalid, aRv)) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_DATA_ERR);
|
|
|
|
}
|
2014-09-27 03:21:57 +04:00
|
|
|
return;
|
|
|
|
}
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2015-09-04 22:12:29 +03:00
|
|
|
if (IsLocaleAware() && !key.IsUnset()) {
|
|
|
|
Key tmp;
|
2019-09-18 09:41:35 +03:00
|
|
|
result = key.ToLocaleAwareKey(tmp, mSourceIndex->Locale(), aRv);
|
2019-07-29 12:05:44 +03:00
|
|
|
if (!result.Is(Ok, aRv)) {
|
|
|
|
if (result.Is(Invalid, aRv)) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_DATA_ERR);
|
|
|
|
}
|
2015-09-04 22:12:29 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
key = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Key& sortKey = IsLocaleAware() ? mSortKey : mKey;
|
|
|
|
|
2010-12-10 05:15:00 +03:00
|
|
|
if (!key.IsUnset()) {
|
|
|
|
switch (mDirection) {
|
2014-09-27 03:21:57 +04:00
|
|
|
case NEXT:
|
|
|
|
case NEXT_UNIQUE:
|
2015-09-04 22:12:29 +03:00
|
|
|
if (key <= sortKey) {
|
2013-08-01 02:28:13 +04:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_DATA_ERR);
|
|
|
|
return;
|
2010-12-10 05:15:00 +03:00
|
|
|
}
|
|
|
|
break;
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
case PREV:
|
|
|
|
case PREV_UNIQUE:
|
2015-09-04 22:12:29 +03:00
|
|
|
if (key >= sortKey) {
|
2013-08-01 02:28:13 +04:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_DATA_ERR);
|
|
|
|
return;
|
2010-12-10 05:15:00 +03:00
|
|
|
}
|
|
|
|
break;
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-12-10 05:15:00 +03:00
|
|
|
default:
|
2014-04-20 11:36:40 +04:00
|
|
|
MOZ_CRASH("Unknown direction type!");
|
2010-12-10 05:15:00 +03:00
|
|
|
}
|
|
|
|
}
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2014-10-16 08:56:52 +04:00
|
|
|
const uint64_t requestSerialNumber = IDBRequest::NextSerialNumber();
|
|
|
|
mRequest->SetLoggingSerialNumber(requestSerialNumber);
|
2013-03-16 10:58:50 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
if (mType == Type_ObjectStore || mType == Type_ObjectStoreKey) {
|
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)."
|
|
|
|
"cursor(%s).continue(%s)",
|
2019-09-27 13:11:45 +03:00
|
|
|
"IDBCursor.continue()", mTransaction->LoggingSerialNumber(),
|
2014-10-16 08:56:52 +04:00
|
|
|
requestSerialNumber, IDB_LOG_STRINGIFY(mTransaction->Database()),
|
|
|
|
IDB_LOG_STRINGIFY(mTransaction), IDB_LOG_STRINGIFY(mSourceObjectStore),
|
|
|
|
IDB_LOG_STRINGIFY(mDirection), IDB_LOG_STRINGIFY(key));
|
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).cursor(%s).continue(%s)",
|
2019-09-27 13:11:45 +03:00
|
|
|
"IDBCursor.continue()", mTransaction->LoggingSerialNumber(),
|
2014-10-16 08:56:52 +04:00
|
|
|
requestSerialNumber, IDB_LOG_STRINGIFY(mTransaction->Database()),
|
|
|
|
IDB_LOG_STRINGIFY(mTransaction),
|
|
|
|
IDB_LOG_STRINGIFY(mSourceIndex->ObjectStore()),
|
|
|
|
IDB_LOG_STRINGIFY(mSourceIndex), IDB_LOG_STRINGIFY(mDirection),
|
|
|
|
IDB_LOG_STRINGIFY(key));
|
|
|
|
}
|
|
|
|
|
2019-10-02 02:28:15 +03:00
|
|
|
mBackgroundActor->SendContinueInternal(ContinueParams(key), Key());
|
2014-10-16 08:56:52 +04:00
|
|
|
|
|
|
|
mContinueCalled = true;
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2016-07-26 10:26:50 +03:00
|
|
|
void IDBCursor::ContinuePrimaryKey(JSContext* aCx, JS::Handle<JS::Value> aKey,
|
|
|
|
JS::Handle<JS::Value> aPrimaryKey,
|
|
|
|
ErrorResult& aRv) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
if (!mTransaction->IsOpen()) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_TRANSACTION_INACTIVE_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsSourceDeleted()) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((mType != Type_Index && mType != Type_IndexKey) ||
|
|
|
|
(mDirection != NEXT && mDirection != PREV)) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_ACCESS_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mHaveValue || mContinueCalled) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Key key;
|
2019-07-29 12:05:44 +03:00
|
|
|
auto result = key.SetFromJSVal(aCx, aKey, aRv);
|
|
|
|
if (!result.Is(Ok, aRv)) {
|
|
|
|
if (result.Is(Invalid, aRv)) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_DATA_ERR);
|
|
|
|
}
|
2016-07-26 10:26:50 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsLocaleAware() && !key.IsUnset()) {
|
|
|
|
Key tmp;
|
2019-09-18 09:41:35 +03:00
|
|
|
result = key.ToLocaleAwareKey(tmp, mSourceIndex->Locale(), aRv);
|
2019-07-29 12:05:44 +03:00
|
|
|
if (!result.Is(Ok, aRv)) {
|
|
|
|
if (result.Is(Invalid, aRv)) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_DATA_ERR);
|
|
|
|
}
|
2016-07-26 10:26:50 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
key = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (key.IsUnset()) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_DATA_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Key primaryKey;
|
2019-07-29 12:05:44 +03:00
|
|
|
result = primaryKey.SetFromJSVal(aCx, aPrimaryKey, aRv);
|
|
|
|
if (!result.Is(Ok, aRv)) {
|
|
|
|
if (result.Is(Invalid, aRv)) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_DATA_ERR);
|
|
|
|
}
|
2016-07-26 10:26:50 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (primaryKey.IsUnset()) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_DATA_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-07-30 17:51:21 +03:00
|
|
|
const Key& sortKey = IsLocaleAware() ? mSortKey : mKey;
|
|
|
|
|
2016-07-26 10:26:50 +03:00
|
|
|
switch (mDirection) {
|
|
|
|
case NEXT:
|
|
|
|
if (key < sortKey || (key == sortKey && primaryKey <= mPrimaryKey)) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_DATA_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PREV:
|
|
|
|
if (key > sortKey || (key == sortKey && primaryKey >= mPrimaryKey)) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_DATA_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
MOZ_CRASH("Unknown direction type!");
|
|
|
|
}
|
|
|
|
|
|
|
|
const uint64_t requestSerialNumber = IDBRequest::NextSerialNumber();
|
|
|
|
mRequest->SetLoggingSerialNumber(requestSerialNumber);
|
|
|
|
|
2019-09-27 13:11:45 +03:00
|
|
|
IDB_LOG_MARK_CHILD_TRANSACTION_REQUEST(
|
2016-07-26 10:26:50 +03:00
|
|
|
"database(%s).transaction(%s).objectStore(%s)."
|
|
|
|
"index(%s).cursor(%s).continuePrimaryKey(%s, %s)",
|
2019-09-27 13:11:45 +03:00
|
|
|
"IDBCursor.continuePrimaryKey()", mTransaction->LoggingSerialNumber(),
|
2016-07-26 10:26:50 +03:00
|
|
|
requestSerialNumber, IDB_LOG_STRINGIFY(mTransaction->Database()),
|
|
|
|
IDB_LOG_STRINGIFY(mTransaction),
|
|
|
|
IDB_LOG_STRINGIFY(mSourceIndex->ObjectStore()),
|
|
|
|
IDB_LOG_STRINGIFY(mSourceIndex), IDB_LOG_STRINGIFY(mDirection),
|
|
|
|
IDB_LOG_STRINGIFY(key), IDB_LOG_STRINGIFY(primaryKey));
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-07-26 10:26:50 +03:00
|
|
|
mBackgroundActor->SendContinueInternal(
|
2019-10-02 02:28:15 +03:00
|
|
|
ContinuePrimaryKeyParams(key, primaryKey), Key());
|
2016-07-26 10:26:50 +03:00
|
|
|
|
|
|
|
mContinueCalled = true;
|
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void IDBCursor::Advance(uint32_t aCount, ErrorResult& aRv) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
2015-07-02 20:47:53 +03:00
|
|
|
if (!aCount) {
|
2019-09-20 05:19:18 +03:00
|
|
|
aRv.ThrowTypeError(u"0 (Zero) is not a valid advance count.");
|
2014-09-27 03:21:57 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-07-02 20:47:53 +03:00
|
|
|
if (!mTransaction->IsOpen()) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_TRANSACTION_INACTIVE_ERR);
|
2014-09-27 03:21:57 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-07-02 20:47:53 +03:00
|
|
|
if (IsSourceDeleted() || !mHaveValue || mContinueCalled) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR);
|
2015-07-02 21:22:28 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-10-16 08:56:52 +04:00
|
|
|
const uint64_t requestSerialNumber = IDBRequest::NextSerialNumber();
|
|
|
|
mRequest->SetLoggingSerialNumber(requestSerialNumber);
|
|
|
|
|
|
|
|
if (mType == Type_ObjectStore || mType == Type_ObjectStoreKey) {
|
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)."
|
|
|
|
"cursor(%s).advance(%ld)",
|
2019-09-27 13:11:45 +03:00
|
|
|
"IDBCursor.advance()", mTransaction->LoggingSerialNumber(),
|
2014-10-16 08:56:52 +04:00
|
|
|
requestSerialNumber, IDB_LOG_STRINGIFY(mTransaction->Database()),
|
|
|
|
IDB_LOG_STRINGIFY(mTransaction), IDB_LOG_STRINGIFY(mSourceObjectStore),
|
|
|
|
IDB_LOG_STRINGIFY(mDirection), aCount);
|
|
|
|
} 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).cursor(%s).advance(%ld)",
|
2019-09-27 13:11:45 +03:00
|
|
|
"IDBCursor.advance()", mTransaction->LoggingSerialNumber(),
|
2014-10-16 08:56:52 +04:00
|
|
|
requestSerialNumber, IDB_LOG_STRINGIFY(mTransaction->Database()),
|
|
|
|
IDB_LOG_STRINGIFY(mTransaction),
|
|
|
|
IDB_LOG_STRINGIFY(mSourceIndex->ObjectStore()),
|
|
|
|
IDB_LOG_STRINGIFY(mSourceIndex), IDB_LOG_STRINGIFY(mDirection), aCount);
|
|
|
|
}
|
|
|
|
|
2019-10-02 02:28:15 +03:00
|
|
|
mBackgroundActor->SendContinueInternal(AdvanceParams(aCount), Key());
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
mContinueCalled = true;
|
|
|
|
}
|
|
|
|
|
2013-08-01 02:28:13 +04:00
|
|
|
already_AddRefed<IDBRequest> IDBCursor::Update(JSContext* aCx,
|
|
|
|
JS::Handle<JS::Value> aValue,
|
|
|
|
ErrorResult& aRv) {
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-12-16 00:21:17 +03:00
|
|
|
if (!mTransaction->IsOpen()) {
|
2013-08-01 02:28:13 +04:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_TRANSACTION_INACTIVE_ERR);
|
|
|
|
return nullptr;
|
2010-12-16 00:21:14 +03:00
|
|
|
}
|
|
|
|
|
2015-07-02 20:47:53 +03:00
|
|
|
if (!mTransaction->IsWriteAllowed()) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_READ_ONLY_ERR);
|
2013-08-01 02:28:13 +04:00
|
|
|
return nullptr;
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2016-03-15 09:00:37 +03:00
|
|
|
if (mTransaction->GetMode() == IDBTransaction::CLEANUP || IsSourceDeleted() ||
|
2015-07-02 20:47:53 +03:00
|
|
|
!mHaveValue || mType == Type_ObjectStoreKey || mType == Type_IndexKey ||
|
2016-04-20 09:36:19 +03:00
|
|
|
mContinueCalled) {
|
2015-07-02 20:47:53 +03:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR);
|
2014-09-18 03:36:01 +04:00
|
|
|
return nullptr;
|
2014-09-13 20:12:19 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(mType == Type_ObjectStore || mType == Type_Index);
|
2014-09-18 03:36:01 +04:00
|
|
|
MOZ_ASSERT(!mKey.IsUnset());
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT_IF(mType == Type_Index, !mPrimaryKey.IsUnset());
|
2014-09-13 20:12:19 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
IDBObjectStore* objectStore;
|
|
|
|
if (mType == Type_ObjectStore) {
|
|
|
|
objectStore = mSourceObjectStore;
|
|
|
|
} else {
|
|
|
|
objectStore = mSourceIndex->ObjectStore();
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(objectStore);
|
|
|
|
|
2018-07-24 19:19:10 +03:00
|
|
|
IDBObjectStore::ValueWrapper valueWrapper(aCx, aValue);
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
const Key& primaryKey = (mType == Type_ObjectStore) ? mKey : mPrimaryKey;
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<IDBRequest> request;
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
if (objectStore->HasValidKeyPath()) {
|
2018-07-24 19:19:10 +03:00
|
|
|
if (!valueWrapper.Clone(aCx)) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_DATA_CLONE_ERR);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2010-12-16 00:21:11 +03:00
|
|
|
// Make sure the object given has the correct keyPath value set on it.
|
2014-09-27 03:21:57 +04:00
|
|
|
const KeyPath& keyPath = objectStore->GetKeyPath();
|
2010-12-16 00:21:11 +03:00
|
|
|
Key key;
|
2012-06-22 02:27:13 +04:00
|
|
|
|
2018-07-24 19:19:10 +03:00
|
|
|
aRv = keyPath.ExtractKey(aCx, valueWrapper.Value(), key);
|
2013-08-01 02:28:13 +04:00
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
if (key != primaryKey) {
|
2013-08-01 02:28:13 +04:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_DATA_ERR);
|
|
|
|
return nullptr;
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2014-10-16 08:56:52 +04:00
|
|
|
request = objectStore->AddOrPut(aCx, valueWrapper,
|
|
|
|
/* aKey */ JS::UndefinedHandleValue,
|
|
|
|
/* aOverwrite */ true,
|
|
|
|
/* aFromCursor */ true, aRv);
|
2013-08-01 02:28:13 +04:00
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
2013-03-16 10:58:50 +04:00
|
|
|
}
|
|
|
|
} else {
|
2013-05-02 13:12:47 +04:00
|
|
|
JS::Rooted<JS::Value> keyVal(aCx);
|
2014-09-27 03:21:57 +04:00
|
|
|
aRv = primaryKey.ToJSVal(aCx, &keyVal);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-03-16 10:58:50 +04:00
|
|
|
|
2014-10-16 08:56:52 +04:00
|
|
|
request = objectStore->AddOrPut(aCx, valueWrapper, keyVal,
|
|
|
|
/* aOverwrite */ true,
|
|
|
|
/* aFromCursor */ true, aRv);
|
2013-08-01 02:28:13 +04:00
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
2013-03-16 10:58:50 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
request->SetSource(this);
|
|
|
|
|
2014-10-16 08:56:52 +04:00
|
|
|
if (mType == Type_ObjectStore) {
|
2019-09-27 13:11:45 +03:00
|
|
|
IDB_LOG_MARK_CHILD_TRANSACTION_REQUEST(
|
|
|
|
" %s: Child Transaction[%lld] Request[%llu]: "
|
2014-10-16 08:56:52 +04:00
|
|
|
"database(%s).transaction(%s).objectStore(%s)."
|
|
|
|
"cursor(%s).update(%s)",
|
2019-09-27 13:11:45 +03:00
|
|
|
"IDBCursor.update()", mTransaction->LoggingSerialNumber(),
|
2014-10-16 08:56:52 +04:00
|
|
|
request->LoggingSerialNumber(),
|
|
|
|
IDB_LOG_STRINGIFY(mTransaction->Database()),
|
|
|
|
IDB_LOG_STRINGIFY(mTransaction), IDB_LOG_STRINGIFY(objectStore),
|
|
|
|
IDB_LOG_STRINGIFY(mDirection),
|
|
|
|
IDB_LOG_STRINGIFY(objectStore, primaryKey));
|
|
|
|
} 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).cursor(%s).update(%s)",
|
2019-09-27 13:11:45 +03:00
|
|
|
"IDBCursor.update()", mTransaction->LoggingSerialNumber(),
|
2014-10-16 08:56:52 +04:00
|
|
|
request->LoggingSerialNumber(),
|
|
|
|
IDB_LOG_STRINGIFY(mTransaction->Database()),
|
|
|
|
IDB_LOG_STRINGIFY(mTransaction), IDB_LOG_STRINGIFY(objectStore),
|
|
|
|
IDB_LOG_STRINGIFY(mSourceIndex), IDB_LOG_STRINGIFY(mDirection),
|
|
|
|
IDB_LOG_STRINGIFY(objectStore, primaryKey));
|
2013-03-16 10:58:50 +04:00
|
|
|
}
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2013-08-01 02:28:13 +04:00
|
|
|
return request.forget();
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2013-08-01 02:28:13 +04:00
|
|
|
already_AddRefed<IDBRequest> IDBCursor::Delete(JSContext* aCx,
|
|
|
|
ErrorResult& aRv) {
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-12-16 00:21:17 +03:00
|
|
|
if (!mTransaction->IsOpen()) {
|
2013-08-01 02:28:13 +04:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_TRANSACTION_INACTIVE_ERR);
|
|
|
|
return nullptr;
|
2010-12-16 00:21:14 +03:00
|
|
|
}
|
|
|
|
|
2015-07-02 20:47:53 +03:00
|
|
|
if (!mTransaction->IsWriteAllowed()) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_READ_ONLY_ERR);
|
2013-08-01 02:28:13 +04:00
|
|
|
return nullptr;
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2015-07-02 20:47:53 +03:00
|
|
|
if (IsSourceDeleted() || !mHaveValue || mType == Type_ObjectStoreKey ||
|
2015-07-29 01:59:55 +03:00
|
|
|
mType == Type_IndexKey || mContinueCalled) {
|
2015-07-02 20:47:53 +03:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR);
|
2014-09-18 03:36:01 +04:00
|
|
|
return nullptr;
|
2014-09-13 20:12:19 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(mType == Type_ObjectStore || mType == Type_Index);
|
2014-09-18 03:36:01 +04:00
|
|
|
MOZ_ASSERT(!mKey.IsUnset());
|
2014-09-13 20:12:19 +04:00
|
|
|
|
2019-10-03 10:56:45 +03:00
|
|
|
IDBObjectStore* const objectStore = mType == Type_ObjectStore
|
|
|
|
? mSourceObjectStore.get()
|
|
|
|
: mSourceIndex->ObjectStore();
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
MOZ_ASSERT(objectStore);
|
|
|
|
|
|
|
|
const Key& primaryKey = (mType == Type_ObjectStore) ? mKey : mPrimaryKey;
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2013-05-02 13:12:47 +04:00
|
|
|
JS::Rooted<JS::Value> key(aCx);
|
2014-09-27 03:21:57 +04:00
|
|
|
aRv = primaryKey.ToJSVal(aCx, &key);
|
|
|
|
if (NS_WARN_IF(aRv.Failed())) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<IDBRequest> request =
|
2014-10-16 08:56:52 +04:00
|
|
|
objectStore->DeleteInternal(aCx, key, /* aFromCursor */ true, aRv);
|
2014-09-27 03:21:57 +04:00
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
request->SetSource(this);
|
2013-03-16 10:58:50 +04:00
|
|
|
|
2014-10-16 08:56:52 +04:00
|
|
|
if (mType == Type_ObjectStore) {
|
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)."
|
|
|
|
"cursor(%s).delete(%s)",
|
2019-09-27 13:11:45 +03:00
|
|
|
"IDBCursor.delete()", mTransaction->LoggingSerialNumber(),
|
2014-10-16 08:56:52 +04:00
|
|
|
request->LoggingSerialNumber(),
|
|
|
|
IDB_LOG_STRINGIFY(mTransaction->Database()),
|
|
|
|
IDB_LOG_STRINGIFY(mTransaction), IDB_LOG_STRINGIFY(objectStore),
|
|
|
|
IDB_LOG_STRINGIFY(mDirection),
|
|
|
|
IDB_LOG_STRINGIFY(objectStore, primaryKey));
|
|
|
|
} 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).cursor(%s).delete(%s)",
|
2019-09-27 13:11:45 +03:00
|
|
|
"IDBCursor.delete()", mTransaction->LoggingSerialNumber(),
|
2014-10-16 08:56:52 +04:00
|
|
|
request->LoggingSerialNumber(),
|
|
|
|
IDB_LOG_STRINGIFY(mTransaction->Database()),
|
|
|
|
IDB_LOG_STRINGIFY(mTransaction), IDB_LOG_STRINGIFY(objectStore),
|
|
|
|
IDB_LOG_STRINGIFY(mSourceIndex), IDB_LOG_STRINGIFY(mDirection),
|
|
|
|
IDB_LOG_STRINGIFY(objectStore, primaryKey));
|
2013-03-16 10:58:50 +04:00
|
|
|
}
|
|
|
|
|
2013-08-01 02:28:13 +04:00
|
|
|
return request.forget();
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void IDBCursor::Reset(Key&& aKey, StructuredCloneReadInfo&& aValue) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mType == Type_ObjectStore);
|
2011-11-08 03:37:19 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
Reset();
|
2011-11-08 03:37:19 +04:00
|
|
|
|
2018-05-30 22:15:35 +03:00
|
|
|
mKey = std::move(aKey);
|
|
|
|
mCloneInfo = std::move(aValue);
|
2013-03-16 10:58:50 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
mHaveValue = !mKey.IsUnset();
|
2011-11-08 03:37:19 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void IDBCursor::Reset(Key&& aKey) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mType == Type_ObjectStoreKey);
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
Reset();
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2018-05-30 22:15:35 +03:00
|
|
|
mKey = std::move(aKey);
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
mHaveValue = !mKey.IsUnset();
|
2012-06-01 21:21:12 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void IDBCursor::Reset(Key&& aKey, Key&& aSortKey, Key&& aPrimaryKey,
|
|
|
|
StructuredCloneReadInfo&& aValue) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mType == Type_Index);
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
Reset();
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2018-05-30 22:15:35 +03:00
|
|
|
mKey = std::move(aKey);
|
|
|
|
mSortKey = std::move(aSortKey);
|
|
|
|
mPrimaryKey = std::move(aPrimaryKey);
|
|
|
|
mCloneInfo = std::move(aValue);
|
2010-09-10 08:54:25 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
mHaveValue = !mKey.IsUnset();
|
2010-12-10 05:15:00 +03:00
|
|
|
}
|
|
|
|
|
2015-09-04 22:12:29 +03:00
|
|
|
void IDBCursor::Reset(Key&& aKey, Key&& aSortKey, Key&& aPrimaryKey) {
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mType == Type_IndexKey);
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
Reset();
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2018-05-30 22:15:35 +03:00
|
|
|
mKey = std::move(aKey);
|
|
|
|
mSortKey = std::move(aSortKey);
|
|
|
|
mPrimaryKey = std::move(aPrimaryKey);
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
mHaveValue = !mKey.IsUnset();
|
2014-09-18 03:36:01 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(IDBCursor)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(IDBCursor)
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(IDBCursor)
|
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_END
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(IDBCursor)
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(IDBCursor)
|
2014-11-08 03:42:53 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mRequest)
|
2014-09-27 03:21:57 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSourceObjectStore)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSourceIndex)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(IDBCursor)
|
|
|
|
MOZ_ASSERT_IF(!tmp->mHaveCachedKey, tmp->mCachedKey.isUndefined());
|
|
|
|
MOZ_ASSERT_IF(!tmp->mHaveCachedPrimaryKey,
|
|
|
|
tmp->mCachedPrimaryKey.isUndefined());
|
|
|
|
MOZ_ASSERT_IF(!tmp->mHaveCachedValue, tmp->mCachedValue.isUndefined());
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +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(mCachedKey)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mCachedPrimaryKey)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mCachedValue)
|
2014-09-27 03:21:57 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(IDBCursor)
|
2014-11-08 03:42:53 +03:00
|
|
|
// Don't unlink mRequest, mSourceObjectStore, or mSourceIndex!
|
2014-09-27 03:21:57 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
|
|
|
|
tmp->DropJSObjects();
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
2014-09-18 03:36:01 +04: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 17:13:33 +03:00
|
|
|
JSObject* IDBCursor::WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
switch (mType) {
|
|
|
|
case Type_ObjectStore:
|
|
|
|
case Type_Index:
|
2018-06-26 00:20:54 +03:00
|
|
|
return IDBCursorWithValue_Binding::Wrap(aCx, this, aGivenProto);
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
case Type_ObjectStoreKey:
|
|
|
|
case Type_IndexKey:
|
2018-06-26 00:20:54 +03:00
|
|
|
return IDBCursor_Binding::Wrap(aCx, this, aGivenProto);
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
default:
|
|
|
|
MOZ_CRASH("Bad type!");
|
2014-09-18 03:36:01 +04:00
|
|
|
}
|
2010-12-10 05:15:00 +03:00
|
|
|
}
|
2010-11-16 00:49:49 +03:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|