use microtasks to await a stable state

This commit is contained in:
Gregory Terzian 2017-05-15 07:19:58 +08:00
parent 5da0aa9f11
commit a8390aea24
12 changed files with 47 additions and 97 deletions

View file

@ -11,6 +11,7 @@ use dom::bindings::cell::DOMRefCell;
use dom::bindings::codegen::Bindings::PromiseBinding::PromiseJobCallback;
use dom::bindings::js::Root;
use dom::globalscope::GlobalScope;
use dom::htmlmediaelement::MediaElementMicrotask;
use dom::mutationobserver::MutationObserver;
use msg::constellation_msg::PipelineId;
use std::cell::Cell;
@ -29,9 +30,14 @@ pub struct MicrotaskQueue {
#[derive(JSTraceable, HeapSizeOf)]
pub enum Microtask {
Promise(EnqueuedPromiseCallback),
MediaElement(MediaElementMicrotask),
NotifyMutationObservers,
}
pub trait MicrotaskRunnable {
fn handler(&self) {}
}
/// A promise callback scheduled to run during the next microtask checkpoint (#4283).
#[derive(JSTraceable, HeapSizeOf)]
pub struct EnqueuedPromiseCallback {
@ -72,6 +78,9 @@ impl MicrotaskQueue {
if let Some(target) = target_provider(job.pipeline) {
let _ = job.callback.Call_(&*target, ExceptionHandling::Report);
}
},
Microtask::MediaElement(ref task) => {
task.handler();
}
Microtask::NotifyMutationObservers => {
MutationObserver::notify_mutation_observers();