Auto merge of #11462 - Manishearth:devtools-fixes, r=Ms2ger

devtools: fix segfault, remove println

This fixes the segfault from #11457 by adding an autocompartment.

It also removes the print statements which clog the command line and replaces
them with `debug!()`

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #11457 (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [x] These changes do not require tests because we don't have full-server
  devtools tests

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/11462)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-05-27 08:49:43 -05:00
commit 3ab5c07559
9 changed files with 20 additions and 12 deletions

View file

@ -19,3 +19,4 @@ serde = "0.7"
serde_json = "0.7"
serde_macros = "0.7"
time = "0.1"
log = "0.3.5"

View file

@ -92,7 +92,7 @@ impl ActorRegistry {
}
pub fn register_script_actor(&self, script_id: String, actor: String) {
println!("registering {} ({})", actor, script_id);
debug!("registering {} ({})", actor, script_id);
let mut script_actors = self.script_actors.borrow_mut();
script_actors.insert(script_id, actor);
}
@ -110,7 +110,7 @@ impl ActorRegistry {
pub fn actor_to_script(&self, actor: String) -> String {
for (key, value) in &*self.script_actors.borrow() {
println!("checking {}", value);
debug!("checking {}", value);
if *value == actor {
return key.to_owned();
}
@ -156,12 +156,12 @@ impl ActorRegistry {
let to = msg.get("to").unwrap().as_string().unwrap();
match self.actors.get(to) {
None => println!("message received for unknown actor \"{}\"", to),
None => debug!("message received for unknown actor \"{}\"", to),
Some(actor) => {
let msg_type = msg.get("type").unwrap().as_string().unwrap();
if try!(actor.handle_message(self, msg_type, msg, stream))
!= ActorMessageStatus::Processed {
println!("unexpected message type \"{}\" found for actor \"{}\"",
debug!("unexpected message type \"{}\" found for actor \"{}\"",
msg_type, to);
}
}

View file

@ -110,7 +110,7 @@ impl Actor for ConsoleActor {
match str_type {
"PageError" => message_types.insert(PAGE_ERROR),
"ConsoleAPI" => message_types.insert(CONSOLE_API),
s => println!("unrecognized message type requested: \"{}\"", s),
s => debug!("unrecognized message type requested: \"{}\"", s),
};
};
let (chan, port) = ipc::channel().unwrap();

View file

@ -23,6 +23,8 @@
extern crate devtools_traits;
extern crate hyper;
extern crate ipc_channel;
#[macro_use]
extern crate log;
extern crate msg;
extern crate serde;
extern crate serde_json;
@ -204,7 +206,7 @@ fn run_server(sender: Sender<DevtoolsControlMsg>,
/// Process the input from a single devtools client until EOF.
fn handle_client(actors: Arc<Mutex<ActorRegistry>>, mut stream: TcpStream) {
println!("connection established to {}", stream.peer_addr().unwrap());
debug!("connection established to {}", stream.peer_addr().unwrap());
{
let actors = actors.lock().unwrap();
let msg = actors.find::<RootActor>("root").encodable();
@ -218,18 +220,18 @@ fn run_server(sender: Sender<DevtoolsControlMsg>,
&mut stream) {
Ok(()) => {},
Err(()) => {
println!("error: devtools actor stopped responding");
debug!("error: devtools actor stopped responding");
let _ = stream.shutdown(Shutdown::Both);
break 'outer
}
}
}
Ok(None) => {
println!("error: EOF");
debug!("error: EOF");
break 'outer
}
Err(err_msg) => {
println!("error: {}", err_msg);
debug!("error: {}", err_msg);
break 'outer
}
}

View file

@ -20,7 +20,7 @@ pub trait JsonPacketStream {
impl JsonPacketStream for TcpStream {
fn write_json_packet<T: Serialize>(&mut self, obj: &T) {
let s = serde_json::to_string(obj).unwrap();
println!("<- {}", s);
debug!("<- {}", s);
write!(self, "{}:{}", s.len(), s).unwrap();
}
@ -48,7 +48,7 @@ impl JsonPacketStream for TcpStream {
};
let mut packet = String::new();
self.take(packet_len).read_to_string(&mut packet).unwrap();
println!("{}", packet);
debug!("{}", packet);
return match serde_json::from_str(&packet) {
Ok(json) => Ok(Some(json)),
Err(err) => match err {

View file

@ -21,7 +21,7 @@ use dom::element::Element;
use dom::node::Node;
use dom::window::Window;
use ipc_channel::ipc::IpcSender;
use js::jsapi::{ObjectClassName, RootedObject, RootedValue};
use js::jsapi::{JSAutoCompartment, ObjectClassName, RootedObject, RootedValue};
use js::jsval::UndefinedValue;
use msg::constellation_msg::PipelineId;
use script_thread::get_browsing_context;
@ -35,6 +35,8 @@ pub fn handle_evaluate_js(global: &GlobalRef, eval: String, reply: IpcSender<Eva
// global.get_cx() returns a valid `JSContext` pointer, so this is safe.
let result = unsafe {
let cx = global.get_cx();
let globalhandle = global.reflector().get_jsobject();
let _ac = JSAutoCompartment::new(cx, globalhandle.get());
let mut rval = RootedValue::new(cx, UndefinedValue());
global.evaluate_js_on_global_with_result(&eval, rval.handle_mut());

View file

@ -479,6 +479,7 @@ dependencies = [
"devtools_traits 0.0.1",
"hyper 0.9.5 (registry+https://github.com/rust-lang/crates.io-index)",
"ipc-channel 0.2.2 (git+https://github.com/servo/ipc-channel)",
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"msg 0.0.1",
"plugins 0.0.1",
"serde 0.7.5 (registry+https://github.com/rust-lang/crates.io-index)",

1
ports/cef/Cargo.lock generated
View file

@ -441,6 +441,7 @@ dependencies = [
"devtools_traits 0.0.1",
"hyper 0.9.5 (registry+https://github.com/rust-lang/crates.io-index)",
"ipc-channel 0.2.2 (git+https://github.com/servo/ipc-channel)",
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"msg 0.0.1",
"plugins 0.0.1",
"serde 0.7.5 (registry+https://github.com/rust-lang/crates.io-index)",

1
ports/gonk/Cargo.lock generated
View file

@ -443,6 +443,7 @@ dependencies = [
"devtools_traits 0.0.1",
"hyper 0.9.5 (registry+https://github.com/rust-lang/crates.io-index)",
"ipc-channel 0.2.2 (git+https://github.com/servo/ipc-channel)",
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"msg 0.0.1",
"plugins 0.0.1",
"serde 0.7.5 (registry+https://github.com/rust-lang/crates.io-index)",