Bug 1045436 - Fix more bad implicit constructors in XPCOM; r=froydnj

This commit is contained in:
Ehsan Akhgari 2014-07-29 20:43:56 -04:00
parent 0143a48856
commit b06601767c
26 changed files with 76 additions and 47 deletions

View File

@ -1812,7 +1812,7 @@ nsNPAPIPluginInstance::CheckJavaC2PJSObjectQuirk(uint16_t paramCount,
return; return;
} }
mozilla::Version version = javaVersion.get(); mozilla::Version version(javaVersion.get());
if (version >= "1.7.0.4") { if (version >= "1.7.0.4") {
return; return;

View File

@ -1388,8 +1388,8 @@ PromiseWorkerProxy::StoreISupports(nsISupports* aSupports)
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
nsMainThreadPtrHandle<nsISupports> supports = nsMainThreadPtrHandle<nsISupports> supports(
new nsMainThreadPtrHolder<nsISupports>(aSupports); new nsMainThreadPtrHolder<nsISupports>(aSupports));
mSupportsArray.AppendElement(supports); mSupportsArray.AppendElement(supports);
} }

View File

@ -416,8 +416,8 @@ protected:
// Point WorkerDataStoreCursor to DataStoreCursor. // Point WorkerDataStoreCursor to DataStoreCursor.
nsRefPtr<DataStoreCursor> cursor = mBackingStore->Sync(mRevisionId, mRv); nsRefPtr<DataStoreCursor> cursor = mBackingStore->Sync(mRevisionId, mRv);
nsMainThreadPtrHandle<DataStoreCursor> backingCursor = nsMainThreadPtrHandle<DataStoreCursor> backingCursor(
new nsMainThreadPtrHolder<DataStoreCursor>(cursor); new nsMainThreadPtrHolder<DataStoreCursor>(cursor));
mWorkerCursor->SetBackingDataStoreCursor(backingCursor); mWorkerCursor->SetBackingDataStoreCursor(backingCursor);
return true; return true;

View File

@ -122,7 +122,7 @@ GetDataStoresStructuredCloneCallbacksRead(JSContext* aCx,
{ {
nsRefPtr<WorkerDataStore> workerStore = nsRefPtr<WorkerDataStore> workerStore =
new WorkerDataStore(workerPrivate->GlobalScope()); new WorkerDataStore(workerPrivate->GlobalScope());
nsMainThreadPtrHandle<DataStore> backingStore = dataStoreholder; nsMainThreadPtrHandle<DataStore> backingStore(dataStoreholder);
// When we're on the worker thread, prepare a DataStoreChangeEventProxy. // When we're on the worker thread, prepare a DataStoreChangeEventProxy.
nsRefPtr<DataStoreChangeEventProxy> eventProxy = nsRefPtr<DataStoreChangeEventProxy> eventProxy =

View File

@ -261,8 +261,8 @@ public:
return; return;
} }
nsMainThreadPtrHandle<ServiceWorkerUpdateInstance> handle = nsMainThreadPtrHandle<ServiceWorkerUpdateInstance> handle(
new nsMainThreadPtrHolder<ServiceWorkerUpdateInstance>(this); new nsMainThreadPtrHolder<ServiceWorkerUpdateInstance>(this));
// FIXME(nsm): Deal with error case (worker failed to download, redirect, // FIXME(nsm): Deal with error case (worker failed to download, redirect,
// parse) in error handler patch. // parse) in error handler patch.
nsRefPtr<FinishSuccessfulFetchWorkerRunnable> r = nsRefPtr<FinishSuccessfulFetchWorkerRunnable> r =
@ -1009,8 +1009,8 @@ ServiceWorkerManager::Install(ServiceWorkerRegistration* aRegistration,
InvalidateServiceWorkerContainerWorker(aRegistration, InvalidateServiceWorkerContainerWorker(aRegistration,
WhichServiceWorker::INSTALLING_WORKER); WhichServiceWorker::INSTALLING_WORKER);
nsMainThreadPtrHandle<ServiceWorkerRegistration> handle = nsMainThreadPtrHandle<ServiceWorkerRegistration> handle(
new nsMainThreadPtrHolder<ServiceWorkerRegistration>(aRegistration); new nsMainThreadPtrHolder<ServiceWorkerRegistration>(aRegistration));
nsRefPtr<ServiceWorker> serviceWorker; nsRefPtr<ServiceWorker> serviceWorker;
nsresult rv = nsresult rv =
@ -1085,8 +1085,8 @@ public:
return rv; return rv;
} }
nsMainThreadPtrHandle<ServiceWorkerRegistration> handle = nsMainThreadPtrHandle<ServiceWorkerRegistration> handle(
new nsMainThreadPtrHolder<ServiceWorkerRegistration>(mRegistration); new nsMainThreadPtrHolder<ServiceWorkerRegistration>(mRegistration));
nsRefPtr<ActivateEventRunnable> r = nsRefPtr<ActivateEventRunnable> r =
new ActivateEventRunnable(serviceWorker->GetWorkerPrivate(), handle); new ActivateEventRunnable(serviceWorker->GetWorkerPrivate(), handle);

