nsCOMPtr<nsIDocument> document = aElement->GetDocument();
nsCOMPtr<nsIDocument> document; aElement->GetDocument(*getter_AddRefs(document));
nsXBLBinding::AddScriptEventListener(nsIContent* aElement, nsIAtom* aName,                                     const nsString& aValue){  nsAutoString val;  aName->ToString(val);    nsAutoString eventStr(NS_LITERAL_STRING("on"));  eventStr += val;  nsCOMPtr<nsIAtom> eventName = do_GetAtom(eventStr);  nsresult rv;  nsCOMPtr<nsIDocument> document = aElement->GetDocument();  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;  if (!context) return NS_OK;  nsCOMPtr<nsIEventListenerManager> manager;  rv = receiver->GetListenerManager(getter_AddRefs(manager));  if (NS_FAILED(rv)) return rv;  rv = manager->AddScriptEventListener(context, receiver, eventName,                                       aValue, PR_FALSE);  return rv;}