Auto merge of #15495 - prampey:mql-borrow-error, r=jdm

Calling matchMedia during a MQL change event will not panic

<!-- 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. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/15495)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-02-19 04:10:04 -08:00 committed by GitHub
commit debdebe8de
3 changed files with 51 additions and 6 deletions

View file

@ -138,17 +138,23 @@ impl WeakMediaQueryListVec {
/// 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>());
}
}
}