aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/devtools.rs
diff options
context:
space:
mode:
authorbors-servo <metajack+bors@gmail.com>2015-08-09 18:27:53 -0600
committerbors-servo <metajack+bors@gmail.com>2015-08-09 18:27:53 -0600
commitf77973c903a3e08067feed3ba39cff3c6bf8ac11 (patch)
treef1281eb62e5bbec2a2002ee17aafe979368b4a84 /components/script/devtools.rs
parent44d93bc37aa8226554fc73bba20421a150b002de (diff)
parente0f007a940b5d0799f904d12ff46fece45736fc9 (diff)
downloadservo-f77973c903a3e08067feed3ba39cff3c6bf8ac11.tar.gz
servo-f77973c903a3e08067feed3ba39cff3c6bf8ac11.zip
Auto merge of #7101 - HarryLovesCode:master, r=jdm
Allows object evaluation in devtools -- Closes #6724 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. <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/7101) <!-- Reviewable:end -->
Diffstat (limited to 'components/script/devtools.rs')
-rw-r--r--components/script/devtools.rs17
1 files changed, 14 insertions, 3 deletions
diff --git a/components/script/devtools.rs b/components/script/devtools.rs
index 3307eb20dc3..2211df2931b 100644
--- a/components/script/devtools.rs
+++ b/components/script/devtools.rs
@@ -20,11 +20,14 @@ use page::{IterablePage, Page};
use ipc_channel::ipc::IpcSender;
use msg::constellation_msg::PipelineId;
use script_task::{get_page, ScriptTask};
-use js::jsapi::RootedValue;
+use js::jsapi::{ObjectClassName, RootedObject, RootedValue};
use js::jsval::UndefinedValue;
-
+use std::ffi::CStr;
use std::rc::Rc;
+use std::str;
+use uuid::Uuid;
+#[allow(unsafe_code)]
pub fn handle_evaluate_js(global: &GlobalRef, eval: String, reply: IpcSender<EvaluateJSReply>) {
let cx = global.get_cx();
let mut rval = RootedValue::new(cx, UndefinedValue());
@@ -43,7 +46,15 @@ pub fn handle_evaluate_js(global: &GlobalRef, eval: String, reply: IpcSender<Eva
EvaluateJSReply::NullValue
} else {
assert!(rval.ptr.is_object());
- panic!("object values unimplemented")
+
+ let obj = RootedObject::new(cx, rval.ptr.to_object());
+ let class_name = unsafe { CStr::from_ptr(ObjectClassName(cx, obj.handle())) };
+ let class_name = str::from_utf8(class_name.to_bytes()).unwrap();
+
+ EvaluateJSReply::ActorValue {
+ class: class_name.to_owned(),
+ uuid: Uuid::new_v4().to_string(),
+ }
}).unwrap();
}