servo: Merge #4220 - devtools: handle script task panics gracefully in ConsoleActor (from eddyb:devtools-panic); r=jdm

r? @jdm

Source-Repo: https://github.com/servo/servo
Source-Revision: b8444f96f82791d7bbac456dfe23b71b2b09fea3
This commit is contained in:
Eduard Burtescu 2014-12-04 18:04:06 -07:00
Родитель 5ae1b287f9
Коммит 149f986db8
6 изменённых файлов: 44 добавлений и 31 удалений

Просмотреть файл

@ -21,7 +21,7 @@ pub trait Actor : Any {
registry: &ActorRegistry,
msg_type: &String,
msg: &json::JsonObject,
stream: &mut TcpStream) -> bool;
stream: &mut TcpStream) -> Result<bool, ()>;
fn name(&self) -> String;
}
@ -148,13 +148,16 @@ impl ActorRegistry {
/// Attempt to process a message as directed by its `to` property. If the actor is not
/// found or does not indicate that it knew how to process the message, ignore the failure.
pub fn handle_message(&mut self, msg: &json::JsonObject, stream: &mut TcpStream) {
pub fn handle_message(&mut self,
msg: &json::JsonObject,
stream: &mut TcpStream)
-> Result<(), ()> {
let to = msg.get(&"to".to_string()).unwrap().as_string().unwrap();
match self.actors.get(&to.to_string()) {
None => println!("message received for unknown actor \"{:s}\"", to),
Some(actor) => {
let msg_type = msg.get(&"type".to_string()).unwrap().as_string().unwrap();
if !actor.handle_message(self, &msg_type.to_string(), msg, stream) {
if !try!(actor.handle_message(self, &msg_type.to_string(), msg, stream)) {
println!("unexpected message type \"{:s}\" found for actor \"{:s}\"",
msg_type, to);
}
@ -164,5 +167,6 @@ impl ActorRegistry {
for actor in new_actors.into_iter() {
self.actors.insert(actor.name().to_string(), actor);
}
Ok(())
}
}

Просмотреть файл

@ -118,8 +118,8 @@ impl Actor for ConsoleActor {
_registry: &ActorRegistry,
msg_type: &String,
msg: &json::JsonObject,
stream: &mut TcpStream) -> bool {
match msg_type.as_slice() {
stream: &mut TcpStream) -> Result<bool, ()> {
Ok(match msg_type.as_slice() {
"getCachedMessages" => {
let types = msg.get(&"messageTypes".to_string()).unwrap().as_list().unwrap();
let /*mut*/ messages = vec!();
@ -223,7 +223,7 @@ impl Actor for ConsoleActor {
self.script_chan.send(EvaluateJS(self.pipeline, input.clone(), chan));
//TODO: extract conversion into protocol module or some other useful place
let result = match port.recv() {
let result = match try!(port.recv_opt()) {
VoidValue => {
let mut m = TreeMap::new();
m.insert("type".to_string(), "undefined".to_string().to_json());
@ -285,6 +285,6 @@ impl Actor for ConsoleActor {
}
_ => false
}
})
}
}

Просмотреть файл

@ -66,8 +66,8 @@ impl Actor for HighlighterActor {
_registry: &ActorRegistry,
msg_type: &String,
_msg: &json::JsonObject,
stream: &mut TcpStream) -> bool {
match msg_type.as_slice() {
stream: &mut TcpStream) -> Result<bool, ()> {
Ok(match msg_type.as_slice() {
"showBoxModel" => {
let msg = ShowBoxModelReply {
from: self.name(),
@ -85,7 +85,7 @@ impl Actor for HighlighterActor {
}
_ => false,
}
})
}
}
@ -103,8 +103,8 @@ impl Actor for NodeActor {
registry: &ActorRegistry,
msg_type: &String,
msg: &json::JsonObject,
stream: &mut TcpStream) -> bool {
match msg_type.as_slice() {
stream: &mut TcpStream) -> Result<bool, ()> {
Ok(match msg_type.as_slice() {
"modifyAttributes" => {
let target = msg.get(&"to".to_string()).unwrap().as_string().unwrap();
let mods = msg.get(&"modifications".to_string()).unwrap().as_list().unwrap();
@ -123,7 +123,7 @@ impl Actor for NodeActor {
}
_ => false,
}
})
}
}
@ -276,8 +276,8 @@ impl Actor for WalkerActor {
registry: &ActorRegistry,
msg_type: &String,
msg: &json::JsonObject,
stream: &mut TcpStream) -> bool {
match msg_type.as_slice() {
stream: &mut TcpStream) -> Result<bool, ()> {
Ok(match msg_type.as_slice() {
"querySelector" => {
let msg = QuerySelectorReply {
from: self.name(),
@ -329,7 +329,7 @@ impl Actor for WalkerActor {
}
_ => false,
}
})
}
}
@ -421,8 +421,8 @@ impl Actor for PageStyleActor {
registry: &ActorRegistry,
msg_type: &String,
msg: &json::JsonObject,
stream: &mut TcpStream) -> bool {
match msg_type.as_slice() {
stream: &mut TcpStream) -> Result<bool, ()> {
Ok(match msg_type.as_slice() {
"getApplied" => {
//TODO: query script for relevant applied styles to node (msg.node)
let msg = GetAppliedReply {
@ -479,7 +479,7 @@ impl Actor for PageStyleActor {
}
_ => false,
}
})
}
}
@ -492,8 +492,8 @@ impl Actor for InspectorActor {
registry: &ActorRegistry,
msg_type: &String,
_msg: &json::JsonObject,
stream: &mut TcpStream) -> bool {
match msg_type.as_slice() {
stream: &mut TcpStream) -> Result<bool, ()> {
Ok(match msg_type.as_slice() {
"getWalker" => {
if self.walker.borrow().is_none() {
let walker = WalkerActor {
@ -569,6 +569,6 @@ impl Actor for InspectorActor {
}
_ => false,
}
})
}
}

Просмотреть файл

@ -54,8 +54,8 @@ impl Actor for RootActor {
registry: &ActorRegistry,
msg_type: &String,
_msg: &json::JsonObject,
stream: &mut TcpStream) -> bool {
match msg_type.as_slice() {
stream: &mut TcpStream) -> Result<bool, ()> {
Ok(match msg_type.as_slice() {
"listAddons" => {
let actor = ErrorReply {
from: "root".to_string(),
@ -80,7 +80,7 @@ impl Actor for RootActor {
}
_ => false
}
})
}
}

Просмотреть файл

@ -78,8 +78,8 @@ impl Actor for TabActor {
registry: &ActorRegistry,
msg_type: &String,
_msg: &json::JsonObject,
stream: &mut TcpStream) -> bool {
match msg_type.as_slice() {
stream: &mut TcpStream) -> Result<bool, ()> {
Ok(match msg_type.as_slice() {
"reconfigure" => {
stream.write_json_packet(&ReconfigureReply { from: self.name() });
true
@ -125,7 +125,7 @@ impl Actor for TabActor {
}
_ => false
}
})
}
}

Просмотреть файл

@ -101,9 +101,18 @@ fn run_server(receiver: Receiver<DevtoolsControlMsg>, port: u16) {
'outer: loop {
match stream.read_json_packet() {
Ok(json_packet) =>
actors.lock().handle_message(json_packet.as_object().unwrap(),
&mut stream),
Ok(json_packet) => {
match actors.lock().handle_message(json_packet.as_object().unwrap(),
&mut stream) {
Ok(()) => {},
Err(()) => {
println!("error: devtools actor stopped responding");
stream.close_read();
stream.close_write();
break 'outer
}
}
}
Err(e) => {
println!("error: {}", e.desc);
break 'outer