nsHTMLSelectElement::SetLength(PRUint32 aLength)
nsHTMLOptionCollection::SetLength(PRUint32 aLength)
nsHTMLSelectElement::SetLength(PRUint32 aLength){  if (!mOptions) {    Init();  }  nsresult rv=NS_OK;  PRUint32 curlen;  PRInt32 i;  GetLength(&curlen);  if (curlen && (curlen > aLength)) { // Remove extra options    for (i = (curlen - 1); (i >= (PRInt32)aLength) && NS_SUCCEEDED(rv); i--) {      rv = Remove(i);    }  } else if (aLength) {    // This violates the W3C DOM but we do this for backwards compatibility    nsCOMPtr<nsIHTMLContent> element;    nsCOMPtr<nsINodeInfo> nodeInfo;    mNodeInfo->NameChanged(nsHTMLAtoms::option, *getter_AddRefs(nodeInfo));    rv = NS_NewHTMLOptionElement(getter_AddRefs(element), nodeInfo);    NS_ENSURE_SUCCESS(rv, rv);    nsCOMPtr<nsIContent> text;    rv = NS_NewTextNode(getter_AddRefs(text));    NS_ENSURE_SUCCESS(rv, rv);    rv = element->AppendChildTo(text, PR_FALSE, PR_FALSE);    NS_ENSURE_SUCCESS(rv, rv);    nsCOMPtr<nsIDOMNode> node(do_QueryInterface(element));    for (i = curlen; i < (PRInt32)aLength; i++) {      nsCOMPtr<nsIDOMNode> tmpNode;      rv = AppendChild(node, getter_AddRefs(tmpNode));      NS_ENSURE_SUCCESS(rv, rv);      if (i < ((PRInt32)aLength - 1)) {        nsCOMPtr<nsIDOMNode> newNode;        rv = node->CloneNode(PR_TRUE, getter_AddRefs(newNode));        NS_ENSURE_SUCCESS(rv, rv);        node = newNode;      }    }  }  return NS_OK;}