Bug 984466 - change CallQueryInterface to assert in cases of trivial conversions; r=ehsan
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
//*****************************************************************************
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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");
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user