diff options
author | Anthony Ramine <n.oxyde@gmail.com> | 2017-09-13 10:48:39 +0200 |
---|---|---|
committer | Anthony Ramine <n.oxyde@gmail.com> | 2017-09-13 15:02:45 +0200 |
commit | 24cf15a014d7239b7091edb38bb1f7d062556b5c (patch) | |
tree | 3a94d23f6c8c6ac511a17e06a4117fae4ef8d976 /components/script/dom/globalscope.rs | |
parent | 7481ce177f4b124f869d3cf8b8f1c2fbf8b84429 (diff) | |
download | servo-24cf15a014d7239b7091edb38bb1f7d062556b5c.tar.gz servo-24cf15a014d7239b7091edb38bb1f7d062556b5c.zip |
Store microtask queues in their global (fixes #18467)
Diffstat (limited to 'components/script/dom/globalscope.rs')
-rw-r--r-- | components/script/dom/globalscope.rs | 41 |
1 files changed, 20 insertions, 21 deletions
diff --git a/components/script/dom/globalscope.rs b/components/script/dom/globalscope.rs index 90f5b7a9596..681953defdd 100644 --- a/components/script/dom/globalscope.rs +++ b/components/script/dom/globalscope.rs @@ -33,7 +33,7 @@ use js::jsapi::{JS_GetObjectRuntime, MutableHandleValue}; use js::panic::maybe_resume_unwind; use js::rust::{CompileOptionsWrapper, Runtime, get_object_class}; use libc; -use microtask::Microtask; +use microtask::{Microtask, MicrotaskQueue}; use msg::constellation_msg::PipelineId; use net_traits::{CoreResourceThread, ResourceThreads, IpcSend}; use profile_traits::{mem, time}; @@ -46,6 +46,7 @@ use std::cell::Cell; use std::collections::HashMap; use std::collections::hash_map::Entry; use std::ffi::CString; +use std::rc::Rc; use task_source::file_reading::FileReadingTaskSource; use task_source::networking::NetworkingTaskSource; use task_source::performance_timeline::PerformanceTimelineTaskSource; @@ -99,6 +100,15 @@ pub struct GlobalScope { /// The origin of the globalscope origin: MutableOrigin, + + /// The microtask queue associated with this global. + /// + /// It is refcounted because windows in the same script thread share the + /// same microtask queue. + /// + /// https://html.spec.whatwg.org/multipage/#microtask-queue + #[ignore_heap_size_of = "Rc<T> is hard"] + microtask_queue: Rc<MicrotaskQueue>, } impl GlobalScope { @@ -112,6 +122,7 @@ impl GlobalScope { resource_threads: ResourceThreads, timer_event_chan: IpcSender<TimerEvent>, origin: MutableOrigin, + microtask_queue: Rc<MicrotaskQueue>, ) -> Self { Self { eventtarget: EventTarget::new_inherited(), @@ -129,6 +140,7 @@ impl GlobalScope { resource_threads, timers: OneshotTimers::new(timer_event_chan, scheduler_chan), origin, + microtask_queue, } } @@ -479,30 +491,12 @@ impl GlobalScope { /// Perform a microtask checkpoint. pub fn perform_a_microtask_checkpoint(&self) { - 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(); - } - if let Some(worker) = self.downcast::<WorkletGlobalScope>() { - return worker.perform_a_microtask_checkpoint(); - } - unreachable!(); + self.microtask_queue.checkpoint(|_| Some(Root::from_ref(self))); } /// Enqueue a microtask for subsequent execution. pub fn enqueue_microtask(&self, job: Microtask) { - if let Some(window) = self.downcast::<Window>() { - return window.enqueue_microtask(job); - } - if let Some(worker) = self.downcast::<WorkerGlobalScope>() { - return worker.enqueue_microtask(job); - } - if let Some(worker) = self.downcast::<WorkletGlobalScope>() { - return worker.enqueue_microtask(job); - } - unreachable!(); + self.microtask_queue.enqueue(job); } /// Create a new sender/receiver pair that can be used to implement an on-demand @@ -518,6 +512,11 @@ impl GlobalScope { unreachable!(); } + /// Returns the microtask queue of this global. + pub fn microtask_queue(&self) -> &Rc<MicrotaskQueue> { + &self.microtask_queue + } + /// Process a single event as if it were the next event /// in the thread queue for this global scope. pub fn process_event(&self, msg: CommonScriptMsg) { |