nsCOMPtr<nsIDocument> document; aElement->GetDocument(*getter_AddRefs(document));
nsCOMPtr<nsIDocument> document = aElement->GetDocument();
nsXBLBinding::AddScriptEventListener(nsIContent* aElement, nsIAtom* aName, const nsString& aValue, REFNSIID aIID){  nsAutoString val;  aName->ToString(val);    nsAutoString eventStr; eventStr.AssignWithConversion("on");  eventStr += val;  nsCOMPtr<nsIAtom> eventName = getter_AddRefs(NS_NewAtom(eventStr));  nsresult rv;  nsCOMPtr<nsIDocument> document;  aElement->GetDocument(*getter_AddRefs(document));  if (!document)    return NS_OK;  nsCOMPtr<nsIDOMEventReceiver> receiver(do_QueryInterface(aElement));  if (!receiver)    return NS_OK;  nsCOMPtr<nsIScriptGlobalObject> global;  document->GetScriptGlobalObject(getter_AddRefs(global));  // This can happen normally as part of teardown code.  if (!global)    return NS_OK;  nsCOMPtr<nsIScriptContext> context;  rv = global->GetContext(getter_AddRefs(context));  if (NS_FAILED(rv)) return rv;  nsCOMPtr<nsIEventListenerManager> manager;  rv = receiver->GetListenerManager(getter_AddRefs(manager));  if (NS_FAILED(rv)) return rv;  nsCOMPtr<nsIScriptObjectOwner> scriptOwner(do_QueryInterface(receiver));  if (!scriptOwner)    return NS_OK;  rv = manager->AddScriptEventListener(context, scriptOwner, eventName, aValue, aIID, PR_FALSE);  return rv;}