win->GetDocument(getter_AddRefs(dom_doc));
nsContentUtils::GetDocumentFromCaller(getter_AddRefs(dom_doc));
NS_NewHTMLImageElement(nsIHTMLContent** aInstancePtrResult,                       nsINodeInfo *aNodeInfo){  NS_ENSURE_ARG_POINTER(aInstancePtrResult);  /*   * nsHTMLImageElement's will be created without a nsINodeInfo passed in   * if someone says "var img = new Image();" in JavaScript, in a case like   * that we request the nsINodeInfo from the anonymous nodeinfo list.   */  nsCOMPtr<nsINodeInfo> nodeInfo(aNodeInfo);  if (!nodeInfo) {    nsCOMPtr<nsIJSContextStack> stack =      do_GetService("@mozilla.org/js/xpc/ContextStack;1");    NS_ENSURE_TRUE(stack, NS_ERROR_NOT_AVAILABLE);    JSContext *cx = nsnull;    nsresult rv = stack->Peek(&cx);    if (NS_FAILED(rv) || !cx)      return NS_ERROR_UNEXPECTED;    nsCOMPtr<nsIScriptGlobalObject> globalObject;    nsContentUtils::GetStaticScriptGlobal(cx, ::JS_GetGlobalObject(cx),                                          getter_AddRefs(globalObject));;    nsCOMPtr<nsIDOMWindowInternal> win(do_QueryInterface(globalObject));    NS_ENSURE_TRUE(win, NS_ERROR_UNEXPECTED);    nsCOMPtr<nsIDOMDocument> dom_doc;    win->GetDocument(getter_AddRefs(dom_doc));    nsCOMPtr<nsIDocument> doc(do_QueryInterface(dom_doc));    NS_ENSURE_TRUE(doc, NS_ERROR_UNEXPECTED);    nsCOMPtr<nsINodeInfoManager> nodeInfoManager;    doc->GetNodeInfoManager(*getter_AddRefs(nodeInfoManager));    NS_ENSURE_TRUE(nodeInfoManager, NS_ERROR_UNEXPECTED);    rv = nodeInfoManager->GetNodeInfo(nsHTMLAtoms::img, nsnull,                                      kNameSpaceID_None,                                      *getter_AddRefs(nodeInfo));    NS_ENSURE_SUCCESS(rv, rv);  }  nsHTMLImageElement* it = new nsHTMLImageElement();  if (!it) {    return NS_ERROR_OUT_OF_MEMORY;  }  nsresult rv = it->Init(nodeInfo);  if (NS_FAILED(rv)) {    delete it;    return rv;  }  *aInstancePtrResult = NS_STATIC_CAST(nsIHTMLContent *, it);  NS_ADDREF(*aInstancePtrResult);  return NS_OK;}