Store a Rc<MicrotaskQueue> directly on Window

This commit is contained in:
Anthony Ramine 2017-09-13 10:34:07 +02:00
parent 7f9f95b7ce
commit 7481ce177f
3 changed files with 22 additions and 4 deletions

View file

@ -479,8 +479,8 @@ impl GlobalScope {
/// Perform a microtask checkpoint.
pub fn perform_a_microtask_checkpoint(&self) {
if self.is::<Window>() {
return ScriptThread::invoke_perform_a_microtask_checkpoint();
if let Some(window) = self.downcast::<Window>() {
return window.perform_a_microtask_checkpoint();
}
if let Some(worker) = self.downcast::<WorkerGlobalScope>() {
return worker.perform_a_microtask_checkpoint();
@ -493,8 +493,8 @@ impl GlobalScope {
/// Enqueue a microtask for subsequent execution.
pub fn enqueue_microtask(&self, job: Microtask) {
if self.is::<Window>() {
return ScriptThread::enqueue_microtask(job);
if let Some(window) = self.downcast::<Window>() {
return window.enqueue_microtask(job);
}
if let Some(worker) = self.downcast::<WorkerGlobalScope>() {
return worker.enqueue_microtask(job);

View file

@ -59,6 +59,7 @@ use js::jsapi::{JS_GC, JS_GetRuntime};
use js::jsval::UndefinedValue;
use js::rust::Runtime;
use layout_image::fetch_image_for_layout;
use microtask::{Microtask, MicrotaskQueue};
use msg::constellation_msg::{FrameType, PipelineId};
use net_traits::{ResourceThreads, ReferrerPolicy};
use net_traits::image_cache::{ImageCache, ImageResponder, ImageResponse};
@ -287,6 +288,10 @@ pub struct Window {
test_worklet: MutNullableJS<Worklet>,
/// https://drafts.css-houdini.org/css-paint-api-1/#paint-worklet
paint_worklet: MutNullableJS<Worklet>,
/// https://html.spec.whatwg.org/multipage/#microtask-queue
#[ignore_heap_size_of = "Rc<T> is hard"]
microtask_queue: Rc<MicrotaskQueue>,
}
impl Window {
@ -1785,6 +1790,16 @@ impl Window {
.send(msg)
.unwrap();
}
pub fn enqueue_microtask(&self, job: Microtask) {
self.microtask_queue.enqueue(job);
}
pub fn perform_a_microtask_checkpoint(&self) {
self.microtask_queue.checkpoint(|_| {
Some(Root::from_ref(self.upcast::<GlobalScope>()))
});
}
}
impl Window {
@ -1818,6 +1833,7 @@ impl Window {
navigation_start_precise: f64,
webgl_chan: WebGLChan,
webvr_chan: Option<IpcSender<WebVRMsg>>,
microtask_queue: Rc<MicrotaskQueue>,
) -> Root<Self> {
let layout_rpc: Box<LayoutRPC + Send> = {
let (rpc_send, rpc_recv) = channel();
@ -1890,6 +1906,7 @@ impl Window {
unminified_js_dir: Default::default(),
test_worklet: Default::default(),
paint_worklet: Default::default(),
microtask_queue,
};
unsafe {