diff options
Diffstat (limited to 'components/script/script_task.rs')
-rw-r--r-- | components/script/script_task.rs | 73 |
1 files changed, 38 insertions, 35 deletions
diff --git a/components/script/script_task.rs b/components/script/script_task.rs index 0d9e935483a..8d342a9eaf5 100644 --- a/components/script/script_task.rs +++ b/components/script/script_task.rs @@ -32,8 +32,8 @@ use dom::bindings::js::{RootCollectionPtr, Root, RootedReference}; use dom::bindings::refcounted::{LiveDOMReferences, Trusted, TrustedReference, trace_refcounted_objects}; use dom::bindings::trace::{JSTraceable, trace_traceables, RootedVec}; use dom::bindings::utils::{WRAP_CALLBACKS, DOM_CALLBACKS}; -use dom::document::{Document, IsHTMLDocument, DocumentHelpers, DocumentProgressHandler, - DocumentProgressTask, DocumentSource, MouseEventType}; +use dom::document::{Document, IsHTMLDocument, DocumentHelpers, DocumentProgressHandler}; +use dom::document::{DocumentProgressTask, DocumentSource, MouseEventType}; use dom::element::{Element, AttributeHandlers}; use dom::event::{EventHelpers, EventBubbles, EventCancelable}; use dom::htmliframeelement::HTMLIFrameElementHelpers; @@ -190,7 +190,7 @@ pub enum CommonScriptMsg { /// A DOM object's last pinned reference was removed (dispatched to all tasks). RefcountCleanup(TrustedReference), /// Generic message that encapsulates event handling. - RunnableMsg(Box<Runnable+Send>), + RunnableMsg(Box<Runnable + Send>), } /// Messages used to control the script event loop @@ -203,7 +203,7 @@ pub enum MainThreadScriptMsg { /// should be closed (only dispatched to ScriptTask). ExitWindow(PipelineId), /// Generic message for running tasks in the ScriptTask - MainThreadRunnableMsg(Box<MainThreadRunnable+Send>), + MainThreadRunnableMsg(Box<MainThreadRunnable + Send>), /// Begins a content-initiated load on the specified pipeline (only /// dispatched to ScriptTask). Navigate(PipelineId, LoadData), @@ -214,10 +214,10 @@ pub trait ScriptChan { /// Send a message to the associated event loop. fn send(&self, msg: CommonScriptMsg) -> Result<(), ()>; /// Clone this handle. - fn clone(&self) -> Box<ScriptChan+Send>; + fn clone(&self) -> Box<ScriptChan + Send>; } -impl OpaqueSender<CommonScriptMsg> for Box<ScriptChan+Send> { +impl OpaqueSender<CommonScriptMsg> for Box<ScriptChan + Send> { fn send(&self, msg: CommonScriptMsg) { ScriptChan::send(&**self, msg).unwrap(); } @@ -267,10 +267,10 @@ pub struct SendableMainThreadScriptChan(pub Sender<CommonScriptMsg>); impl ScriptChan for SendableMainThreadScriptChan { fn send(&self, msg: CommonScriptMsg) -> Result<(), ()> { let SendableMainThreadScriptChan(ref chan) = *self; - return chan.send(msg).map_err(|_| ()); + chan.send(msg).map_err(|_| ()) } - fn clone(&self) -> Box<ScriptChan+Send> { + fn clone(&self) -> Box<ScriptChan + Send> { let SendableMainThreadScriptChan(ref chan) = *self; box SendableMainThreadScriptChan((*chan).clone()) } @@ -294,7 +294,7 @@ impl ScriptChan for MainThreadScriptChan { return chan.send(MainThreadScriptMsg::Common(msg)).map_err(|_| ()); } - fn clone(&self) -> Box<ScriptChan+Send> { + fn clone(&self) -> Box<ScriptChan + Send> { let MainThreadScriptChan(ref chan) = *self; box MainThreadScriptChan((*chan).clone()) } @@ -436,8 +436,8 @@ impl ScriptTaskFactory for ScriptTask { ScriptLayoutChan::new(chan, port) } - fn clone_layout_channel(_phantom: Option<&mut ScriptTask>, pair: &OpaqueScriptLayoutChannel) -> Box<Any+Send> { - box pair.sender() as Box<Any+Send> + fn clone_layout_channel(_phantom: Option<&mut ScriptTask>, pair: &OpaqueScriptLayoutChannel) -> Box<Any + Send> { + box pair.sender() as Box<Any + Send> } fn create(_phantom: Option<&mut ScriptTask>, @@ -550,7 +550,7 @@ unsafe extern "C" fn debug_gc_callback(_rt: *mut JSRuntime, status: JSGCStatus, unsafe extern "C" fn shadow_check_callback(_cx: *mut JSContext, _object: HandleObject, _id: HandleId) -> DOMProxyShadowsResult { // XXX implement me - return DOMProxyShadowsResult::ShadowCheckFailed; + DOMProxyShadowsResult::ShadowCheckFailed } impl ScriptTask { @@ -709,7 +709,7 @@ impl ScriptTask { } } - for (id, size) in resizes.into_iter() { + for (id, size) in resizes { self.handle_event(id, ResizeEvent(size)); } @@ -814,7 +814,7 @@ impl ScriptTask { } // Process the gathered events. - for msg in sequential.into_iter() { + for msg in sequential { match msg { MixedMessage::FromConstellation(ConstellationControlMsg::ExitPipeline(id, exit_type)) => { if self.handle_exit_pipeline_msg(id, exit_type) { @@ -1062,7 +1062,7 @@ impl ScriptTask { return ScriptState::DocumentLoading; } - return ScriptState::DocumentLoaded; + ScriptState::DocumentLoaded } fn handle_new_layout(&self, new_layout_info: NewLayoutInfo) { @@ -1188,23 +1188,26 @@ impl ScriptTask { let mut urls = vec![]; let mut dom_tree_size = 0; let mut reports = vec![]; - for it_page in self.root_page().iter() { - let current_url = it_page.document().url().serialize(); - urls.push(current_url.clone()); - for child in NodeCast::from_ref(&*it_page.document()).traverse_preorder() { - let target = EventTargetCast::from_ref(&*child); + if let Some(root_page) = self.page.borrow().as_ref() { + for it_page in root_page.iter() { + let current_url = it_page.document().url().serialize(); + urls.push(current_url.clone()); + + for child in NodeCast::from_ref(&*it_page.document()).traverse_preorder() { + let target = EventTargetCast::from_ref(&*child); + dom_tree_size += heap_size_of_eventtarget(target); + } + let window = it_page.window(); + let target = EventTargetCast::from_ref(&*window); dom_tree_size += heap_size_of_eventtarget(target); + + reports.push(Report { + path: path![format!("url({})", current_url), "dom-tree"], + kind: ReportKind::ExplicitJemallocHeapSize, + size: dom_tree_size, + }) } - let window = it_page.window(); - let target = EventTargetCast::from_ref(&*window); - dom_tree_size += heap_size_of_eventtarget(target); - - reports.push(Report { - path: path![format!("url({})", current_url), "dom-tree"], - kind: ReportKind::ExplicitJemallocHeapSize, - size: dom_tree_size, - }) } let path_seg = format!("url({})", urls.join(", ")); reports.extend(ScriptTask::get_reports(self.get_cx(), path_seg)); @@ -1403,7 +1406,7 @@ impl ScriptTask { if let Some(ref mut child_page) = page.remove(id) { shut_down_layout(&*child_page, exit_type); } - return false; + false } /// Handles when layout task finishes all animation in one tick @@ -1547,7 +1550,7 @@ impl ScriptTask { DocumentSource::FromParser, loader); - let frame_element = frame_element.r().map(|elem| ElementCast::from_ref(elem)); + let frame_element = frame_element.r().map(ElementCast::from_ref); window.r().init_browsing_context(document.r(), frame_element); // Create the root frame @@ -1649,7 +1652,7 @@ impl ScriptTask { let document = page.document(); let mut prev_mouse_over_targets: RootedVec<JS<Node>> = RootedVec::new(); - for target in self.mouse_over_targets.borrow_mut().iter() { + for target in &*self.mouse_over_targets.borrow_mut() { prev_mouse_over_targets.push(target.clone()); } @@ -1660,7 +1663,7 @@ impl ScriptTask { document.r().handle_mouse_move_event(self.js_runtime.rt(), point, &mut mouse_over_targets); // Notify Constellation about anchors that are no longer mouse over targets. - for target in prev_mouse_over_targets.iter() { + for target in &*prev_mouse_over_targets { if !mouse_over_targets.contains(target) { if target.root().r().is_anchor_element() { let event = ConstellationMsg::NodeStatus(None); @@ -1672,7 +1675,7 @@ impl ScriptTask { } // Notify Constellation about the topmost anchor mouse over target. - for target in mouse_over_targets.iter() { + for target in &*mouse_over_targets { let target = target.root(); if target.r().is_anchor_element() { let element = ElementCast::to_ref(target.r()).unwrap(); @@ -1933,7 +1936,7 @@ fn shut_down_layout(page_tree: &Rc<Page>, exit_type: PipelineExitType) { } // Destroy the layout task. If there were node leaks, layout will now crash safely. - for chan in channels.into_iter() { + for chan in channels { chan.send(layout_interface::Msg::ExitNow(exit_type)).ok(); } } |