From 6e3be6d894e311f2f2331d9437b4956fb5fd4752 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Tue, 4 Oct 2016 16:00:40 +0200 Subject: [PATCH] Introduce GlobalScope::flush_promise_jobs --- components/script/dom/bindings/global.rs | 9 --------- components/script/dom/globalscope.rs | 14 +++++++++++++- components/script/script_runtime.rs | 2 +- components/script/script_thread.rs | 4 ++-- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/components/script/dom/bindings/global.rs b/components/script/dom/bindings/global.rs index 2d984db4598..92b79e352e2 100644 --- a/components/script/dom/bindings/global.rs +++ b/components/script/dom/bindings/global.rs @@ -92,15 +92,6 @@ impl<'a> GlobalRef<'a> { GlobalRef::Worker(ref worker) => worker.enqueue_promise_job(job), } } - - /// Start the process of executing the pending promise callbacks. They will be invoked - /// in FIFO order, synchronously, at some point in the future. - pub fn flush_promise_jobs(&self) { - match *self { - GlobalRef::Window(_) => ScriptThread::flush_promise_jobs(*self), - GlobalRef::Worker(ref worker) => worker.flush_promise_jobs(), - } - } } impl<'a> Reflectable for GlobalRef<'a> { diff --git a/components/script/dom/globalscope.rs b/components/script/dom/globalscope.rs index 159b934f8ae..f9eaead2189 100644 --- a/components/script/dom/globalscope.rs +++ b/components/script/dom/globalscope.rs @@ -27,7 +27,7 @@ use msg::constellation_msg::PipelineId; use net_traits::{CoreResourceThread, ResourceThreads, IpcSend}; use profile_traits::{mem, time}; use script_runtime::{ScriptChan, maybe_take_panic_result}; -use script_thread::{MainThreadScriptChan, RunnableWrapper}; +use script_thread::{MainThreadScriptChan, RunnableWrapper, ScriptThread}; use script_traits::{MsDuration, ScriptMsg as ConstellationMsg, TimerEvent}; use script_traits::{TimerEventId, TimerEventRequest, TimerSource}; use std::cell::Cell; @@ -408,6 +408,18 @@ impl GlobalScope { } unreachable!(); } + + /// Start the process of executing the pending promise callbacks. They will be invoked + /// in FIFO order, synchronously, at some point in the future. + pub fn flush_promise_jobs(&self) { + if self.is::() { + return ScriptThread::flush_promise_jobs(self); + } + if let Some(worker) = self.downcast::() { + return worker.flush_promise_jobs(); + } + unreachable!(); + } } fn timestamp_in_ms(time: Timespec) -> u64 { diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index ab7cb607985..df9341a3777 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -142,7 +142,7 @@ impl PromiseJobQueue { self.promise_job_queue.borrow_mut().push(job); if !self.pending_promise_job_runnable.get() { self.pending_promise_job_runnable.set(true); - global.flush_promise_jobs(); + global.as_global_scope().flush_promise_jobs(); } } diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index b495cbadd06..b0814187f85 100644 --- a/components/script/script_thread.rs +++ b/components/script/script_thread.rs @@ -2180,11 +2180,11 @@ impl ScriptThread { }); } - pub fn flush_promise_jobs(global: GlobalRef) { + pub fn flush_promise_jobs(global: &GlobalScope) { SCRIPT_THREAD_ROOT.with(|root| { let script_thread = unsafe { &*root.get().unwrap() }; let _ = script_thread.dom_manipulation_task_source.queue( - box FlushPromiseJobs, global.as_global_scope()); + box FlushPromiseJobs, global); }) }