Bug 900577 - Remove mGlobal and GetParentObject from IDBKeyRange; r=dom-storage-reviewers,asuth

This is done based on the note in Web IDL bindings documentation:

If your object can only be reflected into JS by creating it, not by retrieving
it from somewhere, you can skip steps 1 and 2 above and instead add
'wrapperCache': False to your descriptor. You will need to flag the functions
that return your object as [NewObject] in the Web IDL. If your object is not
refcounted then the return value of functions that return it should return a
UniquePtr.

The step 1 is about inheriting from nsWrapperCache and step 2 is about ensuring
GetParentObject for the class.

Differential Revision: https://phabricator.services.mozilla.com/D234817
This commit is contained in:
Jan Varga
2025-01-21 19:40:31 +00:00
parent f569e522a1
commit d71d19b77a
2 changed files with 10 additions and 24 deletions

View File

@@ -35,10 +35,8 @@ void GetKeyFromJSVal(JSContext* aCx, JS::Handle<JS::Value> aVal, Key& aKey,
} // namespace } // namespace
IDBKeyRange::IDBKeyRange(nsISupports* aGlobal, bool aLowerOpen, bool aUpperOpen, IDBKeyRange::IDBKeyRange(bool aLowerOpen, bool aUpperOpen, bool aIsOnly)
bool aIsOnly) : mCachedLowerVal(JS::UndefinedValue()),
: mGlobal(aGlobal),
mCachedLowerVal(JS::UndefinedValue()),
mCachedUpperVal(JS::UndefinedValue()), mCachedUpperVal(JS::UndefinedValue()),
mLowerOpen(aLowerOpen), mLowerOpen(aLowerOpen),
mUpperOpen(aUpperOpen), mUpperOpen(aUpperOpen),
@@ -75,7 +73,7 @@ void IDBKeyRange::FromJSVal(JSContext* aCx, JS::Handle<JS::Value> aVal,
} }
// A valid key returns an 'only' IDBKeyRange. // A valid key returns an 'only' IDBKeyRange.
keyRange = new IDBKeyRange(nullptr, false, false, true); keyRange = new IDBKeyRange(false, false, true);
GetKeyFromJSVal(aCx, aVal, keyRange->Lower(), aRv); GetKeyFromJSVal(aCx, aVal, keyRange->Lower(), aRv);
if (!aRv.Failed()) { if (!aRv.Failed()) {
*aKeyRange = std::move(keyRange); *aKeyRange = std::move(keyRange);
@@ -85,9 +83,8 @@ void IDBKeyRange::FromJSVal(JSContext* aCx, JS::Handle<JS::Value> aVal,
// static // static
RefPtr<IDBKeyRange> IDBKeyRange::FromSerialized( RefPtr<IDBKeyRange> IDBKeyRange::FromSerialized(
const SerializedKeyRange& aKeyRange) { const SerializedKeyRange& aKeyRange) {
RefPtr<IDBKeyRange> keyRange = RefPtr<IDBKeyRange> keyRange = new IDBKeyRange(
new IDBKeyRange(nullptr, aKeyRange.lowerOpen(), aKeyRange.upperOpen(), aKeyRange.lowerOpen(), aKeyRange.upperOpen(), aKeyRange.isOnly());
aKeyRange.isOnly());
keyRange->Lower() = aKeyRange.lower(); keyRange->Lower() = aKeyRange.lower();
if (!keyRange->IsOnly()) { if (!keyRange->IsOnly()) {
keyRange->Upper() = aKeyRange.upper(); keyRange->Upper() = aKeyRange.upper();
@@ -109,7 +106,6 @@ void IDBKeyRange::ToSerialized(SerializedKeyRange& aKeyRange) const {
NS_IMPL_CYCLE_COLLECTION_CLASS(IDBKeyRange) NS_IMPL_CYCLE_COLLECTION_CLASS(IDBKeyRange)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(IDBKeyRange) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(IDBKeyRange)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mGlobal)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(IDBKeyRange) NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(IDBKeyRange)
@@ -118,7 +114,6 @@ NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(IDBKeyRange)
NS_IMPL_CYCLE_COLLECTION_TRACE_END NS_IMPL_CYCLE_COLLECTION_TRACE_END
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(IDBKeyRange) NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(IDBKeyRange)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mGlobal)
tmp->DropJSObjects(); tmp->DropJSObjects();
NS_IMPL_CYCLE_COLLECTION_UNLINK_END NS_IMPL_CYCLE_COLLECTION_UNLINK_END
@@ -227,8 +222,7 @@ bool IDBKeyRange::Includes(JSContext* aCx, JS::Handle<JS::Value> aValue,
RefPtr<IDBKeyRange> IDBKeyRange::Only(const GlobalObject& aGlobal, RefPtr<IDBKeyRange> IDBKeyRange::Only(const GlobalObject& aGlobal,
JS::Handle<JS::Value> aValue, JS::Handle<JS::Value> aValue,
ErrorResult& aRv) { ErrorResult& aRv) {
RefPtr<IDBKeyRange> keyRange = RefPtr<IDBKeyRange> keyRange = new IDBKeyRange(false, false, true);
new IDBKeyRange(aGlobal.GetAsSupports(), false, false, true);
GetKeyFromJSVal(aGlobal.Context(), aValue, keyRange->Lower(), aRv); GetKeyFromJSVal(aGlobal.Context(), aValue, keyRange->Lower(), aRv);
if (aRv.Failed()) { if (aRv.Failed()) {
@@ -242,8 +236,7 @@ RefPtr<IDBKeyRange> IDBKeyRange::Only(const GlobalObject& aGlobal,
RefPtr<IDBKeyRange> IDBKeyRange::LowerBound(const GlobalObject& aGlobal, RefPtr<IDBKeyRange> IDBKeyRange::LowerBound(const GlobalObject& aGlobal,
JS::Handle<JS::Value> aValue, JS::Handle<JS::Value> aValue,
bool aOpen, ErrorResult& aRv) { bool aOpen, ErrorResult& aRv) {
RefPtr<IDBKeyRange> keyRange = RefPtr<IDBKeyRange> keyRange = new IDBKeyRange(aOpen, true, false);
new IDBKeyRange(aGlobal.GetAsSupports(), aOpen, true, false);
GetKeyFromJSVal(aGlobal.Context(), aValue, keyRange->Lower(), aRv); GetKeyFromJSVal(aGlobal.Context(), aValue, keyRange->Lower(), aRv);
if (aRv.Failed()) { if (aRv.Failed()) {
@@ -257,8 +250,7 @@ RefPtr<IDBKeyRange> IDBKeyRange::LowerBound(const GlobalObject& aGlobal,
RefPtr<IDBKeyRange> IDBKeyRange::UpperBound(const GlobalObject& aGlobal, RefPtr<IDBKeyRange> IDBKeyRange::UpperBound(const GlobalObject& aGlobal,
JS::Handle<JS::Value> aValue, JS::Handle<JS::Value> aValue,
bool aOpen, ErrorResult& aRv) { bool aOpen, ErrorResult& aRv) {
RefPtr<IDBKeyRange> keyRange = RefPtr<IDBKeyRange> keyRange = new IDBKeyRange(true, aOpen, false);
new IDBKeyRange(aGlobal.GetAsSupports(), true, aOpen, false);
GetKeyFromJSVal(aGlobal.Context(), aValue, keyRange->Upper(), aRv); GetKeyFromJSVal(aGlobal.Context(), aValue, keyRange->Upper(), aRv);
if (aRv.Failed()) { if (aRv.Failed()) {
@@ -274,8 +266,7 @@ RefPtr<IDBKeyRange> IDBKeyRange::Bound(const GlobalObject& aGlobal,
JS::Handle<JS::Value> aUpper, JS::Handle<JS::Value> aUpper,
bool aLowerOpen, bool aUpperOpen, bool aLowerOpen, bool aUpperOpen,
ErrorResult& aRv) { ErrorResult& aRv) {
RefPtr<IDBKeyRange> keyRange = RefPtr<IDBKeyRange> keyRange = new IDBKeyRange(aLowerOpen, aUpperOpen, false);
new IDBKeyRange(aGlobal.GetAsSupports(), aLowerOpen, aUpperOpen, false);
GetKeyFromJSVal(aGlobal.Context(), aLower, keyRange->Lower(), aRv); GetKeyFromJSVal(aGlobal.Context(), aLower, keyRange->Lower(), aRv);
if (aRv.Failed()) { if (aRv.Failed()) {

View File

@@ -14,7 +14,6 @@
#include "mozilla/dom/indexedDB/Key.h" #include "mozilla/dom/indexedDB/Key.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsCycleCollectionParticipant.h" #include "nsCycleCollectionParticipant.h"
#include "nsISupports.h"
#include "nsString.h" #include "nsString.h"
class mozIStorageStatement; class mozIStorageStatement;
@@ -33,7 +32,6 @@ class SerializedKeyRange;
class IDBKeyRange { class IDBKeyRange {
protected: protected:
nsCOMPtr<nsISupports> mGlobal;
indexedDB::Key mLower; indexedDB::Key mLower;
indexedDB::Key mUpper; indexedDB::Key mUpper;
JS::Heap<JS::Value> mCachedLowerVal; JS::Heap<JS::Value> mCachedLowerVal;
@@ -99,8 +97,6 @@ class IDBKeyRange {
bool WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto, bool WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto,
JS::MutableHandle<JSObject*> aReflector); JS::MutableHandle<JSObject*> aReflector);
nsISupports* GetParentObject() const { return mGlobal; }
void GetLower(JSContext* aCx, JS::MutableHandle<JS::Value> aResult, void GetLower(JSContext* aCx, JS::MutableHandle<JS::Value> aResult,
ErrorResult& aRv); ErrorResult& aRv);
@@ -112,8 +108,7 @@ class IDBKeyRange {
bool UpperOpen() const { return mUpperOpen; } bool UpperOpen() const { return mUpperOpen; }
protected: protected:
IDBKeyRange(nsISupports* aGlobal, bool aLowerOpen, bool aUpperOpen, IDBKeyRange(bool aLowerOpen, bool aUpperOpen, bool aIsOnly);
bool aIsOnly);
virtual ~IDBKeyRange(); virtual ~IDBKeyRange();
}; };