nsStringKey key(aName); if (!mLookupTable) { mLookupTable = new nsSupportsHashtable(NS_FORM_CONTROL_LIST_HASHTABLE_SIZE); NS_ENSURE_TRUE(mLookupTable, NS_ERROR_OUT_OF_MEMORY); }  nsCOMPtr<nsISupports> supports; supports = dont_AddRef((nsISupports *)mLookupTable->Get(&key));  if (!supports) {  nsCOMPtr<nsISupports> child(do_QueryInterface(aChild));  mLookupTable->Put(&key, child.get()); } else {  nsCOMPtr<nsIContent> content(do_QueryInterface(supports)); nsCOMPtr<nsIContent> newChild(do_QueryInterface(aChild));  if (content) {     if (content == newChild) { return NS_OK; }    nsContentList *list = new nsContentList(nsnull); NS_ENSURE_TRUE(list, NS_ERROR_OUT_OF_MEMORY);  list->Add(content);   list->Add(newChild);  nsCOMPtr<nsISupports> listSupports; list->QueryInterface(NS_GET_IID(nsISupports), getter_AddRefs(listSupports));  mLookupTable->Put(&key, listSupports.get()); } else {  nsCOMPtr<nsIDOMNodeList> nodeList(do_QueryInterface(supports)); NS_ENSURE_TRUE(nodeList, NS_ERROR_FAILURE);   nsContentList *list = NS_STATIC_CAST(nsContentList *, (nsIDOMNodeList *)nodeList.get());  PRInt32 oldIndex = -1; list->IndexOf(newChild, oldIndex);   if (oldIndex < 0) { list->Add(newChild); } } }  return NS_OK;
return mControls->AddElementToTable(aChild, aName);
nsFormControlList::AddElementToTable(nsIFormControl* aChild, const nsString& aName){  nsStringKey key(aName);  if (!mLookupTable) {    mLookupTable = new nsSupportsHashtable(NS_FORM_CONTROL_LIST_HASHTABLE_SIZE);    NS_ENSURE_TRUE(mLookupTable, NS_ERROR_OUT_OF_MEMORY);  }  nsCOMPtr<nsISupports> supports;  supports = dont_AddRef((nsISupports *)mLookupTable->Get(&key));  if (!supports) {    // No entry found, add the form control    nsCOMPtr<nsISupports> child(do_QueryInterface(aChild));    mLookupTable->Put(&key, child.get());  } else {    // Found something in the hash, check its type    nsCOMPtr<nsIContent> content(do_QueryInterface(supports));    nsCOMPtr<nsIContent> newChild(do_QueryInterface(aChild));    if (content) {      // Check if the new content is the same as the one we found in the      // hash, if it is then we leave it in the hash as it is, this will      // happen if a form control has both a name and an id with the same      // value      if (content == newChild) {        return NS_OK;      }      // Found an element, create a list, add the element to the list and put      // the list in the hash      nsContentList *list = new nsContentList(nsnull);      NS_ENSURE_TRUE(list, NS_ERROR_OUT_OF_MEMORY);      list->Add(content);      // Add the new child too      list->Add(newChild);      nsCOMPtr<nsISupports> listSupports;      list->QueryInterface(NS_GET_IID(nsISupports),                           getter_AddRefs(listSupports));      // Replace the element with the list.      mLookupTable->Put(&key, listSupports.get());    } else {      // There's already a list in the hash, add the child to the list      nsCOMPtr<nsIDOMNodeList> nodeList(do_QueryInterface(supports));      NS_ENSURE_TRUE(nodeList, NS_ERROR_FAILURE);      // Upcast, uggly, but it works!      nsContentList *list = NS_STATIC_CAST(nsContentList *,                                           (nsIDOMNodeList *)nodeList.get());      PRInt32 oldIndex = -1;      list->IndexOf(newChild, oldIndex);      // Add the new child only if it's not in our list already      if (oldIndex < 0) {        list->Add(newChild);      }    }  }  return NS_OK;}