Bug 968804 - Part a: Add inner window assertions to DETH and {Add,Remove}EventTargetObject; r=peterv

This commit is contained in:
Ms2ger 2014-05-20 21:50:57 +02:00
parent 54bd037fd0
commit d02b9c0ccb
4 changed files with 9 additions and 8 deletions

View File

@ -1344,12 +1344,14 @@ nsGlobalWindow::~nsGlobalWindow()
void
nsGlobalWindow::AddEventTargetObject(DOMEventTargetHelper* aObject)
{
MOZ_ASSERT(IsInnerWindow());
mEventTargetObjects.PutEntry(aObject);
}
void
nsGlobalWindow::RemoveEventTargetObject(DOMEventTargetHelper* aObject)
{
MOZ_ASSERT(IsInnerWindow());
mEventTargetObjects.RemoveEntry(aObject);
}

View File

@ -696,6 +696,7 @@ public:
void UnmarkGrayTimers();
// Inner windows only.
void AddEventTargetObject(mozilla::DOMEventTargetHelper* aObject);
void RemoveEventTargetObject(mozilla::DOMEventTargetHelper* aObject);

View File

@ -91,7 +91,7 @@ DOMEventTargetHelper::~DOMEventTargetHelper()
void
DOMEventTargetHelper::BindToOwner(nsPIDOMWindow* aOwner)
{
MOZ_ASSERT(!aOwner || aOwner->IsInnerWindow());
MOZ_ASSERT_IF(aOwner, aOwner->IsInnerWindow());
nsCOMPtr<nsIGlobalObject> glob = do_QueryInterface(aOwner);
BindToOwner(glob);
}
@ -112,6 +112,7 @@ DOMEventTargetHelper::BindToOwner(nsIGlobalObject* aOwner)
// Let's cache the result of this QI for fast access and off main thread usage
mOwnerWindow = nsCOMPtr<nsPIDOMWindow>(do_QueryInterface(aOwner)).get();
if (mOwnerWindow) {
MOZ_ASSERT(mOwnerWindow->IsInnerWindow());
mHasOrHasHadOwnerWindow = true;
static_cast<nsGlobalWindow*>(mOwnerWindow)->AddEventTargetObject(this);
}
@ -134,6 +135,7 @@ DOMEventTargetHelper::BindToOwner(DOMEventTargetHelper* aOther)
// Let's cache the result of this QI for fast access and off main thread usage
mOwnerWindow = nsCOMPtr<nsPIDOMWindow>(do_QueryInterface(mParentObject)).get();
if (mOwnerWindow) {
MOZ_ASSERT(mOwnerWindow->IsInnerWindow());
mHasOrHasHadOwnerWindow = true;
static_cast<nsGlobalWindow*>(mOwnerWindow)->AddEventTargetObject(this);
}

View File

@ -120,12 +120,8 @@ public:
nsresult CheckInnerWindowCorrectness()
{
NS_ENSURE_STATE(!mHasOrHasHadOwnerWindow || mOwnerWindow);
if (mOwnerWindow) {
NS_ASSERTION(mOwnerWindow->IsInnerWindow(), "Should have inner window here!\n");
nsPIDOMWindow* outer = mOwnerWindow->GetOuterWindow();
if (!outer || outer->GetCurrentInnerWindow() != mOwnerWindow) {
return NS_ERROR_FAILURE;
}
if (mOwnerWindow && !mOwnerWindow->IsCurrentInnerWindow()) {
return NS_ERROR_FAILURE;
}
return NS_OK;
}
@ -159,7 +155,7 @@ protected:
private:
// Inner window or sandbox.
nsIGlobalObject* mParentObject;
// mParentObject pre QI-ed and cached
// mParentObject pre QI-ed and cached (inner window)
// (it is needed for off main thread access)
nsPIDOMWindow* mOwnerWindow;
bool mHasOrHasHadOwnerWindow;