options->GetLength(&numOptions);  for (PRUint32 i = 0; i < numOptions; i++) { nsIDOMNode* node = nsnull; if ((NS_OK == options->Item(i, &node)) && node) { nsIDOMHTMLOptionElement* option = nsnull; if (NS_OK == node->QueryInterface(kIDOMHTMLOptionElementIID, (void** )&option)) { PRBool selected; option->GetDefaultSelected(&selected); NS_RELEASE(option); if (selected) { *aValue = i; NS_RELEASE(node); break;
rv = options->GetLength(&numOptions); if (NS_SUCCEEDED(rv)) { for (PRUint32 i = 0; i < numOptions; i++) { nsCOMPtr<nsIDOMNode> node; rv = options->Item(i, getter_AddRefs(node)); if (NS_SUCCEEDED(rv) && node) { nsCOMPtr<nsIDOMHTMLOptionElement> option = do_QueryInterface(node); if (NS_SUCCEEDED(rv) && option) { PRBool selected; rv = option->GetDefaultSelected(&selected); if (NS_SUCCEEDED(rv) && selected) { *aValue = i; break; }
nsHTMLSelectElement::GetSelectedIndex(PRInt32* aValue){  nsIFormControlFrame* formControlFrame = nsnull;  if (NS_OK == nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame)) {    nsString value;    formControlFrame->GetProperty(nsHTMLAtoms::selectedindex, value);    if (value.Length() > 0) {      PRInt32 retval = 0;      PRInt32 error = 0;      retval = value.ToInteger(&error, 10); // Convert to integer, base 10      if (!error) {        *aValue = retval;        return NS_OK;      }    }  } else { // The frame hasn't been created yet.  Use the options array    *aValue = -1;    nsIDOMHTMLCollection* options;    if (NS_OK == GetOptions(&options)) {      PRUint32 numOptions;      options->GetLength(&numOptions);      for (PRUint32 i = 0; i < numOptions; i++) {        nsIDOMNode* node = nsnull;        if ((NS_OK == options->Item(i, &node)) && node) {          nsIDOMHTMLOptionElement* option = nsnull;          if (NS_OK == node->QueryInterface(kIDOMHTMLOptionElementIID, (void**)&option)) {            PRBool selected;            option->GetDefaultSelected(&selected); // DefaultSelected == HTML Selected            NS_RELEASE(option);            if (selected) {              *aValue = i;              NS_RELEASE(node); // Have to release this as the call below is skipped.              break;            }          }          NS_RELEASE(node);        }      }      NS_RELEASE(options);    }  }  return NS_OK;}