mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-03 04:27:41 +00:00
Bug 891944 - Move IDBCursor to WebIDL, r=janv
This commit is contained in:
parent
0310984563
commit
3c66a55593
@ -53,6 +53,5 @@ exports.indexedDB = Object.freeze({
|
||||
|
||||
exports.IDBKeyRange = IDBKeyRange;
|
||||
exports.DOMException = Ci.nsIDOMDOMException;
|
||||
exports.IDBCursor = Ci.nsIIDBCursor;
|
||||
exports.IDBOpenDBRequest = Ci.nsIIDBOpenDBRequest;
|
||||
exports.IDBRequest = Ci.nsIIDBRequest;
|
||||
|
@ -8,7 +8,7 @@ let xulApp = require("sdk/system/xul-app");
|
||||
if (xulApp.versionInRange(xulApp.platformVersion, "16.0a1", "*")) {
|
||||
new function tests() {
|
||||
|
||||
const { indexedDB, IDBKeyRange, DOMException, IDBCursor,
|
||||
const { indexedDB, IDBKeyRange, DOMException
|
||||
IDBOpenDBRequest, IDBRequest
|
||||
} = require("sdk/indexed-db");
|
||||
|
||||
@ -22,7 +22,7 @@ exports["test indexedDB is frozen"] = function(assert){
|
||||
};
|
||||
|
||||
exports["test db variables"] = function(assert) {
|
||||
[ indexedDB, IDBKeyRange, DOMException, IDBCursor,
|
||||
[ indexedDB, IDBKeyRange, DOMException
|
||||
IDBOpenDBRequest, IDBOpenDBRequest, IDBRequest
|
||||
].forEach(function(value) {
|
||||
assert.notEqual(typeof(value), "undefined", "variable is defined");
|
||||
|
@ -203,7 +203,6 @@
|
||||
|
||||
#include "mozilla/dom/indexedDB/IDBWrapperCache.h"
|
||||
#include "mozilla/dom/indexedDB/IDBRequest.h"
|
||||
#include "mozilla/dom/indexedDB/IDBCursor.h"
|
||||
#include "mozilla/dom/indexedDB/IDBKeyRange.h"
|
||||
|
||||
using mozilla::dom::indexedDB::IDBWrapperCache;
|
||||
@ -633,10 +632,6 @@ static nsDOMClassInfoData sClassInfoData[] = {
|
||||
|
||||
NS_DEFINE_CLASSINFO_DATA(IDBRequest, IDBEventTargetSH,
|
||||
IDBEVENTTARGET_SCRIPTABLE_FLAGS)
|
||||
NS_DEFINE_CLASSINFO_DATA(IDBCursor, nsDOMGenericSH,
|
||||
DOM_DEFAULT_SCRIPTABLE_FLAGS)
|
||||
NS_DEFINE_CLASSINFO_DATA(IDBCursorWithValue, nsDOMGenericSH,
|
||||
DOM_DEFAULT_SCRIPTABLE_FLAGS)
|
||||
NS_DEFINE_CLASSINFO_DATA(IDBKeyRange, nsDOMGenericSH,
|
||||
DOM_DEFAULT_SCRIPTABLE_FLAGS)
|
||||
NS_DEFINE_CLASSINFO_DATA(IDBOpenDBRequest, IDBEventTargetSH,
|
||||
@ -1532,15 +1527,6 @@ nsDOMClassInfo::Init()
|
||||
DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget)
|
||||
DOM_CLASSINFO_MAP_END
|
||||
|
||||
DOM_CLASSINFO_MAP_BEGIN(IDBCursor, nsIIDBCursor)
|
||||
DOM_CLASSINFO_MAP_ENTRY(nsIIDBCursor)
|
||||
DOM_CLASSINFO_MAP_END
|
||||
|
||||
DOM_CLASSINFO_MAP_BEGIN(IDBCursorWithValue, nsIIDBCursorWithValue)
|
||||
DOM_CLASSINFO_MAP_ENTRY(nsIIDBCursor)
|
||||
DOM_CLASSINFO_MAP_ENTRY(nsIIDBCursorWithValue)
|
||||
DOM_CLASSINFO_MAP_END
|
||||
|
||||
DOM_CLASSINFO_MAP_BEGIN(IDBKeyRange, nsIIDBKeyRange)
|
||||
DOM_CLASSINFO_MAP_ENTRY(nsIIDBKeyRange)
|
||||
DOM_CLASSINFO_MAP_END
|
||||
@ -2809,7 +2795,7 @@ DefineInterfaceConstants(JSContext *cx, JS::Handle<JSObject*> obj, const nsIID *
|
||||
}
|
||||
|
||||
// This code is temporary until we remove support for the constants defined
|
||||
// on IDBCursor/IDBRequest
|
||||
// on IDBRequest
|
||||
|
||||
struct IDBConstant
|
||||
{
|
||||
@ -2817,18 +2803,12 @@ struct IDBConstant
|
||||
const char* name;
|
||||
const char* value;
|
||||
|
||||
static const char* IDBCursor;
|
||||
static const char* IDBRequest;
|
||||
};
|
||||
|
||||
const char* IDBConstant::IDBCursor = "IDBCursor";
|
||||
const char* IDBConstant::IDBRequest = "IDBRequest";
|
||||
|
||||
static const IDBConstant sIDBConstants[] = {
|
||||
{ IDBConstant::IDBCursor, "NEXT", "next" },
|
||||
{ IDBConstant::IDBCursor, "NEXT_NO_DUPLICATE", "nextunique" },
|
||||
{ IDBConstant::IDBCursor, "PREV", "prev" },
|
||||
{ IDBConstant::IDBCursor, "PREV_NO_DUPLICATE", "prevunique" },
|
||||
{ IDBConstant::IDBRequest, "LOADING", "pending" },
|
||||
{ IDBConstant::IDBRequest, "DONE", "done" },
|
||||
};
|
||||
@ -2918,10 +2898,7 @@ static nsresult
|
||||
DefineIDBInterfaceConstants(JSContext *cx, JS::Handle<JSObject*> obj, const nsIID *aIID)
|
||||
{
|
||||
const char* interface;
|
||||
if (aIID->Equals(NS_GET_IID(nsIIDBCursor))) {
|
||||
interface = IDBConstant::IDBCursor;
|
||||
}
|
||||
else if (aIID->Equals(NS_GET_IID(nsIIDBRequest))) {
|
||||
if (aIID->Equals(NS_GET_IID(nsIIDBRequest))) {
|
||||
interface = IDBConstant::IDBRequest;
|
||||
}
|
||||
else {
|
||||
@ -3345,8 +3322,7 @@ nsDOMConstructor::ResolveInterfaceConstants(JSContext *cx, JS::Handle<JSObject*>
|
||||
|
||||
// Special case a few IDB interfaces which for now are getting transitional
|
||||
// constants.
|
||||
if (class_iid->Equals(NS_GET_IID(nsIIDBCursor)) ||
|
||||
class_iid->Equals(NS_GET_IID(nsIIDBRequest))) {
|
||||
if (class_iid->Equals(NS_GET_IID(nsIIDBRequest))) {
|
||||
rv = DefineIDBInterfaceConstants(cx, obj, class_iid);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
@ -3483,8 +3459,7 @@ ResolvePrototype(nsIXPConnect *aXPConnect, nsGlobalWindow *aWin, JSContext *cx,
|
||||
|
||||
// Special case a few IDB interfaces which for now are getting transitional
|
||||
// constants.
|
||||
if (primary_iid->Equals(NS_GET_IID(nsIIDBCursor)) ||
|
||||
primary_iid->Equals(NS_GET_IID(nsIIDBRequest))) {
|
||||
if (primary_iid->Equals(NS_GET_IID(nsIIDBRequest))) {
|
||||
rv = DefineIDBInterfaceConstants(cx, class_obj, primary_iid);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
@ -120,8 +120,6 @@ DOMCI_CLASS(ChromeMessageBroadcaster)
|
||||
DOMCI_CLASS(ChromeMessageSender)
|
||||
|
||||
DOMCI_CLASS(IDBRequest)
|
||||
DOMCI_CLASS(IDBCursor)
|
||||
DOMCI_CLASS(IDBCursorWithValue)
|
||||
DOMCI_CLASS(IDBKeyRange)
|
||||
DOMCI_CLASS(IDBOpenDBRequest)
|
||||
|
||||
|
@ -538,6 +538,18 @@ DOMInterfaces = {
|
||||
'nativeType' : 'mozilla::dom::HTMLSharedListElement'
|
||||
},
|
||||
|
||||
'IDBCursor': {
|
||||
'nativeType': 'mozilla::dom::indexedDB::IDBCursor',
|
||||
'implicitJSContext': [ 'delete' ],
|
||||
'binaryNames': {
|
||||
'direction': 'getDirection'
|
||||
}
|
||||
},
|
||||
|
||||
'IDBCursorWithValue': {
|
||||
'nativeType': 'mozilla::dom::indexedDB::IDBCursor',
|
||||
},
|
||||
|
||||
'IDBDatabase': {
|
||||
'nativeType': 'mozilla::dom::indexedDB::IDBDatabase',
|
||||
},
|
||||
|
@ -44,3 +44,4 @@ MSG_DEF(MSG_INVALID_VERSION, 0, "0 (Zero) is not a valid database version.")
|
||||
MSG_DEF(MSG_INVALID_BYTESTRING, 2, "Cannot convert string to ByteString because the character"
|
||||
" at index {0} has value {1} which is greater than 255.")
|
||||
MSG_DEF(MSG_NOT_DATE, 1, "{0} is not a date.")
|
||||
MSG_DEF(MSG_INVALID_ADVANCE_COUNT, 0, "0 (Zero) is not a valid advance count.")
|
||||
|
@ -28,9 +28,12 @@
|
||||
#include "ipc/IndexedDBParent.h"
|
||||
|
||||
#include "IndexedDatabaseInlines.h"
|
||||
#include "mozilla/dom/BindingDeclarations.h"
|
||||
|
||||
USING_INDEXEDDB_NAMESPACE
|
||||
using namespace mozilla::dom::indexedDB::ipc;
|
||||
using mozilla::dom::Optional;
|
||||
using mozilla::ErrorResult;
|
||||
|
||||
static_assert(sizeof(size_t) >= sizeof(IDBCursor::Direction),
|
||||
"Relying on conversion between size_t and "
|
||||
@ -353,6 +356,8 @@ IDBCursor::IDBCursor()
|
||||
mHaveValue(true)
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
|
||||
SetIsDOMBinding();
|
||||
}
|
||||
|
||||
IDBCursor::~IDBCursor()
|
||||
@ -388,19 +393,20 @@ IDBCursor::DropJSObjects()
|
||||
NS_DROP_JS_OBJECTS(this, IDBCursor);
|
||||
}
|
||||
|
||||
nsresult
|
||||
IDBCursor::ContinueInternal(const Key& aKey,
|
||||
int32_t aCount)
|
||||
void
|
||||
IDBCursor::ContinueInternal(const Key& aKey, int32_t aCount, ErrorResult& aRv)
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
NS_ASSERTION(aCount > 0, "Must have a count!");
|
||||
|
||||
if (!mTransaction->IsOpen()) {
|
||||
return NS_ERROR_DOM_INDEXEDDB_TRANSACTION_INACTIVE_ERR;
|
||||
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_TRANSACTION_INACTIVE_ERR);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!mHaveValue || mContinueCalled) {
|
||||
return NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR;
|
||||
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR);
|
||||
return;
|
||||
}
|
||||
|
||||
mContinueToKey = aKey;
|
||||
@ -436,10 +442,13 @@ IDBCursor::ContinueInternal(const Key& aKey,
|
||||
}
|
||||
|
||||
nsresult rv = helper->DispatchToTransactionPool();
|
||||
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING("Failed to dispatch!");
|
||||
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
||||
return;
|
||||
}
|
||||
|
||||
mContinueCalled = true;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(IDBCursor)
|
||||
@ -451,6 +460,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(IDBCursor)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(IDBCursor)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
|
||||
NS_ASSERTION(tmp->mHaveCachedKey || JSVAL_IS_VOID(tmp->mCachedKey),
|
||||
"Should have a cached key");
|
||||
NS_ASSERTION(tmp->mHaveCachedPrimaryKey ||
|
||||
@ -465,76 +475,79 @@ NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(IDBCursor)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(IDBCursor)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
|
||||
// Don't unlink mObjectStore, mIndex, or mTransaction!
|
||||
tmp->DropJSObjects();
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mRequest)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(IDBCursor)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIIDBCursor)
|
||||
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIIDBCursorWithValue, mType != INDEXKEY)
|
||||
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO_CONDITIONAL(IDBCursorWithValue,
|
||||
mType != INDEXKEY)
|
||||
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO_CONDITIONAL(IDBCursor,
|
||||
mType == INDEXKEY)
|
||||
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
||||
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(IDBCursor)
|
||||
NS_IMPL_CYCLE_COLLECTING_RELEASE(IDBCursor)
|
||||
|
||||
DOMCI_DATA(IDBCursor, IDBCursor)
|
||||
DOMCI_DATA(IDBCursorWithValue, IDBCursor)
|
||||
JSObject*
|
||||
IDBCursor::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
|
||||
{
|
||||
return mType != INDEXKEY
|
||||
? IDBCursorWithValueBinding::Wrap(aCx, aScope, this)
|
||||
: IDBCursorBinding::Wrap(aCx, aScope, this);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
IDBCursor::GetDirection(nsAString& aDirection)
|
||||
mozilla::dom::IDBCursorDirection
|
||||
IDBCursor::GetDirection() const
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
|
||||
switch (mDirection) {
|
||||
case NEXT:
|
||||
aDirection.AssignLiteral("next");
|
||||
break;
|
||||
return mozilla::dom::IDBCursorDirection::Next;
|
||||
|
||||
case NEXT_UNIQUE:
|
||||
aDirection.AssignLiteral("nextunique");
|
||||
break;
|
||||
return mozilla::dom::IDBCursorDirection::Nextunique;
|
||||
|
||||
case PREV:
|
||||
aDirection.AssignLiteral("prev");
|
||||
break;
|
||||
return mozilla::dom::IDBCursorDirection::Prev;
|
||||
|
||||
case PREV_UNIQUE:
|
||||
aDirection.AssignLiteral("prevunique");
|
||||
break;
|
||||
return mozilla::dom::IDBCursorDirection::Prevunique;
|
||||
|
||||
case DIRECTION_INVALID:
|
||||
default:
|
||||
NS_NOTREACHED("Bad direction value!");
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
MOZ_CRASH("Unknown direction!");
|
||||
return mozilla::dom::IDBCursorDirection::Next;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
IDBCursor::GetSource(nsISupports** aSource)
|
||||
|
||||
already_AddRefed<nsISupports>
|
||||
IDBCursor::Source() const
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
|
||||
return mType == OBJECTSTORE ?
|
||||
CallQueryInterface(mObjectStore, aSource) :
|
||||
CallQueryInterface(mIndex, aSource);
|
||||
nsCOMPtr<nsISupports> source;
|
||||
if (mType == OBJECTSTORE) {
|
||||
source = do_QueryInterface(mObjectStore);
|
||||
}
|
||||
else {
|
||||
source = do_QueryInterface(mIndex);
|
||||
}
|
||||
|
||||
return source.forget();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
IDBCursor::GetKey(JSContext* aCx,
|
||||
jsval* aKey)
|
||||
JS::Value
|
||||
IDBCursor::GetKey(JSContext* aCx, ErrorResult& aRv)
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
|
||||
NS_ASSERTION(!mKey.IsUnset() || !mHaveValue, "Bad key!");
|
||||
|
||||
if (!mHaveValue) {
|
||||
*aKey = JSVAL_VOID;
|
||||
return NS_OK;
|
||||
return JSVAL_VOID;
|
||||
}
|
||||
|
||||
if (!mHaveCachedKey) {
|
||||
@ -543,25 +556,22 @@ IDBCursor::GetKey(JSContext* aCx,
|
||||
mRooted = true;
|
||||
}
|
||||
|
||||
nsresult rv = mKey.ToJSVal(aCx, mCachedKey);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
aRv = mKey.ToJSVal(aCx, mCachedKey);
|
||||
ENSURE_SUCCESS(aRv, JSVAL_VOID);
|
||||
|
||||
mHaveCachedKey = true;
|
||||
}
|
||||
|
||||
*aKey = mCachedKey;
|
||||
return NS_OK;
|
||||
return mCachedKey;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
IDBCursor::GetPrimaryKey(JSContext* aCx,
|
||||
jsval* aValue)
|
||||
JS::Value
|
||||
IDBCursor::GetPrimaryKey(JSContext* aCx, ErrorResult& aRv)
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
|
||||
if (!mHaveValue) {
|
||||
*aValue = JSVAL_VOID;
|
||||
return NS_OK;
|
||||
return JSVAL_VOID;
|
||||
}
|
||||
|
||||
if (!mHaveCachedPrimaryKey) {
|
||||
@ -577,26 +587,23 @@ IDBCursor::GetPrimaryKey(JSContext* aCx,
|
||||
|
||||
const Key& key = mType == OBJECTSTORE ? mKey : mObjectKey;
|
||||
|
||||
nsresult rv = key.ToJSVal(aCx, mCachedPrimaryKey);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
aRv = key.ToJSVal(aCx, mCachedPrimaryKey);
|
||||
ENSURE_SUCCESS(aRv, JSVAL_VOID);
|
||||
|
||||
mHaveCachedPrimaryKey = true;
|
||||
}
|
||||
|
||||
*aValue = mCachedPrimaryKey;
|
||||
return NS_OK;
|
||||
return mCachedPrimaryKey;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
IDBCursor::GetValue(JSContext* aCx,
|
||||
jsval* aValue)
|
||||
JS::Value
|
||||
IDBCursor::GetValue(JSContext* aCx, ErrorResult& aRv)
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
NS_ASSERTION(mType != INDEXKEY, "GetValue shouldn't exist on index keys");
|
||||
|
||||
if (!mHaveValue) {
|
||||
*aValue = JSVAL_VOID;
|
||||
return NS_OK;
|
||||
return JSVAL_VOID;
|
||||
}
|
||||
|
||||
if (!mHaveCachedValue) {
|
||||
@ -607,7 +614,8 @@ IDBCursor::GetValue(JSContext* aCx,
|
||||
|
||||
JS::Rooted<JS::Value> val(aCx);
|
||||
if (!IDBObjectStore::DeserializeValue(aCx, mCloneReadInfo, &val)) {
|
||||
return NS_ERROR_DOM_DATA_CLONE_ERR;
|
||||
aRv.Throw(NS_ERROR_DOM_DATA_CLONE_ERR);
|
||||
return JSVAL_VOID;
|
||||
}
|
||||
|
||||
mCloneReadInfo.mCloneBuffer.clear();
|
||||
@ -616,33 +624,37 @@ IDBCursor::GetValue(JSContext* aCx,
|
||||
mHaveCachedValue = true;
|
||||
}
|
||||
|
||||
*aValue = mCachedValue;
|
||||
return NS_OK;
|
||||
return mCachedValue;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
IDBCursor::Continue(const jsval& aKey,
|
||||
JSContext* aCx)
|
||||
void
|
||||
IDBCursor::Continue(JSContext* aCx,
|
||||
const Optional<JS::Handle<JS::Value> >& aKey,
|
||||
ErrorResult &aRv)
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
|
||||
Key key;
|
||||
nsresult rv = key.SetFromJSVal(aCx, aKey);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
if (aKey.WasPassed()) {
|
||||
aRv = key.SetFromJSVal(aCx, aKey.Value());
|
||||
ENSURE_SUCCESS_VOID(aRv);
|
||||
}
|
||||
|
||||
if (!key.IsUnset()) {
|
||||
switch (mDirection) {
|
||||
case IDBCursor::NEXT:
|
||||
case IDBCursor::NEXT_UNIQUE:
|
||||
if (key <= mKey) {
|
||||
return NS_ERROR_DOM_INDEXEDDB_DATA_ERR;
|
||||
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_DATA_ERR);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
|
||||
case IDBCursor::PREV:
|
||||
case IDBCursor::PREV_UNIQUE:
|
||||
if (key >= mKey) {
|
||||
return NS_ERROR_DOM_INDEXEDDB_DATA_ERR;
|
||||
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_DATA_ERR);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
|
||||
@ -651,9 +663,9 @@ IDBCursor::Continue(const jsval& aKey,
|
||||
}
|
||||
}
|
||||
|
||||
rv = ContinueInternal(key, 1);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
ContinueInternal(key, 1, aRv);
|
||||
if (aRv.Failed()) {
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef IDB_PROFILER_USE_MARKS
|
||||
@ -683,73 +695,70 @@ IDBCursor::Continue(const jsval& aKey,
|
||||
key.IsUnset() ? "" : IDB_PROFILER_STRING(key));
|
||||
}
|
||||
#endif
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
IDBCursor::Update(const jsval& aValue,
|
||||
JSContext* aCx,
|
||||
nsIIDBRequest** _retval)
|
||||
already_AddRefed<IDBRequest>
|
||||
IDBCursor::Update(JSContext* aCx, JS::Handle<JS::Value> aValue,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
|
||||
if (!mTransaction->IsOpen()) {
|
||||
return NS_ERROR_DOM_INDEXEDDB_TRANSACTION_INACTIVE_ERR;
|
||||
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_TRANSACTION_INACTIVE_ERR);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!mTransaction->IsWriteAllowed()) {
|
||||
return NS_ERROR_DOM_INDEXEDDB_READ_ONLY_ERR;
|
||||
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_READ_ONLY_ERR);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!mHaveValue || mType == INDEXKEY) {
|
||||
return NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR;
|
||||
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NS_ASSERTION(mObjectStore, "This cannot be null!");
|
||||
NS_ASSERTION(!mKey.IsUnset() , "Bad key!");
|
||||
NS_ASSERTION(mType != INDEXOBJECT || !mObjectKey.IsUnset(), "Bad key!");
|
||||
|
||||
nsresult rv;
|
||||
|
||||
JSAutoRequest ar(aCx);
|
||||
|
||||
Key& objectKey = (mType == OBJECTSTORE) ? mKey : mObjectKey;
|
||||
|
||||
nsCOMPtr<nsIIDBRequest> request;
|
||||
nsRefPtr<IDBRequest> request;
|
||||
if (mObjectStore->HasValidKeyPath()) {
|
||||
// Make sure the object given has the correct keyPath value set on it.
|
||||
const KeyPath& keyPath = mObjectStore->GetKeyPath();
|
||||
Key key;
|
||||
|
||||
rv = keyPath.ExtractKey(aCx, aValue, key);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
aRv = keyPath.ExtractKey(aCx, aValue, key);
|
||||
if (aRv.Failed()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (key != objectKey) {
|
||||
return NS_ERROR_DOM_INDEXEDDB_DATA_ERR;
|
||||
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_DATA_ERR);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ErrorResult error;
|
||||
JS::Rooted<JS::Value> value(aCx, aValue);
|
||||
Optional<JS::Handle<JS::Value> > keyValue(aCx);
|
||||
request = mObjectStore->Put(aCx, value, keyValue, error);
|
||||
if (error.Failed()) {
|
||||
return error.ErrorCode();
|
||||
request = mObjectStore->Put(aCx, value, keyValue, aRv);
|
||||
if (aRv.Failed()) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
else {
|
||||
JS::Rooted<JS::Value> keyVal(aCx);
|
||||
rv = objectKey.ToJSVal(aCx, &keyVal);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
aRv = objectKey.ToJSVal(aCx, &keyVal);
|
||||
ENSURE_SUCCESS(aRv, nullptr);
|
||||
|
||||
ErrorResult error;
|
||||
JS::Rooted<JS::Value> value(aCx, aValue);
|
||||
Optional<JS::Handle<JS::Value> > keyValue(aCx, keyVal);
|
||||
request = mObjectStore->Put(aCx, value, keyValue, error);
|
||||
if (error.Failed()) {
|
||||
return error.ErrorCode();
|
||||
request = mObjectStore->Put(aCx, value, keyValue, aRv);
|
||||
if (aRv.Failed()) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@ -787,26 +796,27 @@ IDBCursor::Update(const jsval& aValue,
|
||||
}
|
||||
#endif
|
||||
|
||||
request.forget(_retval);
|
||||
return NS_OK;
|
||||
return request.forget();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
IDBCursor::Delete(JSContext* aCx,
|
||||
nsIIDBRequest** _retval)
|
||||
already_AddRefed<IDBRequest>
|
||||
IDBCursor::Delete(JSContext* aCx, ErrorResult& aRv)
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
|
||||
if (!mTransaction->IsOpen()) {
|
||||
return NS_ERROR_DOM_INDEXEDDB_TRANSACTION_INACTIVE_ERR;
|
||||
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_TRANSACTION_INACTIVE_ERR);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!mTransaction->IsWriteAllowed()) {
|
||||
return NS_ERROR_DOM_INDEXEDDB_READ_ONLY_ERR;
|
||||
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_READ_ONLY_ERR);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!mHaveValue || mType == INDEXKEY) {
|
||||
return NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR;
|
||||
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NS_ASSERTION(mObjectStore, "This cannot be null!");
|
||||
@ -815,19 +825,17 @@ IDBCursor::Delete(JSContext* aCx,
|
||||
Key& objectKey = (mType == OBJECTSTORE) ? mKey : mObjectKey;
|
||||
|
||||
JS::Rooted<JS::Value> key(aCx);
|
||||
nsresult rv = objectKey.ToJSVal(aCx, &key);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
aRv = objectKey.ToJSVal(aCx, &key);
|
||||
ENSURE_SUCCESS(aRv, nullptr);
|
||||
|
||||
ErrorResult error;
|
||||
nsCOMPtr<nsIIDBRequest> request = mObjectStore->Delete(aCx, key, error);
|
||||
if (error.Failed()) {
|
||||
return error.ErrorCode();
|
||||
nsRefPtr<IDBRequest> request = mObjectStore->Delete(aCx, key, aRv);
|
||||
if (aRv.Failed()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
#ifdef IDB_PROFILER_USE_MARKS
|
||||
{
|
||||
uint64_t requestSerial =
|
||||
static_cast<IDBRequest*>(request.get())->GetSerialNumber();
|
||||
uint64_t requestSerial = request->GetSerialNumber();
|
||||
if (mType == OBJECTSTORE) {
|
||||
IDB_PROFILER_MARK("IndexedDB Request %llu: "
|
||||
"database(%s).transaction(%s).objectStore(%s)."
|
||||
@ -858,24 +866,22 @@ IDBCursor::Delete(JSContext* aCx,
|
||||
}
|
||||
#endif
|
||||
|
||||
request.forget(_retval);
|
||||
return NS_OK;
|
||||
return request.forget();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
IDBCursor::Advance(int64_t aCount)
|
||||
void
|
||||
IDBCursor::Advance(uint32_t aCount, ErrorResult &aRv)
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
|
||||
if (aCount < 1 || aCount > UINT32_MAX) {
|
||||
return NS_ERROR_TYPE_ERR;
|
||||
if (aCount < 1) {
|
||||
aRv.ThrowTypeError(MSG_INVALID_ADVANCE_COUNT);
|
||||
return;
|
||||
}
|
||||
|
||||
Key key;
|
||||
nsresult rv = ContinueInternal(key, int32_t(aCount));
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
ContinueInternal(key, int32_t(aCount), aRv);
|
||||
ENSURE_SUCCESS_VOID(aRv);
|
||||
|
||||
#ifdef IDB_PROFILER_USE_MARKS
|
||||
{
|
||||
@ -904,8 +910,6 @@ IDBCursor::Advance(int64_t aCount)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -9,15 +9,15 @@
|
||||
|
||||
#include "mozilla/dom/indexedDB/IndexedDatabase.h"
|
||||
|
||||
#include "nsIIDBCursorWithValue.h"
|
||||
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/dom/IDBCursorBinding.h"
|
||||
#include "mozilla/ErrorResult.h"
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
#include "nsWrapperCache.h"
|
||||
|
||||
#include "mozilla/dom/indexedDB/IDBObjectStore.h"
|
||||
#include "mozilla/dom/indexedDB/Key.h"
|
||||
|
||||
|
||||
class nsIRunnable;
|
||||
class nsIScriptContext;
|
||||
class nsPIDOMWindow;
|
||||
@ -34,7 +34,8 @@ class IDBTransaction;
|
||||
class IndexedDBCursorChild;
|
||||
class IndexedDBCursorParent;
|
||||
|
||||
class IDBCursor MOZ_FINAL : public nsIIDBCursorWithValue
|
||||
class IDBCursor MOZ_FINAL : public nsISupports,
|
||||
public nsWrapperCache
|
||||
{
|
||||
friend class ContinueHelper;
|
||||
friend class ContinueObjectStoreHelper;
|
||||
@ -43,9 +44,6 @@ class IDBCursor MOZ_FINAL : public nsIIDBCursorWithValue
|
||||
|
||||
public:
|
||||
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||
NS_DECL_NSIIDBCURSOR
|
||||
NS_DECL_NSIIDBCURSORWITHVALUE
|
||||
|
||||
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(IDBCursor)
|
||||
|
||||
enum Type
|
||||
@ -146,9 +144,48 @@ public:
|
||||
return mActorParent;
|
||||
}
|
||||
|
||||
nsresult
|
||||
ContinueInternal(const Key& aKey,
|
||||
int32_t aCount);
|
||||
void
|
||||
ContinueInternal(const Key& aKey, int32_t aCount,
|
||||
ErrorResult& aRv);
|
||||
|
||||
// nsWrapperCache
|
||||
virtual JSObject*
|
||||
WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
|
||||
|
||||
// WebIDL
|
||||
IDBTransaction*
|
||||
GetParentObject() const
|
||||
{
|
||||
return mTransaction;
|
||||
}
|
||||
|
||||
already_AddRefed<nsISupports>
|
||||
Source() const;
|
||||
|
||||
IDBCursorDirection
|
||||
GetDirection() const;
|
||||
|
||||
JS::Value
|
||||
GetKey(JSContext* aCx, ErrorResult& aRv);
|
||||
|
||||
JS::Value
|
||||
GetPrimaryKey(JSContext* aCx, ErrorResult& aRv);
|
||||
|
||||
already_AddRefed<IDBRequest>
|
||||
Update(JSContext* aCx, JS::Handle<JS::Value> aValue, ErrorResult& aRv);
|
||||
|
||||
void
|
||||
Advance(uint32_t aCount, ErrorResult& aRv);
|
||||
|
||||
void
|
||||
Continue(JSContext* aCx, const Optional<JS::Handle<JS::Value> >& aKey,
|
||||
ErrorResult& aRv);
|
||||
|
||||
already_AddRefed<IDBRequest>
|
||||
Delete(JSContext* aCx, ErrorResult& aRv);
|
||||
|
||||
JS::Value
|
||||
GetValue(JSContext* aCx, ErrorResult& aRv);
|
||||
|
||||
protected:
|
||||
IDBCursor();
|
||||
|
@ -2044,8 +2044,9 @@ IndexedDBCursorRequestParent::Continue(const ContinueParams& aParams)
|
||||
{
|
||||
AutoSetCurrentTransaction asct(mCursor->Transaction());
|
||||
|
||||
nsresult rv = mCursor->ContinueInternal(aParams.key(), aParams.count());
|
||||
NS_ENSURE_SUCCESS(rv, false);
|
||||
ErrorResult rv;
|
||||
mCursor->ContinueInternal(aParams.key(), aParams.count(), rv);
|
||||
ENSURE_SUCCESS(rv, false);
|
||||
}
|
||||
|
||||
mRequest = mCursor->Request();
|
||||
|
@ -8,8 +8,6 @@ DIRS += ['ipc']
|
||||
TEST_DIRS += ['test']
|
||||
|
||||
XPIDL_SOURCES += [
|
||||
'nsIIDBCursor.idl',
|
||||
'nsIIDBCursorWithValue.idl',
|
||||
'nsIIDBKeyRange.idl',
|
||||
'nsIIDBOpenDBRequest.idl',
|
||||
'nsIIDBRequest.idl',
|
||||
|
@ -1,45 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* 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/. */
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
interface nsIIDBRequest;
|
||||
|
||||
/**
|
||||
* IDBCursor interface. See
|
||||
* http://dev.w3.org/2006/webapi/WebSimpleDB/#idl-def-IDBCursor for more
|
||||
* information.
|
||||
*/
|
||||
[scriptable, builtinclass, uuid(148579a3-6b28-4b2a-92c3-ff5719e8e03e)]
|
||||
interface nsIIDBCursor : nsISupports
|
||||
{
|
||||
// "next", "nextunique", "prev" or "prevunique"
|
||||
readonly attribute DOMString direction;
|
||||
|
||||
readonly attribute nsISupports source;
|
||||
|
||||
[implicit_jscontext]
|
||||
readonly attribute jsval key;
|
||||
|
||||
[implicit_jscontext]
|
||||
readonly attribute jsval primaryKey;
|
||||
|
||||
// Calling continue means that the same onsuccess function will be called
|
||||
// again with the new key/value (or null if no more matches).
|
||||
[implicit_jscontext]
|
||||
void continue([optional /* undefined */] in jsval key);
|
||||
|
||||
// Success fires IDBTransactionEvent, result == key
|
||||
[implicit_jscontext]
|
||||
nsIIDBRequest update(in jsval value);
|
||||
|
||||
// Success fires IDBTransactionEvent, result == null
|
||||
[implicit_jscontext]
|
||||
nsIIDBRequest delete();
|
||||
|
||||
void
|
||||
advance(in long long count);
|
||||
};
|
@ -1,19 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* 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/. */
|
||||
|
||||
#include "nsIIDBCursor.idl"
|
||||
|
||||
/**
|
||||
* IDBCursor interface. See
|
||||
* http://dev.w3.org/2006/webapi/WebSimpleDB/#idl-def-IDBCursor for more
|
||||
* information.
|
||||
*/
|
||||
[scriptable, builtinclass, uuid(b6b7e08a-4379-4441-a176-447c5c96df69)]
|
||||
interface nsIIDBCursorWithValue : nsIIDBCursor
|
||||
{
|
||||
[implicit_jscontext]
|
||||
readonly attribute jsval value;
|
||||
};
|
@ -6,7 +6,6 @@
|
||||
const { 'classes': Cc, 'interfaces': Ci } = Components;
|
||||
|
||||
const DOMException = Ci.nsIDOMDOMException;
|
||||
const IDBCursor = Ci.nsIIDBCursor;
|
||||
const IDBOpenDBRequest = Ci.nsIIDBOpenDBRequest;
|
||||
const IDBRequest = Ci.nsIIDBRequest
|
||||
|
||||
|
@ -13,3 +13,33 @@ enum IDBCursorDirection {
|
||||
"prev",
|
||||
"prevunique"
|
||||
};
|
||||
|
||||
interface IDBCursor {
|
||||
// This should be: readonly attribute (IDBObjectStore or IDBIndex) source;
|
||||
readonly attribute nsISupports source;
|
||||
|
||||
readonly attribute IDBCursorDirection direction;
|
||||
|
||||
[Throws]
|
||||
readonly attribute any key;
|
||||
|
||||
[Throws]
|
||||
readonly attribute any primaryKey;
|
||||
|
||||
[Throws]
|
||||
IDBRequest update (any value);
|
||||
|
||||
[Throws]
|
||||
void advance ([EnforceRange] unsigned long count);
|
||||
|
||||
[Throws]
|
||||
void continue (optional any key);
|
||||
|
||||
[Throws]
|
||||
IDBRequest delete ();
|
||||
};
|
||||
|
||||
interface IDBCursorWithValue : IDBCursor {
|
||||
[Throws]
|
||||
readonly attribute any value;
|
||||
};
|
||||
|
@ -84,8 +84,6 @@ members = [
|
||||
'nsIBoxObject.height',
|
||||
|
||||
# dom/indexedDB
|
||||
'nsIIDBCursor.*',
|
||||
'nsIIDBCursorWithValue.*',
|
||||
'nsIIDBKeyRange.*',
|
||||
'nsIIDBRequest.*',
|
||||
'nsIIDBOpenDBRequest.*',
|
||||
|
Loading…
x
Reference in New Issue
Block a user