Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement MutationObserver.disconnect() #20740

Merged
merged 1 commit into from May 19, 2018
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -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();
}
}
@@ -392,6 +392,13 @@ impl Node {
self.mutation_observers.borrow_mut()
}

/// Removes the mutation observer for a given node.
pub fn remove_mutation_observer(&self, observer: &MutationObserver) {
self.mutation_observers.borrow_mut().retain(|reg_obs| {
&*reg_obs.observer != observer
})
}

/// Dumps the subtree rooted at this node, for debugging.
pub fn dump(&self) {
self.dump_indent(0);
@@ -11,7 +11,7 @@
interface MutationObserver {
[Throws]
void observe(Node target, optional MutationObserverInit options);
//void disconnect();
void disconnect();
sequence<MutationRecord> takeRecords();
};

@@ -1,6 +1,5 @@
[Element-classlist.html]
type: testharness
expected: TIMEOUT
[classList.remove("a") with attribute value null (HTML node)]
expected: FAIL

This file was deleted.

@@ -1,7 +1,5 @@
[MutationObserver-document.html]
type: testharness
[setup test]
expected: FAIL

[parser insertion mutations]
expected: FAIL

This file was deleted.

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.