diff options
Diffstat (limited to 'components/script/script_task.rs')
-rw-r--r-- | components/script/script_task.rs | 42 |
1 files changed, 30 insertions, 12 deletions
diff --git a/components/script/script_task.rs b/components/script/script_task.rs index 0a202752336..ae27dc671c7 100644 --- a/components/script/script_task.rs +++ b/components/script/script_task.rs @@ -64,7 +64,7 @@ use geom::point::Point2D; use hyper::header::{Header, HeaderFormat}; use hyper::header::common::util as header_util; use js::jsapi::{JS_SetWrapObjectCallbacks, JS_SetGCZeal, JS_DEFAULT_ZEAL_FREQ, JS_GC}; -use js::jsapi::{JSContext, JSRuntime, JSTracer}; +use js::jsapi::{JSContext, JSRuntime}; use js::jsapi::{JS_SetGCParameter, JSGC_MAX_BYTES}; use js::jsapi::{JS_SetGCCallback, JSGCStatus, JSGC_BEGIN, JSGC_END}; use js::rust::{Cx, RtUtils}; @@ -113,7 +113,7 @@ pub enum ScriptMsg { ExitWindow(PipelineId), /// Message sent through Worker.postMessage (only dispatched to /// DedicatedWorkerGlobalScope). - DOMMessage(TrustedWorkerAddress, *mut u64, size_t), + DOMMessage(*mut u64, size_t), /// Posts a message to the Worker object (dispatched to all tasks). WorkerPostMessage(TrustedWorkerAddress, *mut u64, size_t), /// Generic message that encapsulates event handling. @@ -122,17 +122,35 @@ pub enum ScriptMsg { RefcountCleanup(*const libc::c_void), } +/// A cloneable interface for communicating with an event loop. +pub trait ScriptChan { + /// Send a message to the associated event loop. + fn send(&self, msg: ScriptMsg); + /// Clone this handle. + fn clone(&self) -> Box<ScriptChan+Send>; +} + /// Encapsulates internal communication within the script task. -#[deriving(Clone)] -pub struct ScriptChan(pub Sender<ScriptMsg>); +#[jstraceable] +pub struct NonWorkerScriptChan(pub Sender<ScriptMsg>); -no_jsmanaged_fields!(ScriptChan) +impl ScriptChan for NonWorkerScriptChan { + fn send(&self, msg: ScriptMsg) { + let NonWorkerScriptChan(ref chan) = *self; + chan.send(msg); + } + + fn clone(&self) -> Box<ScriptChan+Send> { + let NonWorkerScriptChan(ref chan) = *self; + box NonWorkerScriptChan(chan.clone()) + } +} -impl ScriptChan { +impl NonWorkerScriptChan { /// Creates a new script chan. - pub fn new() -> (Receiver<ScriptMsg>, ScriptChan) { + pub fn new() -> (Receiver<ScriptMsg>, Box<NonWorkerScriptChan>) { let (chan, port) = channel(); - (port, ScriptChan(chan)) + (port, box NonWorkerScriptChan(chan)) } } @@ -167,7 +185,7 @@ pub struct ScriptTask { port: Receiver<ScriptMsg>, /// A channel to hand out to script task-based entities that need to be able to enqueue /// events in the event queue. - chan: ScriptChan, + chan: NonWorkerScriptChan, /// A channel to hand out to tasks that need to respond to a message from the script task. control_chan: ScriptControlChan, @@ -282,7 +300,7 @@ impl ScriptTaskFactory for ScriptTask { box compositor as Box<ScriptListener>, layout_chan, script_port, - ScriptChan(script_chan), + NonWorkerScriptChan(script_chan), control_chan, control_port, constellation_chan, @@ -314,7 +332,7 @@ impl ScriptTask { compositor: Box<ScriptListener+'static>, layout_chan: LayoutChan, port: Receiver<ScriptMsg>, - chan: ScriptChan, + chan: NonWorkerScriptChan, control_chan: ScriptControlChan, control_port: Receiver<ConstellationControlMsg>, constellation_chan: ConstellationChan, @@ -583,7 +601,7 @@ impl ScriptTask { ScriptMsg::RunnableMsg(runnable) => runnable.handler(), ScriptMsg::RefcountCleanup(addr) => - LiveDOMReferences::cleanup(self.js_context.borrow().as_ref().unwrap().ptr, addr), + LiveDOMReferences::cleanup(self.get_cx(), addr), } } |