From ed2a9cfb16b45f68cbe9bc91202d8308cb35397e Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Fri, 2 Aug 2013 11:38:49 +0200 Subject: [PATCH] Backout changeset 531f544bc9ce for breaking B2G tests. --- dom/base/nsDOMClassInfo.cpp | 26 +- dom/base/nsDOMClassInfoClasses.h | 2 + dom/bindings/Bindings.conf | 5 - dom/indexedDB/IDBIndex.cpp | 2 + dom/indexedDB/IDBKeyRange.cpp | 315 ++++++++++++++++------- dom/indexedDB/IDBKeyRange.h | 61 +---- dom/indexedDB/IndexedDatabaseManager.cpp | 14 +- dom/indexedDB/moz.build | 1 + dom/indexedDB/nsIIDBKeyRange.idl | 25 ++ dom/webidl/IDBKeyRange.webidl | 29 --- dom/webidl/WebIDL.mk | 1 - js/xpconnect/src/dom_quickstubs.qsconf | 1 + 12 files changed, 298 insertions(+), 184 deletions(-) create mode 100644 dom/indexedDB/nsIIDBKeyRange.idl delete mode 100644 dom/webidl/IDBKeyRange.webidl diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp index 49b4bd6a742..89549d09f64 100644 --- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -202,6 +202,7 @@ #include "mozilla/dom/Element.h" #include "mozilla/dom/indexedDB/IDBWrapperCache.h" +#include "mozilla/dom/indexedDB/IDBKeyRange.h" using mozilla::dom::indexedDB::IDBWrapperCache; using mozilla::dom::workers::ResolveWorkerClasses; @@ -629,6 +630,10 @@ static nsDOMClassInfoData sClassInfoData[] = { NS_DEFINE_CHROME_ONLY_CLASSINFO_DATA(ChromeMessageSender, nsDOMGenericSH, DOM_DEFAULT_SCRIPTABLE_FLAGS) + NS_DEFINE_CLASSINFO_DATA(IDBKeyRange, nsDOMGenericSH, + DOM_DEFAULT_SCRIPTABLE_FLAGS) + + NS_DEFINE_CLASSINFO_DATA(MozCSSKeyframeRule, nsDOMGenericSH, DOM_DEFAULT_SCRIPTABLE_FLAGS) NS_DEFINE_CLASSINFO_DATA(MozCSSKeyframesRule, nsDOMGenericSH, @@ -1513,6 +1518,10 @@ nsDOMClassInfo::Init() DOM_CLASSINFO_MAP_ENTRY(nsIMessageSender) DOM_CLASSINFO_MAP_END + DOM_CLASSINFO_MAP_BEGIN(IDBKeyRange, nsIIDBKeyRange) + DOM_CLASSINFO_MAP_ENTRY(nsIIDBKeyRange) + DOM_CLASSINFO_MAP_END + DOM_CLASSINFO_MAP_BEGIN(MozCSSKeyframeRule, nsIDOMMozCSSKeyframeRule) DOM_CLASSINFO_MAP_ENTRY(nsIDOMMozCSSKeyframeRule) DOM_CLASSINFO_MAP_END @@ -3214,7 +3223,16 @@ nsDOMConstructor::ResolveInterfaceConstants(JSContext *cx, JS::Handle return NS_OK; } - return DefineInterfaceConstants(cx, obj, class_iid); + nsresult rv = DefineInterfaceConstants(cx, obj, class_iid); + NS_ENSURE_SUCCESS(rv, rv); + + // Special case for |IDBKeyRange| which gets funny "static" functions. + if (class_iid->Equals(NS_GET_IID(nsIIDBKeyRange)) && + !indexedDB::IDBKeyRange::DefineConstructors(cx, obj)) { + return NS_ERROR_FAILURE; + } + + return NS_OK; } NS_IMETHODIMP @@ -3338,6 +3356,12 @@ ResolvePrototype(nsIXPConnect *aXPConnect, nsGlobalWindow *aWin, JSContext *cx, rv = DefineInterfaceConstants(cx, class_obj, primary_iid); NS_ENSURE_SUCCESS(rv, rv); + // Special case for |IDBKeyRange| which gets funny "static" functions. + if (primary_iid->Equals(NS_GET_IID(nsIIDBKeyRange)) && + !indexedDB::IDBKeyRange::DefineConstructors(cx, class_obj)) { + return NS_ERROR_FAILURE; + } + nsCOMPtr iim(do_GetService(NS_INTERFACEINFOMANAGER_SERVICE_CONTRACTID)); NS_ENSURE_TRUE(iim, NS_ERROR_NOT_AVAILABLE); diff --git a/dom/base/nsDOMClassInfoClasses.h b/dom/base/nsDOMClassInfoClasses.h index 8ee2a189072..6d388c879bd 100644 --- a/dom/base/nsDOMClassInfoClasses.h +++ b/dom/base/nsDOMClassInfoClasses.h @@ -119,6 +119,8 @@ DOMCI_CLASS(ContentFrameMessageManager) DOMCI_CLASS(ChromeMessageBroadcaster) DOMCI_CLASS(ChromeMessageSender) +DOMCI_CLASS(IDBKeyRange) + DOMCI_CLASS(MozCSSKeyframeRule) DOMCI_CLASS(MozCSSKeyframesRule) diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf index 7f7c99d9a51..dbd22ef00de 100644 --- a/dom/bindings/Bindings.conf +++ b/dom/bindings/Bindings.conf @@ -591,11 +591,6 @@ DOMInterfaces = { 'nativeType': 'mozilla::dom::indexedDB::IDBTransaction', }, -'IDBKeyRange': { - 'nativeType': 'mozilla::dom::indexedDB::IDBKeyRange', - 'wrapperCache': False, -}, - 'IDBVersionChangeEvent': { 'nativeType': 'mozilla::dom::indexedDB::IDBVersionChangeEvent', 'headerFile': 'IDBEvents.h', diff --git a/dom/indexedDB/IDBIndex.cpp b/dom/indexedDB/IDBIndex.cpp index 637d31b5b4e..3561c7d7ee4 100644 --- a/dom/indexedDB/IDBIndex.cpp +++ b/dom/indexedDB/IDBIndex.cpp @@ -8,6 +8,8 @@ #include "IDBIndex.h" +#include "nsIIDBKeyRange.h" + #include "mozilla/dom/ContentChild.h" #include "mozilla/dom/ContentParent.h" #include "mozilla/dom/ipc/Blob.h" diff --git a/dom/indexedDB/IDBKeyRange.cpp b/dom/indexedDB/IDBKeyRange.cpp index 48c31914e72..3c02ff634a7 100644 --- a/dom/indexedDB/IDBKeyRange.cpp +++ b/dom/indexedDB/IDBKeyRange.cpp @@ -18,16 +18,54 @@ #include "mozilla/dom/indexedDB/PIndexedDBIndex.h" #include "mozilla/dom/indexedDB/PIndexedDBObjectStore.h" -#include "mozilla/dom/IDBKeyRangeBinding.h" -using namespace mozilla; -using namespace mozilla::dom; USING_INDEXEDDB_NAMESPACE using namespace mozilla::dom::indexedDB::ipc; -static inline nsresult +namespace { + +inline +bool +ReturnKeyRange(JSContext* aCx, + jsval* aVp, + IDBKeyRange* aKeyRange) +{ + NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); + NS_ASSERTION(aCx, "Null pointer!"); + NS_ASSERTION(aVp, "Null pointer!"); + NS_ASSERTION(aKeyRange, "Null pointer!"); + + nsIXPConnect* xpc = nsContentUtils::XPConnect(); + NS_ASSERTION(xpc, "This should never be null!"); + + JSObject* global = JS::CurrentGlobalOrNull(aCx); + if (!global) { + NS_WARNING("Couldn't get global object!"); + return false; + } + + nsCOMPtr holder; + if (NS_FAILED(xpc->WrapNative(aCx, global, aKeyRange, + NS_GET_IID(nsIIDBKeyRange), + getter_AddRefs(holder)))) { + JS_ReportError(aCx, "Couldn't wrap IDBKeyRange object."); + return false; + } + + JS::Rooted result(aCx, holder->GetJSObject()); + if (!result) { + JS_ReportError(aCx, "Couldn't get JSObject from wrapper."); + return false; + } + + JS_SET_RVAL(aCx, aVp, OBJECT_TO_JSVAL(result)); + return true; +} + +inline +nsresult GetKeyFromJSVal(JSContext* aCx, - JS::Handle aVal, + jsval aVal, Key& aKey, bool aAllowUnset = false) { @@ -45,121 +83,196 @@ GetKeyFromJSVal(JSContext* aCx, return NS_OK; } -JSObject* -IDBKeyRange::WrapObject(JSContext* aCx, JS::Handle aScope) +inline +void +ThrowException(JSContext* aCx, + nsresult aErrorCode) { - return IDBKeyRangeBinding::Wrap(aCx, aScope, this); + NS_ASSERTION(NS_FAILED(aErrorCode), "Not an error code!"); + xpc::Throw(aCx, aErrorCode); } -/* static */ already_AddRefed -IDBKeyRange::Only(const GlobalObject& aGlobal, JSContext* aCx, - JS::Handle aValue, ErrorResult& aRv) +inline +bool +GetKeyFromJSValOrThrow(JSContext* aCx, + jsval aVal, + Key& aKey) { - MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!"); - - nsRefPtr keyRange = new IDBKeyRange(aGlobal.Get(), false, false, true); - - aRv = GetKeyFromJSVal(aCx, aValue, keyRange->Lower()); - if (aRv.Failed()) { - return nullptr; + nsresult rv = GetKeyFromJSVal(aCx, aVal, aKey); + if (NS_FAILED(rv)) { + ThrowException(aCx, rv); + return false; } - - return keyRange.forget(); + return true; } -/* static */ already_AddRefed -IDBKeyRange::LowerBound(const GlobalObject& aGlobal, JSContext* aCx, - JS::Handle aValue, bool aOpen, - ErrorResult& aRv) +JSBool +MakeOnlyKeyRange(JSContext* aCx, + unsigned aArgc, + jsval* aVp) { - MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!"); + NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); - nsRefPtr keyRange = new IDBKeyRange(aGlobal.Get(), aOpen, true, false); - - aRv = GetKeyFromJSVal(aCx, aValue, keyRange->Lower()); - if (aRv.Failed()) { - return nullptr; + JS::Rooted val(aCx); + if (!JS_ConvertArguments(aCx, aArgc, JS_ARGV(aCx, aVp), "v", val.address())) { + return false; } - return keyRange.forget(); + nsRefPtr keyRange = new IDBKeyRange(false, false, true); + + if (!GetKeyFromJSValOrThrow(aCx, val, keyRange->Lower())) { + return false; + } + + return ReturnKeyRange(aCx, aVp, keyRange); } -/* static */ already_AddRefed -IDBKeyRange::UpperBound(const GlobalObject& aGlobal, JSContext* aCx, - JS::Handle aValue, bool aOpen, - ErrorResult& aRv) +JSBool +MakeLowerBoundKeyRange(JSContext* aCx, + unsigned aArgc, + jsval* aVp) { - MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!"); + NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); - nsRefPtr keyRange = new IDBKeyRange(aGlobal.Get(), true, aOpen, false); - - aRv = GetKeyFromJSVal(aCx, aValue, keyRange->Upper()); - if (aRv.Failed()) { - return nullptr; + JS::Rooted val(aCx); + JSBool open = false; + if (!JS_ConvertArguments(aCx, aArgc, JS_ARGV(aCx, aVp), "v/b", val.address(), + &open)) { + return false; } - return keyRange.forget(); + nsRefPtr keyRange = new IDBKeyRange(open, true, false); + + if (!GetKeyFromJSValOrThrow(aCx, val, keyRange->Lower())) { + return false; + } + + return ReturnKeyRange(aCx, aVp, keyRange); } -/* static */ already_AddRefed -IDBKeyRange::Bound(const GlobalObject& aGlobal, JSContext* aCx, - JS::Handle aLower, JS::Handle aUpper, - bool aLowerOpen, bool aUpperOpen, ErrorResult& aRv) +JSBool +MakeUpperBoundKeyRange(JSContext* aCx, + unsigned aArgc, + jsval* aVp) { - MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!"); + NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); - nsRefPtr keyRange = new IDBKeyRange(aGlobal.Get(), aLowerOpen, - aUpperOpen, false); - - aRv = GetKeyFromJSVal(aCx, aLower, keyRange->Lower()); - if (aRv.Failed()) { - return nullptr; + JS::Rooted val(aCx); + JSBool open = false; + if (!JS_ConvertArguments(aCx, aArgc, JS_ARGV(aCx, aVp), "v/b", val.address(), + &open)) { + return false; } - aRv = GetKeyFromJSVal(aCx, aUpper, keyRange->Upper()); - if (aRv.Failed()) { - return nullptr; + nsRefPtr keyRange = new IDBKeyRange(true, open, false); + + if (!GetKeyFromJSValOrThrow(aCx, val, keyRange->Upper())) { + return false; + } + + return ReturnKeyRange(aCx, aVp, keyRange); +} + +JSBool +MakeBoundKeyRange(JSContext* aCx, + unsigned aArgc, + jsval* aVp) +{ + NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); + + JS::Rooted lowerVal(aCx), upperVal(aCx); + JSBool lowerOpen = false, upperOpen = false; + if (!JS_ConvertArguments(aCx, aArgc, JS_ARGV(aCx, aVp), "vv/bb", + lowerVal.address(), upperVal.address(), + &lowerOpen, &upperOpen)) { + return false; + } + + nsRefPtr keyRange = new IDBKeyRange(lowerOpen, upperOpen, false); + + if (!GetKeyFromJSValOrThrow(aCx, lowerVal, keyRange->Lower()) || + !GetKeyFromJSValOrThrow(aCx, upperVal, keyRange->Upper())) { + return false; } if (keyRange->Lower() > keyRange->Upper() || - (keyRange->Lower() == keyRange->Upper() && (aLowerOpen || aUpperOpen))) { - aRv.Throw(NS_ERROR_DOM_INDEXEDDB_DATA_ERR); - return nullptr; + (keyRange->Lower() == keyRange->Upper() && (lowerOpen || upperOpen))) { + ThrowException(aCx, NS_ERROR_DOM_INDEXEDDB_DATA_ERR); + return false; } - return keyRange.forget(); + return ReturnKeyRange(aCx, aVp, keyRange); +} + +#define KEYRANGE_FUNCTION_FLAGS (JSPROP_ENUMERATE | JSPROP_PERMANENT) + +const JSFunctionSpec gKeyRangeConstructors[] = { + JS_FN("only", MakeOnlyKeyRange, 1, KEYRANGE_FUNCTION_FLAGS), + JS_FN("lowerBound", MakeLowerBoundKeyRange, 1, KEYRANGE_FUNCTION_FLAGS), + JS_FN("upperBound", MakeUpperBoundKeyRange, 1, KEYRANGE_FUNCTION_FLAGS), + JS_FN("bound", MakeBoundKeyRange, 2, KEYRANGE_FUNCTION_FLAGS), + JS_FS_END +}; + +#undef KEYRANGE_FUNCTION_FLAGS + +} // anonymous namespace + +// static +JSBool +IDBKeyRange::DefineConstructors(JSContext* aCx, + JSObject* aObject) +{ + NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); + NS_ASSERTION(aCx, "Null pointer!"); + NS_ASSERTION(aObject, "Null pointer!"); + + // Add the constructor methods for key ranges. + return JS_DefineFunctions(aCx, aObject, gKeyRangeConstructors); } // static nsresult IDBKeyRange::FromJSVal(JSContext* aCx, - const jsval& aValue, + const jsval& aVal, IDBKeyRange** aKeyRange) { - JS::Rooted value(aCx, aValue); + nsresult rv; nsRefPtr keyRange; - if (value.isNullOrUndefined()) { + if (JSVAL_IS_VOID(aVal) || JSVAL_IS_NULL(aVal)) { // undefined and null returns no IDBKeyRange. } - else if (value.isPrimitive() || - JS_IsArrayObject(aCx, &value.toObject()) || - JS_ObjectIsDate(aCx, &value.toObject())) { + else if (JSVAL_IS_PRIMITIVE(aVal) || + JS_IsArrayObject(aCx, JSVAL_TO_OBJECT(aVal)) || + JS_ObjectIsDate(aCx, JSVAL_TO_OBJECT(aVal))) { // A valid key returns an 'only' IDBKeyRange. - keyRange = new IDBKeyRange(nullptr, false, false, true); + keyRange = new IDBKeyRange(false, false, true); - nsresult rv = GetKeyFromJSVal(aCx, value, keyRange->Lower()); + rv = GetKeyFromJSVal(aCx, aVal, keyRange->Lower()); if (NS_FAILED(rv)) { return rv; } } else { - MOZ_ASSERT(value.isObject()); // An object is not permitted unless it's another IDBKeyRange. - if (NS_FAILED(UnwrapObject(aCx, &value.toObject(), - keyRange))) { + nsIXPConnect* xpc = nsContentUtils::XPConnect(); + NS_ASSERTION(xpc, "This should never be null!"); + + nsCOMPtr wrapper; + rv = xpc->GetWrappedNativeOfJSObject(aCx, JSVAL_TO_OBJECT(aVal), + getter_AddRefs(wrapper)); + if (NS_FAILED(rv)) { return NS_ERROR_DOM_INDEXEDDB_DATA_ERR; } + + nsCOMPtr iface; + if (!wrapper || !(iface = do_QueryInterface(wrapper->Native()))) { + // Some random JS object? + return NS_ERROR_DOM_INDEXEDDB_DATA_ERR; + } + + keyRange = static_cast(iface.get()); } keyRange.forget(aKeyRange); @@ -172,7 +285,7 @@ already_AddRefed IDBKeyRange::FromSerializedKeyRange(const T& aKeyRange) { nsRefPtr keyRange = - new IDBKeyRange(nullptr, aKeyRange.lowerOpen(), aKeyRange.upperOpen(), + new IDBKeyRange(aKeyRange.lowerOpen(), aKeyRange.upperOpen(), aKeyRange.isOnly()); keyRange->Lower() = aKeyRange.lower(); if (!keyRange->IsOnly()) { @@ -195,9 +308,7 @@ IDBKeyRange::ToSerializedKeyRange(T& aKeyRange) } } - NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(IDBKeyRange) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mGlobal) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END @@ -207,17 +318,20 @@ NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(IDBKeyRange) NS_IMPL_CYCLE_COLLECTION_TRACE_END NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(IDBKeyRange) - NS_IMPL_CYCLE_COLLECTION_UNLINK(mGlobal) tmp->DropJSObjects(); NS_IMPL_CYCLE_COLLECTION_UNLINK_END NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(IDBKeyRange) NS_INTERFACE_MAP_ENTRY(nsISupports) + NS_INTERFACE_MAP_ENTRY(nsIIDBKeyRange) + NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(IDBKeyRange) NS_INTERFACE_MAP_END NS_IMPL_CYCLE_COLLECTING_ADDREF(IDBKeyRange) NS_IMPL_CYCLE_COLLECTING_RELEASE(IDBKeyRange) +DOMCI_DATA(IDBKeyRange, IDBKeyRange) + void IDBKeyRange::DropJSObjects() { @@ -237,10 +351,11 @@ IDBKeyRange::~IDBKeyRange() DropJSObjects(); } -JS::Value -IDBKeyRange::GetLower(JSContext* aCx, ErrorResult& aRv) +NS_IMETHODIMP +IDBKeyRange::GetLower(JSContext* aCx, + jsval* aLower) { - MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!"); + NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); if (!mHaveCachedLowerVal) { if (!mRooted) { @@ -248,21 +363,21 @@ IDBKeyRange::GetLower(JSContext* aCx, ErrorResult& aRv) mRooted = true; } - aRv = Lower().ToJSVal(aCx, mCachedLowerVal); - if (aRv.Failed()) { - return JS::UndefinedValue(); - } + nsresult rv = Lower().ToJSVal(aCx, mCachedLowerVal); + NS_ENSURE_SUCCESS(rv, rv); mHaveCachedLowerVal = true; } - return mCachedLowerVal; + *aLower = mCachedLowerVal; + return NS_OK; } -JS::Value -IDBKeyRange::GetUpper(JSContext* aCx, ErrorResult& aRv) +NS_IMETHODIMP +IDBKeyRange::GetUpper(JSContext* aCx, + jsval* aUpper) { - MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!"); + NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); if (!mHaveCachedUpperVal) { if (!mRooted) { @@ -270,15 +385,33 @@ IDBKeyRange::GetUpper(JSContext* aCx, ErrorResult& aRv) mRooted = true; } - aRv = Upper().ToJSVal(aCx, mCachedUpperVal); - if (aRv.Failed()) { - return JS::UndefinedValue(); - } + nsresult rv = Upper().ToJSVal(aCx, mCachedUpperVal); + NS_ENSURE_SUCCESS(rv, rv); mHaveCachedUpperVal = true; } - return mCachedUpperVal; + *aUpper = mCachedUpperVal; + return NS_OK; +} + +NS_IMETHODIMP +IDBKeyRange::GetLowerOpen(bool* aLowerOpen) +{ + NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); + + *aLowerOpen = mLowerOpen; + return NS_OK; +} + + +NS_IMETHODIMP +IDBKeyRange::GetUpperOpen(bool* aUpperOpen) +{ + NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); + + *aUpperOpen = mUpperOpen; + return NS_OK; } // Explicitly instantiate for all our key range types... Grumble. diff --git a/dom/indexedDB/IDBKeyRange.h b/dom/indexedDB/IDBKeyRange.h index d08677e4c9e..733f24b1d49 100644 --- a/dom/indexedDB/IDBKeyRange.h +++ b/dom/indexedDB/IDBKeyRange.h @@ -9,18 +9,13 @@ #include "mozilla/dom/indexedDB/IndexedDatabase.h" #include "mozilla/dom/indexedDB/Key.h" -#include "mozilla/ErrorResult.h" + +#include "nsIIDBKeyRange.h" + #include "nsCycleCollectionParticipant.h" -#include "nsISupports.h" class mozIStorageStatement; -namespace mozilla { -namespace dom { -class GlobalObject; -} // namespace dom -} // namespace mozilla - BEGIN_INDEXEDDB_NAMESPACE namespace ipc { @@ -29,44 +24,15 @@ class KeyRange; } // namespace FIXME_Bug_521898_objectstore } // namespace ipc -class IDBKeyRange MOZ_FINAL : public nsISupports +class IDBKeyRange MOZ_FINAL : public nsIIDBKeyRange { public: NS_DECL_CYCLE_COLLECTING_ISUPPORTS + NS_DECL_NSIIDBKEYRANGE NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(IDBKeyRange) - JSObject* WrapObject(JSContext* aCx, JS::Handle aScope); - nsISupports* GetParentObject() const - { - return mGlobal; - } - - // WebIDL - JS::Value GetLower(JSContext* aCx, ErrorResult& aRv); - JS::Value GetUpper(JSContext* aCx, ErrorResult& aRv); - bool LowerOpen() const - { - return mLowerOpen; - } - bool UpperOpen() const - { - return mUpperOpen; - } - - static already_AddRefed - Only(const GlobalObject& aGlobal, JSContext* aCx, - JS::Handle aValue, ErrorResult& aRv); - static already_AddRefed - LowerBound(const GlobalObject& aGlobal, JSContext* aCx, - JS::Handle aValue, bool aOpen, ErrorResult& aRv); - static already_AddRefed - UpperBound(const GlobalObject& aGlobal, JSContext* aCx, - JS::Handle aValue, bool aOpen, ErrorResult& aRv); - static already_AddRefed - Bound(const GlobalObject& aGlobal, JSContext* aCx, - JS::Handle aLower, JS::Handle aUpper, - bool aLowerOpen, bool aUpperOpen, ErrorResult& aRv); - + static JSBool DefineConstructors(JSContext* aCx, + JSObject* aObject); static nsresult FromJSVal(JSContext* aCx, const jsval& aVal, @@ -76,11 +42,10 @@ public: static already_AddRefed FromSerializedKeyRange(const T& aKeyRange); - IDBKeyRange(nsISupports* aGlobal, - bool aLowerOpen, + IDBKeyRange(bool aLowerOpen, bool aUpperOpen, bool aIsOnly) - : mGlobal(aGlobal), mCachedLowerVal(JSVAL_VOID), mCachedUpperVal(JSVAL_VOID), + : mCachedLowerVal(JSVAL_VOID), mCachedUpperVal(JSVAL_VOID), mLowerOpen(aLowerOpen), mUpperOpen(aUpperOpen), mIsOnly(aIsOnly), mHaveCachedLowerVal(false), mHaveCachedUpperVal(false), mRooted(false) { } @@ -105,7 +70,6 @@ public: return mIsOnly ? mLower : mUpper; } - // TODO (bug 900578): Remove these in favour of LowerOpen() / UpperOpen(). bool IsLowerOpen() const { return mLowerOpen; @@ -191,14 +155,13 @@ public: private: ~IDBKeyRange(); - nsCOMPtr mGlobal; Key mLower; Key mUpper; JS::Heap mCachedLowerVal; JS::Heap mCachedUpperVal; - const bool mLowerOpen; - const bool mUpperOpen; - const bool mIsOnly; + bool mLowerOpen; + bool mUpperOpen; + bool mIsOnly; bool mHaveCachedLowerVal; bool mHaveCachedUpperVal; bool mRooted; diff --git a/dom/indexedDB/IndexedDatabaseManager.cpp b/dom/indexedDB/IndexedDatabaseManager.cpp index 4062ff65535..1c8b2c21b1b 100644 --- a/dom/indexedDB/IndexedDatabaseManager.cpp +++ b/dom/indexedDB/IndexedDatabaseManager.cpp @@ -6,7 +6,6 @@ #include "IndexedDatabaseManager.h" -#include "jsfriendapi.h" #include "nsIConsoleService.h" #include "nsIDiskSpaceWatcher.h" #include "nsIDOMScriptObjectFactory.h" @@ -17,7 +16,6 @@ #include "mozilla/ClearOnShutdown.h" #include "mozilla/CondVar.h" -#include "mozilla/dom/IDBKeyRangeBinding.h" #include "mozilla/dom/quota/QuotaManager.h" #include "mozilla/dom/quota/Utilities.h" #include "mozilla/dom/TabContext.h" @@ -527,10 +525,6 @@ IndexedDatabaseManager::InitWindowless(const jsval& aObj, JSContext* aCx) NS_ENSURE_ARG(!JSVAL_IS_PRIMITIVE(aObj)); JS::Rooted obj(aCx, JSVAL_TO_OBJECT(aObj)); - if (!(js::GetObjectClass(obj)->flags & JSCLASS_DOM_GLOBAL)) { - NS_WARNING("initWindowless should only be called on a DOM global object."); - return NS_ERROR_FAILURE; - } JSBool hasIndexedDB; if (!JS_HasProperty(aCx, obj, "indexedDB", &hasIndexedDB)) { @@ -566,10 +560,14 @@ IndexedDatabaseManager::InitWindowless(const jsval& aObj, JSContext* aCx) return NS_ERROR_FAILURE; } - JS::Handle keyrangeObj = - IDBKeyRangeBinding::GetConstructorObject(aCx, obj); + JS::Rooted keyrangeObj(aCx, + JS_NewObject(aCx, nullptr, nullptr, nullptr)); NS_ENSURE_TRUE(keyrangeObj, NS_ERROR_OUT_OF_MEMORY); + if (!IDBKeyRange::DefineConstructors(aCx, keyrangeObj)) { + return NS_ERROR_FAILURE; + } + if (!JS_DefineProperty(aCx, obj, "IDBKeyRange", OBJECT_TO_JSVAL(keyrangeObj), nullptr, nullptr, JSPROP_ENUMERATE)) { return NS_ERROR_FAILURE; diff --git a/dom/indexedDB/moz.build b/dom/indexedDB/moz.build index 4b809e63285..7ed4918afd3 100644 --- a/dom/indexedDB/moz.build +++ b/dom/indexedDB/moz.build @@ -8,6 +8,7 @@ DIRS += ['ipc'] TEST_DIRS += ['test'] XPIDL_SOURCES += [ + 'nsIIDBKeyRange.idl', 'nsIIndexedDatabaseManager.idl', ] diff --git a/dom/indexedDB/nsIIDBKeyRange.idl b/dom/indexedDB/nsIIDBKeyRange.idl new file mode 100644 index 00000000000..f7b0838df2a --- /dev/null +++ b/dom/indexedDB/nsIIDBKeyRange.idl @@ -0,0 +1,25 @@ +/* -*- 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" + +/** + * IDBKeyRange interface. See + * http://dev.w3.org/2006/webapi/WebSimpleDB/#idl-def-IDBKeyRange for more + * information. + */ +[scriptable, builtinclass, uuid(8aeb8660-76b3-4651-b8c2-9894ae6dfe68)] +interface nsIIDBKeyRange : nsISupports +{ + [implicit_jscontext] + readonly attribute jsval lower; + + [implicit_jscontext] + readonly attribute jsval upper; + + readonly attribute boolean lowerOpen; + readonly attribute boolean upperOpen; +}; diff --git a/dom/webidl/IDBKeyRange.webidl b/dom/webidl/IDBKeyRange.webidl deleted file mode 100644 index d087856b1a9..00000000000 --- a/dom/webidl/IDBKeyRange.webidl +++ /dev/null @@ -1,29 +0,0 @@ -/* 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/. */ -/* - * The origin of this IDL file is - * https://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html - * - * Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C - * liability, trademark and document use rules apply. - */ - -interface IDBKeyRange { - [Throws] - readonly attribute any lower; - [Throws] - readonly attribute any upper; - [Constant] - readonly attribute boolean lowerOpen; - [Constant] - readonly attribute boolean upperOpen; - [Creator, Throws] - static IDBKeyRange only (any value); - [Creator, Throws] - static IDBKeyRange lowerBound (any lower, optional boolean open = false); - [Creator, Throws] - static IDBKeyRange upperBound (any upper, optional boolean open = false); - [Creator, Throws] - static IDBKeyRange bound (any lower, any upper, optional boolean lowerOpen = false, optional boolean upperOpen = false); -}; diff --git a/dom/webidl/WebIDL.mk b/dom/webidl/WebIDL.mk index 88900b19489..8a05491a229 100644 --- a/dom/webidl/WebIDL.mk +++ b/dom/webidl/WebIDL.mk @@ -169,7 +169,6 @@ webidl_files = \ IDBFactory.webidl \ IDBFileHandle.webidl \ IDBIndex.webidl \ - IDBKeyRange.webidl \ IDBObjectStore.webidl \ IDBOpenDBRequest.webidl \ IDBRequest.webidl \ diff --git a/js/xpconnect/src/dom_quickstubs.qsconf b/js/xpconnect/src/dom_quickstubs.qsconf index 27cef489b88..4f08ca12e33 100644 --- a/js/xpconnect/src/dom_quickstubs.qsconf +++ b/js/xpconnect/src/dom_quickstubs.qsconf @@ -84,6 +84,7 @@ members = [ 'nsIBoxObject.height', # dom/indexedDB + 'nsIIDBKeyRange.*', 'nsIIndexedDatabaseManager.*', # dom/file