diff options
Diffstat (limited to 'components/devtools/actors/console.rs')
-rw-r--r-- | components/devtools/actors/console.rs | 43 |
1 files changed, 22 insertions, 21 deletions
diff --git a/components/devtools/actors/console.rs b/components/devtools/actors/console.rs index 5628506d5af..d8e88cdba8b 100644 --- a/components/devtools/actors/console.rs +++ b/components/devtools/actors/console.rs @@ -13,18 +13,19 @@ use devtools_traits::{EvaluateJS, NullValue, VoidValue, NumberValue, StringValue use devtools_traits::{ActorValue, DevtoolScriptControlMsg}; use servo_msg::constellation_msg::PipelineId; -use collections::TreeMap; +use collections::BTreeMap; use core::cell::RefCell; use serialize::json::{mod, Json, ToJson}; use std::io::TcpStream; use std::num::Float; +use std::sync::mpsc::{channel, Sender}; -#[deriving(Encodable)] +#[derive(RustcEncodable)] struct StartedListenersTraits { customNetworkRequest: bool, } -#[deriving(Encodable)] +#[derive(RustcEncodable)] struct StartedListenersReply { from: String, nativeConsoleAPI: bool, @@ -32,13 +33,13 @@ struct StartedListenersReply { traits: StartedListenersTraits, } -#[deriving(Encodable)] +#[derive(RustcEncodable)] #[allow(dead_code)] struct ConsoleAPIMessage { _type: String, //FIXME: should this be __type__ instead? } -#[deriving(Encodable)] +#[derive(RustcEncodable)] #[allow(dead_code)] struct PageErrorMessage { _type: String, //FIXME: should this be __type__ instead? @@ -56,7 +57,7 @@ struct PageErrorMessage { private: bool, } -#[deriving(Encodable)] +#[derive(RustcEncodable)] #[allow(dead_code)] struct LogMessage { _type: String, //FIXME: should this be __type__ instead? @@ -64,7 +65,7 @@ struct LogMessage { message: String, } -#[deriving(Encodable)] +#[derive(RustcEncodable)] #[allow(dead_code)] enum ConsoleMessageType { ConsoleAPIType(ConsoleAPIMessage), @@ -72,26 +73,26 @@ enum ConsoleMessageType { LogMessageType(LogMessage), } -#[deriving(Encodable)] +#[derive(RustcEncodable)] struct GetCachedMessagesReply { from: String, messages: Vec<json::Object>, } -#[deriving(Encodable)] +#[derive(RustcEncodable)] struct StopListenersReply { from: String, stoppedListeners: Vec<String>, } -#[deriving(Encodable)] +#[derive(RustcEncodable)] struct AutocompleteReply { from: String, matches: Vec<String>, matchProp: String, } -#[deriving(Encodable)] +#[derive(RustcEncodable)] struct EvaluateJSReply { from: String, input: String, @@ -220,28 +221,28 @@ impl Actor for ConsoleActor { "evaluateJS" => { let input = msg.get(&"text".to_string()).unwrap().as_string().unwrap().to_string(); let (chan, port) = channel(); - self.script_chan.send(EvaluateJS(self.pipeline, input.clone(), chan)); + self.script_chan.send(EvaluateJS(self.pipeline, input.clone(), chan)).unwrap(); //TODO: extract conversion into protocol module or some other useful place - let result = match try!(port.recv_opt()) { + let result = match try!(port.recv().map_err(|_| ())) { VoidValue => { - let mut m = TreeMap::new(); + let mut m = BTreeMap::new(); m.insert("type".to_string(), "undefined".to_string().to_json()); Json::Object(m) } NullValue => { - let mut m = TreeMap::new(); + let mut m = BTreeMap::new(); m.insert("type".to_string(), "null".to_string().to_json()); Json::Object(m) } BooleanValue(val) => val.to_json(), NumberValue(val) => { if val.is_nan() { - let mut m = TreeMap::new(); + let mut m = BTreeMap::new(); m.insert("type".to_string(), "NaN".to_string().to_json()); Json::Object(m) } else if val.is_infinite() { - let mut m = TreeMap::new(); + let mut m = BTreeMap::new(); if val < 0. { m.insert("type".to_string(), "-Infinity".to_string().to_json()); } else { @@ -249,7 +250,7 @@ impl Actor for ConsoleActor { } Json::Object(m) } else if val == Float::neg_zero() { - let mut m = TreeMap::new(); + let mut m = BTreeMap::new(); m.insert("type".to_string(), "-0".to_string().to_json()); Json::Object(m) } else { @@ -259,7 +260,7 @@ impl Actor for ConsoleActor { StringValue(s) => s.to_json(), ActorValue(s) => { //TODO: make initial ActorValue message include these properties. - let mut m = TreeMap::new(); + let mut m = BTreeMap::new(); m.insert("type".to_string(), "object".to_string().to_json()); m.insert("class".to_string(), "???".to_string().to_json()); m.insert("actor".to_string(), s.to_json()); @@ -276,9 +277,9 @@ impl Actor for ConsoleActor { input: input, result: result, timestamp: 0, - exception: Json::Object(TreeMap::new()), + exception: Json::Object(BTreeMap::new()), exceptionMessage: "".to_string(), - helperResult: Json::Object(TreeMap::new()), + helperResult: Json::Object(BTreeMap::new()), }; stream.write_json_packet(&msg); true |