Bug 984466 - change CallQueryInterface to assert in cases of trivial conversions; r=ehsan

This commit is contained in:
Nathan Froyd
2014-03-17 13:00:17 -04:00
parent b788024a9a
commit c8acba35ef
13 changed files with 69 additions and 35 deletions

View File

@@ -345,12 +345,14 @@ nsPluginDirServiceProvider::GetFile(const char *charProp, bool *persistant,
}
}
if (localFile && NS_SUCCEEDED(rv))
return CallQueryInterface(localFile, _retval);
if (NS_FAILED(rv)) {
return rv;
}
localFile.forget(_retval);
return NS_OK;
}
nsresult
nsPluginDirServiceProvider::GetPLIDDirectories(nsISimpleEnumerator **aEnumerator)
{

View File

@@ -1116,12 +1116,14 @@ nsresult nsWebBrowserPersist::GetLocalFileFromURI(nsIURI *aURI, nsIFile **aLocal
nsCOMPtr<nsIFile> file;
rv = fileURL->GetFile(getter_AddRefs(file));
if (NS_SUCCEEDED(rv))
rv = CallQueryInterface(file, aLocalFile);
if (NS_FAILED(rv)) {
return rv;
}
file.forget(aLocalFile);
return NS_OK;
}
nsresult nsWebBrowserPersist::AppendPathToURI(nsIURI *aURI, const nsAString & aPath) const
{
NS_ENSURE_ARG_POINTER(aURI);

View File

@@ -720,7 +720,9 @@ Preferences::GetBranch(const char *aPrefRoot, nsIPrefBranch **_retval)
rv = CallQueryInterface(prefBranch, _retval);
} else {
// special case caching the default root
rv = CallQueryInterface(sRootBranch, _retval);
nsCOMPtr<nsIPrefBranch> root(sRootBranch);
root.forget(_retval);
rv = NS_OK;
}
return rv;
}
@@ -729,15 +731,18 @@ NS_IMETHODIMP
Preferences::GetDefaultBranch(const char *aPrefRoot, nsIPrefBranch **_retval)
{
if (!aPrefRoot || !aPrefRoot[0]) {
return CallQueryInterface(sDefaultRootBranch, _retval);
nsCOMPtr<nsIPrefBranch> root(sDefaultRootBranch);
root.forget(_retval);
return NS_OK;
}
// TODO: - cache this stuff and allow consumers to share branches (hold weak references I think)
nsPrefBranch* prefBranch = new nsPrefBranch(aPrefRoot, true);
nsRefPtr<nsPrefBranch> prefBranch = new nsPrefBranch(aPrefRoot, true);
if (!prefBranch)
return NS_ERROR_OUT_OF_MEMORY;
return CallQueryInterface(prefBranch, _retval);
prefBranch.forget(_retval);
return NS_OK;
}

View File

@@ -232,13 +232,14 @@ nsProfileDirServiceProvider::GetFile(const char *prop, bool *persistant, nsIFile
}
}
if (localFile && NS_SUCCEEDED(rv))
return CallQueryInterface(localFile, _retval);
if (NS_FAILED(rv)) {
return rv;
}
localFile.forget(_retval);
return NS_OK;
}
//*****************************************************************************
// Protected methods
//*****************************************************************************

View File

@@ -3202,12 +3202,17 @@ nsDownload::GetTargetFile(nsIFile **aTargetFile)
nsresult rv;
nsCOMPtr<nsIFileURL> fileURL = do_QueryInterface(mTarget, &rv);
if (NS_FAILED(rv)) return rv;
if (NS_FAILED(rv)) {
return rv;
}
nsCOMPtr<nsIFile> file;
rv = fileURL->GetFile(getter_AddRefs(file));
if (NS_SUCCEEDED(rv))
rv = CallQueryInterface(file, aTargetFile);
if (NS_FAILED(rv)) {
return rv;
}
file.forget(aTargetFile);
return rv;
}

View File

