Closes #6724 (Allows object evaluation in devtools)

The purpose of this is to fix how objects were previously evaluated in
the developer tools.

- Before this, evaluating an object such as the `window` would `panic!`
- After this, evaluating an object such as the `window` outputs `[object
  Window]`

A few things to note:

- This commit contains `unsafe` code.
- This does not contain a test because the developer tools cannot be properly tested until #5971 lands.
This commit is contained in:
Harrison G 2015-08-08 15:08:45 -04:00
parent 6a8bc85284
commit e0f007a940
5 changed files with 71 additions and 11 deletions

View file

@ -0,0 +1,44 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use actor::{Actor, ActorRegistry};
use rustc_serialize::json;
use std::net::TcpStream;
pub struct ObjectActor {
pub name: String,
pub uuid: String,
}
impl Actor for ObjectActor {
fn name(&self) -> String {
self.name.clone()
}
fn handle_message(&self,
_: &ActorRegistry,
_: &str,
_: &json::Object,
_: &mut TcpStream) -> Result<bool, ()> {
Ok(false)
}
}
impl ObjectActor {
pub fn new(registry: &ActorRegistry, uuid: String) -> String {
if !registry.script_actor_registered(uuid.clone()) {
let name = registry.new_name("object");
let actor = ObjectActor {
name: name.clone(),
uuid: uuid.clone(),
};
registry.register_script_actor(uuid, name.clone());
registry.register_later(box actor);
name
} else {
registry.script_to_actor(uuid)
}
}
}