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>, applets: MutNullableHeap>, /// List of stylesheets associated with nodes in this document. |None| if the list needs to be refreshed. - stylesheets: DOMRefCell>>>, + stylesheets: DOMRefCell, Arc)>>>, /// Whether the list of stylesheets has changed since the last reflow was triggered. stylesheets_changed_since_reflow: Cell, ready_state: Cell, @@ -1635,11 +1635,11 @@ impl Document { } /// Returns the list of stylesheets associated with nodes in the document. - pub fn stylesheets(&self) -> Ref>> { + pub fn stylesheets(&self) -> Vec> { { let mut stylesheets = self.stylesheets.borrow_mut(); if stylesheets.is_none() { - let new_stylesheets: Vec> = self.upcast::() + *stylesheets = Some(self.upcast::() .traverse_preorder() .filter_map(|node| { if let Some(node) = node.downcast::() { @@ -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::().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,