Move boxing to runnable initialization

This commit is contained in:
Connor Brewster 2016-07-13 11:10:13 -06:00
parent 5f7324a9a5
commit ad30275d04
10 changed files with 20 additions and 20 deletions

View file

@ -73,7 +73,7 @@ impl VirtualMethods for HTMLDetailsElement {
let window = window_from_node(self); let window = window_from_node(self);
let task_source = window.dom_manipulation_task_source(); let task_source = window.dom_manipulation_task_source();
let details = Trusted::new(self); let details = Trusted::new(self);
let runnable = DetailsNotificationRunnable { let runnable = box DetailsNotificationRunnable {
element: details, element: details,
toggle_number: counter toggle_number: counter
}; };

View file

@ -474,7 +474,7 @@ impl HTMLFormElement {
self.generation_id.set(GenerationId(prev_id + 1)); self.generation_id.set(GenerationId(prev_id + 1));
// Step 2 // Step 2
let nav = PlannedNavigation { let nav = box PlannedNavigation {
load_data: load_data, load_data: load_data,
pipeline_id: window.pipeline(), pipeline_id: window.pipeline(),
script_chan: window.main_thread_script_chan().clone(), script_chan: window.main_thread_script_chan().clone(),

View file

@ -140,7 +140,7 @@ impl HTMLImageElement {
// Return the image via a message to the script thread, which marks the element // Return the image via a message to the script thread, which marks the element
// as dirty and triggers a reflow. // as dirty and triggers a reflow.
let image_response = message.to().unwrap(); let image_response = message.to().unwrap();
let runnable = ImageResponseHandlerRunnable::new( let runnable = box ImageResponseHandlerRunnable::new(
trusted_node.clone(), image_response); trusted_node.clone(), image_response);
let runnable = wrapper.wrap_runnable(runnable); let runnable = wrapper.wrap_runnable(runnable);
let _ = script_chan.send(CommonScriptMsg::RunnableMsg( let _ = script_chan.send(CommonScriptMsg::RunnableMsg(
@ -179,7 +179,7 @@ impl HTMLImageElement {
} }
} }
let runnable = ImgParseErrorRunnable { let runnable = box ImgParseErrorRunnable {
img: Trusted::new(self), img: Trusted::new(self),
src: src.into(), src: src.into(),
}; };

View file

@ -237,7 +237,7 @@ impl HTMLMediaElement {
} }
} }
let task = Task { let task = box Task {
elem: Trusted::new(self), elem: Trusted::new(self),
}; };
let win = window_from_node(self); let win = window_from_node(self);
@ -261,7 +261,7 @@ impl HTMLMediaElement {
} }
} }
let task = Task { let task = box Task {
elem: Trusted::new(self), elem: Trusted::new(self),
}; };
let win = window_from_node(self); let win = window_from_node(self);
@ -270,7 +270,7 @@ impl HTMLMediaElement {
fn queue_fire_simple_event(&self, type_: &'static str) { fn queue_fire_simple_event(&self, type_: &'static str) {
let win = window_from_node(self); let win = window_from_node(self);
let task = FireSimpleEventTask::new(self, type_); let task = box FireSimpleEventTask::new(self, type_);
let _ = win.dom_manipulation_task_source().queue(task, win.r()); let _ = win.dom_manipulation_task_source().queue(task, win.r());
} }
@ -498,7 +498,7 @@ impl HTMLMediaElement {
fn queue_dedicated_media_source_failure_steps(&self) { fn queue_dedicated_media_source_failure_steps(&self) {
let window = window_from_node(self); let window = window_from_node(self);
let _ = window.dom_manipulation_task_source().queue(DedicatedMediaSourceFailureTask::new(self), window.r()); let _ = window.dom_manipulation_task_source().queue(box DedicatedMediaSourceFailureTask::new(self), window.r());
} }
// https://html.spec.whatwg.org/multipage/#dedicated-media-source-failure-steps // https://html.spec.whatwg.org/multipage/#dedicated-media-source-failure-steps

View file

@ -161,7 +161,7 @@ impl Storage {
let window = global_ref.as_window(); let window = global_ref.as_window();
let task_source = window.dom_manipulation_task_source(); let task_source = window.dom_manipulation_task_source();
let trusted_storage = Trusted::new(self); let trusted_storage = Trusted::new(self);
task_source.queue(StorageEventRunnable::new(trusted_storage, key, old_value, new_value), window).unwrap(); task_source.queue(box StorageEventRunnable::new(trusted_storage, key, old_value, new_value), window).unwrap();
} }
} }

View file

