Auto merge of #7006 - Wafflespeanut:script_cleanup, r=jdm

Splitting ScriptMsg into various enums...

... for #3734, which is also one of the oldest issues. (/cc @jdm)

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/7006)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2015-08-15 03:48:47 -06:00
commit 6a52ec9484
18 changed files with 261 additions and 164 deletions

View file

@ -15,7 +15,7 @@ use dom::document::DocumentHelpers;
use dom::workerglobalscope::{WorkerGlobalScope, WorkerGlobalScopeHelpers};
use dom::window::{self, WindowHelpers, ScriptHelpers};
use devtools_traits::ScriptToDevtoolsControlMsg;
use script_task::{ScriptChan, ScriptPort, ScriptMsg, ScriptTask};
use script_task::{ScriptChan, ScriptPort, CommonScriptMsg, ScriptTask};
use msg::constellation_msg::{ConstellationChan, PipelineId, WorkerId};
use net_traits::ResourceTask;
@ -168,7 +168,7 @@ impl<'a> GlobalRef<'a> {
/// Process a single event as if it were the next event in the task queue for
/// this global.
pub fn process_event(&self, msg: ScriptMsg) {
pub fn process_event(&self, msg: CommonScriptMsg) {
match *self {
GlobalRef::Window(_) => ScriptTask::process_event(msg),
GlobalRef::Worker(ref worker) => worker.process_event(msg),

View file

@ -25,7 +25,7 @@
use dom::bindings::js::Root;
use dom::bindings::utils::{Reflector, Reflectable};
use dom::bindings::trace::trace_reflector;
use script_task::{ScriptMsg, ScriptChan};
use script_task::{ScriptChan, CommonScriptMsg};
use js::jsapi::{JSContext, JSTracer};
@ -130,7 +130,7 @@ impl<T: Reflectable> Drop for Trusted<T> {
// It's possible this send will fail if the script task
// has already exited. There's not much we can do at this
// point though.
let msg = ScriptMsg::RefcountCleanup(TrustedReference(self.ptr));
let msg = CommonScriptMsg::RefcountCleanup(TrustedReference(self.ptr));
let _ = self.script_chan.send(msg);
}
}

View file

@ -22,8 +22,7 @@ use dom::messageevent::MessageEvent;
use dom::worker::{TrustedWorkerAddress, WorkerMessageHandler, WorkerEventHandler, WorkerErrorHandler};
use dom::workerglobalscope::{WorkerGlobalScope, WorkerGlobalScopeHelpers};
use dom::workerglobalscope::{WorkerGlobalScopeTypeId, WorkerGlobalScopeInit};
use script_task::{ScriptTask, ScriptChan, ScriptMsg, TimerSource, ScriptPort};
use script_task::StackRootTLS;
use script_task::{ScriptTask, ScriptChan, TimerSource, ScriptPort, StackRootTLS, CommonScriptMsg};
use devtools_traits::DevtoolScriptControlMsg;
use msg::constellation_msg::PipelineId;
@ -45,17 +44,25 @@ use std::mem::replace;
use std::rc::Rc;
use std::sync::mpsc::{Sender, Receiver, channel, Select, RecvError};
/// Messages used to control the worker event loops
pub enum WorkerScriptMsg {
/// Common variants associated with the script messages
Common(CommonScriptMsg),
/// Message sent through Worker.postMessage
DOMMessage(StructuredCloneData),
}
/// A ScriptChan that can be cloned freely and will silently send a TrustedWorkerAddress with
/// every message. While this SendableWorkerScriptChan is alive, the associated Worker object
/// will remain alive.
/// common event loop messages. While this SendableWorkerScriptChan is alive, the associated
/// Worker object will remain alive.
#[derive(JSTraceable, Clone)]
pub struct SendableWorkerScriptChan {
sender: Sender<(TrustedWorkerAddress, ScriptMsg)>,
sender: Sender<(TrustedWorkerAddress, CommonScriptMsg)>,
worker: TrustedWorkerAddress,
}
impl ScriptChan for SendableWorkerScriptChan {
fn send(&self, msg: ScriptMsg) -> Result<(), ()> {
fn send(&self, msg: CommonScriptMsg) -> Result<(), ()> {
return self.sender.send((self.worker.clone(), msg)).map_err(|_| ());
}
@ -67,6 +74,39 @@ impl ScriptChan for SendableWorkerScriptChan {
}
}
/// A ScriptChan that can be cloned freely and will silently send a TrustedWorkerAddress with
/// worker event loop messages. While this SendableWorkerScriptChan is alive, the associated
/// Worker object will remain alive.
#[derive(JSTraceable, Clone)]
pub struct WorkerThreadWorkerChan {
sender: Sender<(TrustedWorkerAddress, WorkerScriptMsg)>,
worker: TrustedWorkerAddress,
}
impl ScriptChan for WorkerThreadWorkerChan {
fn send(&self, msg: CommonScriptMsg) -> Result<(), ()> {
return self.sender
.send((self.worker.clone(), WorkerScriptMsg::Common(msg)))
.map_err(|_| ());
}
fn clone(&self) -> Box<ScriptChan + Send> {
box WorkerThreadWorkerChan {
sender: self.sender.clone(),
worker: self.worker.clone(),
}
}
}
impl ScriptPort for Receiver<(TrustedWorkerAddress, WorkerScriptMsg)> {
fn recv(&self) -> CommonScriptMsg {
match self.recv().unwrap().1 {
WorkerScriptMsg::Common(script_msg) => script_msg,
WorkerScriptMsg::DOMMessage(_) => panic!("unexpected worker event message!"),
}
}
}
/// Set the `worker` field of a related DedicatedWorkerGlobalScope object to a particular
/// value for the duration of this object's lifetime. This ensures that the related Worker
/// object only lives as long as necessary (ie. while events are being executed), while
@ -92,7 +132,7 @@ impl<'a> Drop for AutoWorkerReset<'a> {
}
enum MixedMessage {
FromWorker((TrustedWorkerAddress, ScriptMsg)),
FromWorker((TrustedWorkerAddress, WorkerScriptMsg)),
FromDevtools(DevtoolScriptControlMsg),
}
@ -103,9 +143,9 @@ pub struct DedicatedWorkerGlobalScope {
workerglobalscope: WorkerGlobalScope,
id: PipelineId,
#[ignore_heap_size_of = "Defined in std"]
receiver: Receiver<(TrustedWorkerAddress, ScriptMsg)>,
receiver: Receiver<(TrustedWorkerAddress, WorkerScriptMsg)>,
#[ignore_heap_size_of = "Defined in std"]
own_sender: Sender<(TrustedWorkerAddress, ScriptMsg)>,
own_sender: Sender<(TrustedWorkerAddress, WorkerScriptMsg)>,
#[ignore_heap_size_of = "Trusted<T> has unclear ownership like JS<T>"]
worker: DOMRefCell<Option<TrustedWorkerAddress>>,
#[ignore_heap_size_of = "Can't measure trait objects"]
@ -120,8 +160,8 @@ impl DedicatedWorkerGlobalScope {
devtools_port: Receiver<DevtoolScriptControlMsg>,
runtime: Rc<Runtime>,
parent_sender: Box<ScriptChan+Send>,
own_sender: Sender<(TrustedWorkerAddress, ScriptMsg)>,
receiver: Receiver<(TrustedWorkerAddress, ScriptMsg)>)
own_sender: Sender<(TrustedWorkerAddress, WorkerScriptMsg)>,
receiver: Receiver<(TrustedWorkerAddress, WorkerScriptMsg)>)
-> DedicatedWorkerGlobalScope {
DedicatedWorkerGlobalScope {
workerglobalscope: WorkerGlobalScope::new_inherited(
@ -141,8 +181,8 @@ impl DedicatedWorkerGlobalScope {
devtools_port: Receiver<DevtoolScriptControlMsg>,
runtime: Rc<Runtime>,
parent_sender: Box<ScriptChan+Send>,
own_sender: Sender<(TrustedWorkerAddress, ScriptMsg)>,
receiver: Receiver<(TrustedWorkerAddress, ScriptMsg)>)
own_sender: Sender<(TrustedWorkerAddress, WorkerScriptMsg)>,
receiver: Receiver<(TrustedWorkerAddress, WorkerScriptMsg)>)
-> Root<DedicatedWorkerGlobalScope> {
let scope = box DedicatedWorkerGlobalScope::new_inherited(
init, worker_url, id, devtools_port, runtime.clone(), parent_sender,
@ -158,8 +198,8 @@ impl DedicatedWorkerGlobalScope {
devtools_ipc_port: IpcReceiver<DevtoolScriptControlMsg>,
worker: TrustedWorkerAddress,
parent_sender: Box<ScriptChan+Send>,
own_sender: Sender<(TrustedWorkerAddress, ScriptMsg)>,
receiver: Receiver<(TrustedWorkerAddress, ScriptMsg)>) {
own_sender: Sender<(TrustedWorkerAddress, WorkerScriptMsg)>,
receiver: Receiver<(TrustedWorkerAddress, WorkerScriptMsg)>) {
let serialized_worker_url = worker_url.serialize();
spawn_named(format!("WebWorker for {}", serialized_worker_url), move || {
task_state::initialize(SCRIPT | IN_WORKER);
@ -170,7 +210,7 @@ impl DedicatedWorkerGlobalScope {
let (url, source) = match load_whole_resource(&init.resource_task, worker_url) {
Err(_) => {
println!("error loading script {}", serialized_worker_url);
parent_sender.send(ScriptMsg::RunnableMsg(
parent_sender.send(CommonScriptMsg::RunnableMsg(
box WorkerEventHandler::new(worker))).unwrap();
return;
}
@ -201,7 +241,7 @@ impl DedicatedWorkerGlobalScope {
while let Ok(event) = global.receive_event() {
global.handle_event(event);
}
}, reporter_name, parent_sender, ScriptMsg::CollectReports);
}, reporter_name, parent_sender, CommonScriptMsg::CollectReports);
});
}
}
@ -210,12 +250,12 @@ pub trait DedicatedWorkerGlobalScopeHelpers {
fn script_chan(self) -> Box<ScriptChan+Send>;
fn pipeline(self) -> PipelineId;
fn new_script_pair(self) -> (Box<ScriptChan+Send>, Box<ScriptPort+Send>);
fn process_event(self, msg: ScriptMsg);
fn process_event(self, msg: CommonScriptMsg);
}
impl<'a> DedicatedWorkerGlobalScopeHelpers for &'a DedicatedWorkerGlobalScope {
fn script_chan(self) -> Box<ScriptChan+Send> {
box SendableWorkerScriptChan {
box WorkerThreadWorkerChan {
sender: self.own_sender.clone(),
worker: self.worker.borrow().as_ref().unwrap().clone(),
}
@ -234,13 +274,13 @@ impl<'a> DedicatedWorkerGlobalScopeHelpers for &'a DedicatedWorkerGlobalScope {
(chan, box rx)
}
fn process_event(self, msg: ScriptMsg) {
self.handle_script_event(msg);
fn process_event(self, msg: CommonScriptMsg) {
self.handle_script_event(WorkerScriptMsg::Common(msg));
}
}
trait PrivateDedicatedWorkerGlobalScopeHelpers {
fn handle_script_event(self, msg: ScriptMsg);
fn handle_script_event(self, msg: WorkerScriptMsg);
fn dispatch_error_to_worker(self, &ErrorEvent);
fn receive_event(self) -> Result<MixedMessage, RecvError>;
fn handle_event(self, event: MixedMessage);
@ -272,9 +312,9 @@ impl<'a> PrivateDedicatedWorkerGlobalScopeHelpers for &'a DedicatedWorkerGlobalS
}
}
fn handle_script_event(self, msg: ScriptMsg) {
fn handle_script_event(self, msg: WorkerScriptMsg) {
match msg {
ScriptMsg::DOMMessage(data) => {
WorkerScriptMsg::DOMMessage(data) => {
let scope = WorkerGlobalScopeCast::from_ref(self);
let target = EventTargetCast::from_ref(self);
let _ar = JSAutoRequest::new(scope.get_cx());
@ -283,24 +323,27 @@ impl<'a> PrivateDedicatedWorkerGlobalScopeHelpers for &'a DedicatedWorkerGlobalS
data.read(GlobalRef::Worker(scope), message.handle_mut());
MessageEvent::dispatch_jsval(target, GlobalRef::Worker(scope), message.handle());
},
ScriptMsg::RunnableMsg(runnable) => {
WorkerScriptMsg::Common(CommonScriptMsg::RunnableMsg(runnable)) => {
runnable.handler()
},
ScriptMsg::RefcountCleanup(addr) => {
WorkerScriptMsg::Common(CommonScriptMsg::RefcountCleanup(addr)) => {
LiveDOMReferences::cleanup(addr);
}
ScriptMsg::FireTimer(TimerSource::FromWorker, timer_id) => {
},
WorkerScriptMsg::Common(
CommonScriptMsg::FireTimer(TimerSource::FromWorker, timer_id)) => {
let scope = WorkerGlobalScopeCast::from_ref(self);
scope.handle_fire_timer(timer_id);
}
ScriptMsg::CollectReports(reports_chan) => {
},
WorkerScriptMsg::Common(CommonScriptMsg::CollectReports(reports_chan)) => {
let scope = WorkerGlobalScopeCast::from_ref(self);
let cx = scope.get_cx();
let path_seg = format!("url({})", scope.get_url());
let reports = ScriptTask::get_reports(cx, path_seg);
reports_chan.send(reports);
}
_ => panic!("Unexpected message"),
},
WorkerScriptMsg::Common(CommonScriptMsg::FireTimer(_, _)) => {
panic!("obtained a fire timeout from window for the worker!")
},
}
}
@ -331,7 +374,7 @@ impl<'a> PrivateDedicatedWorkerGlobalScopeHelpers for &'a DedicatedWorkerGlobalS
let line_num = errorevent.Lineno();
let col_num = errorevent.Colno();
let worker = self.worker.borrow().as_ref().unwrap().clone();
self.parent_sender.send(ScriptMsg::RunnableMsg(
self.parent_sender.send(CommonScriptMsg::RunnableMsg(
box WorkerErrorHandler::new(worker, msg, file_name, line_num, col_num))).unwrap();
}
}
@ -341,7 +384,7 @@ impl<'a> DedicatedWorkerGlobalScopeMethods for &'a DedicatedWorkerGlobalScope {
fn PostMessage(self, cx: *mut JSContext, message: HandleValue) -> ErrorResult {
let data = try!(StructuredCloneData::write(cx, message));
let worker = self.worker.borrow().as_ref().unwrap().clone();
self.parent_sender.send(ScriptMsg::RunnableMsg(
self.parent_sender.send(CommonScriptMsg::RunnableMsg(
box WorkerMessageHandler::new(worker, data))).unwrap();
Ok(())
}

View file

@ -22,7 +22,7 @@ use encoding::types::{EncodingRef, DecoderTrap};
use encoding::label::encoding_from_whatwg_label;
use hyper::mime::{Mime, Attr};
use std::sync::mpsc;
use script_task::{ScriptChan, ScriptMsg, Runnable, ScriptPort};
use script_task::{ScriptChan, Runnable, ScriptPort, CommonScriptMsg};
use std::cell::{Cell, RefCell};
use std::sync::mpsc::Receiver;
use util::str::DOMString;
@ -408,22 +408,22 @@ fn perform_annotated_read_operation(gen_id: GenerationId, data: ReadMetaData, bl
let chan = &script_chan;
// Step 4
let task = box FileReaderEvent::ProcessRead(filereader.clone(), gen_id);
chan.send(ScriptMsg::RunnableMsg(task)).unwrap();
chan.send(CommonScriptMsg::RunnableMsg(task)).unwrap();
let task = box FileReaderEvent::ProcessReadData(filereader.clone(),
gen_id, DOMString::new());
chan.send(ScriptMsg::RunnableMsg(task)).unwrap();
chan.send(CommonScriptMsg::RunnableMsg(task)).unwrap();
let bytes = match blob_contents.recv() {
Ok(bytes) => bytes,
Err(_) => {
let task = box FileReaderEvent::ProcessReadError(filereader,
gen_id, DOMErrorName::NotFoundError);
chan.send(ScriptMsg::RunnableMsg(task)).unwrap();
chan.send(CommonScriptMsg::RunnableMsg(task)).unwrap();
return;
}
};
let task = box FileReaderEvent::ProcessReadEOF(filereader, gen_id, data, bytes);
chan.send(ScriptMsg::RunnableMsg(task)).unwrap();
chan.send(CommonScriptMsg::RunnableMsg(task)).unwrap();
}

View file

@ -34,7 +34,7 @@ use hyper::header::ContentType;
use hyper::mime;
use msg::constellation_msg::LoadData;
use util::str::DOMString;
use script_task::{ScriptChan, ScriptMsg};
use script_task::{ScriptChan, MainThreadScriptMsg};
use url::UrlParser;
use url::form_urlencoded::serialize;
use string_cache::Atom;
@ -232,7 +232,8 @@ impl<'a> HTMLFormElementHelpers for &'a HTMLFormElement {
}
// This is wrong. https://html.spec.whatwg.org/multipage/#planned-navigation
win.r().script_chan().send(ScriptMsg::Navigate(win.r().pipeline(), load_data)).unwrap();
win.r().main_thread_script_chan().send(MainThreadScriptMsg::Navigate(
win.r().pipeline(), load_data)).unwrap();
}
fn get_form_dataset<'b>(self, submitter: Option<FormSubmitter<'b>>) -> Vec<FormDatum> {

View file

@ -23,7 +23,7 @@ use dom::htmlelement::{HTMLElement, HTMLElementTypeId};
use dom::node::{document_from_node, Node, NodeTypeId, NodeHelpers, NodeDamage, window_from_node};
use dom::virtualmethods::VirtualMethods;
use dom::window::WindowHelpers;
use script_task::{Runnable, ScriptChan, ScriptMsg};
use script_task::{Runnable, ScriptChan, CommonScriptMsg};
use util::str::DOMString;
use string_cache::Atom;
@ -140,9 +140,9 @@ impl<'a> PrivateHTMLImageElementHelpers for &'a HTMLImageElement {
// Return the image via a message to the script task, which marks the element
// as dirty and triggers a reflow.
let image_response = message.to().unwrap();
script_chan.send(ScriptMsg::RunnableMsg(box ImageResponseHandlerRunnable::new(
trusted_node.clone(),
image_response))).unwrap();
script_chan.send(CommonScriptMsg::RunnableMsg(
box ImageResponseHandlerRunnable::new(
trusted_node.clone(), image_response))).unwrap();
});
image_cache.request_image(img_url,
@ -345,4 +345,3 @@ impl<'a> VirtualMethods for &'a HTMLImageElement {
}
}
}

View file

@ -33,7 +33,7 @@ use dom::servohtmlparser::ServoHTMLParserHelpers;
use dom::virtualmethods::VirtualMethods;
use dom::window::{WindowHelpers, ScriptHelpers};
use network_listener::{NetworkListener, PreInvoke};
use script_task::{ScriptChan, ScriptMsg, Runnable};
use script_task::{ScriptChan, Runnable, CommonScriptMsg};
use js::jsapi::RootedValue;
use js::jsval::UndefinedValue;
@ -459,7 +459,7 @@ impl<'a> HTMLScriptElementHelpers for &'a HTMLScriptElement {
element: handler,
is_error: false,
};
chan.send(ScriptMsg::RunnableMsg(dispatcher)).unwrap();
chan.send(CommonScriptMsg::RunnableMsg(dispatcher)).unwrap();
}
}
@ -472,7 +472,7 @@ impl<'a> HTMLScriptElementHelpers for &'a HTMLScriptElement {
element: handler,
is_error: true,
};
chan.send(ScriptMsg::RunnableMsg(dispatcher)).unwrap();
chan.send(CommonScriptMsg::RunnableMsg(dispatcher)).unwrap();
}
fn dispatch_before_script_execute_event(self) -> bool {

View file

@ -28,7 +28,7 @@ use dom::node::{NodeHelpers, NodeTypeId, document_from_node, window_from_node};
use textinput::{TextInput, Lines, KeyReaction};
use dom::virtualmethods::VirtualMethods;
use dom::window::WindowHelpers;
use script_task::{ScriptMsg, Runnable};
use script_task::{Runnable, CommonScriptMsg};
use msg::constellation_msg::ConstellationChan;
use util::str::DOMString;
@ -368,7 +368,7 @@ impl<'a> VirtualMethods for &'a HTMLTextAreaElement {
let dispatcher = ChangeEventRunnable {
element: handler,
};
let _ = chan.send(ScriptMsg::RunnableMsg(box dispatcher));
let _ = chan.send(CommonScriptMsg::RunnableMsg(box dispatcher));
}
self.force_relayout();

View file

@ -17,12 +17,11 @@ use ipc_channel::ipc;
use util::str::DOMString;
use page::IterablePage;
use net_traits::storage_task::{StorageTask, StorageTaskMsg, StorageType};
use script_task::{ScriptTask, MainThreadRunnable, MainThreadScriptMsg};
use std::borrow::ToOwned;
use std::sync::mpsc::channel;
use url::Url;
use script_task::{ScriptTask, ScriptMsg, MainThreadRunnable};
#[dom_struct]
#[derive(HeapSizeOf)]
pub struct Storage {
@ -148,12 +147,12 @@ impl<'a> PrivateStorageHelpers for &'a Storage {
new_value: Option<DOMString>){
let global_root = self.global.root();
let global_ref = global_root.r();
let main_script_chan = global_ref.as_window().main_thread_script_chan();
let script_chan = global_ref.script_chan();
let trusted_storage = Trusted::new(global_ref.get_cx(), self,
script_chan.clone());
script_chan.send(ScriptMsg::MainThreadRunnableMsg(
box StorageEventRunnable::new(trusted_storage, key,
old_value, new_value))).unwrap();
main_script_chan.send(MainThreadScriptMsg::MainThreadRunnableMsg(
box StorageEventRunnable::new(trusted_storage, key, old_value, new_value))).unwrap();
}
}

View file

@ -22,8 +22,7 @@ use dom::closeevent::CloseEvent;
use dom::event::{Event, EventBubbles, EventCancelable, EventHelpers};
use dom::eventtarget::{EventTarget, EventTargetHelpers, EventTargetTypeId};
use dom::messageevent::MessageEvent;
use script_task::Runnable;
use script_task::ScriptMsg;
use script_task::{Runnable, CommonScriptMsg};
use net_traits::hosts::replace_hosts;
use util::str::DOMString;
@ -179,7 +178,7 @@ impl WebSocket {
let task = box CloseTask {
addr: address,
};
sender.send(ScriptMsg::RunnableMsg(task)).unwrap();
sender.send(CommonScriptMsg::RunnableMsg(task)).unwrap();
return;
}
};
@ -189,7 +188,7 @@ impl WebSocket {
addr: address.clone(),
sender: ws_sender.clone(),
};
sender.send(ScriptMsg::RunnableMsg(open_task)).unwrap();
sender.send(CommonScriptMsg::RunnableMsg(open_task)).unwrap();
for message in receiver.incoming_messages() {
let message = match message {
@ -205,7 +204,7 @@ impl WebSocket {
let task = box CloseTask {
addr: address,
};
sender.send(ScriptMsg::RunnableMsg(task)).unwrap();
sender.send(CommonScriptMsg::RunnableMsg(task)).unwrap();
break;
},
Err(_) => break,
@ -214,7 +213,7 @@ impl WebSocket {
address: address.clone(),
message: message,
};
sender.send(ScriptMsg::RunnableMsg(message_task)).unwrap();
sender.send(CommonScriptMsg::RunnableMsg(message_task)).unwrap();
}
});

View file

@ -34,8 +34,8 @@ use dom::storage::Storage;
use layout_interface::{ReflowGoal, ReflowQueryType, LayoutRPC, LayoutChan, Reflow, Msg};
use layout_interface::{ContentBoxResponse, ContentBoxesResponse, ResolvedStyleResponse, ScriptReflow};
use page::Page;
use script_task::{TimerSource, ScriptChan, ScriptPort, NonWorkerScriptChan};
use script_task::ScriptMsg;
use script_task::{TimerSource, ScriptChan, ScriptPort, MainThreadScriptMsg};
use script_task::{SendableMainThreadScriptChan, MainThreadScriptChan};
use script_traits::ConstellationControlMsg;
use timers::{IsInterval, TimerId, TimerManager, TimerCallback};
use webdriver_handlers::jsval_to_webdriver;
@ -110,7 +110,7 @@ pub enum ReflowReason {
pub struct Window {
eventtarget: EventTarget,
#[ignore_heap_size_of = "trait objects are hard"]
script_chan: Box<ScriptChan+Send>,
script_chan: MainThreadScriptChan,
#[ignore_heap_size_of = "channels are hard"]
control_chan: Sender<ConstellationControlMsg>,
console: MutNullableHeap<JS<Console>>,
@ -236,6 +236,11 @@ impl Window {
self.script_chan.clone()
}
pub fn main_thread_script_chan(&self) -> &Sender<MainThreadScriptMsg> {
let MainThreadScriptChan(ref sender) = self.script_chan;
sender
}
pub fn image_cache_chan(&self) -> ImageCacheChan {
self.image_cache_chan.clone()
}
@ -261,7 +266,7 @@ impl Window {
pub fn new_script_pair(&self) -> (Box<ScriptChan+Send>, Box<ScriptPort+Send>) {
let (tx, rx) = channel();
(box NonWorkerScriptChan(tx), box rx)
(box SendableMainThreadScriptChan(tx), box rx)
}
pub fn image_cache_task<'a>(&'a self) -> &'a ImageCacheTask {
@ -370,7 +375,7 @@ impl<'a> WindowMethods for &'a Window {
// https://html.spec.whatwg.org/multipage/#dom-window-close
fn Close(self) {
self.script_chan.send(ScriptMsg::ExitWindow(self.id.clone())).unwrap();
self.main_thread_script_chan().send(MainThreadScriptMsg::ExitWindow(self.id.clone())).unwrap();
}
// https://html.spec.whatwg.org/multipage/#dom-document-0
@ -887,7 +892,8 @@ impl<'a> WindowHelpers for &'a Window {
/// Commence a new URL load which will either replace this window or scroll to a fragment.
fn load_url(self, url: Url) {
self.script_chan.send(ScriptMsg::Navigate(self.id, LoadData::new(url))).unwrap();
self.main_thread_script_chan().send(
MainThreadScriptMsg::Navigate(self.id, LoadData::new(url))).unwrap();
}
fn handle_fire_timer(self, timer_id: TimerId) {
@ -1064,7 +1070,7 @@ impl<'a> WindowHelpers for &'a Window {
impl Window {
pub fn new(runtime: Rc<Runtime>,
page: Rc<Page>,
script_chan: Box<ScriptChan+Send>,
script_chan: MainThreadScriptChan,
image_cache_chan: ImageCacheChan,
control_chan: Sender<ConstellationControlMsg>,
compositor: ScriptListener,

View file

@ -15,23 +15,22 @@ use dom::bindings::trace::JSTraceable;
use dom::bindings::utils::{Reflectable, reflect_dom_object};
use dom::bindings::js::Root;
use dom::window::WindowHelpers;
use dom::dedicatedworkerglobalscope::DedicatedWorkerGlobalScope;
use dom::dedicatedworkerglobalscope::{DedicatedWorkerGlobalScope, WorkerScriptMsg};
use dom::errorevent::ErrorEvent;
use dom::event::{Event, EventBubbles, EventCancelable, EventHelpers};
use dom::eventtarget::{EventTarget, EventTargetHelpers, EventTargetTypeId};
use dom::messageevent::MessageEvent;
use dom::workerglobalscope::WorkerGlobalScopeInit;
use script_task::{ScriptChan, ScriptMsg, Runnable};
use devtools_traits::{DevtoolsPageInfo, ScriptToDevtoolsControlMsg};
use util::str::DOMString;
use script_task::{ScriptChan, Runnable};
use ipc_channel::ipc;
use js::jsapi::{JSContext, HandleValue, RootedValue};
use js::jsapi::{JSAutoRequest, JSAutoCompartment};
use js::jsval::UndefinedValue;
use url::UrlParser;
use util::str::DOMString;
use std::borrow::ToOwned;
use std::sync::mpsc::{channel, Sender};
@ -47,11 +46,13 @@ pub struct Worker {
#[ignore_heap_size_of = "Defined in std"]
/// Sender to the Receiver associated with the DedicatedWorkerGlobalScope
/// this Worker created.
sender: Sender<(TrustedWorkerAddress, ScriptMsg)>,
sender: Sender<(TrustedWorkerAddress, WorkerScriptMsg)>,
}
impl Worker {
fn new_inherited(global: GlobalRef, sender: Sender<(TrustedWorkerAddress, ScriptMsg)>) -> Worker {
fn new_inherited(global: GlobalRef,
sender: Sender<(TrustedWorkerAddress, WorkerScriptMsg)>)
-> Worker {
Worker {
eventtarget: EventTarget::new_inherited(EventTargetTypeId::Worker),
global: GlobalField::from_rooted(&global),
@ -59,7 +60,9 @@ impl Worker {
}
}
pub fn new(global: GlobalRef, sender: Sender<(TrustedWorkerAddress, ScriptMsg)>) -> Root<Worker> {
pub fn new(global: GlobalRef,
sender: Sender<(TrustedWorkerAddress, WorkerScriptMsg)>)
-> Root<Worker> {
reflect_dom_object(box Worker::new_inherited(global, sender),
global,
WorkerBinding::Wrap)
@ -157,7 +160,7 @@ impl<'a> WorkerMethods for &'a Worker {
fn PostMessage(self, cx: *mut JSContext, message: HandleValue) -> ErrorResult {
let data = try!(StructuredCloneData::write(cx, message));
let address = Trusted::new(cx, self, self.global.root().r().script_chan().clone());
self.sender.send((address, ScriptMsg::DOMMessage(data))).unwrap();
self.sender.send((address, WorkerScriptMsg::DOMMessage(data))).unwrap();
Ok(())
}

View file

@ -17,7 +17,7 @@ use dom::eventtarget::{EventTarget, EventTargetTypeId};
use dom::workerlocation::WorkerLocation;
use dom::workernavigator::WorkerNavigator;
use dom::window::{base64_atob, base64_btoa};
use script_task::{ScriptChan, TimerSource, ScriptPort, ScriptMsg};
use script_task::{CommonScriptMsg, ScriptChan, TimerSource, ScriptPort};
use timers::{IsInterval, TimerId, TimerManager, TimerCallback};
use devtools_traits::{ScriptToDevtoolsControlMsg, DevtoolScriptControlMsg};
@ -291,7 +291,7 @@ pub trait WorkerGlobalScopeHelpers {
fn script_chan(self) -> Box<ScriptChan+Send>;
fn pipeline(self) -> PipelineId;
fn new_script_pair(self) -> (Box<ScriptChan+Send>, Box<ScriptPort+Send>);
fn process_event(self, msg: ScriptMsg);
fn process_event(self, msg: CommonScriptMsg);
fn get_cx(self) -> *mut JSContext;
fn set_devtools_wants_updates(self, value: bool);
}
@ -338,7 +338,7 @@ impl<'a> WorkerGlobalScopeHelpers for &'a WorkerGlobalScope {
}
}
fn process_event(self, msg: ScriptMsg) {
fn process_event(self, msg: CommonScriptMsg) {
let dedicated =
DedicatedWorkerGlobalScopeCast::to_ref(self);
match dedicated {

View file

@ -28,7 +28,7 @@ use dom::xmlhttprequesteventtarget::XMLHttpRequestEventTarget;
use dom::xmlhttprequesteventtarget::XMLHttpRequestEventTargetTypeId;
use dom::xmlhttprequestupload::XMLHttpRequestUpload;
use network_listener::{NetworkListener, PreInvoke};
use script_task::{ScriptChan, ScriptMsg, Runnable, ScriptPort};
use script_task::{ScriptChan, Runnable, ScriptPort, CommonScriptMsg};
use encoding::all::UTF_8;
use encoding::label::encoding_from_whatwg_label;
@ -1013,7 +1013,7 @@ impl<'a> PrivateXMLHttpRequestHelpers for &'a XMLHttpRequest {
sleep_ms(duration_ms);
match cancel_rx.try_recv() {
Err(TryRecvError::Empty) => {
timeout_target.send(ScriptMsg::RunnableMsg(box XHRTimeout {
timeout_target.send(CommonScriptMsg::RunnableMsg(box XHRTimeout {
xhr: xhr,
gen_id: gen_id,
})).unwrap();