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),
mAppUnitsPerPhysicalInch(-1),
mFullZoom(1.0f), mPrintingScale(1.0f)
#ifdef DEBUG
, mIsInitialized(false)
#endif
{
MOZ_ASSERT(NS_IsMainThread(), "nsDeviceContext created off main thread");
}
@ -299,6 +302,13 @@ nsDeviceContext::SetDPI(double* aScale)
nsresult
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;
if (mScreenManager && mWidget == aWidget)
return rv;
@ -438,13 +448,18 @@ nsDeviceContext::InitForPrinting(nsIDeviceContextSpec *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();
if (!mPrintTarget) {
return NS_ERROR_FAILURE;
}
mDeviceContextSpec = aDevice;
Init(nullptr);
if (!CalcPrintingSize()) {

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

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