mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Auto merge of #6540 - jdm:devtoolsfix, r=glennw
Make devtools usable once more. This fixes the panic by rebasing #6189, and also makes cached messages appear once more. <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/6540) <!-- Reviewable:end -->
This commit is contained in:
commit
c04b7bbf6e
4 changed files with 81 additions and 47 deletions
|
@ -13,6 +13,7 @@ use protocol::JsonPacketStream;
|
||||||
use devtools_traits::EvaluateJSReply::{NullValue, VoidValue, NumberValue};
|
use devtools_traits::EvaluateJSReply::{NullValue, VoidValue, NumberValue};
|
||||||
use devtools_traits::EvaluateJSReply::{StringValue, BooleanValue, ActorValue};
|
use devtools_traits::EvaluateJSReply::{StringValue, BooleanValue, ActorValue};
|
||||||
use devtools_traits::{CachedConsoleMessageTypes, DevtoolScriptControlMsg, PAGE_ERROR, CONSOLE_API};
|
use devtools_traits::{CachedConsoleMessageTypes, DevtoolScriptControlMsg, PAGE_ERROR, CONSOLE_API};
|
||||||
|
use devtools_traits::CachedConsoleMessage;
|
||||||
use msg::constellation_msg::PipelineId;
|
use msg::constellation_msg::PipelineId;
|
||||||
|
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
@ -21,6 +22,19 @@ use rustc_serialize::json::{self, Json, ToJson};
|
||||||
use std::net::TcpStream;
|
use std::net::TcpStream;
|
||||||
use std::sync::mpsc::{channel, Sender};
|
use std::sync::mpsc::{channel, Sender};
|
||||||
|
|
||||||
|
trait EncodableConsoleMessage {
|
||||||
|
fn encode(&self) -> json::EncodeResult<String>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl EncodableConsoleMessage for CachedConsoleMessage {
|
||||||
|
fn encode(&self) -> json::EncodeResult<String> {
|
||||||
|
match *self {
|
||||||
|
CachedConsoleMessage::PageError(ref a) => json::encode(a),
|
||||||
|
CachedConsoleMessage::ConsoleAPI(ref a) => json::encode(a),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(RustcEncodable)]
|
#[derive(RustcEncodable)]
|
||||||
struct StartedListenersTraits {
|
struct StartedListenersTraits {
|
||||||
customNetworkRequest: bool,
|
customNetworkRequest: bool,
|
||||||
|
@ -98,7 +112,9 @@ impl Actor for ConsoleActor {
|
||||||
self.script_chan.send(DevtoolScriptControlMsg::GetCachedMessages(
|
self.script_chan.send(DevtoolScriptControlMsg::GetCachedMessages(
|
||||||
self.pipeline, message_types, chan)).unwrap();
|
self.pipeline, message_types, chan)).unwrap();
|
||||||
let messages = try!(port.recv().map_err(|_| ())).into_iter().map(|message| {
|
let messages = try!(port.recv().map_err(|_| ())).into_iter().map(|message| {
|
||||||
json::encode(&message).unwrap().to_json().as_object().unwrap().to_owned()
|
let json_string = message.encode().unwrap();
|
||||||
|
let json = Json::from_str(&json_string).unwrap();
|
||||||
|
json.as_object().unwrap().to_owned()
|
||||||
}).collect();
|
}).collect();
|
||||||
|
|
||||||
let msg = GetCachedMessagesReply {
|
let msg = GetCachedMessagesReply {
|
||||||
|
|
|
@ -250,7 +250,10 @@ fn run_server(sender: Sender<DevtoolsControlMsg>,
|
||||||
id: PipelineId,
|
id: PipelineId,
|
||||||
console_message: ConsoleMessage,
|
console_message: ConsoleMessage,
|
||||||
actor_pipelines: &HashMap<PipelineId, String>) {
|
actor_pipelines: &HashMap<PipelineId, String>) {
|
||||||
let console_actor_name = find_console_actor(actors.clone(), id, actor_pipelines);
|
let console_actor_name = match find_console_actor(actors.clone(), id, actor_pipelines) {
|
||||||
|
Some(name) => name,
|
||||||
|
None => return,
|
||||||
|
};
|
||||||
let actors = actors.lock().unwrap();
|
let actors = actors.lock().unwrap();
|
||||||
let console_actor = actors.find::<ConsoleActor>(&console_actor_name);
|
let console_actor = actors.find::<ConsoleActor>(&console_actor_name);
|
||||||
let msg = ConsoleAPICall {
|
let msg = ConsoleAPICall {
|
||||||
|
@ -278,12 +281,15 @@ fn run_server(sender: Sender<DevtoolsControlMsg>,
|
||||||
|
|
||||||
fn find_console_actor(actors: Arc<Mutex<ActorRegistry>>,
|
fn find_console_actor(actors: Arc<Mutex<ActorRegistry>>,
|
||||||
id: PipelineId,
|
id: PipelineId,
|
||||||
actor_pipelines: &HashMap<PipelineId, String>) -> String {
|
actor_pipelines: &HashMap<PipelineId, String>) -> Option<String> {
|
||||||
let actors = actors.lock().unwrap();
|
let actors = actors.lock().unwrap();
|
||||||
let ref tab_actor_name = (*actor_pipelines)[&id];
|
let tab_actor_name = match (*actor_pipelines).get(&id) {
|
||||||
|
Some(name) => name,
|
||||||
|
None => return None,
|
||||||
|
};
|
||||||
let tab_actor = actors.find::<TabActor>(tab_actor_name);
|
let tab_actor = actors.find::<TabActor>(tab_actor_name);
|
||||||
let console_actor_name = tab_actor.console.clone();
|
let console_actor_name = tab_actor.console.clone();
|
||||||
return console_actor_name;
|
return Some(console_actor_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_network_event(actors: Arc<Mutex<ActorRegistry>>,
|
fn handle_network_event(actors: Arc<Mutex<ActorRegistry>>,
|
||||||
|
@ -294,7 +300,11 @@ fn run_server(sender: Sender<DevtoolsControlMsg>,
|
||||||
request_id: String,
|
request_id: String,
|
||||||
network_event: NetworkEvent) {
|
network_event: NetworkEvent) {
|
||||||
|
|
||||||
let console_actor_name = find_console_actor(actors.clone(), pipeline_id, actor_pipelines);
|
let console_actor_name = match find_console_actor(actors.clone(), pipeline_id,
|
||||||
|
actor_pipelines) {
|
||||||
|
Some(name) => name,
|
||||||
|
None => return,
|
||||||
|
};
|
||||||
let netevent_actor_name = find_network_event_actor(actors.clone(), actor_requests, request_id.clone());
|
let netevent_actor_name = find_network_event_actor(actors.clone(), actor_requests, request_id.clone());
|
||||||
let mut actors = actors.lock().unwrap();
|
let mut actors = actors.lock().unwrap();
|
||||||
let actor = actors.find_mut::<NetworkEventActor>(&netevent_actor_name);
|
let actor = actors.find_mut::<NetworkEventActor>(&netevent_actor_name);
|
||||||
|
|
|
@ -175,32 +175,37 @@ bitflags! {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(RustcEncodable)]
|
#[derive(RustcEncodable)]
|
||||||
|
pub struct PageError {
|
||||||
|
pub _type: String,
|
||||||
|
pub errorMessage: String,
|
||||||
|
pub sourceName: String,
|
||||||
|
pub lineText: String,
|
||||||
|
pub lineNumber: u32,
|
||||||
|
pub columnNumber: u32,
|
||||||
|
pub category: String,
|
||||||
|
pub timeStamp: u64,
|
||||||
|
pub error: bool,
|
||||||
|
pub warning: bool,
|
||||||
|
pub exception: bool,
|
||||||
|
pub strict: bool,
|
||||||
|
pub private: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(RustcEncodable)]
|
||||||
|
pub struct ConsoleAPI {
|
||||||
|
pub _type: String,
|
||||||
|
pub level: String,
|
||||||
|
pub filename: String,
|
||||||
|
pub lineNumber: u32,
|
||||||
|
pub functionName: String,
|
||||||
|
pub timeStamp: u64,
|
||||||
|
pub private: bool,
|
||||||
|
pub arguments: Vec<String>,
|
||||||
|
}
|
||||||
|
|
||||||
pub enum CachedConsoleMessage {
|
pub enum CachedConsoleMessage {
|
||||||
PageError {
|
PageError(PageError),
|
||||||
__type__: String,
|
ConsoleAPI(ConsoleAPI),
|
||||||
errorMessage: String,
|
|
||||||
sourceName: String,
|
|
||||||
lineText: String,
|
|
||||||
lineNumber: u32,
|
|
||||||
columnNumber: u32,
|
|
||||||
category: String,
|
|
||||||
timeStamp: u64,
|
|
||||||
error: bool,
|
|
||||||
warning: bool,
|
|
||||||
exception: bool,
|
|
||||||
strict: bool,
|
|
||||||
private: bool,
|
|
||||||
},
|
|
||||||
ConsoleAPI {
|
|
||||||
__type__: String,
|
|
||||||
level: String,
|
|
||||||
filename: String,
|
|
||||||
lineNumber: u32,
|
|
||||||
functionName: String,
|
|
||||||
timeStamp: u64,
|
|
||||||
private: bool,
|
|
||||||
arguments: Vec<String>,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
use devtools_traits::{CachedConsoleMessage, CachedConsoleMessageTypes, PAGE_ERROR, CONSOLE_API};
|
use devtools_traits::{CachedConsoleMessage, CachedConsoleMessageTypes, PAGE_ERROR, CONSOLE_API};
|
||||||
use devtools_traits::{EvaluateJSReply, NodeInfo, Modification, TimelineMarker, TimelineMarkerType};
|
use devtools_traits::{EvaluateJSReply, NodeInfo, Modification, TimelineMarker, TimelineMarkerType};
|
||||||
|
use devtools_traits::{ConsoleAPI, PageError};
|
||||||
use dom::bindings::conversions::FromJSValConvertible;
|
use dom::bindings::conversions::FromJSValConvertible;
|
||||||
use dom::bindings::conversions::StringificationBehavior;
|
use dom::bindings::conversions::StringificationBehavior;
|
||||||
use dom::bindings::js::Root;
|
use dom::bindings::js::Root;
|
||||||
|
@ -104,23 +105,10 @@ pub fn handle_get_cached_messages(_pipeline_id: PipelineId,
|
||||||
//TODO: check the messageTypes against a global Cache for console messages and page exceptions
|
//TODO: check the messageTypes against a global Cache for console messages and page exceptions
|
||||||
let mut messages = Vec::new();
|
let mut messages = Vec::new();
|
||||||
if message_types.contains(PAGE_ERROR) {
|
if message_types.contains(PAGE_ERROR) {
|
||||||
//TODO: do for real
|
|
||||||
messages.push(CachedConsoleMessage::ConsoleAPI {
|
|
||||||
__type__: "consoleAPICall".to_owned(),
|
|
||||||
level: "error".to_owned(),
|
|
||||||
filename: "http://localhost/~mihai/mozilla/test.html".to_owned(),
|
|
||||||
lineNumber: 0,
|
|
||||||
functionName: String::new(),
|
|
||||||
timeStamp: 0,
|
|
||||||
private: false,
|
|
||||||
arguments: Vec::new(),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
if message_types.contains(CONSOLE_API) {
|
|
||||||
//TODO: make script error reporter pass all reported errors
|
//TODO: make script error reporter pass all reported errors
|
||||||
// to devtools and cache them for returning here.
|
// to devtools and cache them for returning here.
|
||||||
messages.push(CachedConsoleMessage::PageError {
|
let msg = PageError {
|
||||||
__type__: "pageError".to_owned(),
|
_type: "PageError".to_owned(),
|
||||||
errorMessage: "page error test".to_owned(),
|
errorMessage: "page error test".to_owned(),
|
||||||
sourceName: String::new(),
|
sourceName: String::new(),
|
||||||
lineText: String::new(),
|
lineText: String::new(),
|
||||||
|
@ -133,7 +121,22 @@ pub fn handle_get_cached_messages(_pipeline_id: PipelineId,
|
||||||
exception: false,
|
exception: false,
|
||||||
strict: false,
|
strict: false,
|
||||||
private: false,
|
private: false,
|
||||||
})
|
};
|
||||||
|
messages.push(CachedConsoleMessage::PageError(msg));
|
||||||
|
}
|
||||||
|
if message_types.contains(CONSOLE_API) {
|
||||||
|
//TODO: do for real
|
||||||
|
let msg = ConsoleAPI {
|
||||||
|
_type: "ConsoleAPI".to_owned(),
|
||||||
|
level: "error".to_owned(),
|
||||||
|
filename: "http://localhost/~mihai/mozilla/test.html".to_owned(),
|
||||||
|
lineNumber: 0,
|
||||||
|
functionName: String::new(),
|
||||||
|
timeStamp: 0,
|
||||||
|
private: false,
|
||||||
|
arguments: vec!["console error test".to_owned()],
|
||||||
|
};
|
||||||
|
messages.push(CachedConsoleMessage::ConsoleAPI(msg));
|
||||||
}
|
}
|
||||||
reply.send(messages).unwrap();
|
reply.send(messages).unwrap();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue