PRUint32 index    = 0;
PRInt32 index = -1;
nsHTMLSelectElement::IsOptionSelected(nsIDOMHTMLOptionElement* aOption,                                      PRBool * aIsSelected){  // start off by assuming it isn't in the list of index objects  *aIsSelected = PR_FALSE;  // first find the index of the incoming option  PRUint32 index    = 0;  if (NS_FAILED(GetOptionIndex(aOption, &index))) {    return NS_ERROR_FAILURE;  }  // The PresState hold a nsISupportsArray that contain  // nsISupportsPRInt32 objects that hold the index of the option that  // is selected, for example, there are 10 options and option 2 and  // oiption 8 are selected then the array hold to objects, one that  // contains 2 and one that contains 8  nsCOMPtr<nsIPresState> presState;  nsCOMPtr<nsISupportsArray> value;  nsresult res = GetPresState(getter_AddRefs(presState),                              getter_AddRefs(value));  if (NS_SUCCEEDED(res) && presState) {    // get the property by name. I am not sure why this is done, versus    // just using the value array above    nsCOMPtr<nsISupports> supp;    presState->GetStatePropertyAsSupports(NS_LITERAL_STRING("selecteditems"),                                          getter_AddRefs(supp));    res = NS_ERROR_NULL_POINTER;    if (supp) {      // Query for nsISupportArray from nsISupports      nsCOMPtr<nsISupportsArray> svalue = do_QueryInterface(supp);      if (svalue) {        PRUint32 count = 0, i; // num items in array        svalue->Count(&count);        // loop through the array look for "index" object and then we        // compare it against the option's index to see if there is a        // match        nsCOMPtr<nsISupportsPRInt32> thisVal;        for (i=0; i < count; i++) {          // get index obj          nsCOMPtr<nsISupports> suppval = getter_AddRefs(svalue->ElementAt(i));          thisVal = do_QueryInterface(suppval);          if (thisVal) {            // get out the index            PRInt32 optIndex;            res = thisVal->GetData(&optIndex);            if (NS_SUCCEEDED(res)) {              // ccompare them then bail if they match              if (PRUint32(optIndex) == index) {                *aIsSelected = PR_TRUE;                return NS_OK;              }            }          } else {            res = NS_ERROR_UNEXPECTED;          }          if (NS_FAILED(res))            break;        }      }    }  }  return NS_OK;}