Bug 1015430 - Fix more XPCOM constructors to clarify whether they should be explicit; r=froydnj

This commit is contained in:
Ehsan Akhgari 2014-05-25 21:16:01 -04:00
parent 6f94b1e656
commit a6264cb1ae
11 changed files with 47 additions and 41 deletions

View File

@ -419,7 +419,7 @@ NS_CreateJSTimeoutHandler(nsGlobalWindow *aWindow, Function& aFunction,
FallibleTArray<JS::Heap<JS::Value> > args;
if (!args.AppendElements(aArguments)) {
aError.Throw(NS_ERROR_OUT_OF_MEMORY);
return 0;
return nullptr;
}
nsRefPtr<nsJSScriptTimeoutHandler> handler =

View File

@ -1160,7 +1160,7 @@ nsXBLPrototypeBinding::Write(nsIObjectOutputStream* aStream)
nsAutoString attrValue;
for (uint32_t i = 0; i < attributes; ++i) {
const nsAttrName* attr = mBinding->GetAttrNameAt(i);
nsDependentAtomString attrName = attr->LocalName();
nsDependentAtomString attrName(attr->LocalName());
mBinding->GetAttr(attr->NamespaceID(), attr->LocalName(), attrValue);
rv = aStream->Write8(XBLBinding_Serialize_Attribute);
NS_ENSURE_SUCCESS(rv, rv);

View File

@ -927,7 +927,7 @@ ParentImpl::GetContentParent(PBackgroundParent* aBackgroundActor)
MOZ_ALWAYS_TRUE(NS_SUCCEEDED(NS_DispatchToMainThread(runnable)));
}
return actor->mContent.get();
return already_AddRefed<ContentParent>(actor->mContent.get());
}
// static

View File

@ -2693,7 +2693,7 @@ IMEInputHandler::CreateTextRangeArray(NSAttributedString *aAttrString,
return textRangeArray.forget();
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
NS_OBJC_END_TRY_ABORT_BLOCK_NSNULL;
}
bool

View File

