mirror of
https://github.com/servo/servo.git
synced 2025-07-24 15:50:21 +01:00
Use the conversion traits from js.
This commit is contained in:
parent
acb24e80b8
commit
6d2ae85c1f
15 changed files with 285 additions and 647 deletions
|
@ -28,33 +28,37 @@ 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());
|
||||
global.evaluate_js_on_global_with_result(&eval, rval.handle_mut());
|
||||
// global.get_cx() returns a valid `JSContext` pointer, so this is safe.
|
||||
let result = unsafe {
|
||||
let cx = global.get_cx();
|
||||
let mut rval = RootedValue::new(cx, UndefinedValue());
|
||||
global.evaluate_js_on_global_with_result(&eval, rval.handle_mut());
|
||||
|
||||
reply.send(if rval.ptr.is_undefined() {
|
||||
EvaluateJSReply::VoidValue
|
||||
} else if rval.ptr.is_boolean() {
|
||||
EvaluateJSReply::BooleanValue(rval.ptr.to_boolean())
|
||||
} else if rval.ptr.is_double() || rval.ptr.is_int32() {
|
||||
EvaluateJSReply::NumberValue(
|
||||
FromJSValConvertible::from_jsval(cx, rval.handle(), ()).unwrap())
|
||||
} else if rval.ptr.is_string() {
|
||||
EvaluateJSReply::StringValue(jsstring_to_str(cx, rval.ptr.to_string()).0)
|
||||
} else if rval.ptr.is_null() {
|
||||
EvaluateJSReply::NullValue
|
||||
} else {
|
||||
assert!(rval.ptr.is_object());
|
||||
if rval.ptr.is_undefined() {
|
||||
EvaluateJSReply::VoidValue
|
||||
} else if rval.ptr.is_boolean() {
|
||||
EvaluateJSReply::BooleanValue(rval.ptr.to_boolean())
|
||||
} else if rval.ptr.is_double() || rval.ptr.is_int32() {
|
||||
EvaluateJSReply::NumberValue(
|
||||
FromJSValConvertible::from_jsval(cx, rval.handle(), ()).unwrap())
|
||||
} else if rval.ptr.is_string() {
|
||||
EvaluateJSReply::StringValue(jsstring_to_str(cx, rval.ptr.to_string()).0)
|
||||
} else if rval.ptr.is_null() {
|
||||
EvaluateJSReply::NullValue
|
||||
} else {
|
||||
assert!(rval.ptr.is_object());
|
||||
|
||||
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();
|
||||
let obj = RootedObject::new(cx, rval.ptr.to_object());
|
||||
let class_name = 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(),
|
||||
EvaluateJSReply::ActorValue {
|
||||
class: class_name.to_owned(),
|
||||
uuid: Uuid::new_v4().to_string(),
|
||||
}
|
||||
}
|
||||
}).unwrap();
|
||||
};
|
||||
reply.send(result).unwrap();
|
||||
}
|
||||
|
||||
pub fn handle_get_root_node(page: &Rc<Page>, pipeline: PipelineId, reply: IpcSender<NodeInfo>) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue