nsCOMPtr<nsIDOMNode> parent; aBefore->GetParentNode(getter_AddRefs(parent)); if (!parent) {   return NS_ERROR_DOM_NOT_FOUND_ERR; }  nsCOMPtr<nsIDOMNode> ancestor(parent); nsCOMPtr<nsIDOMNode> temp; while (ancestor != NS_STATIC_CAST(nsIDOMNode*, this)) { ancestor->GetParentNode(getter_AddRefs(temp)); if (!temp) {   return NS_ERROR_DOM_NOT_FOUND_ERR; } temp.swap(ancestor); }    return parent->InsertBefore(aElement, aBefore, getter_AddRefs(added));
return result;
nsHTMLSelectElement::Add(nsIDOMHTMLElement* aElement,                         nsIDOMHTMLElement* aBefore){  nsCOMPtr<nsIDOMNode> added;  if (!aBefore) {    return AppendChild(aElement, getter_AddRefs(added));  }  // Just in case we're not the parent, get the parent of the reference  // element  nsCOMPtr<nsIDOMNode> parent;  aBefore->GetParentNode(getter_AddRefs(parent));  if (!parent) {    // NOT_FOUND_ERR: Raised if before is not a descendant of the SELECT    // element.    return NS_ERROR_DOM_NOT_FOUND_ERR;  }  nsCOMPtr<nsIDOMNode> ancestor(parent);  nsCOMPtr<nsIDOMNode> temp;  while (ancestor != NS_STATIC_CAST(nsIDOMNode*, this)) {    ancestor->GetParentNode(getter_AddRefs(temp));    if (!temp) {      // NOT_FOUND_ERR: Raised if before is not a descendant of the SELECT      // element.      return NS_ERROR_DOM_NOT_FOUND_ERR;    }    temp.swap(ancestor);  }  // If the before parameter is not null, we are equivalent to the  // insertBefore method on the parent of before.  return parent->InsertBefore(aElement, aBefore, getter_AddRefs(added));}