@ -19,14 +19,14 @@ pub struct NetworkListener<Listener: PreInvoke + Send + 'static> {
impl<Listener: PreInvoke + Send + 'static> NetworkListener<Listener> { impl<Listener: PreInvoke + Send + 'static> NetworkListener<Listener> {
pub fn notify<A: Action<Listener> + Send + 'static>(&self, action: A) { pub fn notify<A: Action<Listener> + Send + 'static>(&self, action: A) {
let runnable = ListenerRunnable { let runnable = box ListenerRunnable {
context: self.context.clone(), context: self.context.clone(),
action: action, action: action,
}; };
let result = if let Some(ref wrapper) = self.wrapper { let result = if let Some(ref wrapper) = self.wrapper {
self.script_chan.send(CommonScriptMsg::RunnableMsg(NetworkEvent, wrapper.wrap_runnable(runnable))) self.script_chan.send(CommonScriptMsg::RunnableMsg(NetworkEvent, wrapper.wrap_runnable(runnable)))
} else { } else {
self.script_chan.send(CommonScriptMsg::RunnableMsg(NetworkEvent, box runnable)) self.script_chan.send(CommonScriptMsg::RunnableMsg(NetworkEvent, runnable))
}; };
if let Err(err) = result { if let Err(err) = result {
warn!("failed to deliver network data: {:?}", err); warn!("failed to deliver network data: {:?}", err);

View file

@ -174,10 +174,10 @@ pub struct RunnableWrapper {
} }
impl RunnableWrapper { impl RunnableWrapper {
pub fn wrap_runnable<T: Runnable + Send + 'static>(&self, runnable: T) -> Box<Runnable + Send> { pub fn wrap_runnable<T: Runnable + Send + 'static>(&self, runnable: Box<T>) -> Box<Runnable + Send> {
box CancellableRunnable { box CancellableRunnable {
cancelled: self.cancelled.clone(), cancelled: self.cancelled.clone(),
inner: box runnable, inner: runnable,
} }
} }
} }
@ -1226,7 +1226,7 @@ impl ScriptThread {
doc.mut_loader().inhibit_events(); doc.mut_loader().inhibit_events();
// https://html.spec.whatwg.org/multipage/#the-end step 7 // https://html.spec.whatwg.org/multipage/#the-end step 7
let handler = DocumentProgressHandler::new(Trusted::new(doc)); let handler = box DocumentProgressHandler::new(Trusted::new(doc));
self.dom_manipulation_task_source.queue(handler, doc.window()).unwrap(); self.dom_manipulation_task_source.queue(handler, doc.window()).unwrap();
self.constellation_chan.send(ConstellationMsg::LoadComplete(pipeline)).unwrap(); self.constellation_chan.send(ConstellationMsg::LoadComplete(pipeline)).unwrap();

View file

@ -16,7 +16,7 @@ use task_source::TaskSource;
pub struct DOMManipulationTaskSource(pub Sender<MainThreadScriptMsg>); pub struct DOMManipulationTaskSource(pub Sender<MainThreadScriptMsg>);
impl TaskSource for DOMManipulationTaskSource { impl TaskSource for DOMManipulationTaskSource {
fn queue<T: Runnable + Send + 'static>(&self, msg: T, window: &Window) -> Result<(), ()> { fn queue<T: Runnable + Send + 'static>(&self, msg: Box<T>, window: &Window) -> Result<(), ()> {
let msg = DOMManipulationTask(window.get_runnable_wrapper().wrap_runnable(msg)); let msg = DOMManipulationTask(window.get_runnable_wrapper().wrap_runnable(msg));
self.0.send(MainThreadScriptMsg::DOMManipulation(msg)).map_err(|_| ()) self.0.send(MainThreadScriptMsg::DOMManipulation(msg)).map_err(|_| ())
} }
@ -30,7 +30,7 @@ impl DOMManipulationTaskSource {
cancelable: EventCancelable, cancelable: EventCancelable,
window: &Window) { window: &Window) {
let target = Trusted::new(target); let target = Trusted::new(target);
let runnable = EventRunnable { let runnable = box EventRunnable {
target: target, target: target,
name: name, name: name,
bubbles: bubbles, bubbles: bubbles,
@ -41,7 +41,7 @@ impl DOMManipulationTaskSource {
pub fn queue_simple_event(&self, target: &EventTarget, name: Atom, window: &Window) { pub fn queue_simple_event(&self, target: &EventTarget, name: Atom, window: &Window) {
let target = Trusted::new(target); let target = Trusted::new(target);
let runnable = SimpleEventRunnable { let runnable = box SimpleEventRunnable {
target: target, target: target,
name: name, name: name,
}; };

View file

@ -13,5 +13,5 @@ use script_thread::Runnable;
use std::result::Result; use std::result::Result;
pub trait TaskSource { pub trait TaskSource {
fn queue<T: Runnable + Send + 'static>(&self, msg: T, window: &Window) -> Result<(), ()>; fn queue<T: Runnable + Send + 'static>(&self, msg: Box<T>, window: &Window) -> Result<(), ()>;
} }

View file

@ -16,7 +16,7 @@ use task_source::TaskSource;
pub struct UserInteractionTaskSource(pub Sender<MainThreadScriptMsg>); pub struct UserInteractionTaskSource(pub Sender<MainThreadScriptMsg>);
impl TaskSource for UserInteractionTaskSource { impl TaskSource for UserInteractionTaskSource {
fn queue<T: Runnable + Send + 'static>(&self, msg: T, window: &Window) -> Result<(), ()> { fn queue<T: Runnable + Send + 'static>(&self, msg: Box<T>, window: &Window) -> Result<(), ()> {
let msg = UserInteractionTask(window.get_runnable_wrapper().wrap_runnable(msg)); let msg = UserInteractionTask(window.get_runnable_wrapper().wrap_runnable(msg));
self.0.send(MainThreadScriptMsg::UserInteraction(msg)).map_err(|_| ()) self.0.send(MainThreadScriptMsg::UserInteraction(msg)).map_err(|_| ())
} }
@ -30,7 +30,7 @@ impl UserInteractionTaskSource {
cancelable: EventCancelable, cancelable: EventCancelable,
window: &Window) { window: &Window) {
let target = Trusted::new(target); let target = Trusted::new(target);
let runnable = EventRunnable { let runnable = box EventRunnable {
target: target, target: target,
name: name, name: name,
bubbles: bubbles, bubbles: bubbles,