Bug 1376931 Part 4: Before MediaQueryList iteration for event listeners, copy the array before sending any events. r=heycam
authorBrad Werth <bwerth@mozilla.com>
Tue, 19 Sep 2017 17:05:16 -0700
changeset 384584 914b4cd64a4a99f6dc94728020bb42246fa68445
parent 384583 06c8706c06c9b9cafd87e3f445baee8ef2718a76
child 384585 abdc7d29ddf851e80f2e594ccbed3770fcca9aad
push id32631
push userarchaeopteryx@coole-files.de
push dateThu, 05 Oct 2017 08:51:33 +0000
treeherdermozilla-central@66042a706980 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam
bugs1376931
milestone58.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 1376931 Part 4: Before MediaQueryList iteration for event listeners, copy the array before sending any events. r=heycam MozReview-Commit-ID: 4eDs6viuxvT
layout/base/nsPresContext.cpp
--- a/layout/base/nsPresContext.cpp
+++ b/layout/base/nsPresContext.cpp
@@ -2112,17 +2112,26 @@ nsPresContext::MediaFeatureValuesChanged
   // flushes.  (We're already running off an event.)
   //
   // Note that we do this after the new style from media queries in
   // style sheets has been computed.
 
   if (!mDocument->MediaQueryLists().isEmpty()) {
     // We build a list of all the notifications we're going to send
     // before we send any of them.
-    for (auto mql : mDocument->MediaQueryLists()) {
+
+    // Copy pointers to all the lists into a new array, in case one of our
+    // notifications modifies the list.
+    nsTArray<RefPtr<mozilla::dom::MediaQueryList>> localMediaQueryLists;
+    for (auto* mql : mDocument->MediaQueryLists()) {
+      localMediaQueryLists.AppendElement(mql);
+    }
+
+    // Now iterate our local array of the lists.
+    for (auto mql : localMediaQueryLists) {
       nsAutoMicroTask mt;
       mql->MaybeNotify();
     }
   }
 }
 
 void
 nsPresContext::PostMediaFeatureValuesChangedEvent()