Introduce GlobalScope::new_script_pair

This commit is contained in:
Anthony Ramine 2016-10-05 09:40:04 +02:00
parent 1f8bb3a89f
commit cdf3ef05e7
3 changed files with 17 additions and 13 deletions

View file

@ -26,7 +26,8 @@ use libc;
use msg::constellation_msg::PipelineId;
use net_traits::{CoreResourceThread, ResourceThreads, IpcSend};
use profile_traits::{mem, time};
use script_runtime::{EnqueuedPromiseCallback, ScriptChan, maybe_take_panic_result};
use script_runtime::{EnqueuedPromiseCallback, ScriptChan};
use script_runtime::{ScriptPort, maybe_take_panic_result};
use script_thread::{MainThreadScriptChan, RunnableWrapper, ScriptThread};
use script_traits::{MsDuration, ScriptMsg as ConstellationMsg, TimerEvent};
use script_traits::{TimerEventId, TimerEventRequest, TimerSource};
@ -431,6 +432,19 @@ impl GlobalScope {
}
unreachable!();
}
/// Create a new sender/receiver pair that can be used to implement an on-demand
/// event loop. Used for implementing web APIs that require blocking semantics
/// without resorting to nested event loops.
pub fn new_script_pair(&self) -> (Box<ScriptChan + Send>, Box<ScriptPort + Send>) {
if let Some(window) = self.downcast::<Window>() {
return window.new_script_pair();
}
if let Some(worker) = self.downcast::<WorkerGlobalScope>() {
return worker.new_script_pair();
}
unreachable!();
}
}
fn timestamp_in_ms(time: Timespec) -> u64 {