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
Mutation observer API #16190
Mutation observer API #16190
Changes from 1 commit
73f2c6e
bee1340
a5af9a2
4ec5d92
16c09d4
e162f8a
b0af820
8e6d4e9
4797cc3
dd9ea19
4db8c26
1a7e2d4
ef51869
2d10eb7
3dd78ed
0160982
eefb95b
2cce8c5
7115abd
2821def
a82e79d
3bd4438
c6739ef
File filter...
Jump to…
changes as per review comments
- Loading branch information
| @@ -4,11 +4,12 @@ | ||
|
|
||
| use core::ptr::null; | ||
| use dom; | ||
| use dom::bindings::codegen::Bindings::MutationObserverBinding; | ||
| use dom::bindings::codegen::Bindings::MutationObserverBinding::MutationCallback; | ||
| use dom::bindings::codegen::Bindings::MutationObserverBinding::MutationObserverInit; | ||
| use dom::bindings::error::Fallible; | ||
| use dom::bindings::js::Root; | ||
| use dom::bindings::reflector::Reflector; | ||
| use dom::bindings::reflector::{Reflector, reflect_dom_object}; | ||
| use dom::bindings::trace::JSTraceable; | ||
| use dom::mutationrecord::MutationRecord; | ||
| use dom::node::Node; | ||
| @@ -21,11 +22,17 @@ use std::rc::Rc; | ||
| #[dom_struct] | ||
| pub struct MutationObserver { | ||
| reflector_: Reflector, | ||
| callback: MutationCallback, | ||
| #[ignore_heap_size_of = "can't measure Rc values"] | ||
| callback: Rc<MutationCallback>, | ||
| } | ||
|
|
||
| impl MutationObserver { | ||
| fn new(global: &Window, callback: Rc<MutationCallback>) -> MutationObserver { | ||
| pub fn new(global: &Window, callback: Rc<MutationCallback>) -> Root<MutationObserver> { | ||
| let boxed_observer = box MutationObserver::new_inherited(callback); | ||
| reflect_dom_object(boxed_observer, global, MutationObserverBinding::Wrap) | ||
| } | ||
|
|
||
| pub fn new_inherited(callback: Rc<MutationCallback>) -> MutationObserver { | ||
|
||
| MutationObserver { | ||
| reflector_: Reflector::new(), | ||
| callback: callback, | ||
| @@ -34,7 +41,7 @@ impl MutationObserver { | ||
|
|
||
| pub fn Constructor(global: &Window, callback: Rc<MutationCallback>) -> Fallible<Root<MutationObserver>> { | ||
| let observer = MutationObserver::new(global, callback); | ||
jdm
Member
|
||
| ScriptThread::add_mutation_observer(Root::from_ref(&*observer)) | ||
| ScriptThread::add_mutation_observer(observer.deref()); | ||
| return Ok(observer); | ||
| } | ||
jdm
Member
|
||
|
|
||
| } | ||
| @@ -18,6 +18,7 @@ | ||
| //! loop. | ||
|
|
||
| use bluetooth_traits::BluetoothRequest; | ||
| use core::borrow::BorrowMut; | ||
srivassumit
Author
Contributor
|
||
| use devtools; | ||
| use devtools_traits::{DevtoolScriptControlMsg, DevtoolsPageInfo}; | ||
| use devtools_traits::{ScriptToDevtoolsControlMsg, WorkerId}; | ||
| @@ -575,10 +576,11 @@ impl ScriptThreadFactory for ScriptThread { | ||
|
|
||
| impl ScriptThread { | ||
| pub fn add_mutation_observer(observer: &MutationObserver) { | ||
| SCRIPT_THREAD_ROOT.with(|root| { | ||
| SCRIPT_THREAD_ROOT.with(|root| { | ||
|
||
| let script_thread = unsafe { &*root.get().unwrap() }; | ||
| script_thread.mutation_observers | ||
| .push(JS::from_ref(&*observer)); | ||
| .borrow_mut() | ||
| .push(JS::from_ref(observer)); | ||
| }) | ||
| } | ||
|
|
||
Let's not make these methods public. Only the constructor should be used here.