aboutsummaryrefslogtreecommitdiffstats
path: root/components/devtools
diff options
context:
space:
mode:
Diffstat (limited to 'components/devtools')
-rw-r--r--components/devtools/actor.rs60
-rw-r--r--components/devtools/actors/console.rs43
-rw-r--r--components/devtools/actors/inspector.rs72
-rw-r--r--components/devtools/actors/root.rs8
-rw-r--r--components/devtools/actors/tab.rs14
-rw-r--r--components/devtools/lib.rs27
-rw-r--r--components/devtools/protocol.rs4
7 files changed, 94 insertions, 134 deletions
diff --git a/components/devtools/actor.rs b/components/devtools/actor.rs
index 87c3d45f139..2b4f408cd45 100644
--- a/components/devtools/actor.rs
+++ b/components/devtools/actor.rs
@@ -4,13 +4,11 @@
/// General actor system infrastructure.
-use std::any::{Any, AnyRefExt, AnyMutRefExt};
+use std::any::Any;
use std::collections::HashMap;
use std::cell::{Cell, RefCell};
-use std::intrinsics::TypeId;
use std::io::TcpStream;
-use std::mem::{transmute, transmute_copy, replace};
-use std::raw::TraitObject;
+use std::mem::replace;
use serialize::json;
/// A common trait for all devtools actors that encompasses an immutable name
@@ -25,46 +23,6 @@ pub trait Actor : Any {
fn name(&self) -> String;
}
-impl<'a> AnyMutRefExt<'a> for &'a mut (Actor + 'a) {
- fn downcast_mut<T: 'static>(self) -> Option<&'a mut T> {
- if self.is::<T>() {
- unsafe {
- // Get the raw representation of the trait object
- let to: TraitObject = transmute_copy(&self);
-
- // Extract the data pointer
- Some(transmute(to.data))
- }
- } else {
- None
- }
- }
-}
-
-impl<'a> AnyRefExt<'a> for &'a (Actor + 'a) {
- fn is<T: 'static>(self) -> bool {
- // This implementation is only needed so long as there's a Rust bug that
- // prevents downcast_ref from giving realistic return values.
- let t = TypeId::of::<T>();
- let boxed: TypeId = (*self).get_type_id();
- t == boxed
- }
-
- fn downcast_ref<T: 'static>(self) -> Option<&'a T> {
- if self.is::<T>() {
- unsafe {
- // Get the raw representation of the trait object
- let to: TraitObject = transmute_copy(&self);
-
- // Extract the data pointer
- Some(transmute(to.data))
- }
- } else {
- None
- }
- }
-}
-
/// A list of known, owned actors.
pub struct ActorRegistry {
actors: HashMap<String, Box<Actor+Send+Sized>>,
@@ -130,20 +88,14 @@ impl ActorRegistry {
/// Find an actor by registered name
pub fn find<'a, T: 'static>(&'a self, name: &str) -> &'a T {
- //FIXME: Rust bug forces us to implement bogus Any for Actor since downcast_ref currently
- // fails for unknown reasons.
- /*let actor: &Actor+Send+Sized = *self.actors.find(&name.to_string()).unwrap();
- (actor as &Any).downcast_ref::<T>().unwrap()*/
- self.actors.get(&name.to_string()).unwrap().downcast_ref::<T>().unwrap()
+ let actor: &Any = self.actors.get(&name.to_string()).unwrap();
+ actor.downcast_ref::<T>().unwrap()
}
/// Find an actor by registered name
pub fn find_mut<'a, T: 'static>(&'a mut self, name: &str) -> &'a mut T {
- //FIXME: Rust bug forces us to implement bogus Any for Actor since downcast_ref currently
- // fails for unknown reasons.
- /*let actor: &mut Actor+Send+Sized = *self.actors.find_mut(&name.to_string()).unwrap();
- (actor as &mut Any).downcast_mut::<T>().unwrap()*/
- self.actors.get_mut(&name.to_string()).unwrap().downcast_mut::<T>().unwrap()
+ let actor: &mut Any = self.actors.get_mut(&name.to_string()).unwrap();
+ actor.downcast_mut::<T>().unwrap()
}
/// Attempt to process a message as directed by its `to` property. If the actor is not
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
diff --git a/components/devtools/actors/inspector.rs b/components/devtools/actors/inspector.rs
index ac3b51cf34f..20611226edc 100644
--- a/components/devtools/actors/inspector.rs
+++ b/components/devtools/actors/inspector.rs
@@ -10,11 +10,12 @@ use devtools_traits::{GetLayout, NodeInfo, ModifyAttribute};
use actor::{Actor, ActorRegistry};
use protocol::JsonPacketStream;
-use collections::TreeMap;
+use collections::BTreeMap;
use servo_msg::constellation_msg::PipelineId;
use serialize::json::{mod, Json, ToJson};
use std::cell::RefCell;
use std::io::TcpStream;
+use std::sync::mpsc::{channel, Sender};
use std::num::Float;
pub struct InspectorActor {
@@ -26,13 +27,13 @@ pub struct InspectorActor {
pub pipeline: PipelineId,
}
-#[deriving(Encodable)]
+#[derive(RustcEncodable)]
struct GetHighlighterReply {
highligter: HighlighterMsg, // sic.
from: String,
}
-#[deriving(Encodable)]
+#[derive(RustcEncodable)]
struct HighlighterMsg {
actor: String,
}
@@ -47,12 +48,12 @@ pub struct NodeActor {
pipeline: PipelineId,
}
-#[deriving(Encodable)]
+#[derive(RustcEncodable)]
struct ShowBoxModelReply {
from: String,
}
-#[deriving(Encodable)]
+#[derive(RustcEncodable)]
struct HideBoxModelReply {
from: String,
}
@@ -89,7 +90,7 @@ impl Actor for HighlighterActor {
}
}
-#[deriving(Encodable)]
+#[derive(RustcEncodable)]
struct ModifyAttributeReply{
from: String,
}
@@ -114,7 +115,8 @@ impl Actor for NodeActor {
self.script_chan.send(ModifyAttribute(self.pipeline,
registry.actor_to_script(target.to_string()),
- modifications));
+ modifications))
+ .unwrap();
let reply = ModifyAttributeReply{
from: self.name(),
};
@@ -127,26 +129,26 @@ impl Actor for NodeActor {
}
}
-#[deriving(Encodable)]
+#[derive(RustcEncodable)]
struct GetWalkerReply {
from: String,
walker: WalkerMsg,
}
-#[deriving(Encodable)]
+#[derive(RustcEncodable)]
struct WalkerMsg {
actor: String,
root: NodeActorMsg,
}
-#[deriving(Encodable)]
+#[derive(RustcEncodable)]
struct AttrMsg {
namespace: String,
name: String,
value: String,
}
-#[deriving(Encodable)]
+#[derive(RustcEncodable)]
struct NodeActorMsg {
actor: String,
baseURI: String,
@@ -243,23 +245,23 @@ struct WalkerActor {
pipeline: PipelineId,
}
-#[deriving(Encodable)]
+#[derive(RustcEncodable)]
struct QuerySelectorReply {
from: String,
}
-#[deriving(Encodable)]
+#[derive(RustcEncodable)]
struct DocumentElementReply {
from: String,
node: NodeActorMsg,
}
-#[deriving(Encodable)]
+#[derive(RustcEncodable)]
struct ClearPseudoclassesReply {
from: String,
}
-#[deriving(Encodable)]
+#[derive(RustcEncodable)]
struct ChildrenReply {
hasFirst: bool,
hasLast: bool,
@@ -288,8 +290,8 @@ impl Actor for WalkerActor {
"documentElement" => {
let (tx, rx) = channel();
- self.script_chan.send(GetDocumentElement(self.pipeline, tx));
- let doc_elem_info = rx.recv();
+ self.script_chan.send(GetDocumentElement(self.pipeline, tx)).unwrap();
+ let doc_elem_info = rx.recv().unwrap();
let node = doc_elem_info.encode(registry, true, self.script_chan.clone(), self.pipeline);
let msg = DocumentElementReply {
@@ -313,8 +315,9 @@ impl Actor for WalkerActor {
let (tx, rx) = channel();
self.script_chan.send(GetChildren(self.pipeline,
registry.actor_to_script(target.to_string()),
- tx));
- let children = rx.recv();
+ tx))
+ .unwrap();
+ let children = rx.recv().unwrap();
let msg = ChildrenReply {
hasFirst: true,
@@ -333,13 +336,13 @@ impl Actor for WalkerActor {
}
}
-#[deriving(Encodable)]
+#[derive(RustcEncodable)]
struct GetPageStyleReply {
from: String,
pageStyle: PageStyleMsg,
}
-#[deriving(Encodable)]
+#[derive(RustcEncodable)]
struct PageStyleMsg {
actor: String,
}
@@ -350,7 +353,7 @@ struct PageStyleActor {
pipeline: PipelineId,
}
-#[deriving(Encodable)]
+#[derive(RustcEncodable)]
struct GetAppliedReply {
entries: Vec<AppliedEntry>,
rules: Vec<AppliedRule>,
@@ -358,13 +361,13 @@ struct GetAppliedReply {
from: String,
}
-#[deriving(Encodable)]
+#[derive(RustcEncodable)]
struct GetComputedReply {
computed: Vec<uint>, //XXX all css props
from: String,
}
-#[deriving(Encodable)]
+#[derive(RustcEncodable)]
struct AppliedEntry {
rule: String,
pseudoElement: Json,
@@ -372,7 +375,7 @@ struct AppliedEntry {
matchedSelectors: Vec<String>,
}
-#[deriving(Encodable)]
+#[derive(RustcEncodable)]
struct AppliedRule {
actor: String,
__type__: uint,
@@ -383,7 +386,7 @@ struct AppliedRule {
parentStyleSheet: String,
}
-#[deriving(Encodable)]
+#[derive(RustcEncodable)]
struct AppliedSheet {
actor: String,
href: String,
@@ -395,7 +398,7 @@ struct AppliedSheet {
ruleCount: uint,
}
-#[deriving(Encodable)]
+#[derive(RustcEncodable)]
struct GetLayoutReply {
width: int,
height: int,
@@ -403,7 +406,7 @@ struct GetLayoutReply {
from: String,
}
-#[deriving(Encodable)]
+#[derive(RustcEncodable)]
#[allow(dead_code)]
struct AutoMargins {
top: String,
@@ -450,9 +453,10 @@ impl Actor for PageStyleActor {
let target = msg.get(&"node".to_string()).unwrap().as_string().unwrap();
let (tx, rx) = channel();
self.script_chan.send(GetLayout(self.pipeline,
- registry.actor_to_script(target.to_string()),
- tx));
- let (width, height) = rx.recv();
+ registry.actor_to_script(target.to_string()),
+ tx))
+ .unwrap();
+ let (width, height) = rx.recv().unwrap();
let auto_margins = msg.get(&"autoMargins".to_string()).unwrap().as_boolean().unwrap();
@@ -463,7 +467,7 @@ impl Actor for PageStyleActor {
height: height.round() as int,
autoMargins: if auto_margins {
//TODO: real values like processMargins in http://mxr.mozilla.org/mozilla-central/source/toolkit/devtools/server/actors/styles.js
- let mut m = TreeMap::new();
+ let mut m = BTreeMap::new();
m.insert("top".to_string(), "auto".to_string().to_json());
m.insert("bottom".to_string(), "auto".to_string().to_json());
m.insert("left".to_string(), "auto".to_string().to_json());
@@ -507,8 +511,8 @@ impl Actor for InspectorActor {
}
let (tx, rx) = channel();
- self.script_chan.send(GetRootNode(self.pipeline, tx));
- let root_info = rx.recv();
+ self.script_chan.send(GetRootNode(self.pipeline, tx)).unwrap();
+ let root_info = rx.recv().unwrap();
let node = root_info.encode(registry, false, self.script_chan.clone(), self.pipeline);
diff --git a/components/devtools/actors/root.rs b/components/devtools/actors/root.rs
index da0e33d7c7d..cd9084c0282 100644
--- a/components/devtools/actors/root.rs
+++ b/components/devtools/actors/root.rs
@@ -13,28 +13,28 @@ use protocol::JsonPacketStream;
use serialize::json;
use std::io::TcpStream;
-#[deriving(Encodable)]
+#[derive(RustcEncodable)]
struct ActorTraits {
sources: bool,
highlightable: bool,
customHighlighters: Vec<String>,
}
-#[deriving(Encodable)]
+#[derive(RustcEncodable)]
struct ErrorReply {
from: String,
error: String,
message: String,
}
-#[deriving(Encodable)]
+#[derive(RustcEncodable)]
struct ListTabsReply {
from: String,
selected: uint,
tabs: Vec<TabActorMsg>,
}
-#[deriving(Encodable)]
+#[derive(RustcEncodable)]
struct RootActorMsg {
from: String,
applicationType: String,
diff --git a/components/devtools/actors/tab.rs b/components/devtools/actors/tab.rs
index 519e3e48128..69450cd4b32 100644
--- a/components/devtools/actors/tab.rs
+++ b/components/devtools/actors/tab.rs
@@ -13,10 +13,10 @@ use protocol::JsonPacketStream;
use serialize::json;
use std::io::TcpStream;
-#[deriving(Encodable)]
+#[derive(RustcEncodable)]
struct TabTraits;
-#[deriving(Encodable)]
+#[derive(RustcEncodable)]
struct TabAttachedReply {
from: String,
__type__: String,
@@ -26,24 +26,24 @@ struct TabAttachedReply {
traits: TabTraits,
}
-#[deriving(Encodable)]
+#[derive(RustcEncodable)]
struct TabDetachedReply {
from: String,
__type__: String,
}
-#[deriving(Encodable)]
+#[derive(RustcEncodable)]
struct ReconfigureReply {
from: String
}
-#[deriving(Encodable)]
+#[derive(RustcEncodable)]
struct ListFramesReply {
from: String,
frames: Vec<FrameMsg>,
}
-#[deriving(Encodable)]
+#[derive(RustcEncodable)]
struct FrameMsg {
id: uint,
url: String,
@@ -51,7 +51,7 @@ struct FrameMsg {
parentID: uint,
}
-#[deriving(Encodable)]
+#[derive(RustcEncodable)]
pub struct TabActorMsg {
actor: String,
title: String,
diff --git a/components/devtools/lib.rs b/components/devtools/lib.rs
index fd4b57aa0d6..f653dd289ce 100644
--- a/components/devtools/lib.rs
+++ b/components/devtools/lib.rs
@@ -10,17 +10,19 @@
#![crate_name = "devtools"]
#![crate_type = "rlib"]
+#![feature(int_uint, box_syntax)]
+
#![allow(non_snake_case)]
#![allow(missing_copy_implementations)]
+#![allow(unstable)]
-#![feature(phase)]
-
-#[phase(plugin, link)]
+#[macro_use]
extern crate log;
extern crate collections;
extern crate core;
extern crate devtools_traits;
+extern crate "serialize" as rustc_serialize;
extern crate serialize;
extern crate "msg" as servo_msg;
extern crate "util" as servo_util;
@@ -39,8 +41,8 @@ use servo_util::task::spawn_named;
use std::borrow::ToOwned;
use std::cell::RefCell;
use std::collections::HashMap;
-use std::comm;
-use std::comm::{Disconnected, Empty};
+use std::sync::mpsc::{channel, Receiver, Sender};
+use std::sync::mpsc::TryRecvError::{Disconnected, Empty};
use std::io::{TcpListener, TcpStream};
use std::io::{Acceptor, Listener, TimedOut};
use std::sync::{Arc, Mutex};
@@ -57,8 +59,8 @@ mod protocol;
/// Spin up a devtools server that listens for connections on the specified port.
pub fn start_server(port: u16) -> Sender<DevtoolsControlMsg> {
- let (sender, receiver) = comm::channel();
- spawn_named("Devtools".to_owned(), proc() {
+ let (sender, receiver) = channel();
+ spawn_named("Devtools".to_owned(), move || {
run_server(receiver, port)
});
sender
@@ -92,7 +94,7 @@ fn run_server(receiver: Receiver<DevtoolsControlMsg>, port: u16) {
fn handle_client(actors: Arc<Mutex<ActorRegistry>>, mut stream: TcpStream) {
println!("connection established to {}", stream.peer_name().unwrap());
{
- let actors = actors.lock();
+ let actors = actors.lock().unwrap();
let msg = actors.find::<RootActor>("root").encodable();
stream.write_json_packet(&msg);
}
@@ -100,8 +102,9 @@ fn run_server(receiver: Receiver<DevtoolsControlMsg>, port: u16) {
'outer: loop {
match stream.read_json_packet() {
Ok(json_packet) => {
- match actors.lock().handle_message(json_packet.as_object().unwrap(),
- &mut stream) {
+ let mut actors = actors.lock().unwrap();
+ match actors.handle_message(json_packet.as_object().unwrap(),
+ &mut stream) {
Ok(()) => {},
Err(()) => {
println!("error: devtools actor stopped responding");
@@ -127,7 +130,7 @@ fn run_server(receiver: Receiver<DevtoolsControlMsg>, port: u16) {
sender: Sender<DevtoolScriptControlMsg>,
actor_pipelines: &mut HashMap<PipelineId, String>,
page_info: DevtoolsPageInfo) {
- let mut actors = actors.lock();
+ let mut actors = actors.lock().unwrap();
//TODO: move all this actor creation into a constructor method on TabActor
let (tab, console, inspector) = {
@@ -185,7 +188,7 @@ fn run_server(receiver: Receiver<DevtoolsControlMsg>, port: u16) {
Ok(stream) => {
let actors = actors.clone();
accepted_connections.push(stream.clone());
- spawn_named("DevtoolsClientHandler".to_owned(), proc() {
+ spawn_named("DevtoolsClientHandler".to_owned(), move || {
// connection succeeded
handle_client(actors, stream.clone())
})
diff --git a/components/devtools/protocol.rs b/components/devtools/protocol.rs
index df9078c7bf1..149c3a301d2 100644
--- a/components/devtools/protocol.rs
+++ b/components/devtools/protocol.rs
@@ -12,12 +12,12 @@ use std::io::{IoError, OtherIoError, EndOfFile, TcpStream, IoResult};
use std::num;
pub trait JsonPacketStream {
- fn write_json_packet<'a, T: Encodable<json::Encoder<'a>,IoError>>(&mut self, obj: &T);
+ fn write_json_packet<'a, T: Encodable>(&mut self, obj: &T);
fn read_json_packet(&mut self) -> IoResult<Json>;
}
impl JsonPacketStream for TcpStream {
- fn write_json_packet<'a, T: Encodable<json::Encoder<'a>,IoError>>(&mut self, obj: &T) {
+ fn write_json_packet<'a, T: Encodable>(&mut self, obj: &T) {
let s = json::encode(obj).replace("__type__", "type");
println!("<- {}", s);
self.write_str(s.len().to_string().as_slice()).unwrap();