nsIWebShell* top = this; NS_ADDREF(this); for (;;) { nsIWebShell* parent; top->GetParent(parent); if (nsnull == parent) { break; } NS_RELEASE(top); top = parent; } aResult = top; return NS_OK;
nsCOMPtr<nsIDocShellTreeItem> top; GetSameTypeRootTreeItem(getter_AddRefs(top)); nsCOMPtr<nsIWebShell> topAsWebShell(do_QueryInterface(top)); aResult = topAsWebShell; NS_IF_ADDREF(aResult); return NS_OK;
nsWebShell::GetRootWebShell(nsIWebShell*& aResult){  nsIWebShell* top = this;  NS_ADDREF(this);  for (;;) {    nsIWebShell* parent;    top->GetParent(parent);    if (nsnull == parent) {      break;    }    NS_RELEASE(top);    top = parent;  }  aResult = top;  return NS_OK;}