mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Implement MutationObserver.disconnect()
This commit is contained in:
parent
2c9ef9e558
commit
5bfa819038
7 changed files with 25 additions and 15 deletions
|
@ -27,6 +27,7 @@ pub struct MutationObserver {
|
|||
#[ignore_malloc_size_of = "can't measure Rc values"]
|
||||
callback: Rc<MutationCallback>,
|
||||
record_queue: DomRefCell<Vec<DomRoot<MutationRecord>>>,
|
||||
node_list: DomRefCell<Vec<DomRoot<Node>>>,
|
||||
}
|
||||
|
||||
pub enum Mutation<'a> {
|
||||
|
@ -38,7 +39,7 @@ pub enum Mutation<'a> {
|
|||
|
||||
#[derive(JSTraceable, MallocSizeOf)]
|
||||
pub struct RegisteredObserver {
|
||||
observer: DomRoot<MutationObserver>,
|
||||
pub observer: DomRoot<MutationObserver>,
|
||||
options: ObserverOptions,
|
||||
}
|
||||
|
||||
|
@ -64,6 +65,7 @@ impl MutationObserver {
|
|||
reflector_: Reflector::new(),
|
||||
callback: callback,
|
||||
record_queue: DomRefCell::new(vec![]),
|
||||
node_list: DomRefCell::new(vec![]),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -286,6 +288,8 @@ impl MutationObserverMethods for MutationObserver {
|
|||
child_list
|
||||
},
|
||||
});
|
||||
|
||||
self.node_list.borrow_mut().push(DomRoot::from_ref(target));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -297,4 +301,16 @@ impl MutationObserverMethods for MutationObserver {
|
|||
self.record_queue.borrow_mut().clear();
|
||||
records
|
||||
}
|
||||
|
||||
/// https://dom.spec.whatwg.org/#dom-mutationobserver-disconnect
|
||||
fn Disconnect(&self) {
|
||||
// Step 1
|
||||
let mut nodes = self.node_list.borrow_mut();
|
||||
for node in nodes.drain(..) {
|
||||
node.remove_mutation_observer(self);
|
||||
}
|
||||
|
||||
// Step 2
|
||||
self.record_queue.borrow_mut().clear();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue