summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwolfbeast <mcwerewolf@gmail.com>2018-12-14 15:08:52 +0100
committerwolfbeast <mcwerewolf@gmail.com>2018-12-14 15:08:52 +0100
commit023af95abeb4a9bd61665f37fc8dec173e0f2f4a (patch)
tree11b1facff61ff5083824158bf48cfc635a86e416
parentfea96b4527a2db6cd97c9053d647478b347d3853 (diff)
downloadUXP-023af95abeb4a9bd61665f37fc8dec173e0f2f4a.tar
UXP-023af95abeb4a9bd61665f37fc8dec173e0f2f4a.tar.gz
UXP-023af95abeb4a9bd61665f37fc8dec173e0f2f4a.tar.lz
UXP-023af95abeb4a9bd61665f37fc8dec173e0f2f4a.tar.xz
UXP-023af95abeb4a9bd61665f37fc8dec173e0f2f4a.zip
Make HTMLOptionsCollection::mSelect into a strong reference.
The cycle collector makes weak references like this obsolete.
-rw-r--r--dom/html/HTMLOptionsCollection.cpp51
-rw-r--r--dom/html/HTMLOptionsCollection.h9
-rw-r--r--dom/html/HTMLSelectElement.cpp5
-rw-r--r--dom/html/HTMLSelectElement.h2
4 files changed, 8 insertions, 59 deletions
diff --git a/dom/html/HTMLOptionsCollection.cpp b/dom/html/HTMLOptionsCollection.cpp
index 294493c0c..67de97fc4 100644
--- a/dom/html/HTMLOptionsCollection.cpp
+++ b/dom/html/HTMLOptionsCollection.cpp
@@ -35,23 +35,8 @@ namespace mozilla {
namespace dom {
HTMLOptionsCollection::HTMLOptionsCollection(HTMLSelectElement* aSelect)
-{
- // Do not maintain a reference counted reference. When
- // the select goes away, it will let us know.
- mSelect = aSelect;
-}
-
-HTMLOptionsCollection::~HTMLOptionsCollection()
-{
- DropReference();
-}
-
-void
-HTMLOptionsCollection::DropReference()
-{
- // Drop our (non ref-counted) reference
- mSelect = nullptr;
-}
+ : mSelect(aSelect)
+{}
nsresult
HTMLOptionsCollection::GetOptionIndex(Element* aOption,
@@ -88,7 +73,9 @@ HTMLOptionsCollection::GetOptionIndex(Element* aOption,
}
-NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(HTMLOptionsCollection, mElements)
+NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(HTMLOptionsCollection,
+ mElements,
+ mSelect)
// nsISupports
@@ -124,10 +111,6 @@ HTMLOptionsCollection::GetLength(uint32_t* aLength)
NS_IMETHODIMP
HTMLOptionsCollection::SetLength(uint32_t aLength)
{
- if (!mSelect) {
- return NS_ERROR_UNEXPECTED;
- }
-
return mSelect->SetLength(aLength);
}
@@ -135,10 +118,6 @@ NS_IMETHODIMP
HTMLOptionsCollection::SetOption(uint32_t aIndex,
nsIDOMHTMLOptionElement* aOption)
{
- if (!mSelect) {
- return NS_OK;
- }
-
// if the new option is null, just remove this option. Note that it's safe
// to pass a too-large aIndex in here.
if (!aOption) {
@@ -187,11 +166,6 @@ HTMLOptionsCollection::SetOption(uint32_t aIndex,
int32_t
HTMLOptionsCollection::GetSelectedIndex(ErrorResult& aError)
{
- if (!mSelect) {
- aError.Throw(NS_ERROR_UNEXPECTED);
- return 0;
- }
-
int32_t selectedIndex;
aError = mSelect->GetSelectedIndex(&selectedIndex);
return selectedIndex;
@@ -209,11 +183,6 @@ void
HTMLOptionsCollection::SetSelectedIndex(int32_t aSelectedIndex,
ErrorResult& aError)
{
- if (!mSelect) {
- aError.Throw(NS_ERROR_UNEXPECTED);
- return;
- }
-
aError = mSelect->SetSelectedIndex(aSelectedIndex);
}
@@ -339,22 +308,12 @@ HTMLOptionsCollection::Add(const HTMLOptionOrOptGroupElement& aElement,
const Nullable<HTMLElementOrLong>& aBefore,
ErrorResult& aError)
{
- if (!mSelect) {
- aError.Throw(NS_ERROR_NOT_INITIALIZED);
- return;
- }
-
mSelect->Add(aElement, aBefore, aError);
}
void
HTMLOptionsCollection::Remove(int32_t aIndex, ErrorResult& aError)
{
- if (!mSelect) {
- aError.Throw(NS_ERROR_UNEXPECTED);
- return;
- }
-
uint32_t len = 0;
mSelect->GetLength(&len);
if (aIndex < 0 || (uint32_t)aIndex >= len)
diff --git a/dom/html/HTMLOptionsCollection.h b/dom/html/HTMLOptionsCollection.h
index 21123b3d2..496919555 100644
--- a/dom/html/HTMLOptionsCollection.h
+++ b/dom/html/HTMLOptionsCollection.h
@@ -46,7 +46,7 @@ public:
using nsWrapperCache::GetWrapper;
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
protected:
- virtual ~HTMLOptionsCollection();
+ virtual ~HTMLOptionsCollection() = default;
virtual JSObject* GetWrapperPreserveColorInternal() override
{
@@ -113,11 +113,6 @@ public:
}
/**
- * Drop the reference to the select. Called during select destruction.
- */
- void DropReference();
-
- /**
* Finds the index of a given option element.
* If the option isn't part of the collection, return NS_ERROR_FAILURE
* without setting aIndex.
@@ -161,7 +156,7 @@ private:
* various members such as InsertOptionAt are also infallible. */
nsTArray<RefPtr<mozilla::dom::HTMLOptionElement> > mElements;
/** The select element that contains this array */
- HTMLSelectElement* mSelect;
+ RefPtr<HTMLSelectElement> mSelect;
};
} // namespace dom
diff --git a/dom/html/HTMLSelectElement.cpp b/dom/html/HTMLSelectElement.cpp
index 53f42317a..9ba0a1efe 100644
--- a/dom/html/HTMLSelectElement.cpp
+++ b/dom/html/HTMLSelectElement.cpp
@@ -130,11 +130,6 @@ HTMLSelectElement::HTMLSelectElement(already_AddRefed<mozilla::dom::NodeInfo>& a
NS_EVENT_STATE_VALID);
}
-HTMLSelectElement::~HTMLSelectElement()
-{
- mOptions->DropReference();
-}
-
// ISupports
NS_IMPL_CYCLE_COLLECTION_CLASS(HTMLSelectElement)
diff --git a/dom/html/HTMLSelectElement.h b/dom/html/HTMLSelectElement.h
index 8a25385de..dc1075cd7 100644
--- a/dom/html/HTMLSelectElement.h
+++ b/dom/html/HTMLSelectElement.h
@@ -436,7 +436,7 @@ public:
void SetOpenInParentProcess(bool aVal);
protected:
- virtual ~HTMLSelectElement();
+ virtual ~HTMLSelectElement() = default;
friend class SafeOptionListMutation;