mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
devtools: handle script task panics gracefully in ConsoleActor.
This commit is contained in:
parent
92a8c7a80c
commit
b328c57caa
6 changed files with 44 additions and 31 deletions
|
@ -21,7 +21,7 @@ pub trait Actor : Any {
|
||||||
registry: &ActorRegistry,
|
registry: &ActorRegistry,
|
||||||
msg_type: &String,
|
msg_type: &String,
|
||||||
msg: &json::JsonObject,
|
msg: &json::JsonObject,
|
||||||
stream: &mut TcpStream) -> bool;
|
stream: &mut TcpStream) -> Result<bool, ()>;
|
||||||
fn name(&self) -> String;
|
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
|
/// 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.
|
/// 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();
|
let to = msg.get(&"to".to_string()).unwrap().as_string().unwrap();
|
||||||
match self.actors.get(&to.to_string()) {
|
match self.actors.get(&to.to_string()) {
|
||||||
None => println!("message received for unknown actor \"{:s}\"", to),
|
None => println!("message received for unknown actor \"{:s}\"", to),
|
||||||
Some(actor) => {
|
Some(actor) => {
|
||||||
let msg_type = msg.get(&"type".to_string()).unwrap().as_string().unwrap();
|
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}\"",
|
println!("unexpected message type \"{:s}\" found for actor \"{:s}\"",
|
||||||
msg_type, to);
|
msg_type, to);
|
||||||
}
|
}
|
||||||
|
@ -164,5 +167,6 @@ impl ActorRegistry {
|
||||||
for actor in new_actors.into_iter() {
|
for actor in new_actors.into_iter() {
|
||||||
self.actors.insert(actor.name().to_string(), actor);
|
self.actors.insert(actor.name().to_string(), actor);
|
||||||
}
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -118,8 +118,8 @@ impl Actor for ConsoleActor {
|
||||||
_registry: &ActorRegistry,
|
_registry: &ActorRegistry,
|
||||||
msg_type: &String,
|
msg_type: &String,
|
||||||
msg: &json::JsonObject,
|
msg: &json::JsonObject,
|
||||||
stream: &mut TcpStream) -> bool {
|
stream: &mut TcpStream) -> Result<bool, ()> {
|
||||||
match msg_type.as_slice() {
|
Ok(match msg_type.as_slice() {
|
||||||
"getCachedMessages" => {
|
"getCachedMessages" => {
|
||||||
let types = msg.get(&"messageTypes".to_string()).unwrap().as_list().unwrap();
|
let types = msg.get(&"messageTypes".to_string()).unwrap().as_list().unwrap();
|
||||||
let /*mut*/ messages = vec!();
|
let /*mut*/ messages = vec!();
|
||||||
|
@ -223,7 +223,7 @@ impl Actor for ConsoleActor {
|
||||||
self.script_chan.send(EvaluateJS(self.pipeline, input.clone(), chan));
|
self.script_chan.send(EvaluateJS(self.pipeline, input.clone(), chan));
|
||||||
|
|
||||||
//TODO: extract conversion into protocol module or some other useful place
|
//TODO: extract conversion into protocol module or some other useful place
|
||||||
let result = match port.recv() {
|
let result = match try!(port.recv_opt()) {
|
||||||
VoidValue => {
|
VoidValue => {
|
||||||
let mut m = TreeMap::new();
|
let mut m = TreeMap::new();
|
||||||
m.insert("type".to_string(), "undefined".to_string().to_json());
|
m.insert("type".to_string(), "undefined".to_string().to_json());
|
||||||
|
@ -285,6 +285,6 @@ impl Actor for ConsoleActor {
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => false
|
_ => false
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,8 +66,8 @@ impl Actor for HighlighterActor {
|
||||||
_registry: &ActorRegistry,
|
_registry: &ActorRegistry,
|
||||||
msg_type: &String,
|
msg_type: &String,
|
||||||
_msg: &json::JsonObject,
|
_msg: &json::JsonObject,
|
||||||
stream: &mut TcpStream) -> bool {
|
stream: &mut TcpStream) -> Result<bool, ()> {
|
||||||
match msg_type.as_slice() {
|
Ok(match msg_type.as_slice() {
|
||||||
"showBoxModel" => {
|
"showBoxModel" => {
|
||||||
let msg = ShowBoxModelReply {
|
let msg = ShowBoxModelReply {
|
||||||
from: self.name(),
|
from: self.name(),
|
||||||
|
@ -85,7 +85,7 @@ impl Actor for HighlighterActor {
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,8 +103,8 @@ impl Actor for NodeActor {
|
||||||
registry: &ActorRegistry,
|
registry: &ActorRegistry,
|
||||||
msg_type: &String,
|
msg_type: &String,
|
||||||
msg: &json::JsonObject,
|
msg: &json::JsonObject,
|
||||||
stream: &mut TcpStream) -> bool {
|
stream: &mut TcpStream) -> Result<bool, ()> {
|
||||||
match msg_type.as_slice() {
|
Ok(match msg_type.as_slice() {
|
||||||
"modifyAttributes" => {
|
"modifyAttributes" => {
|
||||||
let target = msg.get(&"to".to_string()).unwrap().as_string().unwrap();
|
let target = msg.get(&"to".to_string()).unwrap().as_string().unwrap();
|
||||||
let mods = msg.get(&"modifications".to_string()).unwrap().as_list().unwrap();
|
let mods = msg.get(&"modifications".to_string()).unwrap().as_list().unwrap();
|
||||||
|
@ -123,7 +123,7 @@ impl Actor for NodeActor {
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -276,8 +276,8 @@ impl Actor for WalkerActor {
|
||||||
registry: &ActorRegistry,
|
registry: &ActorRegistry,
|
||||||
msg_type: &String,
|
msg_type: &String,
|
||||||
msg: &json::JsonObject,
|
msg: &json::JsonObject,
|
||||||
stream: &mut TcpStream) -> bool {
|
stream: &mut TcpStream) -> Result<bool, ()> {
|
||||||
match msg_type.as_slice() {
|
Ok(match msg_type.as_slice() {
|
||||||
"querySelector" => {
|
"querySelector" => {
|
||||||
let msg = QuerySelectorReply {
|
let msg = QuerySelectorReply {
|
||||||
from: self.name(),
|
from: self.name(),
|
||||||
|
@ -329,7 +329,7 @@ impl Actor for WalkerActor {
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -421,8 +421,8 @@ impl Actor for PageStyleActor {
|
||||||
registry: &ActorRegistry,
|
registry: &ActorRegistry,
|
||||||
msg_type: &String,
|
msg_type: &String,
|
||||||
msg: &json::JsonObject,
|
msg: &json::JsonObject,
|
||||||
stream: &mut TcpStream) -> bool {
|
stream: &mut TcpStream) -> Result<bool, ()> {
|
||||||
match msg_type.as_slice() {
|
Ok(match msg_type.as_slice() {
|
||||||
"getApplied" => {
|
"getApplied" => {
|
||||||
//TODO: query script for relevant applied styles to node (msg.node)
|
//TODO: query script for relevant applied styles to node (msg.node)
|
||||||
let msg = GetAppliedReply {
|
let msg = GetAppliedReply {
|
||||||
|
@ -479,7 +479,7 @@ impl Actor for PageStyleActor {
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -492,8 +492,8 @@ impl Actor for InspectorActor {
|
||||||
registry: &ActorRegistry,
|
registry: &ActorRegistry,
|
||||||
msg_type: &String,
|
msg_type: &String,
|
||||||
_msg: &json::JsonObject,
|
_msg: &json::JsonObject,
|
||||||
stream: &mut TcpStream) -> bool {
|
stream: &mut TcpStream) -> Result<bool, ()> {
|
||||||
match msg_type.as_slice() {
|
Ok(match msg_type.as_slice() {
|
||||||
"getWalker" => {
|
"getWalker" => {
|
||||||
if self.walker.borrow().is_none() {
|
if self.walker.borrow().is_none() {
|
||||||
let walker = WalkerActor {
|
let walker = WalkerActor {
|
||||||
|
@ -569,6 +569,6 @@ impl Actor for InspectorActor {
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,8 +54,8 @@ impl Actor for RootActor {
|
||||||
registry: &ActorRegistry,
|
registry: &ActorRegistry,
|
||||||
msg_type: &String,
|
msg_type: &String,
|
||||||
_msg: &json::JsonObject,
|
_msg: &json::JsonObject,
|
||||||
stream: &mut TcpStream) -> bool {
|
stream: &mut TcpStream) -> Result<bool, ()> {
|
||||||
match msg_type.as_slice() {
|
Ok(match msg_type.as_slice() {
|
||||||
"listAddons" => {
|
"listAddons" => {
|
||||||
let actor = ErrorReply {
|
let actor = ErrorReply {
|
||||||
from: "root".to_string(),
|
from: "root".to_string(),
|
||||||
|
@ -80,7 +80,7 @@ impl Actor for RootActor {
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => false
|
_ => false
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -78,8 +78,8 @@ impl Actor for TabActor {
|
||||||
registry: &ActorRegistry,
|
registry: &ActorRegistry,
|
||||||
msg_type: &String,
|
msg_type: &String,
|
||||||
_msg: &json::JsonObject,
|
_msg: &json::JsonObject,
|
||||||
stream: &mut TcpStream) -> bool {
|
stream: &mut TcpStream) -> Result<bool, ()> {
|
||||||
match msg_type.as_slice() {
|
Ok(match msg_type.as_slice() {
|
||||||
"reconfigure" => {
|
"reconfigure" => {
|
||||||
stream.write_json_packet(&ReconfigureReply { from: self.name() });
|
stream.write_json_packet(&ReconfigureReply { from: self.name() });
|
||||||
true
|
true
|
||||||
|
@ -125,7 +125,7 @@ impl Actor for TabActor {
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => false
|
_ => false
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -101,9 +101,18 @@ fn run_server(receiver: Receiver<DevtoolsControlMsg>, port: u16) {
|
||||||
|
|
||||||
'outer: loop {
|
'outer: loop {
|
||||||
match stream.read_json_packet() {
|
match stream.read_json_packet() {
|
||||||
Ok(json_packet) =>
|
Ok(json_packet) => {
|
||||||
actors.lock().handle_message(json_packet.as_object().unwrap(),
|
match actors.lock().handle_message(json_packet.as_object().unwrap(),
|
||||||
&mut stream),
|
&mut stream) {
|
||||||
|
Ok(()) => {},
|
||||||
|
Err(()) => {
|
||||||
|
println!("error: devtools actor stopped responding");
|
||||||
|
stream.close_read();
|
||||||
|
stream.close_write();
|
||||||
|
break 'outer
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
println!("error: {}", e.desc);
|
println!("error: {}", e.desc);
|
||||||
break 'outer
|
break 'outer
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue