From 2e68821014053ebf547818e017c423a5d52717d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Fri, 8 Jul 2016 14:36:38 -0700 Subject: [PATCH] script: Implement Debug on ConstellationControlMsg to simplify script_thread.rs --- components/script/script_thread.rs | 16 ++++++--------- components/script_traits/lib.rs | 32 ++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index ec2401d6f61..1a32477b999 100644 --- a/components/script/script_thread.rs +++ b/components/script/script_thread.rs @@ -886,22 +886,12 @@ impl ScriptThread { fn handle_msg_from_constellation(&self, msg: ConstellationControlMsg) { match msg { - ConstellationControlMsg::AttachLayout(_) => - panic!("should have handled AttachLayout already"), ConstellationControlMsg::Navigate(pipeline_id, subpage_id, load_data) => self.handle_navigate(pipeline_id, Some(subpage_id), load_data), ConstellationControlMsg::SendEvent(id, event) => self.handle_event(id, event), ConstellationControlMsg::ResizeInactive(id, new_size) => self.handle_resize_inactive_msg(id, new_size), - ConstellationControlMsg::Viewport(..) => - panic!("should have handled Viewport already"), - ConstellationControlMsg::SetScrollState(..) => - panic!("should have handled SetScrollState already"), - ConstellationControlMsg::Resize(..) => - panic!("should have handled Resize already"), - ConstellationControlMsg::ExitPipeline(..) => - panic!("should have handled ExitPipeline already"), ConstellationControlMsg::GetTitle(pipeline_id) => self.handle_get_title_msg(pipeline_id), ConstellationControlMsg::Freeze(pipeline_id) => @@ -943,6 +933,12 @@ impl ScriptThread { self.handle_css_error_reporting(pipeline_id, filename, line, column, msg), ConstellationControlMsg::Reload(pipeline_id) => self.handle_reload(pipeline_id), + msg @ ConstellationControlMsg::AttachLayout(..) | + msg @ ConstellationControlMsg::Viewport(..) | + msg @ ConstellationControlMsg::SetScrollState(..) | + msg @ ConstellationControlMsg::Resize(..) | + msg @ ConstellationControlMsg::ExitPipeline(..) => + panic!("should have handled {:?} already", msg), } } diff --git a/components/script_traits/lib.rs b/components/script_traits/lib.rs index f57ed29f43c..175cc0b82f2 100644 --- a/components/script_traits/lib.rs +++ b/components/script_traits/lib.rs @@ -61,6 +61,7 @@ use profile_traits::mem; use profile_traits::time as profile_time; use serde::{Deserialize, Deserializer, Serialize, Serializer}; use std::collections::HashMap; +use std::fmt; use std::sync::mpsc::{Sender, Receiver}; use style_traits::{PagePx, ViewportPx}; use url::Url; @@ -207,6 +208,37 @@ pub enum ConstellationControlMsg { Reload(PipelineId), } +impl fmt::Debug for ConstellationControlMsg { + fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + use self::ConstellationControlMsg::*; + write!(formatter, "ConstellationMsg::{}", match *self { + AttachLayout(..) => "AttachLayout", + Resize(..) => "Resize", + ResizeInactive(..) => "ResizeInactive", + ExitPipeline(..) => "ExitPipeline", + SendEvent(..) => "SendEvent", + Viewport(..) => "Viewport", + SetScrollState(..) => "SetScrollState", + GetTitle(..) => "GetTitle", + Freeze(..) => "Freeze", + Thaw(..) => "Thaw", + ChangeFrameVisibilityStatus(..) => "ChangeFrameVisibilityStatus", + NotifyVisibilityChange(..) => "NotifyVisibilityChange", + Navigate(..) => "Navigate", + MozBrowserEvent(..) => "MozBrowserEvent", + UpdateSubpageId(..) => "UpdateSubpageId", + FocusIFrame(..) => "FocusIFrame", + WebDriverScriptCommand(..) => "WebDriverScriptCommand", + TickAllAnimations(..) => "TickAllAnimations", + WebFontLoaded(..) => "WebFontLoaded", + DispatchFrameLoadEvent { .. } => "DispatchFrameLoadEvent", + FramedContentChanged(..) => "FramedContentChanged", + ReportCSSError(..) => "ReportCSSError", + Reload(..) => "Reload", + }) + } +} + /// Used to determine if a script has any pending asynchronous activity. #[derive(Copy, Clone, Debug, PartialEq, Deserialize, Serialize)] pub enum DocumentState {