Use JSautoCompartment in devtools handle_evaluate_js to avoid segfault

fixes #11457
This commit is contained in:
Manish Goregaokar 2016-05-27 15:12:27 +05:30
parent 48257ef282
commit 283fc8dd25
No known key found for this signature in database
GPG key ID: 3BBF4D3E2EF79F98

View file

@ -21,7 +21,7 @@ use dom::element::Element;
use dom::node::Node; use dom::node::Node;
use dom::window::Window; use dom::window::Window;
use ipc_channel::ipc::IpcSender; use ipc_channel::ipc::IpcSender;
use js::jsapi::{ObjectClassName, RootedObject, RootedValue}; use js::jsapi::{JSAutoCompartment, ObjectClassName, RootedObject, RootedValue};
use js::jsval::UndefinedValue; use js::jsval::UndefinedValue;
use msg::constellation_msg::PipelineId; use msg::constellation_msg::PipelineId;
use script_thread::get_browsing_context; use script_thread::get_browsing_context;
@ -35,6 +35,8 @@ pub fn handle_evaluate_js(global: &GlobalRef, eval: String, reply: IpcSender<Eva
// global.get_cx() returns a valid `JSContext` pointer, so this is safe. // global.get_cx() returns a valid `JSContext` pointer, so this is safe.
let result = unsafe { let result = unsafe {
let cx = global.get_cx(); let cx = global.get_cx();
let globalhandle = global.reflector().get_jsobject();
let _ac = JSAutoCompartment::new(cx, globalhandle.get());
let mut rval = RootedValue::new(cx, UndefinedValue()); let mut rval = RootedValue::new(cx, UndefinedValue());
global.evaluate_js_on_global_with_result(&eval, rval.handle_mut()); global.evaluate_js_on_global_with_result(&eval, rval.handle_mut());