@@ -2969,9 +2969,7 @@ XREMain::XRE_mainInit(bool* aExitFlag)
if (NS_FAILED(rv))
return 2;
rv = CallQueryInterface(greDir, &mAppData->xreDirectory);
if (NS_FAILED(rv))
return 2;
greDir.forget(&mAppData->xreDirectory);
}
if (!mAppData->directory) {

View File

@@ -265,13 +265,18 @@ nsMIMEInfoBase::GetLocalFileFromURI(nsIURI *aURI, nsIFile **aFile)
nsresult rv;
nsCOMPtr<nsIFileURL> fileUrl = do_QueryInterface(aURI, &rv);
if (NS_FAILED(rv)) return rv;
if (NS_FAILED(rv)) {
return rv;
}
nsCOMPtr<nsIFile> file;
rv = fileUrl->GetFile(getter_AddRefs(file));
if (NS_FAILED(rv)) return rv;
if (NS_FAILED(rv)) {
return rv;
}
return CallQueryInterface(file, aFile);
file.forget(aFile);
return NS_OK;
}
NS_IMETHODIMP

View File

@@ -309,7 +309,8 @@ nsFilePicker::GetFile(nsIFile **aFile)
rv = fileURL->GetFile(getter_AddRefs(file));
NS_ENSURE_SUCCESS(rv, rv);
return CallQueryInterface(file, aFile);
file.forget(aFile);
return NS_OK;
}
NS_IMETHODIMP

View File

@@ -272,9 +272,11 @@ NS_IMETHODIMP nsBaseFilePicker::GetDisplayDirectory(nsIFile **aDirectory)
return NS_OK;
nsCOMPtr<nsIFile> directory;
nsresult rv = mDisplayDirectory->Clone(getter_AddRefs(directory));
if (NS_FAILED(rv))
if (NS_FAILED(rv)) {
return rv;
return CallQueryInterface(directory, aDirectory);
}
directory.forget(aDirectory);
return NS_OK;
}
NS_IMETHODIMP

View File

@@ -11,6 +11,7 @@
#include "nsError.h"
#include "nsDebug.h"
#include "nsISupportsImpl.h"
#include "mozilla/TypeTraits.h"
/**
* Macro for adding a reference to an interface.
@@ -128,6 +129,12 @@ inline
nsresult
CallQueryInterface( T* aSource, DestinationType** aDestination )
{
// We permit nsISupports-to-nsISupports here so that one can still obtain
// the canonical nsISupports pointer with CallQueryInterface.
static_assert(!mozilla::IsSame<T, DestinationType>::value ||
mozilla::IsSame<DestinationType, nsISupports>::value,
"don't use CallQueryInterface for compile-time-determinable casts");
NS_PRECONDITION(aSource, "null parameter");
NS_PRECONDITION(aDestination, "null parameter");

View File

@@ -879,7 +879,8 @@ nsDirectoryService::GetFile(const char *prop, bool *persistent, nsIFile **_retva
if (!localFile)
return NS_ERROR_FAILURE;
return CallQueryInterface(localFile, _retval);
localFile.forget(_retval);
return NS_OK;
}
NS_IMETHODIMP

View File

@@ -1370,11 +1370,14 @@ nsLocalFile::GetParent(nsIFile **aParent)
// make buffer whole again
*slashp = c;
if (NS_SUCCEEDED(rv) && localFile)
rv = CallQueryInterface(localFile, aParent);
if (NS_FAILED(rv)) {
return rv;
}
localFile.forget(aParent);
return NS_OK;
}
/*
* The results of Exists, isWritable and isReadable are not cached.
*/

View File

@@ -2684,12 +2684,14 @@ nsLocalFile::GetParent(nsIFile * *aParent)
nsCOMPtr<nsIFile> localFile;
nsresult rv = NS_NewLocalFile(parentPath, mFollowSymlinks, getter_AddRefs(localFile));
if (NS_SUCCEEDED(rv) && localFile) {
return CallQueryInterface(localFile, aParent);
}
if (NS_FAILED(rv)) {
return rv;
}
localFile.forget(aParent);
return NS_OK;
}
NS_IMETHODIMP
nsLocalFile::Exists(bool *_retval)
{