if (mSelect && aIndex >= 0 && aIndex <= mElements.Count()) {  if (!aOption) { mSelect->Remove(aIndex);
if (aIndex > mElements.Count()) {   rv = SetLength(aIndex); NS_ENSURE_SUCCESS(rv, rv); }
nsHTMLOptionCollection::SetOption(PRInt32 aIndex,                                  nsIDOMHTMLOptionElement *aOption){  nsresult rv = NS_OK;  // If the indx is within range  if (mSelect && aIndex >= 0 && aIndex <= mElements.Count()) {    // if the new option is null, remove this option    if (!aOption) {      mSelect->Remove(aIndex);      // We're done.      return NS_OK;    }    nsCOMPtr<nsIDOMNode> ret;    if (aIndex == mElements.Count()) {      rv = mSelect->AppendChild(aOption, getter_AddRefs(ret));    } else {      // Find the option they're talking about and replace it      nsIDOMHTMLOptionElement *refChild = mElements.ObjectAt(aIndex);      NS_ENSURE_TRUE(refChild, NS_ERROR_UNEXPECTED);      nsCOMPtr<nsIDOMNode> parent;      refChild->GetParentNode(getter_AddRefs(parent));      if (parent) {        rv = parent->ReplaceChild(aOption, refChild, getter_AddRefs(ret));      }    }  }  return rv;}