diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2017-01-24 07:06:51 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-24 07:06:51 -0800 |
commit | c3f0c9054feb97f4b3c106393930887d9841df1f (patch) | |
tree | 89c45e07c6d0bef4707c5c31b14ecbb46e8204dd /components/script/dom | |
parent | 2ff42462154025b1aed97a825e3a171eaa156d9b (diff) | |
parent | 068f9608dc3a2b1ac260df6c600aa470f807b675 (diff) | |
download | servo-c3f0c9054feb97f4b3c106393930887d9841df1f.tar.gz servo-c3f0c9054feb97f4b3c106393930887d9841df1f.zip |
Auto merge of #15145 - SwagColoredKitteh:issue-15101, r=emilio
Prevent crashing when a link tag has two or more in-flight requests (fix for issue #15101)
<!-- Please describe your changes on the following line: -->
The `HTMLLinkElement::set_stylesheet` function now checks whether there already is a stylesheet, and if there is, calls `Document::invalidate_stylesheets` after modifying `self.stylesheet`.
This PR also includes a minimal WPT that causes the panic.
This is fundamentally a timing issue, so while this fix prevents the crash, it does not fix the underlying issue. Making a <link> element send a second request before the first can finish and then getting the two stylesheet responses out-of-order will apply the wrong stylesheet, as demonstrated with https://gist.github.com/SwagColoredKitteh/2c24c7fac635445042eda4a30e10420e.
r? @emilio
---
<!-- 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 #15101 (github issue number if applicable).
<!-- Either: -->
- [X] There are tests for these changes OR
- [ ] 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/15145)
<!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom')
-rw-r--r-- | components/script/dom/htmllinkelement.rs | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/components/script/dom/htmllinkelement.rs b/components/script/dom/htmllinkelement.rs index 7b26fb8bbee..fd41329a9a9 100644 --- a/components/script/dom/htmllinkelement.rs +++ b/components/script/dom/htmllinkelement.rs @@ -37,6 +37,15 @@ use stylesheet_loader::{StylesheetLoader, StylesheetContextSource, StylesheetOwn unsafe_no_jsmanaged_fields!(Stylesheet); +#[derive(JSTraceable, PartialEq, Clone, Copy, HeapSizeOf)] +pub struct RequestGenerationId(u32); + +impl RequestGenerationId { + fn increment(self) -> RequestGenerationId { + RequestGenerationId(self.0 + 1) + } +} + #[dom_struct] pub struct HTMLLinkElement { htmlelement: HTMLElement, @@ -52,6 +61,8 @@ pub struct HTMLLinkElement { pending_loads: Cell<u32>, /// Whether any of the loads have failed. any_failed_load: Cell<bool>, + /// A monotonically increasing counter that keeps track of which stylesheet to apply. + request_generation_id: Cell<RequestGenerationId>, } impl HTMLLinkElement { @@ -65,6 +76,7 @@ impl HTMLLinkElement { cssom_stylesheet: MutNullableJS::new(None), pending_loads: Cell::new(0), any_failed_load: Cell::new(false), + request_generation_id: Cell::new(RequestGenerationId(0)), } } @@ -78,12 +90,15 @@ impl HTMLLinkElement { HTMLLinkElementBinding::Wrap) } + pub fn get_request_generation_id(&self) -> RequestGenerationId { + self.request_generation_id.get() + } + pub fn set_stylesheet(&self, s: Arc<Stylesheet>) { - assert!(self.stylesheet.borrow().is_none()); + assert!(self.stylesheet.borrow().is_none()); // Useful for catching timing issues. *self.stylesheet.borrow_mut() = Some(s); } - pub fn get_stylesheet(&self) -> Option<Arc<Stylesheet>> { self.stylesheet.borrow().clone() } @@ -260,6 +275,8 @@ impl HTMLLinkElement { None => "", }; + self.request_generation_id.set(self.request_generation_id.get().increment()); + // TODO: #8085 - Don't load external stylesheets if the node's mq // doesn't match. let loader = StylesheetLoader::for_element(self.upcast()); |