diff --git a/components/script/dom/bindings/trace.rs b/components/script/dom/bindings/trace.rs index 9c61daaaabb..50307275cd7 100644 --- a/components/script/dom/bindings/trace.rs +++ b/components/script/dom/bindings/trace.rs @@ -668,11 +668,25 @@ pub struct RootedVec<'a, T: 'static + JSTraceable> { root: &'a mut RootableVec, } -impl<'a, T: 'static + JSTraceable + DomObject> RootedVec<'a, JS> { +impl<'a, T: 'static + JSTraceable> RootedVec<'a, T> { /// Create a vector of items of type T that is rooted for /// the lifetime of this struct - pub fn new>>(root: &'a mut RootableVec>, iter: I) - -> RootedVec<'a, JS> { + pub fn new(root: &'a mut RootableVec) -> Self { + unsafe { + RootedTraceableSet::add(root); + } + RootedVec { + root: root, + } + } +} + +impl<'a, T: 'static + JSTraceable + DomObject> RootedVec<'a, JS> { + /// Create a vector of items of type JS that is rooted for + /// the lifetime of this struct + pub fn from_iter(root: &'a mut RootableVec>, iter: I) -> Self + where I: Iterator> + { unsafe { RootedTraceableSet::add(root); } diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index 17ef9df0ed6..8957fcf5ab9 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -1521,8 +1521,11 @@ impl Document { /// https://html.spec.whatwg.org/multipage/#run-the-animation-frame-callbacks pub fn run_the_animation_frame_callbacks(&self) { - let mut animation_frame_list = - mem::replace(&mut *self.animation_frame_list.borrow_mut(), vec![]); + rooted_vec!(let mut animation_frame_list); + mem::swap( + &mut *animation_frame_list, + &mut *self.animation_frame_list.borrow_mut()); + self.running_animation_callbacks.set(true); let timing = self.window.Performance().Now(); @@ -1538,7 +1541,7 @@ impl Document { // message quickly followed by an AnimationCallbacksPresent message. if self.animation_frame_list.borrow().is_empty() { mem::swap(&mut *self.animation_frame_list.borrow_mut(), - &mut animation_frame_list); + &mut *animation_frame_list); let global_scope = self.window.upcast::(); let event = ConstellationMsg::ChangeRunningAnimationsState(global_scope.pipeline_id(), AnimationState::NoAnimationCallbacksPresent); diff --git a/components/script/dom/macros.rs b/components/script/dom/macros.rs index 99b06bae39d..f2174bdd552 100644 --- a/components/script/dom/macros.rs +++ b/components/script/dom/macros.rs @@ -537,14 +537,15 @@ macro_rules! document_and_element_event_handlers( #[macro_export] macro_rules! rooted_vec { (let mut $name:ident) => { - rooted_vec!(let mut $name <- ::std::iter::empty()) + let mut root = $crate::dom::bindings::trace::RootableVec::new_unrooted(); + let mut $name = $crate::dom::bindings::trace::RootedVec::new(&mut root); }; (let $name:ident <- $iter:expr) => { - let mut __root = $crate::dom::bindings::trace::RootableVec::new_unrooted(); - let $name = $crate::dom::bindings::trace::RootedVec::new(&mut __root, $iter); + let mut root = $crate::dom::bindings::trace::RootableVec::new_unrooted(); + let $name = $crate::dom::bindings::trace::RootedVec::from_iter(&mut root, $iter); }; (let mut $name:ident <- $iter:expr) => { - let mut __root = $crate::dom::bindings::trace::RootableVec::new_unrooted(); - let mut $name = $crate::dom::bindings::trace::RootedVec::new(&mut __root, $iter); + let mut root = $crate::dom::bindings::trace::RootableVec::new_unrooted(); + let mut $name = $crate::dom::bindings::trace::RootedVec::from_iter(&mut root, $iter); } }