mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Rust upgrade to rustc hash b03a2755193cd756583bcf5831cf4545d75ecb8a
This commit is contained in:
parent
26045d7fcb
commit
d1b433a3b3
160 changed files with 1427 additions and 1162 deletions
|
@ -4,8 +4,8 @@
|
|||
|
||||
/// General actor system infrastructure.
|
||||
|
||||
use std::any::{AnyPrivate, AnyRefExt, AnyMutRefExt};
|
||||
use std::collections::hashmap::HashMap;
|
||||
use std::any::{Any, AnyRefExt, AnyMutRefExt};
|
||||
use std::collections::HashMap;
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::intrinsics::TypeId;
|
||||
use std::io::TcpStream;
|
||||
|
@ -16,7 +16,7 @@ use serialize::json;
|
|||
/// A common trait for all devtools actors that encompasses an immutable name
|
||||
/// and the ability to process messages that are directed to particular actors.
|
||||
/// TODO: ensure the name is immutable
|
||||
pub trait Actor: AnyPrivate {
|
||||
pub trait Actor {
|
||||
fn handle_message(&self,
|
||||
registry: &ActorRegistry,
|
||||
msg_type: &String,
|
||||
|
@ -45,9 +45,12 @@ 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 = self.get_type_id();
|
||||
t == boxed
|
||||
unsafe {
|
||||
let t = TypeId::of::<T>();
|
||||
let this: &Actor = transmute(self);
|
||||
let boxed: TypeId = this.get_type_id();
|
||||
t == boxed
|
||||
}
|
||||
}
|
||||
|
||||
fn downcast_ref<T: 'static>(self) -> Option<&'a T> {
|
||||
|
@ -94,7 +97,7 @@ impl ActorRegistry {
|
|||
if script_id.as_slice() == "" {
|
||||
return "".to_string();
|
||||
}
|
||||
self.script_actors.borrow().find(&script_id).unwrap().to_string()
|
||||
self.script_actors.borrow().get(&script_id).unwrap().to_string()
|
||||
}
|
||||
|
||||
pub fn script_actor_registered(&self, script_id: String) -> bool {
|
||||
|
@ -108,7 +111,7 @@ impl ActorRegistry {
|
|||
return key.to_string();
|
||||
}
|
||||
}
|
||||
fail!("couldn't find actor named {:s}", actor)
|
||||
panic!("couldn't find actor named {:s}", actor)
|
||||
}
|
||||
|
||||
/// Create a unique name based on a monotonically increasing suffix
|
||||
|
@ -134,7 +137,7 @@ impl ActorRegistry {
|
|||
// 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.find(&name.to_string()).unwrap().downcast_ref::<T>().unwrap()
|
||||
self.actors.get(&name.to_string()).unwrap().downcast_ref::<T>().unwrap()
|
||||
}
|
||||
|
||||
/// Find an actor by registered name
|
||||
|
@ -143,17 +146,17 @@ impl ActorRegistry {
|
|||
// 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.find_mut(&name.to_string()).unwrap().downcast_mut::<T>().unwrap()
|
||||
self.actors.get_mut(&name.to_string()).unwrap().downcast_mut::<T>().unwrap()
|
||||
}
|
||||
|
||||
/// 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) {
|
||||
let to = msg.find(&"to".to_string()).unwrap().as_string().unwrap();
|
||||
match self.actors.find(&to.to_string()) {
|
||||
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.find(&"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) {
|
||||
println!("unexpected message type \"{:s}\" found for actor \"{:s}\"",
|
||||
msg_type, to);
|
||||
|
|
|
@ -32,11 +32,13 @@ struct StartedListenersReply {
|
|||
}
|
||||
|
||||
#[deriving(Encodable)]
|
||||
#[allow(dead_code)]
|
||||
struct ConsoleAPIMessage {
|
||||
_type: String, //FIXME: should this be __type__ instead?
|
||||
}
|
||||
|
||||
#[deriving(Encodable)]
|
||||
#[allow(dead_code)]
|
||||
struct PageErrorMessage {
|
||||
_type: String, //FIXME: should this be __type__ instead?
|
||||
errorMessage: String,
|
||||
|
@ -54,6 +56,7 @@ struct PageErrorMessage {
|
|||
}
|
||||
|
||||
#[deriving(Encodable)]
|
||||
#[allow(dead_code)]
|
||||
struct LogMessage {
|
||||
_type: String, //FIXME: should this be __type__ instead?
|
||||
timeStamp: uint,
|
||||
|
@ -61,6 +64,7 @@ struct LogMessage {
|
|||
}
|
||||
|
||||
#[deriving(Encodable)]
|
||||
#[allow(dead_code)]
|
||||
enum ConsoleMessageType {
|
||||
ConsoleAPIType(ConsoleAPIMessage),
|
||||
PageErrorType(PageErrorMessage),
|
||||
|
@ -115,7 +119,7 @@ impl Actor for ConsoleActor {
|
|||
stream: &mut TcpStream) -> bool {
|
||||
match msg_type.as_slice() {
|
||||
"getCachedMessages" => {
|
||||
let types = msg.find(&"messageTypes".to_string()).unwrap().as_list().unwrap();
|
||||
let types = msg.get(&"messageTypes".to_string()).unwrap().as_list().unwrap();
|
||||
let /*mut*/ messages = vec!();
|
||||
for msg_type in types.iter() {
|
||||
let msg_type = msg_type.as_string().unwrap();
|
||||
|
@ -187,7 +191,7 @@ impl Actor for ConsoleActor {
|
|||
//TODO: actually implement listener filters that support starting/stopping
|
||||
let msg = StopListenersReply {
|
||||
from: self.name(),
|
||||
stoppedListeners: msg.find(&"listeners".to_string())
|
||||
stoppedListeners: msg.get(&"listeners".to_string())
|
||||
.unwrap()
|
||||
.as_list()
|
||||
.unwrap_or(&vec!())
|
||||
|
@ -212,7 +216,7 @@ impl Actor for ConsoleActor {
|
|||
}
|
||||
|
||||
"evaluateJS" => {
|
||||
let input = msg.find(&"text".to_string()).unwrap().as_string().unwrap().to_string();
|
||||
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));
|
||||
|
||||
|
|
|
@ -252,7 +252,7 @@ impl Actor for WalkerActor {
|
|||
}
|
||||
|
||||
"children" => {
|
||||
let target = msg.find(&"node".to_string()).unwrap().as_string().unwrap();
|
||||
let target = msg.get(&"node".to_string()).unwrap().as_string().unwrap();
|
||||
let (tx, rx) = channel();
|
||||
self.script_chan.send(GetChildren(self.pipeline,
|
||||
registry.actor_to_script(target.to_string()),
|
||||
|
@ -347,6 +347,7 @@ struct GetLayoutReply {
|
|||
}
|
||||
|
||||
#[deriving(Encodable)]
|
||||
#[allow(dead_code)]
|
||||
struct AutoMargins {
|
||||
top: String,
|
||||
bottom: String,
|
||||
|
@ -389,14 +390,14 @@ impl Actor for PageStyleActor {
|
|||
|
||||
//TODO: query script for box layout properties of node (msg.node)
|
||||
"getLayout" => {
|
||||
let target = msg.find(&"node".to_string()).unwrap().as_string().unwrap();
|
||||
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();
|
||||
|
||||
let auto_margins = msg.find(&"autoMargins".to_string()).unwrap().as_boolean().unwrap();
|
||||
let auto_margins = msg.get(&"autoMargins".to_string()).unwrap().as_boolean().unwrap();
|
||||
|
||||
//TODO: the remaining layout properties (margin, border, padding, position)
|
||||
// as specified in getLayout in http://mxr.mozilla.org/mozilla-central/source/toolkit/devtools/server/actors/styles.js
|
||||
|
|
|
@ -23,7 +23,6 @@ extern crate log;
|
|||
extern crate collections;
|
||||
extern crate core;
|
||||
extern crate devtools_traits;
|
||||
extern crate debug;
|
||||
extern crate serialize;
|
||||
extern crate sync;
|
||||
extern crate "msg" as servo_msg;
|
||||
|
@ -69,7 +68,7 @@ pub fn start_server(port: u16) -> Sender<DevtoolsControlMsg> {
|
|||
static POLL_TIMEOUT: u64 = 300;
|
||||
|
||||
fn run_server(receiver: Receiver<DevtoolsControlMsg>, port: u16) {
|
||||
let listener = TcpListener::bind("127.0.0.1", port);
|
||||
let listener = TcpListener::bind(format!("{}:{}", "127.0.0.1", port).as_slice());
|
||||
|
||||
// bind the listener to the specified address
|
||||
let mut acceptor = listener.listen().unwrap();
|
||||
|
@ -88,9 +87,9 @@ fn run_server(receiver: Receiver<DevtoolsControlMsg>, port: u16) {
|
|||
|
||||
/// 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_name().unwrap());
|
||||
println!("connection established to {}", stream.peer_name().unwrap());
|
||||
{
|
||||
let mut actors = actors.lock();
|
||||
let actors = actors.lock();
|
||||
let msg = actors.find::<RootActor>("root").encodable();
|
||||
stream.write_json_packet(&msg);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue