servo: Merge #15495 - Calling matchMedia during a MQL change event will not panic (from prampey:mql-borrow-error); r=jdm
authorPrudhvi Rampey <gergteg777@gmail.com>
Sun, 19 Feb 2017 04:10:04 -0800
changeset 372761 f352e364b8d44ef7e57c14fbac541e5522f7101b
parent 372760 5269f2c65663bb16ae9bcd9a004eb3521d0a9443
child 372762 39d52345961356cedc24206585f1472507098065
push id10863
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 23:02:23 +0000
treeherdermozilla-aurora@0931190cd725 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdm
milestone54.0a1
servo: Merge #15495 - Calling matchMedia during a MQL change event will not panic (from prampey:mql-borrow-error); r=jdm <!-- Please describe your changes on the following line: --> Calling matchMedia now leads to a new copy of MQL objects to prevent errors when borrowing references from MQL during an MQL change event. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #14967 (github issue number if applicable). <!-- Either: --> - [X] There are tests for these changes OR - [x] These changes do not require tests because _____ <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: debdebe8dea69c41472002bb49dbb29cc30a85f2
servo/components/script/dom/mediaquerylist.rs
--- a/servo/components/script/dom/mediaquerylist.rs
+++ b/servo/components/script/dom/mediaquerylist.rs
@@ -133,27 +133,33 @@ impl WeakMediaQueryListVec {
 
     pub fn push(&self, mql: &MediaQueryList) {
         self.cell.borrow_mut().push(WeakRef::new(mql));
     }
 
     /// Evaluate media query lists and report changes
     /// https://drafts.csswg.org/cssom-view/#evaluate-media-queries-and-report-changes
     pub fn evaluate_and_report_changes(&self) {
+        rooted_vec!(let mut mql_list);
         self.cell.borrow_mut().update(|mql| {
             let mql = mql.root().unwrap();
             if let MediaQueryListMatchState::Changed(_) = mql.evaluate_changes() {
-                let event = MediaQueryListEvent::new(&mql.global(),
-                                                     atom!("change"),
-                                                     false, false,
-                                                     mql.Media(),
-                                                     mql.Matches());
-                event.upcast::<Event>().fire(mql.upcast::<EventTarget>());
+                // Recording list of changed Media Queries
+                mql_list.push(JS::from_ref(&*mql));
             }
         });
+        // Sending change events for all changed Media Queries
+        for mql in mql_list.iter() {
+            let event = MediaQueryListEvent::new(&mql.global(),
+                                                 atom!("change"),
+                                                 false, false,
+                                                 mql.Media(),
+                                                 mql.Matches());
+            event.upcast::<Event>().fire(mql.upcast::<EventTarget>());
+        }
     }
 }
 
 #[allow(unsafe_code)]
 unsafe impl JSTraceable for WeakMediaQueryListVec {
     unsafe fn trace(&self, _: *mut JSTracer) {
         self.cell.borrow_mut().retain_alive()
     }