From 27bc6e8c920f1200d784a93fe6fe5a3855ccbcd0 Mon Sep 17 00:00:00 2001 From: "tbogard%aol.net" Date: Fri, 3 Dec 1999 11:22:54 +0000 Subject: [PATCH] Fixed a couple of problems with FindChildWithName. --- docshell/base/nsDocShell.cpp | 17 +++++------------ docshell/base/nsWebShell.cpp | 21 ++++++++------------- webshell/src/nsWebShell.cpp | 21 ++++++++------------- 3 files changed, 21 insertions(+), 38 deletions(-) diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index a61cb0f43ac..7fc1fe4f6a9 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -451,21 +451,14 @@ nsDocShell::SetMarginHeight(PRInt32 aHeight) NS_IMETHODIMP nsDocShell::GetName(PRUnichar** aName) { NS_ENSURE_ARG_POINTER(aName); - *aName = nsnull; - if(0 != mName.Length()) - *aName = mName.ToNewUnicode(); + *aName = mName.ToNewUnicode(); return NS_OK; } NS_IMETHODIMP nsDocShell::SetName(const PRUnichar* aName) { - if (aName) { - mName = aName; // this does a copy of aName - } - else { - mName = ""; - } - return NS_OK; + mName = aName; // this does a copy of aName + return NS_OK; } NS_IMETHODIMP nsDocShell::GetParent(nsIDocShellTreeItem** parent) @@ -609,13 +602,13 @@ NS_IMETHODIMP nsDocShell::FindChildWithName(const PRUnichar *aName, nsIDocShellT *_retval = nsnull; // if we don't find one, we return NS_OK and a null result nsAutoString name(aName); - PRUnichar *childName; + nsXPIDLString childName; PRInt32 i, n = mChildren.Count(); for (i = 0; i < n; i++) { nsIDocShellTreeItem* child = (nsIDocShellTreeItem*) mChildren.ElementAt(i); // doesn't addref the result NS_ENSURE_TRUE(child, NS_ERROR_FAILURE); - child->GetName(&childName); + child->GetName(getter_Copies(childName)); if(name.Equals(childName)) { *_retval = child; diff --git a/docshell/base/nsWebShell.cpp b/docshell/base/nsWebShell.cpp index cd53586dd15..2caff91b273 100644 --- a/docshell/base/nsWebShell.cpp +++ b/docshell/base/nsWebShell.cpp @@ -1455,7 +1455,9 @@ nsWebShell::FindChildWithName(const PRUnichar* aName1, NS_ENSURE_SUCCESS(FindChildWithName(aName1, getter_AddRefs(treeItem)), NS_ERROR_FAILURE); - CallQueryInterface(treeItem.get(), &aResult); + + if(treeItem) + CallQueryInterface(treeItem.get(), &aResult); return NS_OK; } @@ -4375,21 +4377,14 @@ nsWebShell::SetMarginHeight(PRInt32 aHeight) NS_IMETHODIMP nsWebShell::GetName(PRUnichar** aName) { NS_ENSURE_ARG_POINTER(aName); - *aName = nsnull; - if(0 != mName.Length()) - *aName = mName.ToNewUnicode(); + *aName = mName.ToNewUnicode(); return NS_OK; } NS_IMETHODIMP nsWebShell::SetName(const PRUnichar* aName) { - if (aName) { - mName = aName; // this does a copy of aName - } - else { - mName = ""; - } - return NS_OK; + mName = aName; // this does a copy of aName + return NS_OK; } NS_IMETHODIMP nsWebShell::GetParent(nsIDocShellTreeItem** parent) @@ -4533,13 +4528,13 @@ NS_IMETHODIMP nsWebShell::FindChildWithName(const PRUnichar *aName, nsIDocShellT *_retval = nsnull; // if we don't find one, we return NS_OK and a null result nsAutoString name(aName); - PRUnichar *childName; + nsXPIDLString childName; PRInt32 i, n = mChildren.Count(); for (i = 0; i < n; i++) { nsIDocShellTreeItem* child = (nsIDocShellTreeItem*) mChildren.ElementAt(i); // doesn't addref the result NS_ENSURE_TRUE(child, NS_ERROR_FAILURE); - child->GetName(&childName); + child->GetName(getter_Copies(childName)); if(name.Equals(childName)) { *_retval = child; diff --git a/webshell/src/nsWebShell.cpp b/webshell/src/nsWebShell.cpp index cd53586dd15..2caff91b273 100644 --- a/webshell/src/nsWebShell.cpp +++ b/webshell/src/nsWebShell.cpp @@ -1455,7 +1455,9 @@ nsWebShell::FindChildWithName(const PRUnichar* aName1, NS_ENSURE_SUCCESS(FindChildWithName(aName1, getter_AddRefs(treeItem)), NS_ERROR_FAILURE); - CallQueryInterface(treeItem.get(), &aResult); + + if(treeItem) + CallQueryInterface(treeItem.get(), &aResult); return NS_OK; } @@ -4375,21 +4377,14 @@ nsWebShell::SetMarginHeight(PRInt32 aHeight) NS_IMETHODIMP nsWebShell::GetName(PRUnichar** aName) { NS_ENSURE_ARG_POINTER(aName); - *aName = nsnull; - if(0 != mName.Length()) - *aName = mName.ToNewUnicode(); + *aName = mName.ToNewUnicode(); return NS_OK; } NS_IMETHODIMP nsWebShell::SetName(const PRUnichar* aName) { - if (aName) { - mName = aName; // this does a copy of aName - } - else { - mName = ""; - } - return NS_OK; + mName = aName; // this does a copy of aName + return NS_OK; } NS_IMETHODIMP nsWebShell::GetParent(nsIDocShellTreeItem** parent) @@ -4533,13 +4528,13 @@ NS_IMETHODIMP nsWebShell::FindChildWithName(const PRUnichar *aName, nsIDocShellT *_retval = nsnull; // if we don't find one, we return NS_OK and a null result nsAutoString name(aName); - PRUnichar *childName; + nsXPIDLString childName; PRInt32 i, n = mChildren.Count(); for (i = 0; i < n; i++) { nsIDocShellTreeItem* child = (nsIDocShellTreeItem*) mChildren.ElementAt(i); // doesn't addref the result NS_ENSURE_TRUE(child, NS_ERROR_FAILURE); - child->GetName(&childName); + child->GetName(getter_Copies(childName)); if(name.Equals(childName)) { *_retval = child;