Mutation Observer API

This commit is contained in:
Sumit 2017-05-14 01:44:14 -04:00 committed by Josh Matthews
parent fa251ec96b
commit 3ca89204ff
15 changed files with 432 additions and 180 deletions

View file

@ -479,6 +479,9 @@ pub struct ScriptThread {
microtask_queue: MicrotaskQueue,
/// Microtask Queue for adding support for mutation observer microtasks
mutation_observer_compound_microtask_queued: Cell<bool>,
/// The unit of related similar-origin browsing contexts' list of MutationObserver objects
mutation_observers: DOMRefCell<Vec<JS<MutationObserver>>>,
@ -587,6 +590,20 @@ impl ScriptThread {
})
}
pub fn set_mutation_observer_compound_microtask_queued(value: bool) {
SCRIPT_THREAD_ROOT.with(|root| {
let script_thread = unsafe { &*root.get().unwrap() };
script_thread.mutation_observer_compound_microtask_queued.set(value);
})
}
pub fn is_mutation_observer_compound_microtask_queued() -> bool {
SCRIPT_THREAD_ROOT.with(|root| {
let script_thread = unsafe { &*root.get().unwrap() };
return script_thread.mutation_observer_compound_microtask_queued.get();
})
}
pub fn add_mutation_observer(observer: &MutationObserver) {
SCRIPT_THREAD_ROOT.with(|root| {
let script_thread = unsafe { &*root.get().unwrap() };
@ -596,6 +613,13 @@ impl ScriptThread {
})
}
pub fn get_mutation_observers() -> Vec<Root<MutationObserver>> {
SCRIPT_THREAD_ROOT.with(|root| {
let script_thread = unsafe { &*root.get().unwrap() };
script_thread.mutation_observers.borrow().iter().map(|o| Root::from_ref(&**o)).collect()
})
}
pub fn mark_document_with_no_blocked_loads(doc: &Document) {
SCRIPT_THREAD_ROOT.with(|root| {
let script_thread = unsafe { &*root.get().unwrap() };
@ -748,6 +772,8 @@ impl ScriptThread {
microtask_queue: MicrotaskQueue::default(),
mutation_observer_compound_microtask_queued: Default::default(),
mutation_observers: Default::default(),
layout_to_constellation_chan: state.layout_to_constellation_chan,