Bug 1166932 - Part 1: Copy the editor observers array before iterating over it. r=roc, a=abillings
authorEhsan Akhgari <ehsan@mozilla.com>
Thu, 21 May 2015 16:15:59 -0400
changeset 274726 60418e3204f8004e658bc412e689bb6782d6b5d8
parent 274725 40319564cfc604d575c410ed8160ec40a0e17153
child 274727 1642ba0f72b4a14b27f8079d64b82e3501192efe
push id863
push userraliiev@mozilla.com
push dateMon, 03 Aug 2015 13:22:43 +0000
treeherdermozilla-release@f6321b14228d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc, abillings
bugs1166932
milestone40.0a2
Bug 1166932 - Part 1: Copy the editor observers array before iterating over it. r=roc, a=abillings
editor/libeditor/nsEditor.cpp
--- a/editor/libeditor/nsEditor.cpp
+++ b/editor/libeditor/nsEditor.cpp
@@ -1802,38 +1802,40 @@ private:
   nsRefPtr<nsEditor> mEditor;
   nsCOMPtr<nsIContent> mTarget;
   bool mIsComposing;
 };
 
 void
 nsEditor::NotifyEditorObservers(NotificationForEditorObservers aNotification)
 {
+  // Copy the observers since EditAction()s can modify mEditorObservers.
+  nsTArray<mozilla::dom::OwningNonNull<nsIEditorObserver>> observers(mEditorObservers);
   switch (aNotification) {
     case eNotifyEditorObserversOfEnd:
       mIsInEditAction = false;
-      for (auto& observer : mEditorObservers) {
+      for (auto& observer : observers) {
         observer->EditAction();
       }
 
       if (!mDispatchInputEvent) {
         return;
       }
 
       FireInputEvent();
       break;
     case eNotifyEditorObserversOfBefore:
       mIsInEditAction = true;
-      for (auto& observer : mEditorObservers) {
+      for (auto& observer : observers) {
         observer->BeforeEditAction();
       }
       break;
     case eNotifyEditorObserversOfCancel:
       mIsInEditAction = false;
-      for (auto& observer : mEditorObservers) {
+      for (auto& observer : observers) {
         observer->CancelEditAction();
       }
       break;
     default:
       MOZ_CRASH("Handle all notifications here");
       break;
   }
 }