diff options
author | Ms2ger <Ms2ger@gmail.com> | 2017-01-05 13:55:10 +0100 |
---|---|---|
committer | Ms2ger <Ms2ger@gmail.com> | 2017-01-05 13:55:10 +0100 |
commit | 8d633fec42f8121ead9177db266ab75303773935 (patch) | |
tree | d20f8e171196ec82497e3d50ebd1de46e4763ff0 /components/script/dom/bindings/callback.rs | |
parent | 143dfc879e609603839502d61bc064fba96cc80f (diff) | |
download | servo-8d633fec42f8121ead9177db266ab75303773935.tar.gz servo-8d633fec42f8121ead9177db266ab75303773935.zip |
Simplify CallSetup.
Diffstat (limited to 'components/script/dom/bindings/callback.rs')
-rw-r--r-- | components/script/dom/bindings/callback.rs | 29 |
1 files changed, 13 insertions, 16 deletions
diff --git a/components/script/dom/bindings/callback.rs b/components/script/dom/bindings/callback.rs index a5f82f1f303..30a6dfd5a2d 100644 --- a/components/script/dom/bindings/callback.rs +++ b/components/script/dom/bindings/callback.rs @@ -5,16 +5,15 @@ //! Base classes to work with IDL callbacks. use dom::bindings::error::{Error, Fallible, report_pending_exception}; +use dom::bindings::js::Root; use dom::bindings::reflector::DomObject; use dom::globalscope::GlobalScope; -use js::jsapi::{Heap, MutableHandleObject, RootedObject}; +use js::jsapi::{Heap, MutableHandleObject}; use js::jsapi::{IsCallable, JSContext, JSObject, JS_WrapObject}; use js::jsapi::{JSCompartment, JS_EnterCompartment, JS_LeaveCompartment}; -use js::jsapi::GetGlobalForObjectCrossCompartment; use js::jsapi::JSAutoCompartment; use js::jsapi::JS_GetProperty; use js::jsval::{JSVal, UndefinedValue}; -use js::rust::RootedGuard; use std::default::Default; use std::ffi::CString; use std::ptr; @@ -147,9 +146,10 @@ pub fn wrap_call_this_object<T: DomObject>(cx: *mut JSContext, /// A class that performs whatever setup we need to safely make a call while /// this class is on the stack. After `new` returns, the call is safe to make. -pub struct CallSetup<'a> { - /// The compartment for reporting exceptions. - exception_compartment: RootedGuard<'a, *mut JSObject>, +pub struct CallSetup { + /// The global for reporting exceptions. This is the global object of the + /// (possibly wrapped) callback object. + exception_global: Root<GlobalScope>, /// The `JSContext` used for the call. cx: *mut JSContext, /// The compartment we were in before the call. @@ -158,21 +158,17 @@ pub struct CallSetup<'a> { handling: ExceptionHandling, } -impl<'a> CallSetup<'a> { +impl CallSetup { /// Performs the setup needed to make a call. #[allow(unrooted_must_root)] - pub fn new<T: CallbackContainer>(exception_compartment: &'a mut RootedObject, - callback: &T, + pub fn new<T: CallbackContainer>(callback: &T, handling: ExceptionHandling) - -> CallSetup<'a> { + -> CallSetup { let global = unsafe { GlobalScope::from_object(callback.callback()) }; let cx = global.get_cx(); - exception_compartment.ptr = unsafe { - GetGlobalForObjectCrossCompartment(callback.callback()) - }; CallSetup { - exception_compartment: RootedGuard::new(cx, exception_compartment), + exception_global: global, cx: cx, old_compartment: unsafe { JS_EnterCompartment(cx, callback.callback()) }, handling: handling, @@ -185,12 +181,13 @@ impl<'a> CallSetup<'a> { } } -impl<'a> Drop for CallSetup<'a> { +impl Drop for CallSetup { fn drop(&mut self) { unsafe { JS_LeaveCompartment(self.cx, self.old_compartment); if self.handling == ExceptionHandling::Report { - let _ac = JSAutoCompartment::new(self.cx, *self.exception_compartment); + let _ac = JSAutoCompartment::new(self.cx, + self.exception_global.reflector().get_jsobject().get()); report_pending_exception(self.cx, true); } } |