if (JSVAL_IS_INT(aID) && mSelect) { PRInt32 indx = JSVAL_TO_INT(aID); nsresult result;   if (mDirty) { GetOptions(); }  PRInt32 length = mElements.Count();   if ((indx >= 0) && (indx <= length)) {   if (JSVAL_IS_NULL(*aVp)) { mSelect->Remove(indx); } else { JSObject* jsobj = JSVAL_TO_OBJECT(*aVp); JSClass* jsclass = JS_GetClass(aContext, jsobj); if ((nsnull != jsclass) && (jsclass->flags & JSCLASS_HAS_PRIVATE)) { nsISupports *supports = (nsISupports *)JS_GetPrivate(aContext, jsobj);  nsCOMPtr<nsIDOMNode> option(do_QueryInterface(supports)); nsCOMPtr<nsIDOMNode> parent; nsCOMPtr<nsIDOMNode> ret;  if (option) { if (indx == length) { result = mSelect->AppendChild(option, getter_AddRefs(ret)); } else { nsIDOMNode *refChild = (nsIDOMNode*)mElements.ElementAt(indx); if (nsnull != refChild) { result = refChild->GetParentNode(getter_AddRefs(parent)); if (NS_SUCCEEDED(result) && parent) {  result = parent->ReplaceChild(option, refChild, getter_AddRefs(ret)); } } } } } } }
if (JSVAL_IS_INT(aID) && mOptions) { res = mOptions->SetProperty(aContext, aObj, aID, aVp); } else { res = nsGenericHTMLContainerFormElement::SetProperty(aContext, aObj, aID, aVp);
nsHTMLOptionCollection::SetProperty(JSContext *aContext, JSObject *aObj,                                     jsval aID, jsval *aVp){  // XXX How about some error reporting and error  // propogation in this method???  if (JSVAL_IS_INT(aID) && mSelect) {    PRInt32 indx = JSVAL_TO_INT(aID);    nsresult result;    // Update the options list    if (mDirty) {      GetOptions();    }        PRInt32 length = mElements.Count();    // If the indx is within range    if ((indx >= 0) && (indx <= length)) {      // if the value is null, remove this option      if (JSVAL_IS_NULL(*aVp)) {        mSelect->Remove(indx);      }      else {        JSObject* jsobj = JSVAL_TO_OBJECT(*aVp);         JSClass* jsclass = JS_GetClass(aContext, jsobj);        if ((nsnull != jsclass) && (jsclass->flags & JSCLASS_HAS_PRIVATE)) {          nsISupports *supports = (nsISupports *)JS_GetPrivate(aContext,                                                               jsobj);          nsCOMPtr<nsIDOMNode> option(do_QueryInterface(supports));          nsCOMPtr<nsIDOMNode> parent;          nsCOMPtr<nsIDOMNode> ret;          if (option) {            if (indx == length) {              result = mSelect->AppendChild(option, getter_AddRefs(ret));            }            else {              nsIDOMNode *refChild = (nsIDOMNode*)mElements.ElementAt(indx);              if (nsnull != refChild) {                result = refChild->GetParentNode(getter_AddRefs(parent));                if (NS_SUCCEEDED(result) && parent) {                                    result = parent->ReplaceChild(option, refChild,                                                getter_AddRefs(ret));                }              }                        }          }        }      }    }  }  return PR_TRUE;}