diff options
author | Josh Matthews <josh@joshmatthews.net> | 2016-09-05 10:55:31 -0400 |
---|---|---|
committer | Josh Matthews <josh@joshmatthews.net> | 2016-09-22 16:16:55 -0400 |
commit | 57b3ccd38cbdf53b8e45f68e8ff6c4fd786118dc (patch) | |
tree | f1b89e2699ce8265d9a4eca72948724d462888f6 /components/script/dom/bindings/global.rs | |
parent | ef501603bf8997e29f8d2d538b7755838236d6c8 (diff) | |
download | servo-57b3ccd38cbdf53b8e45f68e8ff6c4fd786118dc.tar.gz servo-57b3ccd38cbdf53b8e45f68e8ff6c4fd786118dc.zip |
Support promises in workers.
Diffstat (limited to 'components/script/dom/bindings/global.rs')
-rw-r--r-- | components/script/dom/bindings/global.rs | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/components/script/dom/bindings/global.rs b/components/script/dom/bindings/global.rs index baec394b7fb..9b4125bdc6a 100644 --- a/components/script/dom/bindings/global.rs +++ b/components/script/dom/bindings/global.rs @@ -25,7 +25,7 @@ use js::jsapi::HandleValue; use msg::constellation_msg::PipelineId; use net_traits::{CoreResourceThread, IpcSend, ResourceThreads}; use profile_traits::{mem, time}; -use script_runtime::{CommonScriptMsg, ScriptChan, ScriptPort}; +use script_runtime::{CommonScriptMsg, ScriptChan, ScriptPort, EnqueuedPromiseCallback}; use script_thread::{MainThreadScriptChan, RunnableWrapper, ScriptThread}; use script_traits::{MsDuration, ScriptMsg as ConstellationMsg, TimerEventRequest}; use task_source::dom_manipulation::DOMManipulationTaskSource; @@ -290,6 +290,23 @@ impl<'a> GlobalRef<'a> { } } + /// Enqueue a promise callback for subsequent execution. + pub fn enqueue_promise_job(&self, job: EnqueuedPromiseCallback) { + match *self { + GlobalRef::Window(_) => ScriptThread::enqueue_promise_job(job, *self), + 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(), + } + } + /// https://html.spec.whatwg.org/multipage/#report-the-error pub fn report_an_error(&self, error_info: ErrorInfo, value: HandleValue) { match *self { |