if ((nsnull == *aReturn) && (nsnull != mInner.mDocument) && (argc > 0)) { char* str = JS_GetStringBytes(JS_ValueToString(cx, argv[0])); nsAutoString name; name.AssignWithConversion(str); nsCOMPtr<nsIScriptContext> scriptContext; nsCOMPtr<nsIScriptGlobalObject> globalObject; mInner.mDocument->GetScriptGlobalObject(getter_AddRefs(globalObject)); if (globalObject) { result = globalObject->GetContext(getter_AddRefs(scriptContext)); }  nsCOMPtr<nsIDOMHTMLDocument> htmlDoc = do_QueryInterface(mInner.mDocument); if (htmlDoc) { nsCOMPtr<nsIDOMNodeList> list; result = htmlDoc->GetElementsByName(name, getter_AddRefs(list)); if (NS_FAILED(result)) { return result; }  if (list) { PRUint32 count; list->GetLength(&count); if (count > 0) { nsCOMPtr<nsIDOMNode> node;  result = list->Item(0, getter_AddRefs(node)); if (NS_FAILED(result)) { return result; } if (node) { nsCOMPtr<nsIScriptObjectOwner> owner = do_QueryInterface(node); JSObject* obj;  result = owner->GetScriptObject(scriptContext, (void**)&obj); if (NS_FAILED(result)) { return result; } *aReturn = OBJECT_TO_JSVAL(obj); } }
if (supports) {  rv = supports->QueryInterface(NS_GET_IID(nsIDOMNode), (void **)aReturn);  if (NS_FAILED(rv)) {  nsCOMPtr<nsIDOMNodeList> nodeList(do_QueryInterface(supports, &rv));  if (nodeList) {   rv = nodeList->Item(0, aReturn);
nsHTMLFormElement::NamedItem(JSContext* cx, jsval* argv, PRUint32 argc, jsval* aReturn){  nsresult result = mControls->NamedItem(cx, argv, argc, aReturn);  if (NS_FAILED(result)) {    return result;  }  // If we couldn't find it in our controls list, it may be  // a different type of element (IMG, OBJECT, etc.)  if ((nsnull == *aReturn) && (nsnull != mInner.mDocument) && (argc > 0)) {    char* str = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));    nsAutoString name; name.AssignWithConversion(str);     nsCOMPtr<nsIScriptContext> scriptContext;    nsCOMPtr<nsIScriptGlobalObject> globalObject;    mInner.mDocument->GetScriptGlobalObject(getter_AddRefs(globalObject));    if (globalObject) {      result = globalObject->GetContext(getter_AddRefs(scriptContext));    }        nsCOMPtr<nsIDOMHTMLDocument> htmlDoc = do_QueryInterface(mInner.mDocument);    if (htmlDoc) {      nsCOMPtr<nsIDOMNodeList> list;      result = htmlDoc->GetElementsByName(name, getter_AddRefs(list));      if (NS_FAILED(result)) {        return result;      }          if (list) {        PRUint32 count;        list->GetLength(&count);        if (count > 0) {          nsCOMPtr<nsIDOMNode> node;                    result = list->Item(0, getter_AddRefs(node));          if (NS_FAILED(result)) {            return result;          }          if (node) {            nsCOMPtr<nsIScriptObjectOwner> owner = do_QueryInterface(node);            JSObject* obj;                        result = owner->GetScriptObject(scriptContext, (void**)&obj);            if (NS_FAILED(result)) {              return result;            }            *aReturn = OBJECT_TO_JSVAL(obj);          }        }      }    }  }  return NS_OK;}