if ((NS_FAILED(result)) || (nsnull == listWidget)) {
if ((NS_FAILED(result)) || (nsnull == listWidget))
NS_IMETHODIMP nsNativeSelectControlFrame::AddOption(PRInt32 aIndex){    // Grab the content model information (merge with postcreatewidget code?)    nsIDOMHTMLCollection* options = GetOptions();    if (!options) return NS_ERROR_UNEXPECTED;    // Save the cache data structure    PRBool* saveOptionSelected = mOptionSelected;    PRBool selected = PR_FALSE;    nsString text(" ");    // Grab the widget (we need to update it)    nsIListWidget* listWidget;    nsresult result = mWidget->QueryInterface(kListWidgetIID, (void **) &listWidget);    if ((NS_FAILED(result)) || (nsnull == listWidget)) {      return NS_ERROR_UNEXPECTED;    }      mNumOptions++;      mOptionSelected = new PRBool[mNumOptions];      if (!mOptionSelected) return NS_ERROR_OUT_OF_MEMORY;      // Copy saved local cache into new local cache      for (PRInt32 i=0, j=0; j < mNumOptions; i++,j++) {        if (i == aIndex) { // At the point of insertion          // Get the correct selected value and text of the option          nsIDOMNode* node = nsnull;          options->Item(i, &node);          if (node) {            nsIDOMHTMLOptionElement* option = nsnull;            result = node->QueryInterface(kIDOMHTMLOptionElementIID, (void**)&option);            if ((NS_OK == result) && option) {              option->GetDefaultSelected(&selected);              mOptionSelected[j]=selected;              // XXX need to compress whitespace              if (NS_CONTENT_ATTR_HAS_VALUE != option->GetText(text)) {                text = " "; // needed?              }              NS_RELEASE(option);            } else {              mOptionSelected[j]=PR_FALSE; // Couldn't get selected val from content!            }            NS_RELEASE(node);          } else {            mOptionSelected[j]=PR_FALSE; // Couldn't get selected val from content!          }          j++;        }        // Copy old selected value        if (j < mNumOptions) {          mOptionSelected[j]=saveOptionSelected[i];        }      }      // Update widget      listWidget->AddItemAt(text, aIndex);    // Select options as needed (this is needed for Windows at least)    // Note, as mentioned above, we can't restore selection if option is    // replaced - no index is reported back to us - use DefaultSelected instead    listWidget->Deselect();    PRInt32 selectedIndex = -1;    for (PRInt32 k=0; k < mNumOptions; k++) {      GetOptionSelected(k, &selected);      if (selected) {        listWidget->SelectItem(k);        selectedIndex = k;      }    }    if (mIsComboBox && (mNumOptions > 0) && (selectedIndex == -1)) {      listWidget->SelectItem(0);      SetOptionSelected(0, PR_TRUE);    }    NS_RELEASE(options);    NS_RELEASE(listWidget);    if (saveOptionSelected)      delete [] saveOptionSelected;          return NS_OK;}