aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom
diff options
context:
space:
mode:
Diffstat (limited to 'components/script/dom')
-rw-r--r--components/script/dom/document.rs15
-rw-r--r--components/script/dom/window.rs2
2 files changed, 9 insertions, 8 deletions
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs
index ad0ae92eace..f05ed60739f 100644
--- a/components/script/dom/document.rs
+++ b/components/script/dom/document.rs
@@ -157,7 +157,7 @@ pub struct Document {
anchors: MutNullableHeap<JS<HTMLCollection>>,
applets: MutNullableHeap<JS<HTMLCollection>>,
/// List of stylesheets associated with nodes in this document. |None| if the list needs to be refreshed.
- stylesheets: DOMRefCell<Option<Vec<Arc<Stylesheet>>>>,
+ stylesheets: DOMRefCell<Option<Vec<(JS<Node>, Arc<Stylesheet>)>>>,
/// Whether the list of stylesheets has changed since the last reflow was triggered.
stylesheets_changed_since_reflow: Cell<bool>,
ready_state: Cell<DocumentReadyState>,
@@ -1635,11 +1635,11 @@ impl Document {
}
/// Returns the list of stylesheets associated with nodes in the document.
- pub fn stylesheets(&self) -> Ref<Vec<Arc<Stylesheet>>> {
+ pub fn stylesheets(&self) -> Vec<Arc<Stylesheet>> {
{
let mut stylesheets = self.stylesheets.borrow_mut();
if stylesheets.is_none() {
- let new_stylesheets: Vec<Arc<Stylesheet>> = self.upcast::<Node>()
+ *stylesheets = Some(self.upcast::<Node>()
.traverse_preorder()
.filter_map(|node| {
if let Some(node) = node.downcast::<HTMLStyleElement>() {
@@ -1650,13 +1650,14 @@ impl Document {
node.get_stylesheet()
} else {
None
- }
+ }.map(|stylesheet| (JS::from_rooted(&node), stylesheet))
})
- .collect();
- *stylesheets = Some(new_stylesheets);
+ .collect());
};
}
- Ref::map(self.stylesheets.borrow(), |t| t.as_ref().unwrap())
+ self.stylesheets.borrow().as_ref().unwrap().iter()
+ .map(|&(_, ref stylesheet)| stylesheet.clone())
+ .collect()
}
/// https://html.spec.whatwg.org/multipage/#appropriate-template-contents-owner-document
diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs
index 1e79620fb29..a8b55cf8c06 100644
--- a/components/script/dom/window.rs
+++ b/components/script/dom/window.rs
@@ -996,7 +996,7 @@ impl Window {
page_clip_rect: self.page_clip_rect.get(),
},
document: self.Document().upcast::<Node>().to_trusted_node_address(),
- document_stylesheets: document.stylesheets().clone(),
+ document_stylesheets: document.stylesheets(),
stylesheets_changed: stylesheets_changed,
window_size: window_size,
script_join_chan: join_chan,