@ -147,7 +147,7 @@ extern void NS_SealStaticAtomTable();
class nsAtomString : public nsString
{
public:
nsAtomString(nsIAtom* aAtom)
explicit nsAtomString(nsIAtom* aAtom)
{
aAtom->ToString(*this);
}
@ -156,7 +156,7 @@ public:
class nsAtomCString : public nsCString
{
public:
nsAtomCString(nsIAtom* aAtom)
explicit nsAtomCString(nsIAtom* aAtom)
{
aAtom->ToUTF8String(*this);
}
@ -165,7 +165,7 @@ public:
class nsDependentAtomString : public nsDependentString
{
public:
nsDependentAtomString(nsIAtom* aAtom)
explicit nsDependentAtomString(nsIAtom* aAtom)
: nsDependentString(aAtom->GetUTF16String(), aAtom->GetLength())
{
}

View File

@ -145,6 +145,12 @@ struct already_AddRefed
// nothing else to do here
}
#ifdef MOZ_HAVE_CXX11_NULLPTR
// We have to keep this constructor implicit if we don't have nullptr support
// so that returning nullptr from a function which returns an already_AddRefed
// type works on the older b2g toolchains.
explicit
#endif
already_AddRefed( T* aRawPtr )
: mRawPtr(aRawPtr)
{
@ -435,7 +441,7 @@ nsCOMPtr_base
{
public:
nsCOMPtr_base( nsISupports* rawPtr = 0 )
explicit nsCOMPtr_base( nsISupports* rawPtr = 0 )
: mRawPtr(rawPtr)
{
// nothing else to do here
@ -568,7 +574,7 @@ class nsCOMPtr MOZ_FINAL
NSCAP_LOG_ASSIGNMENT(this, aSmartPtr.mRawPtr);
}
nsCOMPtr( T* aRawPtr )
MOZ_IMPLICIT nsCOMPtr( T* aRawPtr )
: NSCAP_CTOR_BASE(aRawPtr)
// construct from a raw pointer (of the right type)
{
@ -578,7 +584,7 @@ class nsCOMPtr MOZ_FINAL
NSCAP_ASSERT_NO_QUERY_NEEDED();
}
nsCOMPtr( already_AddRefed<T>& aSmartPtr )
MOZ_IMPLICIT nsCOMPtr( already_AddRefed<T>& aSmartPtr )
: NSCAP_CTOR_BASE(aSmartPtr.take())
// construct from |already_AddRefed|
{
@ -586,7 +592,7 @@ class nsCOMPtr MOZ_FINAL
NSCAP_ASSERT_NO_QUERY_NEEDED();
}
nsCOMPtr( already_AddRefed<T>&& aSmartPtr )
MOZ_IMPLICIT nsCOMPtr( already_AddRefed<T>&& aSmartPtr )
: NSCAP_CTOR_BASE(aSmartPtr.take())
// construct from |otherComPtr.forget()|
{
@ -595,7 +601,7 @@ class nsCOMPtr MOZ_FINAL
}
template<typename U>
nsCOMPtr( already_AddRefed<U>& aSmartPtr )
MOZ_IMPLICIT nsCOMPtr( already_AddRefed<U>& aSmartPtr )
: NSCAP_CTOR_BASE(static_cast<T*>(aSmartPtr.take()))
// construct from |already_AddRefed|
{
@ -607,7 +613,7 @@ class nsCOMPtr MOZ_FINAL
}
template<typename U>
nsCOMPtr( already_AddRefed<U>&& aSmartPtr )
MOZ_IMPLICIT nsCOMPtr( already_AddRefed<U>&& aSmartPtr )
: NSCAP_CTOR_BASE(static_cast<T*>(aSmartPtr.take()))
// construct from |otherComPtr.forget()|
{
@ -618,7 +624,7 @@ class nsCOMPtr MOZ_FINAL
NSCAP_ASSERT_NO_QUERY_NEEDED();
}
nsCOMPtr( const nsQueryInterface qi )
MOZ_IMPLICIT nsCOMPtr( const nsQueryInterface qi )
: NSCAP_CTOR_BASE(0)
// construct from |do_QueryInterface(expr)|
{
@ -626,7 +632,7 @@ class nsCOMPtr MOZ_FINAL
assign_from_qi(qi, NS_GET_TEMPLATE_IID(T));
}
nsCOMPtr( const nsQueryInterfaceWithError& qi )
MOZ_IMPLICIT nsCOMPtr( const nsQueryInterfaceWithError& qi )
: NSCAP_CTOR_BASE(0)
// construct from |do_QueryInterface(expr, &rv)|
{
@ -634,7 +640,7 @@ class nsCOMPtr MOZ_FINAL
assign_from_qi_with_error(qi, NS_GET_TEMPLATE_IID(T));
}
nsCOMPtr( const nsGetServiceByCID gs )
MOZ_IMPLICIT nsCOMPtr( const nsGetServiceByCID gs )
: NSCAP_CTOR_BASE(0)
// construct from |do_GetService(cid_expr)|
{
@ -642,7 +648,7 @@ class nsCOMPtr MOZ_FINAL
assign_from_gs_cid(gs, NS_GET_TEMPLATE_IID(T));
}
nsCOMPtr( const nsGetServiceByCIDWithError& gs )
MOZ_IMPLICIT nsCOMPtr( const nsGetServiceByCIDWithError& gs )
: NSCAP_CTOR_BASE(0)
// construct from |do_GetService(cid_expr, &rv)|
{
@ -650,7 +656,7 @@ class nsCOMPtr MOZ_FINAL
assign_from_gs_cid_with_error(gs, NS_GET_TEMPLATE_IID(T));
}
nsCOMPtr( const nsGetServiceByContractID gs )
MOZ_IMPLICIT nsCOMPtr( const nsGetServiceByContractID gs )
: NSCAP_CTOR_BASE(0)
// construct from |do_GetService(contractid_expr)|
{
@ -658,7 +664,7 @@ class nsCOMPtr MOZ_FINAL
assign_from_gs_contractid(gs, NS_GET_TEMPLATE_IID(T));
}
nsCOMPtr( const nsGetServiceByContractIDWithError& gs )
MOZ_IMPLICIT nsCOMPtr( const nsGetServiceByContractIDWithError& gs )
: NSCAP_CTOR_BASE(0)
// construct from |do_GetService(contractid_expr, &rv)|
{
@ -666,7 +672,7 @@ class nsCOMPtr MOZ_FINAL
assign_from_gs_contractid_with_error(gs, NS_GET_TEMPLATE_IID(T));
}
nsCOMPtr( const nsCOMPtr_helper& helper )
MOZ_IMPLICIT nsCOMPtr( const nsCOMPtr_helper& helper )
: NSCAP_CTOR_BASE(0)
// ...and finally, anything else we might need to construct from
// can exploit the |nsCOMPtr_helper| facility
@ -943,7 +949,7 @@ class nsCOMPtr<nsISupports>
NSCAP_LOG_ASSIGNMENT(this, aSmartPtr.mRawPtr);
}
nsCOMPtr( nsISupports* aRawPtr )
MOZ_IMPLICIT nsCOMPtr( nsISupports* aRawPtr )
: nsCOMPtr_base(aRawPtr)
// construct from a raw pointer (of the right type)
{
@ -952,21 +958,21 @@ class nsCOMPtr<nsISupports>
NSCAP_LOG_ASSIGNMENT(this, aRawPtr);
}
nsCOMPtr( already_AddRefed<nsISupports>& aSmartPtr )
MOZ_IMPLICIT nsCOMPtr( already_AddRefed<nsISupports>& aSmartPtr )
: nsCOMPtr_base(aSmartPtr.take())
// construct from |already_AddRefed|
{
NSCAP_LOG_ASSIGNMENT(this, mRawPtr);
}
nsCOMPtr( already_AddRefed<nsISupports>&& aSmartPtr )
MOZ_IMPLICIT nsCOMPtr( already_AddRefed<nsISupports>&& aSmartPtr )
: nsCOMPtr_base(aSmartPtr.take())
// construct from |otherComPtr.forget()|
{
NSCAP_LOG_ASSIGNMENT(this, mRawPtr);
}
nsCOMPtr( const nsQueryInterface qi )
MOZ_IMPLICIT nsCOMPtr( const nsQueryInterface qi )
: nsCOMPtr_base(0)
// assign from |do_QueryInterface(expr)|
{
@ -974,7 +980,7 @@ class nsCOMPtr<nsISupports>
assign_from_qi(qi, NS_GET_IID(nsISupports));
}
nsCOMPtr( const nsQueryInterfaceWithError& qi )
MOZ_IMPLICIT nsCOMPtr( const nsQueryInterfaceWithError& qi )
: nsCOMPtr_base(0)
// assign from |do_QueryInterface(expr, &rv)|
{
@ -982,7 +988,7 @@ class nsCOMPtr<nsISupports>
assign_from_qi_with_error(qi, NS_GET_IID(nsISupports));
}
nsCOMPtr( const nsGetServiceByCID gs )
MOZ_IMPLICIT nsCOMPtr( const nsGetServiceByCID gs )
: nsCOMPtr_base(0)
// assign from |do_GetService(cid_expr)|
{
@ -990,7 +996,7 @@ class nsCOMPtr<nsISupports>
assign_from_gs_cid(gs, NS_GET_IID(nsISupports));
}
nsCOMPtr( const nsGetServiceByCIDWithError& gs )
MOZ_IMPLICIT nsCOMPtr( const nsGetServiceByCIDWithError& gs )
: nsCOMPtr_base(0)
// assign from |do_GetService(cid_expr, &rv)|
{
@ -998,7 +1004,7 @@ class nsCOMPtr<nsISupports>
assign_from_gs_cid_with_error(gs, NS_GET_IID(nsISupports));
}
nsCOMPtr( const nsGetServiceByContractID gs )
MOZ_IMPLICIT nsCOMPtr( const nsGetServiceByContractID gs )
: nsCOMPtr_base(0)
// assign from |do_GetService(contractid_expr)|
{
@ -1006,7 +1012,7 @@ class nsCOMPtr<nsISupports>
assign_from_gs_contractid(gs, NS_GET_IID(nsISupports));
}
nsCOMPtr( const nsGetServiceByContractIDWithError& gs )
MOZ_IMPLICIT nsCOMPtr( const nsGetServiceByContractIDWithError& gs )
: nsCOMPtr_base(0)
// assign from |do_GetService(contractid_expr, &rv)|
{
@ -1014,7 +1020,7 @@ class nsCOMPtr<nsISupports>
assign_from_gs_contractid_with_error(gs, NS_GET_IID(nsISupports));
}
nsCOMPtr( const nsCOMPtr_helper& helper )
MOZ_IMPLICIT nsCOMPtr( const nsCOMPtr_helper& helper )
: nsCOMPtr_base(0)
// ...and finally, anything else we might need to construct from
// can exploit the |nsCOMPtr_helper| facility

View File

@ -255,7 +255,7 @@ namespace mozilla {
class ThreadSafeAutoRefCnt {
public:
ThreadSafeAutoRefCnt() : mValue(0) {}
ThreadSafeAutoRefCnt(nsrefcnt aValue) : mValue(aValue) {}
explicit ThreadSafeAutoRefCnt(nsrefcnt aValue) : mValue(aValue) {}
// only support prefix increment/decrement
MOZ_ALWAYS_INLINE nsrefcnt operator++() { return ++mValue; }

View File

@ -54,7 +54,7 @@ public:
Assign(str);
}
nsTString_CharT( const substring_tuple_type& tuple )
MOZ_IMPLICIT nsTString_CharT( const substring_tuple_type& tuple )
: substring_type()
{
Assign(tuple);
@ -524,7 +524,7 @@ public:
Assign(str);
}
nsTAutoString_CharT( const substring_tuple_type& tuple )
MOZ_IMPLICIT nsTAutoString_CharT( const substring_tuple_type& tuple )
: fixed_string_type(mStorage, kDefaultStorageSize, 0)
{
Assign(tuple);
@ -655,7 +655,7 @@ class MOZ_STACK_CLASS nsTGetterCopies_CharT
public:
typedef CharT char_type;
nsTGetterCopies_CharT(nsTSubstring_CharT& str)
explicit nsTGetterCopies_CharT(nsTSubstring_CharT& str)
: mString(str), mData(nullptr) {}
~nsTGetterCopies_CharT()

View File

@ -658,7 +658,7 @@ public:
* this is public to support automatic conversion of tuple to string
* base type, which helps avoid converting to nsTAString.
*/
nsTSubstring_CharT(const substring_tuple_type& tuple)
MOZ_IMPLICIT nsTSubstring_CharT(const substring_tuple_type& tuple)
: mData(nullptr),
mLength(0),
mFlags(F_NONE)

View File

@ -280,7 +280,7 @@ public:
typedef char value_type;
typedef char16_t buffer_type;
ConvertUTF8toUTF16( buffer_type* aBuffer )
explicit ConvertUTF8toUTF16( buffer_type* aBuffer )
: mStart(aBuffer), mBuffer(aBuffer), mErrorEncountered(false) {}
size_t Length() const { return mBuffer - mStart; }
@ -445,7 +445,7 @@ public:
// |ConvertUTF8toUTF16|, but it's that way for backwards
// compatibility.
ConvertUTF16toUTF8( buffer_type* aBuffer )
explicit ConvertUTF16toUTF8( buffer_type* aBuffer )
: mStart(aBuffer), mBuffer(aBuffer) {}
size_t Size() const { return mBuffer - mStart; }
@ -644,7 +644,7 @@ public:
typedef char16_t output_type;
public:
LossyConvertEncoding8to16( char16_t* aDestination ) :
explicit LossyConvertEncoding8to16( char16_t* aDestination ) :
mDestination(aDestination) { }
void
@ -686,7 +686,7 @@ public:
typedef char16_t input_type;
typedef char output_type;
LossyConvertEncoding16to8( char* aDestination ) : mDestination(aDestination) { }
explicit LossyConvertEncoding16to8( char* aDestination ) : mDestination(aDestination) { }
void
write( const char16_t* aSource, uint32_t aSourceLength)

View File

@ -601,7 +601,7 @@ class CopyToUpperCase
public:
typedef char value_type;
CopyToUpperCase( nsACString::iterator& aDestIter )
explicit CopyToUpperCase( nsACString::iterator& aDestIter )
: mIter(aDestIter)
{
}
@ -679,7 +679,7 @@ class CopyToLowerCase
public:
typedef char value_type;
CopyToLowerCase( nsACString::iterator& aDestIter )
explicit CopyToLowerCase( nsACString::iterator& aDestIter )
: mIter(aDestIter)
{
}