View File

@ -32,8 +32,8 @@ class NotifyObserverRunnable : public nsRunnable
public: public:
NotifyObserverRunnable(nsIObserver * observer, NotifyObserverRunnable(nsIObserver * observer,
const char * topicStringLiteral) const char * topicStringLiteral)
: mObserver(), mTopic(topicStringLiteral) { : mObserver(new nsMainThreadPtrHolder<nsIObserver>(observer)),
mObserver = new nsMainThreadPtrHolder<nsIObserver>(observer); mTopic(topicStringLiteral) {
} }
NS_DECL_NSIRUNNABLE NS_DECL_NSIRUNNABLE
private: private:

View File

@ -321,7 +321,7 @@ public:
// For returning a smart reference from a raw reference that must be // For returning a smart reference from a raw reference that must be
// released. Explicit construction is required so as not to risk // released. Explicit construction is required so as not to risk
// unintentionally releasing the resource associated with a raw ref. // unintentionally releasing the resource associated with a raw ref.
explicit nsReturnRef(RawRefOnly aRefToRelease) MOZ_IMPLICIT nsReturnRef(RawRefOnly aRefToRelease)
: BaseClass(aRefToRelease) : BaseClass(aRefToRelease)
{ {
} }
@ -332,7 +332,7 @@ public:
{ {
} }
nsReturnRef(const nsReturningRef<T>& aReturning) MOZ_IMPLICIT nsReturnRef(const nsReturningRef<T>& aReturning)
: BaseClass(aReturning) : BaseClass(aReturning)
{ {
} }
@ -513,7 +513,7 @@ protected:
} }
// Construct with a handle to a resource. // Construct with a handle to a resource.
// A specialization must provide this. // A specialization must provide this.
nsSimpleRef(RawRef aRawRef) explicit nsSimpleRef(RawRef aRawRef)
: mRawRef(aRawRef) : mRawRef(aRawRef)
{ {
} }
@ -567,7 +567,7 @@ protected:
class RawRefOnly class RawRefOnly
{ {
public: public:
RawRefOnly(RawRef aRawRef) MOZ_IMPLICIT RawRefOnly(RawRef aRawRef)
: mRawRef(aRawRef) : mRawRef(aRawRef)
{ {
} }

View File

@ -107,7 +107,7 @@ class GenericModule MOZ_FINAL : public nsIModule
~GenericModule() {} ~GenericModule() {}
public: public:
GenericModule(const mozilla::Module* aData) explicit GenericModule(const mozilla::Module* aData)
: mData(aData) : mData(aData)
{ {
} }

View File

@ -25,7 +25,7 @@ public:
this->size = sizeof(*this); this->size = sizeof(*this);
} }
ScopedAppData(const nsXREAppData* aAppData); explicit ScopedAppData(const nsXREAppData* aAppData);
void Zero() { memset(this, 0, sizeof(*this)); } void Zero() { memset(this, 0, sizeof(*this)); }

View File

