mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Stop calling to_string() in devtools.
This commit is contained in:
parent
62a98e4918
commit
1257a33394
9 changed files with 68 additions and 68 deletions
|
@ -99,9 +99,9 @@ impl ActorRegistry {
|
|||
|
||||
pub fn script_to_actor(&self, script_id: String) -> String {
|
||||
if script_id.is_empty() {
|
||||
return "".to_string();
|
||||
return "".to_owned();
|
||||
}
|
||||
self.script_actors.borrow().get(&script_id).unwrap().to_string()
|
||||
self.script_actors.borrow().get(&script_id).unwrap().clone()
|
||||
}
|
||||
|
||||
pub fn script_actor_registered(&self, script_id: String) -> bool {
|
||||
|
@ -112,7 +112,7 @@ impl ActorRegistry {
|
|||
for (key, value) in &*self.script_actors.borrow() {
|
||||
println!("checking {}", value);
|
||||
if *value == actor {
|
||||
return key.to_string();
|
||||
return key.to_owned();
|
||||
}
|
||||
}
|
||||
panic!("couldn't find actor named {}", actor)
|
||||
|
@ -127,7 +127,7 @@ impl ActorRegistry {
|
|||
|
||||
/// Add an actor to the registry of known actors that can receive messages.
|
||||
pub fn register(&mut self, actor: Box<Actor + Send>) {
|
||||
self.actors.insert(actor.name().to_string(), actor);
|
||||
self.actors.insert(actor.name(), actor);
|
||||
}
|
||||
|
||||
pub fn register_later(&self, actor: Box<Actor + Send>) {
|
||||
|
@ -137,13 +137,13 @@ impl ActorRegistry {
|
|||
|
||||
/// Find an actor by registered name
|
||||
pub fn find<'a, T: Any>(&'a self, name: &str) -> &'a T {
|
||||
let actor = self.actors.get(&name.to_string()).unwrap();
|
||||
let actor = self.actors.get(name).unwrap();
|
||||
actor.actor_as_any().downcast_ref::<T>().unwrap()
|
||||
}
|
||||
|
||||
/// Find an actor by registered name
|
||||
pub fn find_mut<'a, T: Any>(&'a mut self, name: &str) -> &'a mut T {
|
||||
let actor = self.actors.get_mut(&name.to_string()).unwrap();
|
||||
let actor = self.actors.get_mut(name).unwrap();
|
||||
actor.actor_as_any_mut().downcast_mut::<T>().unwrap()
|
||||
}
|
||||
|
||||
|
@ -155,11 +155,11 @@ impl ActorRegistry {
|
|||
-> Result<(), ()> {
|
||||
let to = msg.get("to").unwrap().as_string().unwrap();
|
||||
|
||||
match self.actors.get(&to.to_string()) {
|
||||
match self.actors.get(to) {
|
||||
None => println!("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.to_string(), msg, stream))
|
||||
if try!(actor.handle_message(self, msg_type, msg, stream))
|
||||
!= ActorMessageStatus::Processed {
|
||||
println!("unexpected message type \"{}\" found for actor \"{}\"",
|
||||
msg_type, to);
|
||||
|
@ -168,7 +168,7 @@ impl ActorRegistry {
|
|||
}
|
||||
let new_actors = replace(&mut *self.new_actors.borrow_mut(), vec!());
|
||||
for actor in new_actors.into_iter() {
|
||||
self.actors.insert(actor.name().to_string(), actor);
|
||||
self.actors.insert(actor.name().to_owned(), actor);
|
||||
}
|
||||
|
||||
let old_actors = replace(&mut *self.old_actors.borrow_mut(), vec!());
|
||||
|
|
|
@ -133,7 +133,7 @@ impl Actor for ConsoleActor {
|
|||
from: self.name(),
|
||||
nativeConsoleAPI: true,
|
||||
startedListeners:
|
||||
vec!("PageError".to_string(), "ConsoleAPI".to_string()),
|
||||
vec!("PageError".to_owned(), "ConsoleAPI".to_owned()),
|
||||
traits: StartedListenersTraits {
|
||||
customNetworkRequest: true,
|
||||
}
|
||||
|
@ -146,12 +146,12 @@ impl Actor for ConsoleActor {
|
|||
//TODO: actually implement listener filters that support starting/stopping
|
||||
let msg = StopListenersReply {
|
||||
from: self.name(),
|
||||
stoppedListeners: msg.get(&"listeners".to_string())
|
||||
stoppedListeners: msg.get("listeners")
|
||||
.unwrap()
|
||||
.as_array()
|
||||
.unwrap_or(&vec!())
|
||||
.iter()
|
||||
.map(|listener| listener.as_string().unwrap().to_string())
|
||||
.map(|listener| listener.as_string().unwrap().to_owned())
|
||||
.collect(),
|
||||
};
|
||||
stream.write_json_packet(&msg);
|
||||
|
@ -164,14 +164,14 @@ impl Actor for ConsoleActor {
|
|||
let msg = AutocompleteReply {
|
||||
from: self.name(),
|
||||
matches: vec!(),
|
||||
matchProp: "".to_string(),
|
||||
matchProp: "".to_owned(),
|
||||
};
|
||||
stream.write_json_packet(&msg);
|
||||
ActorMessageStatus::Processed
|
||||
}
|
||||
|
||||
"evaluateJS" => {
|
||||
let input = msg.get(&"text".to_string()).unwrap().as_string().unwrap().to_string();
|
||||
let input = msg.get("text").unwrap().as_string().unwrap().to_owned();
|
||||
let (chan, port) = ipc::channel().unwrap();
|
||||
self.script_chan.send(DevtoolScriptControlMsg::EvaluateJS(
|
||||
self.pipeline, input.clone(), chan)).unwrap();
|
||||
|
@ -180,31 +180,31 @@ impl Actor for ConsoleActor {
|
|||
let result = match try!(port.recv().map_err(|_| ())) {
|
||||
VoidValue => {
|
||||
let mut m = BTreeMap::new();
|
||||
m.insert("type".to_string(), "undefined".to_string().to_json());
|
||||
m.insert("type".to_owned(), "undefined".to_owned().to_json());
|
||||
Json::Object(m)
|
||||
}
|
||||
NullValue => {
|
||||
let mut m = BTreeMap::new();
|
||||
m.insert("type".to_string(), "null".to_string().to_json());
|
||||
m.insert("type".to_owned(), "null".to_owned().to_json());
|
||||
Json::Object(m)
|
||||
}
|
||||
BooleanValue(val) => val.to_json(),
|
||||
NumberValue(val) => {
|
||||
if val.is_nan() {
|
||||
let mut m = BTreeMap::new();
|
||||
m.insert("type".to_string(), "NaN".to_string().to_json());
|
||||
m.insert("type".to_owned(), "NaN".to_owned().to_json());
|
||||
Json::Object(m)
|
||||
} else if val.is_infinite() {
|
||||
let mut m = BTreeMap::new();
|
||||
if val < 0. {
|
||||
m.insert("type".to_string(), "-Infinity".to_string().to_json());
|
||||
m.insert("type".to_owned(), "-Infinity".to_owned().to_json());
|
||||
} else {
|
||||
m.insert("type".to_string(), "Infinity".to_string().to_json());
|
||||
m.insert("type".to_owned(), "Infinity".to_owned().to_json());
|
||||
}
|
||||
Json::Object(m)
|
||||
} else if val == 0. && val.is_sign_negative() {
|
||||
let mut m = BTreeMap::new();
|
||||
m.insert("type".to_string(), "-0".to_string().to_json());
|
||||
m.insert("type".to_owned(), "-0".to_owned().to_json());
|
||||
Json::Object(m)
|
||||
} else {
|
||||
val.to_json()
|
||||
|
@ -216,12 +216,12 @@ impl Actor for ConsoleActor {
|
|||
let mut m = BTreeMap::new();
|
||||
let actor = ObjectActor::new(registry, uuid);
|
||||
|
||||
m.insert("type".to_string(), "object".to_string().to_json());
|
||||
m.insert("class".to_string(), class.to_json());
|
||||
m.insert("actor".to_string(), actor.to_json());
|
||||
m.insert("extensible".to_string(), true.to_json());
|
||||
m.insert("frozen".to_string(), false.to_json());
|
||||
m.insert("sealed".to_string(), false.to_json());
|
||||
m.insert("type".to_owned(), "object".to_owned().to_json());
|
||||
m.insert("class".to_owned(), class.to_json());
|
||||
m.insert("actor".to_owned(), actor.to_json());
|
||||
m.insert("extensible".to_owned(), true.to_json());
|
||||
m.insert("frozen".to_owned(), false.to_json());
|
||||
m.insert("sealed".to_owned(), false.to_json());
|
||||
Json::Object(m)
|
||||
}
|
||||
};
|
||||
|
@ -233,7 +233,7 @@ impl Actor for ConsoleActor {
|
|||
result: result,
|
||||
timestamp: 0,
|
||||
exception: Json::Object(BTreeMap::new()),
|
||||
exceptionMessage: "".to_string(),
|
||||
exceptionMessage: "".to_owned(),
|
||||
helperResult: Json::Object(BTreeMap::new()),
|
||||
};
|
||||
stream.write_json_packet(&msg);
|
||||
|
|
|
@ -109,14 +109,14 @@ impl Actor for NodeActor {
|
|||
stream: &mut TcpStream) -> Result<ActorMessageStatus, ()> {
|
||||
Ok(match msg_type {
|
||||
"modifyAttributes" => {
|
||||
let target = msg.get(&"to".to_string()).unwrap().as_string().unwrap();
|
||||
let mods = msg.get(&"modifications".to_string()).unwrap().as_array().unwrap();
|
||||
let target = msg.get("to").unwrap().as_string().unwrap();
|
||||
let mods = msg.get("modifications").unwrap().as_array().unwrap();
|
||||
let modifications = mods.iter().map(|json_mod| {
|
||||
json::decode(&json_mod.to_string()).unwrap()
|
||||
}).collect();
|
||||
|
||||
self.script_chan.send(ModifyAttribute(self.pipeline,
|
||||
registry.actor_to_script(target.to_string()),
|
||||
registry.actor_to_script(target.to_owned()),
|
||||
modifications))
|
||||
.unwrap();
|
||||
let reply = ModifyAttributeReply {
|
||||
|
@ -313,10 +313,10 @@ impl Actor for WalkerActor {
|
|||
}
|
||||
|
||||
"children" => {
|
||||
let target = msg.get(&"node".to_string()).unwrap().as_string().unwrap();
|
||||
let target = msg.get("node").unwrap().as_string().unwrap();
|
||||
let (tx, rx) = ipc::channel().unwrap();
|
||||
self.script_chan.send(GetChildren(self.pipeline,
|
||||
registry.actor_to_script(target.to_string()),
|
||||
registry.actor_to_script(target.to_owned()),
|
||||
tx))
|
||||
.unwrap();
|
||||
let children = rx.recv().unwrap();
|
||||
|
@ -452,15 +452,15 @@ impl Actor for PageStyleActor {
|
|||
|
||||
//TODO: query script for box layout properties of node (msg.node)
|
||||
"getLayout" => {
|
||||
let target = msg.get(&"node".to_string()).unwrap().as_string().unwrap();
|
||||
let target = msg.get("node").unwrap().as_string().unwrap();
|
||||
let (tx, rx) = ipc::channel().unwrap();
|
||||
self.script_chan.send(GetLayout(self.pipeline,
|
||||
registry.actor_to_script(target.to_string()),
|
||||
registry.actor_to_script(target.to_owned()),
|
||||
tx))
|
||||
.unwrap();
|
||||
let ComputedNodeLayout { width, height } = rx.recv().unwrap();
|
||||
|
||||
let auto_margins = msg.get(&"autoMargins".to_string())
|
||||
let auto_margins = msg.get("autoMargins")
|
||||
.and_then(&Json::as_boolean).unwrap_or(false);
|
||||
|
||||
//TODO: the remaining layout properties (margin, border, padding, position)
|
||||
|
@ -473,10 +473,10 @@ impl Actor for PageStyleActor {
|
|||
//TODO: real values like processMargins in
|
||||
// http://mxr.mozilla.org/mozilla-central/source/toolkit/devtools/server/actors/styles.js
|
||||
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());
|
||||
m.insert("right".to_string(), "auto".to_string().to_json());
|
||||
m.insert("top".to_owned(), "auto".to_owned().to_json());
|
||||
m.insert("bottom".to_owned(), "auto".to_owned().to_json());
|
||||
m.insert("left".to_owned(), "auto".to_owned().to_json());
|
||||
m.insert("right".to_owned(), "auto".to_owned().to_json());
|
||||
Json::Object(m)
|
||||
} else {
|
||||
Json::Null
|
||||
|
|
|
@ -82,7 +82,7 @@ impl Actor for NetworkEventActor {
|
|||
from: self.name(),
|
||||
headers: Vec::new(),
|
||||
headerSize: 10,
|
||||
rawHeaders: "Raw headers".to_string(),
|
||||
rawHeaders: "Raw headers".to_owned(),
|
||||
};
|
||||
stream.write_json_packet(&msg);
|
||||
ActorMessageStatus::Processed
|
||||
|
@ -144,7 +144,7 @@ impl NetworkEventActor {
|
|||
actor: self.name(),
|
||||
url: self.request.url.clone(),
|
||||
method: format!("{}", self.request.method),
|
||||
startedDateTime: "2015-04-22T20:47:08.545Z".to_string(),
|
||||
startedDateTime: "2015-04-22T20:47:08.545Z".to_owned(),
|
||||
isXHR: false,
|
||||
private: false,
|
||||
}
|
||||
|
@ -154,11 +154,11 @@ impl NetworkEventActor {
|
|||
// TODO: Send the correct values for all these fields.
|
||||
// This is a fake message.
|
||||
ResponseStartMsg {
|
||||
httpVersion: "HTTP/1.1".to_string(),
|
||||
remoteAddress: "63.245.217.43".to_string(),
|
||||
httpVersion: "HTTP/1.1".to_owned(),
|
||||
remoteAddress: "63.245.217.43".to_owned(),
|
||||
remotePort: 443,
|
||||
status: "200".to_string(),
|
||||
statusText: "OK".to_string(),
|
||||
status: "200".to_owned(),
|
||||
statusText: "OK".to_owned(),
|
||||
headersSize: 337,
|
||||
discardResponseBody: true
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ pub struct RootActor {
|
|||
|
||||
impl Actor for RootActor {
|
||||
fn name(&self) -> String {
|
||||
"root".to_string()
|
||||
"root".to_owned()
|
||||
}
|
||||
|
||||
fn handle_message(&self,
|
||||
|
@ -59,9 +59,9 @@ impl Actor for RootActor {
|
|||
Ok(match msg_type {
|
||||
"listAddons" => {
|
||||
let actor = ErrorReply {
|
||||
from: "root".to_string(),
|
||||
error: "noAddons".to_string(),
|
||||
message: "This root actor has no browser addons.".to_string(),
|
||||
from: "root".to_owned(),
|
||||
error: "noAddons".to_owned(),
|
||||
message: "This root actor has no browser addons.".to_owned(),
|
||||
};
|
||||
stream.write_json_packet(&actor);
|
||||
ActorMessageStatus::Processed
|
||||
|
@ -70,7 +70,7 @@ impl Actor for RootActor {
|
|||
//https://wiki.mozilla.org/Remote_Debugging_Protocol#Listing_Browser_Tabs
|
||||
"listTabs" => {
|
||||
let actor = ListTabsReply {
|
||||
from: "root".to_string(),
|
||||
from: "root".to_owned(),
|
||||
selected: 0,
|
||||
tabs: self.tabs.iter().map(|tab| {
|
||||
registry.find::<TabActor>(tab).encodable()
|
||||
|
@ -88,12 +88,12 @@ impl Actor for RootActor {
|
|||
impl RootActor {
|
||||
pub fn encodable(&self) -> RootActorMsg {
|
||||
RootActorMsg {
|
||||
from: "root".to_string(),
|
||||
applicationType: "browser".to_string(),
|
||||
from: "root".to_owned(),
|
||||
applicationType: "browser".to_owned(),
|
||||
traits: ActorTraits {
|
||||
sources: true,
|
||||
highlightable: true,
|
||||
customHighlighters: vec!("BoxModelHighlighter".to_string()),
|
||||
customHighlighters: vec!("BoxModelHighlighter".to_owned()),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -98,7 +98,7 @@ impl Actor for TabActor {
|
|||
"attach" => {
|
||||
let msg = TabAttachedReply {
|
||||
from: self.name(),
|
||||
__type__: "tabAttached".to_string(),
|
||||
__type__: "tabAttached".to_owned(),
|
||||
threadActor: self.name(),
|
||||
cacheDisabled: false,
|
||||
javascriptEnabled: true,
|
||||
|
@ -117,7 +117,7 @@ impl Actor for TabActor {
|
|||
"detach" => {
|
||||
let msg = TabDetachedReply {
|
||||
from: self.name(),
|
||||
__type__: "detached".to_string(),
|
||||
__type__: "detached".to_owned(),
|
||||
};
|
||||
let console_actor = registry.find::<ConsoleActor>(&self.console);
|
||||
console_actor.streams.borrow_mut().pop();
|
||||
|
|
|
@ -147,7 +147,7 @@ impl TimelineActor {
|
|||
return;
|
||||
}
|
||||
|
||||
task::spawn_named("PullTimelineMarkers".to_string(), move || {
|
||||
task::spawn_named("PullTimelineMarkers".to_owned(), move || {
|
||||
loop {
|
||||
if !*is_recording.lock().unwrap() {
|
||||
break;
|
||||
|
@ -291,7 +291,7 @@ impl Emitter {
|
|||
fn send(&mut self, markers: Vec<TimelineMarkerReply>) -> () {
|
||||
let end_time = PreciseTime::now();
|
||||
let reply = MarkersEmitterReply {
|
||||
__type__: "markers".to_string(),
|
||||
__type__: "markers".to_owned(),
|
||||
markers: markers,
|
||||
from: self.from.clone(),
|
||||
endTime: HighResolutionStamp::new(self.start_stamp, end_time),
|
||||
|
@ -303,7 +303,7 @@ impl Emitter {
|
|||
let registry = lock.as_mut().unwrap();
|
||||
let framerate_actor = registry.find_mut::<FramerateActor>(actor_name);
|
||||
let framerateReply = FramerateEmitterReply {
|
||||
__type__: "framerate".to_string(),
|
||||
__type__: "framerate".to_owned(),
|
||||
from: framerate_actor.name(),
|
||||
delta: HighResolutionStamp::new(self.start_stamp, end_time),
|
||||
timestamps: framerate_actor.take_pending_ticks(),
|
||||
|
@ -315,7 +315,7 @@ impl Emitter {
|
|||
let registry = self.registry.lock().unwrap();
|
||||
let memory_actor = registry.find::<MemoryActor>(actor_name);
|
||||
let memoryReply = MemoryEmitterReply {
|
||||
__type__: "memory".to_string(),
|
||||
__type__: "memory".to_owned(),
|
||||
from: memory_actor.name(),
|
||||
delta: HighResolutionStamp::new(self.start_stamp, end_time),
|
||||
measurement: memory_actor.measure(),
|
||||
|
|
|
@ -276,7 +276,7 @@ fn run_server(sender: Sender<DevtoolsControlMsg>,
|
|||
let console_actor = actors.find::<ConsoleActor>(&console_actor_name);
|
||||
let msg = ConsoleAPICall {
|
||||
from: console_actor.name.clone(),
|
||||
__type__: "consoleAPICall".to_string(),
|
||||
__type__: "consoleAPICall".to_owned(),
|
||||
message: ConsoleMsg {
|
||||
level: match console_message.logLevel {
|
||||
LogLevel::Debug => "debug",
|
||||
|
@ -284,7 +284,7 @@ fn run_server(sender: Sender<DevtoolsControlMsg>,
|
|||
LogLevel::Warn => "warn",
|
||||
LogLevel::Error => "error",
|
||||
_ => "log"
|
||||
}.to_string(),
|
||||
}.to_owned(),
|
||||
timeStamp: precise_time_ns(),
|
||||
arguments: vec!(console_message.message),
|
||||
filename: console_message.filename,
|
||||
|
@ -344,7 +344,7 @@ fn run_server(sender: Sender<DevtoolsControlMsg>,
|
|||
//Send a networkEvent message to the client
|
||||
let msg = NetworkEventMsg {
|
||||
from: console_actor_name,
|
||||
__type__: "networkEvent".to_string(),
|
||||
__type__: "networkEvent".to_owned(),
|
||||
eventActor: actor.event_actor(),
|
||||
};
|
||||
for stream in &mut connections {
|
||||
|
@ -358,8 +358,8 @@ fn run_server(sender: Sender<DevtoolsControlMsg>,
|
|||
//Send a networkEventUpdate (responseStart) to the client
|
||||
let msg = NetworkEventUpdateMsg {
|
||||
from: netevent_actor_name,
|
||||
__type__: "networkEventUpdate".to_string(),
|
||||
updateType: "responseStart".to_string(),
|
||||
__type__: "networkEventUpdate".to_owned(),
|
||||
updateType: "responseStart".to_owned(),
|
||||
response: actor.response_start()
|
||||
};
|
||||
|
||||
|
|
|
@ -35,17 +35,17 @@ impl JsonPacketStream for TcpStream {
|
|||
Ok(0) => return Ok(None), // EOF
|
||||
Ok(1) => buf[0],
|
||||
Ok(_) => unreachable!(),
|
||||
Err(e) => return Err(e.description().to_string()),
|
||||
Err(e) => return Err(e.description().to_owned()),
|
||||
};
|
||||
match byte {
|
||||
b':' => {
|
||||
let packet_len_str = match String::from_utf8(buffer) {
|
||||
Ok(packet_len) => packet_len,
|
||||
Err(_) => return Err("nonvalid UTF8 in packet length".to_string()),
|
||||
Err(_) => return Err("nonvalid UTF8 in packet length".to_owned()),
|
||||
};
|
||||
let packet_len = match u64::from_str_radix(&packet_len_str, 10) {
|
||||
Ok(packet_len) => packet_len,
|
||||
Err(_) => return Err("packet length missing / not parsable".to_string()),
|
||||
Err(_) => return Err("packet length missing / not parsable".to_owned()),
|
||||
};
|
||||
let mut packet = String::new();
|
||||
self.take(packet_len).read_to_string(&mut packet).unwrap();
|
||||
|
@ -53,7 +53,7 @@ impl JsonPacketStream for TcpStream {
|
|||
return match Json::from_str(&packet) {
|
||||
Ok(json) => Ok(Some(json)),
|
||||
Err(err) => match err {
|
||||
IoError(ioerr) => return Err(ioerr.description().to_string()),
|
||||
IoError(ioerr) => return Err(ioerr.description().to_owned()),
|
||||
SyntaxError(_, l, c) => return Err(format!("syntax at {}:{}", l, c)),
|
||||
},
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue