Bug 968804 - Part a: Add inner window assertions to DETH and {Add,Remove}EventTargetObject; r=peterv
authorMs2ger <ms2ger@gmail.com>
Tue, 20 May 2014 21:50:57 +0200
changeset 184005 f5c8ca9dbaf6c24f25950e49894be359d1c4de8c
parent 184004 6f9b35588b74c3d530a51161ad6d197299fa883f
child 184006 ee76827715891630014801ad59ac7f022641964f
push id43721
push userMs2ger@gmail.com
push dateTue, 20 May 2014 19:53:20 +0000
treeherdermozilla-inbound@e50261fb6800 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspeterv
bugs968804
milestone32.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 968804 - Part a: Add inner window assertions to DETH and {Add,Remove}EventTargetObject; r=peterv
dom/base/nsGlobalWindow.cpp
dom/base/nsGlobalWindow.h
dom/events/DOMEventTargetHelper.cpp
dom/events/DOMEventTargetHelper.h
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -1339,22 +1339,24 @@ nsGlobalWindow::~nsGlobalWindow()
     ac->RemoveWindowAsListener(this);
 
   nsLayoutStatics::Release();
 }
 
 void
 nsGlobalWindow::AddEventTargetObject(DOMEventTargetHelper* aObject)
 {
+  MOZ_ASSERT(IsInnerWindow());
   mEventTargetObjects.PutEntry(aObject);
 }
 
 void
 nsGlobalWindow::RemoveEventTargetObject(DOMEventTargetHelper* aObject)
 {
+  MOZ_ASSERT(IsInnerWindow());
   mEventTargetObjects.RemoveEntry(aObject);
 }
 
 // static
 void
 nsGlobalWindow::ShutDown()
 {
   if (gDumpFile && gDumpFile != stdout) {
--- a/dom/base/nsGlobalWindow.h
+++ b/dom/base/nsGlobalWindow.h
@@ -691,16 +691,17 @@ public:
   static WindowByIdTable* GetWindowsTable() {
     return sWindowsById;
   }
 
   void AddSizeOfIncludingThis(nsWindowSizes* aWindowSizes) const;
 
   void UnmarkGrayTimers();
 
+  // Inner windows only.
   void AddEventTargetObject(mozilla::DOMEventTargetHelper* aObject);
   void RemoveEventTargetObject(mozilla::DOMEventTargetHelper* aObject);
 
   void NotifyIdleObserver(IdleObserverHolder* aIdleObserverHolder,
                           bool aCallOnidle);
   nsresult HandleIdleActiveEvent();
   bool ContainsIdleObserver(nsIIdleObserver* aIdleObserver, uint32_t timeInS);
   void HandleIdleObserverCallback();
--- a/dom/events/DOMEventTargetHelper.cpp
+++ b/dom/events/DOMEventTargetHelper.cpp
@@ -86,17 +86,17 @@ DOMEventTargetHelper::~DOMEventTargetHel
     mListenerManager->Disconnect();
   }
   ReleaseWrapper(this);
 }
 
 void
 DOMEventTargetHelper::BindToOwner(nsPIDOMWindow* aOwner)
 {
-  MOZ_ASSERT(!aOwner || aOwner->IsInnerWindow());
+  MOZ_ASSERT_IF(aOwner, aOwner->IsInnerWindow());
   nsCOMPtr<nsIGlobalObject> glob = do_QueryInterface(aOwner);
   BindToOwner(glob);
 }
 
 void
 DOMEventTargetHelper::BindToOwner(nsIGlobalObject* aOwner)
 {
   if (mParentObject) {
@@ -107,16 +107,17 @@ DOMEventTargetHelper::BindToOwner(nsIGlo
     mParentObject = nullptr;
     mHasOrHasHadOwnerWindow = false;
   }
   if (aOwner) {
     mParentObject = 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);
     }
   }
 }
 
 void
 DOMEventTargetHelper::BindToOwner(DOMEventTargetHelper* aOther)
@@ -129,16 +130,17 @@ DOMEventTargetHelper::BindToOwner(DOMEve
   }
   if (aOther) {
     mHasOrHasHadOwnerWindow = aOther->HasOrHasHadOwner();
     if (aOther->GetParentObject()) {
       mParentObject = aOther->GetParentObject();
       // 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);
       }
     }
   }
 }
 
 void
--- a/dom/events/DOMEventTargetHelper.h
+++ b/dom/events/DOMEventTargetHelper.h
@@ -115,22 +115,18 @@ public:
   virtual nsIDOMWindow* GetOwnerGlobal() MOZ_OVERRIDE
   {
     return nsPIDOMWindow::GetOuterFromCurrentInner(GetOwner());
   }
 
   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;
   }
 
   nsPIDOMWindow* GetOwner() const { return mOwnerWindow; }
   void BindToOwner(nsIGlobalObject* aOwner);
   void BindToOwner(nsPIDOMWindow* aOwner);
   void BindToOwner(DOMEventTargetHelper* aOther);
@@ -154,17 +150,17 @@ protected:
   nsresult DispatchTrustedEvent(const nsAString& aEventName);
   // Make |event| trusted and dispatch |aEvent| to |this|.
   nsresult DispatchTrustedEvent(nsIDOMEvent* aEvent);
 
   virtual void LastRelease() {}
 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;
 };
 
 NS_DEFINE_STATIC_IID_ACCESSOR(DOMEventTargetHelper,
                               NS_DOMEVENTTARGETHELPER_IID)