Bug 1313381 - Add assertions to nsDeviceContext to assert that it is only initialized once. r=mstange

--HG--
extra : rebase_source : b6ccdd30e7443012b4fc061814a7243807663920
This commit is contained in:
Jonathan Watt 2016-10-21 20:39:11 +01:00
Родитель 6f4f6ac656
Коммит fd5181fc38
2 изменённых файлов: 19 добавлений и 1 удалений

Просмотреть файл

@ -194,6 +194,9 @@ nsDeviceContext::nsDeviceContext()
mAppUnitsPerDevPixel(-1), mAppUnitsPerDevPixelAtUnitFullZoom(-1), mAppUnitsPerDevPixel(-1), mAppUnitsPerDevPixelAtUnitFullZoom(-1),
mAppUnitsPerPhysicalInch(-1), mAppUnitsPerPhysicalInch(-1),
mFullZoom(1.0f), mPrintingScale(1.0f) mFullZoom(1.0f), mPrintingScale(1.0f)
#ifdef DEBUG
, mIsInitialized(false)
#endif
{ {
MOZ_ASSERT(NS_IsMainThread(), "nsDeviceContext created off main thread"); MOZ_ASSERT(NS_IsMainThread(), "nsDeviceContext created off main thread");
} }
@ -299,6 +302,13 @@ nsDeviceContext::SetDPI(double* aScale)
nsresult nsresult
nsDeviceContext::Init(nsIWidget *aWidget) nsDeviceContext::Init(nsIWidget *aWidget)
{ {
#ifdef DEBUG
// We can't assert |!mIsInitialized| here since EndSwapDocShellsForDocument
// re-initializes nsDeviceContext objects. We can only assert in
// InitForPrinting (below).
mIsInitialized = true;
#endif
nsresult rv = NS_OK; nsresult rv = NS_OK;
if (mScreenManager && mWidget == aWidget) if (mScreenManager && mWidget == aWidget)
return rv; return rv;
@ -438,13 +448,18 @@ nsDeviceContext::InitForPrinting(nsIDeviceContextSpec *aDevice)
{ {
NS_ENSURE_ARG_POINTER(aDevice); NS_ENSURE_ARG_POINTER(aDevice);
mDeviceContextSpec = aDevice; MOZ_ASSERT(!mIsInitialized,
"Only initialize once, immediately after construction");
// We don't set mIsInitialized here. The Init() call below does that.
mPrintTarget = aDevice->MakePrintTarget(); mPrintTarget = aDevice->MakePrintTarget();
if (!mPrintTarget) { if (!mPrintTarget) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
mDeviceContextSpec = aDevice;
Init(nullptr); Init(nullptr);
if (!CalcPrintingSize()) { if (!CalcPrintingSize()) {

Просмотреть файл

@ -288,6 +288,9 @@ private:
#ifdef XP_MACOSX #ifdef XP_MACOSX
RefPtr<PrintTarget> mCachedPrintTarget; RefPtr<PrintTarget> mCachedPrintTarget;
#endif #endif
#ifdef DEBUG
bool mIsInitialized;
#endif
}; };
#endif /* _NS_DEVICECONTEXT_H_ */ #endif /* _NS_DEVICECONTEXT_H_ */