From 7481ce177f4b124f869d3cf8b8f1c2fbf8b84429 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Wed, 13 Sep 2017 10:34:07 +0200 Subject: [PATCH] Store a Rc directly on Window --- components/script/dom/globalscope.rs | 8 ++++---- components/script/dom/window.rs | 17 +++++++++++++++++ components/script/script_thread.rs | 1 + 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/components/script/dom/globalscope.rs b/components/script/dom/globalscope.rs index 4cd2ac2b8d1..90f5b7a9596 100644 --- a/components/script/dom/globalscope.rs +++ b/components/script/dom/globalscope.rs @@ -479,8 +479,8 @@ impl GlobalScope { /// Perform a microtask checkpoint. pub fn perform_a_microtask_checkpoint(&self) { - if self.is::() { - return ScriptThread::invoke_perform_a_microtask_checkpoint(); + if let Some(window) = self.downcast::() { + return window.perform_a_microtask_checkpoint(); } if let Some(worker) = self.downcast::() { 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::() { - return ScriptThread::enqueue_microtask(job); + if let Some(window) = self.downcast::() { + return window.enqueue_microtask(job); } if let Some(worker) = self.downcast::() { return worker.enqueue_microtask(job); diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index b606192cb54..56022e66f01 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -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, /// https://drafts.css-houdini.org/css-paint-api-1/#paint-worklet paint_worklet: MutNullableJS, + + /// https://html.spec.whatwg.org/multipage/#microtask-queue + #[ignore_heap_size_of = "Rc is hard"] + microtask_queue: Rc, } 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::())) + }); + } } impl Window { @@ -1818,6 +1833,7 @@ impl Window { navigation_start_precise: f64, webgl_chan: WebGLChan, webvr_chan: Option>, + microtask_queue: Rc, ) -> Root { let layout_rpc: Box = { 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 { diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index 597d1dce11c..b2359c3ea94 100644 --- a/components/script/script_thread.rs +++ b/components/script/script_thread.rs @@ -2068,6 +2068,7 @@ impl ScriptThread { incomplete.navigation_start_precise, self.webgl_chan.channel(), self.webvr_chan.clone(), + self.microtask_queue.clone(), ); // Initialize the browsing context for the window.