import from UXP: Make HTMLOptionsCollection::mSelect into a strong reference. (a3386fbe)

This commit is contained in:
2022-03-29 15:45:26 +08:00
parent 5179fc4acb
commit d4bcedec9c
4 changed files with 8 additions and 59 deletions
+5 -46
View File
@@ -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);
}
@@ -136,10 +119,6 @@ HTMLOptionsCollection::IndexedSetter(uint32_t aIndex,
HTMLOptionElement* aOption,
ErrorResult& aError)
{
if (!mSelect) {
return;
}
// 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) {
@@ -186,11 +165,6 @@ HTMLOptionsCollection::IndexedSetter(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;
@@ -208,11 +182,6 @@ void
HTMLOptionsCollection::SetSelectedIndex(int32_t aSelectedIndex,
ErrorResult& aError)
{
if (!mSelect) {
aError.Throw(NS_ERROR_UNEXPECTED);
return;
}
aError = mSelect->SetSelectedIndex(aSelectedIndex);
}
@@ -338,22 +307,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)