if (mAnonymousContentTable) {
for (PRInt32 i = aOldDocument->GetNumberOfShells() - 1; i >= 0; --i) { nsCOMPtr<nsIPresShell> shell = dont_AddRef( aOldDocument->GetShellAt(i) ); NS_ASSERTION(shell != nsnull, "Zoiks! nsIPresShell::ShellAt() broke");
nsBindingManager::ChangeDocumentFor(nsIContent* aContent, nsIDocument* aOldDocument,                                    nsIDocument* aNewDocument){  nsCOMPtr<nsIXBLBinding> binding;  GetBinding(aContent, getter_AddRefs(binding));  if (binding) {    binding->ChangeDocument(aOldDocument, aNewDocument);    SetBinding(aContent, nsnull);    if (aNewDocument) {      nsCOMPtr<nsIBindingManager> otherManager;      aNewDocument->GetBindingManager(getter_AddRefs(otherManager));      otherManager->SetBinding(aContent, binding);    }  }  if (mAnonymousContentTable) {    // See if the element has nsIAnonymousContentCreator-created    // anonymous content...    nsISupportsKey key(aContent);    nsCOMPtr<nsISupportsArray> anonymousElements =      getter_AddRefs(NS_REINTERPRET_CAST(nsISupportsArray*, mAnonymousContentTable->Get(&key)));    if (anonymousElements) {      // ...yep, so be sure to update the doc pointer in those      // elements, too.      PRUint32 count;      anonymousElements->Count(&count);      while (PRInt32(--count) >= 0) {        nsCOMPtr<nsISupports> isupports( getter_AddRefs(anonymousElements->ElementAt(count)) );        nsCOMPtr<nsIContent> content( do_QueryInterface(isupports) );        NS_ASSERTION(content != nsnull, "not an nsIContent");        if (! content)          continue;        content->SetDocument(aNewDocument, PR_TRUE, PR_TRUE);      }    }  }  return NS_OK;}