diff --git a/dom/html/HTMLOptionsCollection.cpp b/dom/html/HTMLOptionsCollection.cpp
index 294493c0c3f2..df6c8d905905 100644
--- a/dom/html/HTMLOptionsCollection.cpp
+++ b/dom/html/HTMLOptionsCollection.cpp
@@ -131,12 +131,13 @@ HTMLOptionsCollection::SetLength(uint32_t aLength)
return mSelect->SetLength(aLength);
}
-NS_IMETHODIMP
-HTMLOptionsCollection::SetOption(uint32_t aIndex,
- nsIDOMHTMLOptionElement* aOption)
+void
+HTMLOptionsCollection::IndexedSetter(uint32_t aIndex,
+ HTMLOptionElement* aOption,
+ ErrorResult& aError)
{
if (!mSelect) {
- return NS_OK;
+ return;
}
// if the new option is null, just remove this option. Note that it's safe
@@ -145,43 +146,41 @@ HTMLOptionsCollection::SetOption(uint32_t aIndex,
mSelect->Remove(aIndex);
// We're done.
- return NS_OK;
+ return;
}
- nsresult rv = NS_OK;
-
- uint32_t index = uint32_t(aIndex);
-
// Now we're going to be setting an option in our collection
- if (index > mElements.Length()) {
+ if (aIndex > mElements.Length()) {
// Fill our array with blank options up to (but not including, since we're
// about to change it) aIndex, for compat with other browsers.
- rv = SetLength(index);
- NS_ENSURE_SUCCESS(rv, rv);
- }
-
- NS_ASSERTION(index <= mElements.Length(), "SetLength lied");
-
- nsCOMPtr ret;
- if (index == mElements.Length()) {
- nsCOMPtr node = do_QueryInterface(aOption);
- rv = mSelect->AppendChild(node, getter_AddRefs(ret));
- } else {
- // Find the option they're talking about and replace it
- // hold a strong reference to follow COM rules.
- RefPtr refChild = ItemAsOption(index);
- NS_ENSURE_TRUE(refChild, NS_ERROR_UNEXPECTED);
-
- nsCOMPtr parent = refChild->GetParent();
- if (parent) {
- nsCOMPtr node = do_QueryInterface(aOption);
- ErrorResult res;
- parent->ReplaceChild(*node, *refChild, res);
- rv = res.StealNSResult();
+ nsresult rv = SetLength(aIndex);
+ if (NS_WARN_IF(NS_FAILED(rv))) {
+ aError.Throw(rv);
+ return;
}
}
- return rv;
+ NS_ASSERTION(aIndex <= mElements.Length(), "SetLength lied");
+
+ if (aIndex == mElements.Length()) {
+ mSelect->AppendChild(*aOption, aError);
+ return;
+ }
+
+ // Find the option they're talking about and replace it
+ // hold a strong reference to follow COM rules.
+ RefPtr refChild = ItemAsOption(aIndex);
+ if (!refChild) {
+ aError.Throw(NS_ERROR_UNEXPECTED);
+ return;
+ }
+
+ nsCOMPtr parent = refChild->GetParent();
+ if (!parent) {
+ return;
+ }
+
+ parent->ReplaceChild(*aOption, *refChild, aError);
}
int32_t
diff --git a/dom/html/HTMLOptionsCollection.h b/dom/html/HTMLOptionsCollection.h
index 21123b3d2188..7889cfa5b230 100644
--- a/dom/html/HTMLOptionsCollection.h
+++ b/dom/html/HTMLOptionsCollection.h
@@ -149,11 +149,8 @@ public:
void Remove(int32_t aIndex, ErrorResult& aError);
int32_t GetSelectedIndex(ErrorResult& aError);
void SetSelectedIndex(int32_t aSelectedIndex, ErrorResult& aError);
- void IndexedSetter(uint32_t aIndex, nsIDOMHTMLOptionElement* aOption,
- ErrorResult& aError)
- {
- aError = SetOption(aIndex, aOption);
- }
+ void IndexedSetter(uint32_t aIndex, HTMLOptionElement* aOption,
+ ErrorResult& aError);
virtual void GetSupportedNames(nsTArray& aNames) override;
private:
diff --git a/dom/html/HTMLSelectElement.h b/dom/html/HTMLSelectElement.h
index 3556b07b6f42..97a8e4d99b86 100644
--- a/dom/html/HTMLSelectElement.h
+++ b/dom/html/HTMLSelectElement.h
@@ -272,6 +272,7 @@ public:
// nsIConstraintValidation::SetCustomValidity() is fine.
using nsINode::Remove;
+ using nsINode::AppendChild;
// nsINode
diff --git a/dom/interfaces/html/nsIDOMHTMLOptionsCollection.idl b/dom/interfaces/html/nsIDOMHTMLOptionsCollection.idl
index 04592656f461..79e277c81472 100644
--- a/dom/interfaces/html/nsIDOMHTMLOptionsCollection.idl
+++ b/dom/interfaces/html/nsIDOMHTMLOptionsCollection.idl
@@ -36,9 +36,6 @@ interface nsIDOMHTMLOptionsCollection : nsISupports
attribute long selectedIndex;
- [noscript] void setOption(in unsigned long index,
- in nsIDOMHTMLOptionElement option);
-
[noscript] readonly attribute nsIDOMHTMLSelectElement select;
// This add method implementation means the following