Bug 1368250 - Give the TextControlInitializer property a dtor to automatically call Revoke when the property is deleted. r=mats
authorJonathan Kew <jkew@mozilla.com>
Sun, 28 May 2017 11:22:29 +0100
changeset 585756 2e61d7b8278567b029369b2dca13a26421c945cb
parent 585755 398d167b26f90af9953523ef4cbef3e38af5eb4a
child 585757 6414aec048aea01d726832dec33e83f3d8503f0c
push id61188
push usermaglione.k@gmail.com
push dateSun, 28 May 2017 22:11:50 +0000
reviewersmats
bugs1368250
milestone55.0a1
Bug 1368250 - Give the TextControlInitializer property a dtor to automatically call Revoke when the property is deleted. r=mats
layout/forms/nsTextControlFrame.cpp
layout/forms/nsTextControlFrame.h
--- a/layout/forms/nsTextControlFrame.cpp
+++ b/layout/forms/nsTextControlFrame.cpp
@@ -119,21 +119,17 @@ nsTextControlFrame::~nsTextControlFrame(
 {
 }
 
 void
 nsTextControlFrame::DestroyFrom(nsIFrame* aDestructRoot)
 {
   mScrollEvent.Revoke();
 
-  EditorInitializer* initializer = GetProperty(TextControlInitializer());
-  if (initializer) {
-    initializer->Revoke();
-    DeleteProperty(TextControlInitializer());
-  }
+  DeleteProperty(TextControlInitializer());
 
   // Unbind the text editor state object from the frame.  The editor will live
   // on, but things like controllers will be released.
   nsCOMPtr<nsITextControlElement> txtCtrl = do_QueryInterface(GetContent());
   NS_ASSERTION(txtCtrl, "Content not a text control element");
   txtCtrl->UnbindFromFrame(this);
 
   nsFormControlFrame::RegUnRegAccessKey(static_cast<nsIFrame*>(this), false);
@@ -389,22 +385,18 @@ nsTextControlFrame::CreateAnonymousConte
       // so are input text controls with spellcheck=true
       element->GetSpellcheck(&initEagerly);
     }
   }
 
   if (initEagerly) {
     NS_ASSERTION(!nsContentUtils::IsSafeToRunScript(),
                  "Someone forgot a script blocker?");
-    EditorInitializer* initializer = GetProperty(TextControlInitializer());
-    if (initializer) {
-      initializer->Revoke();
-    }
-    initializer = new EditorInitializer(this);
-    SetProperty(TextControlInitializer(),initializer);
+    EditorInitializer* initializer = new EditorInitializer(this);
+    SetProperty(TextControlInitializer(), initializer);
     nsContentUtils::AddScriptRunner(initializer);
   }
 
   return NS_OK;
 }
 
 void
 nsTextControlFrame::AppendAnonymousContentTo(nsTArray<nsIContent*>& aElements,
--- a/layout/forms/nsTextControlFrame.h
+++ b/layout/forms/nsTextControlFrame.h
@@ -217,19 +217,24 @@ public: //for methods who access nsTextC
 #undef DEFINE_TEXTCTRL_FORWARDER
 
 protected:
   class EditorInitializer;
   friend class EditorInitializer;
   friend class nsTextEditorState; // needs access to UpdateValueDisplay
 
   // Temp reference to scriptrunner
-  // We could make these auto-Revoking via the "delete" entry for safety
-  NS_DECLARE_FRAME_PROPERTY_WITHOUT_DTOR(TextControlInitializer,
-                                         EditorInitializer)
+  NS_DECLARE_FRAME_PROPERTY_WITH_DTOR(TextControlInitializer,
+                                      EditorInitializer,
+                                      nsTextControlFrame::RevokeInitializer)
+
+  static void
+  RevokeInitializer(EditorInitializer* aInitializer) {
+    aInitializer->Revoke();
+  };
 
   class EditorInitializer : public mozilla::Runnable {
   public:
     explicit EditorInitializer(nsTextControlFrame* aFrame) :
       mFrame(aFrame) {}
 
     NS_IMETHOD Run() override;