aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2017-02-19 04:10:04 -0800
committerGitHub <noreply@github.com>2017-02-19 04:10:04 -0800
commitdebdebe8dea69c41472002bb49dbb29cc30a85f2 (patch)
tree94725c5a619db0fb487d7664fd6ae1686a3ffb59
parent5f813233c9e2b51497c1e5fe4bc10ffd641a3b5e (diff)
parent0c213337774575605a8d171bc1a2d7cc05747aac (diff)
downloadservo-debdebe8dea69c41472002bb49dbb29cc30a85f2.tar.gz
servo-debdebe8dea69c41472002bb49dbb29cc30a85f2.zip
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 -->
-rw-r--r--components/script/dom/mediaquerylist.rs18
-rw-r--r--tests/wpt/mozilla/meta/MANIFEST.json10
-rw-r--r--tests/wpt/mozilla/tests/mozilla/mql_borrow.html29
3 files changed, 51 insertions, 6 deletions
diff --git a/components/script/dom/mediaquerylist.rs b/components/script/dom/mediaquerylist.rs
index c6e569b5e42..2545b911c7a 100644
--- a/components/script/dom/mediaquerylist.rs
+++ b/components/script/dom/mediaquerylist.rs
@@ -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>());
+ }
}
}
diff --git a/tests/wpt/mozilla/meta/MANIFEST.json b/tests/wpt/mozilla/meta/MANIFEST.json
index 0862b709f6b..c4cc18dcf7c 100644
--- a/tests/wpt/mozilla/meta/MANIFEST.json
+++ b/tests/wpt/mozilla/meta/MANIFEST.json
@@ -13269,6 +13269,12 @@
{}
]
],
+ "mozilla/mql_borrow.html": [
+ [
+ "/_mozilla/mozilla/mql_borrow.html",
+ {}
+ ]
+ ],
"mozilla/navigator.html": [
[
"/_mozilla/mozilla/navigator.html",
@@ -25854,6 +25860,10 @@
"5513229f79ab37de67eb4d60ea9dd23cd31d133f",
"support"
],
+ "mozilla/mql_borrow.html": [
+ "f8f9adebe09f9473a52e5ec4f075540b10b32d7e",
+ "testharness"
+ ],
"mozilla/navigator.html": [
"939f453fecfb28a36cb93057382b56439b00b136",
"testharness"
diff --git a/tests/wpt/mozilla/tests/mozilla/mql_borrow.html b/tests/wpt/mozilla/tests/mozilla/mql_borrow.html
new file mode 100644
index 00000000000..17ee0dc48a3
--- /dev/null
+++ b/tests/wpt/mozilla/tests/mozilla/mql_borrow.html
@@ -0,0 +1,29 @@
+<html>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+<body>
+ <iframe id="frame" height="600" width="600">
+</iframe>
+</body>
+<script>
+ // Test to make sure matchMedia can be suitably used inside MediaQueryList listeners without any error in borrowing
+ // mql references
+ var test = async_test("Using matchMedia inside of a MediaQueryList callback does not panic");
+ var frame=document.getElementById("frame");
+ var win=frame.contentWindow;
+ var match1 = win.matchMedia("(min-width: 400px)");
+ match1.addListener(test.step_func(function() {
+ var match2 = win.matchMedia("(orientation: landscape)");
+ assert_not_equals(match2, undefined);
+ match2.addListener(test.step_func_done(function() {
+ var match3 = win.matchMedia("(orientation: portrait)");
+ assert_not_equals(match3, undefined);
+ }));
+ // Resizing frame to trigger match2 listener
+ frame.height=600;
+ frame.width=400;
+ }));
+
+ </script>
+
+</html>