if (anonymous) anonymous->SetDocument(aNewDocument, PR_TRUE);
if (anonymous) {    nsCOMPtr<nsIXULDocument> xuldoc(do_QueryInterface(aOldDocument));  if (mIsStyleBinding) { anonymous->SetDocument(nsnull, PR_TRUE, PR_TRUE); if (xuldoc) xuldoc->RemoveSubtreeFromDocument(anonymous); } else { anonymous->SetDocument(aNewDocument, PR_TRUE, AllowScripts()); if (xuldoc) xuldoc->RemoveSubtreeFromDocument(anonymous);  xuldoc = do_QueryInterface(aNewDocument); if (xuldoc) xuldoc->AddSubtreeToDocument(anonymous); } }
nsXBLBinding::ChangeDocument(nsIDocument* aOldDocument, nsIDocument* aNewDocument){  if (aOldDocument != aNewDocument) {    if (mNextBinding)      mNextBinding->ChangeDocument(aOldDocument, aNewDocument);    if (mScriptObject) {      if (aOldDocument) {        nsCOMPtr<nsIScriptGlobalObject> global;        aOldDocument->GetScriptGlobalObject(getter_AddRefs(global));        if (global) {          nsCOMPtr<nsIScriptContext> context;          global->GetContext(getter_AddRefs(context));          if (context)            context->RemoveReference((void*) &mScriptObject, mScriptObject);        }      }      if (aNewDocument) {        nsCOMPtr<nsIScriptGlobalObject> global;        aNewDocument->GetScriptGlobalObject(getter_AddRefs(global));        if (global) {          nsCOMPtr<nsIScriptContext> context;          global->GetContext(getter_AddRefs(context));          if (context)            context->AddNamedReference((void*) &mScriptObject, mScriptObject, "nsXBLBinding::mScriptObject");        }      }    }    nsCOMPtr<nsIContent> anonymous;    GetAnonymousContent(getter_AddRefs(anonymous));    if (anonymous)      anonymous->SetDocument(aNewDocument, PR_TRUE);  }  return NS_OK;}