@ -271,7 +271,7 @@ static const uint32_t CPU_TYPE = CPU_TYPE_POWERPC64;
class ScopedMMap class ScopedMMap
{ {
public: public:
ScopedMMap(const char* aFilePath) explicit ScopedMMap(const char* aFilePath)
: buf(nullptr) : buf(nullptr)
{ {
fd = open(aFilePath, O_RDONLY); fd = open(aFilePath, O_RDONLY);

View File

@ -28,7 +28,7 @@ public:
NS_DECL_THREADSAFE_ISUPPORTS NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_NSIFACTORY NS_DECL_NSIFACTORY
GenericFactory(ConstructorProcPtr aCtor) explicit GenericFactory(ConstructorProcPtr aCtor)
: mCtor(aCtor) : mCtor(aCtor)
{ {
NS_ASSERTION(mCtor, "GenericFactory with no constructor"); NS_ASSERTION(mCtor, "GenericFactory with no constructor");

View File

@ -41,7 +41,7 @@ public:
* ReentrantMonitor * ReentrantMonitor
* @param aName A name which can reference this monitor * @param aName A name which can reference this monitor
*/ */
ReentrantMonitor(const char* aName) explicit ReentrantMonitor(const char* aName)
: BlockingResourceBase(aName, eReentrantMonitor) : BlockingResourceBase(aName, eReentrantMonitor)
#ifdef DEBUG #ifdef DEBUG
, mEntryCount(0) , mEntryCount(0)
@ -173,7 +173,7 @@ public:
* *
* @param aReentrantMonitor A valid mozilla::ReentrantMonitor*. * @param aReentrantMonitor A valid mozilla::ReentrantMonitor*.
**/ **/
ReentrantMonitorAutoEnter(mozilla::ReentrantMonitor& aReentrantMonitor) explicit ReentrantMonitorAutoEnter(mozilla::ReentrantMonitor& aReentrantMonitor)
: mReentrantMonitor(&aReentrantMonitor) : mReentrantMonitor(&aReentrantMonitor)
{ {
NS_ASSERTION(mReentrantMonitor, "null monitor"); NS_ASSERTION(mReentrantMonitor, "null monitor");
@ -222,7 +222,7 @@ public:
* @param aReentrantMonitor A valid mozilla::ReentrantMonitor*. It * @param aReentrantMonitor A valid mozilla::ReentrantMonitor*. It
* must be already locked. * must be already locked.
**/ **/
ReentrantMonitorAutoExit(ReentrantMonitor& aReentrantMonitor) explicit ReentrantMonitorAutoExit(ReentrantMonitor& aReentrantMonitor)
: mReentrantMonitor(&aReentrantMonitor) : mReentrantMonitor(&aReentrantMonitor)
{ {
NS_ASSERTION(mReentrantMonitor, "null monitor"); NS_ASSERTION(mReentrantMonitor, "null monitor");

View File

@ -24,7 +24,7 @@ public:
NS_DECL_NSISIMPLEENUMERATOR NS_DECL_NSISIMPLEENUMERATOR
// nsSimpleArrayEnumerator methods // nsSimpleArrayEnumerator methods
nsSimpleArrayEnumerator(nsIArray* aValueArray) explicit nsSimpleArrayEnumerator(nsIArray* aValueArray)
: mValueArray(aValueArray) : mValueArray(aValueArray)
, mIndex(0) , mIndex(0)
{ {

View File

@ -27,7 +27,7 @@ class NS_COM_GLUE nsCategoryObserver MOZ_FINAL : public nsIObserver
~nsCategoryObserver(); ~nsCategoryObserver();
public: public:
nsCategoryObserver(const char* aCategory); explicit nsCategoryObserver(const char* aCategory);
void ListenerDied(); void ListenerDied();
nsInterfaceHashtable<nsCStringHashKey, nsISupports>& GetHash() nsInterfaceHashtable<nsCStringHashKey, nsISupports>& GetHash()

View File

@ -105,7 +105,7 @@ public:
NS_IMETHOD HasMoreElements(bool* aResult); NS_IMETHOD HasMoreElements(bool* aResult);
NS_IMETHOD GetNext(nsISupports** aResult); NS_IMETHOD GetNext(nsISupports** aResult);
nsSingletonEnumerator(nsISupports* aValue); explicit nsSingletonEnumerator(nsISupports* aValue);
private: private:
~nsSingletonEnumerator(); ~nsSingletonEnumerator();

View File

@ -46,7 +46,7 @@ TS_tfopen(const char* aPath, const char* aMode)
class AutoFILE class AutoFILE
{ {
public: public:
AutoFILE(FILE* aFp = nullptr) : fp_(aFp) {} explicit AutoFILE(FILE* aFp = nullptr) : fp_(aFp) {}
~AutoFILE() ~AutoFILE()
{ {
if (fp_) { if (fp_) {
@ -95,7 +95,7 @@ nsresult
nsINIParser::Init(const char* aPath) nsINIParser::Init(const char* aPath)
{ {
/* open the file */ /* open the file */
AutoFILE fd = TS_tfopen(aPath, READ_BINARYMODE); AutoFILE fd(TS_tfopen(aPath, READ_BINARYMODE));
if (!fd) { if (!fd) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }

View File

@ -11,7 +11,7 @@
class nsProxyReleaseEvent : public nsRunnable class nsProxyReleaseEvent : public nsRunnable
{ {
public: public:
nsProxyReleaseEvent(nsISupports* aDoomed) : mDoomed(aDoomed) {} explicit nsProxyReleaseEvent(nsISupports* aDoomed) : mDoomed(aDoomed) {}
NS_IMETHOD Run() NS_IMETHOD Run()
{ {

View File

@ -177,7 +177,7 @@ class nsMainThreadPtrHandle
public: public:
nsMainThreadPtrHandle() : mPtr(nullptr) {} nsMainThreadPtrHandle() : mPtr(nullptr) {}
nsMainThreadPtrHandle(nsMainThreadPtrHolder<T>* aHolder) : mPtr(aHolder) {} explicit nsMainThreadPtrHandle(nsMainThreadPtrHolder<T>* aHolder) : mPtr(aHolder) {}
nsMainThreadPtrHandle(const nsMainThreadPtrHandle& aOther) nsMainThreadPtrHandle(const nsMainThreadPtrHandle& aOther)
: mPtr(aOther.mPtr) : mPtr(aOther.mPtr)
{ {
@ -187,6 +187,11 @@ public:
mPtr = aOther.mPtr; mPtr = aOther.mPtr;
return *this; return *this;
} }
nsMainThreadPtrHandle& operator=(nsMainThreadPtrHolder<T>* aHolder)
{
mPtr = aHolder;
return *this;
}
// These all call through to nsMainThreadPtrHolder, and thus implicitly // These all call through to nsMainThreadPtrHolder, and thus implicitly
// assert that we're on the main thread. Off-main-thread consumers must treat // assert that we're on the main thread. Off-main-thread consumers must treat

View File

@ -1307,7 +1307,7 @@ class nsGetterCopies
public: public:
typedef char16_t char_type; typedef char16_t char_type;
nsGetterCopies(nsString& aStr) explicit nsGetterCopies(nsString& aStr)
: mString(aStr) : mString(aStr)
, mData(nullptr) , mData(nullptr)
{ {
@ -1333,7 +1333,7 @@ class nsCGetterCopies
public: public:
typedef char char_type; typedef char char_type;
nsCGetterCopies(nsCString& aStr) explicit nsCGetterCopies(nsCString& aStr)
: mString(aStr) : mString(aStr)
, mData(nullptr) , mData(nullptr)
{ {

View File

@ -311,7 +311,7 @@ public:
typedef nsAutoTObserverArray<T, N> array_type; typedef nsAutoTObserverArray<T, N> array_type;
typedef Iterator base_type; typedef Iterator base_type;
ForwardIterator(const array_type& aArray) explicit ForwardIterator(const array_type& aArray)
: Iterator(0, aArray) : Iterator(0, aArray)
{ {
} }
@ -354,7 +354,7 @@ public:
typedef nsAutoTObserverArray<T, N> array_type; typedef nsAutoTObserverArray<T, N> array_type;
typedef Iterator base_type; typedef Iterator base_type;
EndLimitedIterator(const array_type& aArray) explicit EndLimitedIterator(const array_type& aArray)
: ForwardIterator(aArray) : ForwardIterator(aArray)
, mEnd(aArray, aArray.Length()) , mEnd(aArray, aArray.Length())
{ {
@ -391,7 +391,7 @@ public:
typedef nsAutoTObserverArray<T, N> array_type; typedef nsAutoTObserverArray<T, N> array_type;
typedef Iterator base_type; typedef Iterator base_type;
BackwardIterator(const array_type& aArray) explicit BackwardIterator(const array_type& aArray)
: Iterator(aArray.Length(), aArray) : Iterator(aArray.Length(), aArray)
{ {
} }

View File

@ -171,7 +171,7 @@ private:
int mCnt; int mCnt;
Type* mObj; Type* mObj;
Inner(Type* aObj) explicit Inner(Type* aObj)
: mCnt(1) : mCnt(1)
, mObj(aObj) , mObj(aObj)
{ {

View File

@ -274,7 +274,7 @@ class nsNameThreadRunnable MOZ_FINAL : public nsIRunnable
~nsNameThreadRunnable() {} ~nsNameThreadRunnable() {}
public: public:
nsNameThreadRunnable(const nsACString& aName) : mName(aName) {} explicit nsNameThreadRunnable(const nsACString& aName) : mName(aName) {}
NS_DECL_THREADSAFE_ISUPPORTS NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_NSIRUNNABLE NS_DECL_NSIRUNNABLE

View File

@ -51,7 +51,7 @@ int32_t NS_COM_GLUE CompareVersions(const char16_t* aStrA, const char16_t* aStrB
struct NS_COM_GLUE Version struct NS_COM_GLUE Version
{ {
Version(const char* aVersionString) explicit Version(const char* aVersionString)
{ {
versionContent = strdup(aVersionString); versionContent = strdup(aVersionString);
} }
@ -90,6 +90,30 @@ struct NS_COM_GLUE Version
{ {
return CompareVersions(versionContent, aRhs.ReadContent()) != 0; return CompareVersions(versionContent, aRhs.ReadContent()) != 0;
} }
bool operator<(const char* aRhs) const
{
return CompareVersions(versionContent, aRhs) == -1;
}
bool operator<=(const char* aRhs) const
{
return CompareVersions(versionContent, aRhs) < 1;
}
bool operator>(const char* aRhs) const
{
return CompareVersions(versionContent, aRhs) == 1;
}
bool operator>=(const char* aRhs) const
{
return CompareVersions(versionContent, aRhs) > -1;
}
bool operator==(const char* aRhs) const
{
return CompareVersions(versionContent, aRhs) == 0;
}
bool operator!=(const char* aRhs) const
{
return CompareVersions(versionContent, aRhs) != 0;
}
private: private:
char* versionContent; char* versionContent;

View File

@ -30,7 +30,7 @@ class NS_COM_GLUE nsVoidArray
{ {
public: public:
nsVoidArray(); nsVoidArray();
nsVoidArray(int32_t aCount); // initial count of aCount elements set to nullptr explicit nsVoidArray(int32_t aCount); // initial count of aCount elements set to nullptr
~nsVoidArray(); ~nsVoidArray();
nsVoidArray& operator=(const nsVoidArray& aOther); nsVoidArray& operator=(const nsVoidArray& aOther);

View File

@ -24,7 +24,7 @@ public:
private: private:
friend class nsSupportsWeakReference; friend class nsSupportsWeakReference;
nsWeakReference(nsSupportsWeakReference* aReferent) explicit nsWeakReference(nsSupportsWeakReference* aReferent)
: mReferent(aReferent) : mReferent(aReferent)
// ...I can only be constructed by an |nsSupportsWeakReference| // ...I can only be constructed by an |nsSupportsWeakReference|
{ {

View File

@ -23,10 +23,10 @@ class nsXPTType : public XPTTypeDescriptorPrefix
public: public:
nsXPTType() nsXPTType()
{} // random contents {} // random contents
nsXPTType(const XPTTypeDescriptorPrefix& prefix) MOZ_IMPLICIT nsXPTType(const XPTTypeDescriptorPrefix& prefix)
{*(XPTTypeDescriptorPrefix*)this = prefix;} {*(XPTTypeDescriptorPrefix*)this = prefix;}
nsXPTType(const uint8_t& prefix) MOZ_IMPLICIT nsXPTType(const uint8_t& prefix)
{*(uint8_t*)this = prefix;} {*(uint8_t*)this = prefix;}
nsXPTType& operator=(uint8_t val) nsXPTType& operator=(uint8_t val)
@ -124,7 +124,7 @@ class nsXPTParamInfo : public XPTParamDescriptor
{ {
// NO DATA - this a flyweight wrapper // NO DATA - this a flyweight wrapper
public: public:
nsXPTParamInfo(const XPTParamDescriptor& desc) MOZ_IMPLICIT nsXPTParamInfo(const XPTParamDescriptor& desc)
{*(XPTParamDescriptor*)this = desc;} {*(XPTParamDescriptor*)this = desc;}
@ -183,7 +183,7 @@ class nsXPTMethodInfo : public XPTMethodDescriptor
{ {
// NO DATA - this a flyweight wrapper // NO DATA - this a flyweight wrapper
public: public:
nsXPTMethodInfo(const XPTMethodDescriptor& desc) MOZ_IMPLICIT nsXPTMethodInfo(const XPTMethodDescriptor& desc)
{*(XPTMethodDescriptor*)this = desc;} {*(XPTMethodDescriptor*)this = desc;}
bool IsGetter() const {return 0 != (XPT_MD_IS_GETTER(flags) );} bool IsGetter() const {return 0 != (XPT_MD_IS_GETTER(flags) );}
@ -216,7 +216,7 @@ class nsXPTConstant : public XPTConstDescriptor
{ {
// NO DATA - this a flyweight wrapper // NO DATA - this a flyweight wrapper
public: public:
nsXPTConstant(const XPTConstDescriptor& desc) MOZ_IMPLICIT nsXPTConstant(const XPTConstDescriptor& desc)
{*(XPTConstDescriptor*)this = desc;} {*(XPTConstDescriptor*)this = desc;}
const char* GetName() const const char* GetName() const