Remove the JSAutoCompartment from report_pending_exception.

It doesn't really belong there.
This commit is contained in:
Ms2ger 2016-08-26 17:58:46 +02:00
parent 3b11c5ea2d
commit 5662f0d346
5 changed files with 11 additions and 10 deletions

View file

@ -8,6 +8,7 @@ use dom::bindings::error::{Error, Fallible, report_pending_exception};
use dom::bindings::global::global_root_from_object; use dom::bindings::global::global_root_from_object;
use dom::bindings::reflector::Reflectable; use dom::bindings::reflector::Reflectable;
use js::jsapi::GetGlobalForObjectCrossCompartment; use js::jsapi::GetGlobalForObjectCrossCompartment;
use js::jsapi::JSAutoCompartment;
use js::jsapi::JS_GetProperty; use js::jsapi::JS_GetProperty;
use js::jsapi::{Heap, MutableHandleObject, RootedObject}; use js::jsapi::{Heap, MutableHandleObject, RootedObject};
use js::jsapi::{IsCallable, JSContext, JSObject, JS_WrapObject}; use js::jsapi::{IsCallable, JSContext, JSObject, JS_WrapObject};
@ -189,7 +190,8 @@ impl<'a> Drop for CallSetup<'a> {
unsafe { unsafe {
JS_LeaveCompartment(self.cx, self.old_compartment); JS_LeaveCompartment(self.cx, self.old_compartment);
if self.handling == ExceptionHandling::Report { if self.handling == ExceptionHandling::Report {
report_pending_exception(self.cx, *self.exception_compartment); let _ac = JSAutoCompartment::new(self.cx, *self.exception_compartment);
report_pending_exception(self.cx);
} }
} }
} }

View file

@ -13,9 +13,7 @@ use dom::bindings::str::USVString;
use dom::domexception::{DOMErrorName, DOMException}; use dom::domexception::{DOMErrorName, DOMException};
use js::error::{throw_range_error, throw_type_error}; use js::error::{throw_range_error, throw_type_error};
use js::jsapi::HandleObject; use js::jsapi::HandleObject;
use js::jsapi::JSAutoCompartment;
use js::jsapi::JSContext; use js::jsapi::JSContext;
use js::jsapi::JSObject;
use js::jsapi::JS_ClearPendingException; use js::jsapi::JS_ClearPendingException;
use js::jsapi::JS_ErrorFromException; use js::jsapi::JS_ErrorFromException;
use js::jsapi::JS_GetPendingException; use js::jsapi::JS_GetPendingException;
@ -194,9 +192,8 @@ impl ErrorInfo {
} }
/// Report a pending exception, thereby clearing it. /// Report a pending exception, thereby clearing it.
pub unsafe fn report_pending_exception(cx: *mut JSContext, obj: *mut JSObject) { pub unsafe fn report_pending_exception(cx: *mut JSContext) {
if JS_IsExceptionPending(cx) { if JS_IsExceptionPending(cx) {
let _ac = JSAutoCompartment::new(cx, obj);
rooted!(in(cx) let mut value = UndefinedValue()); rooted!(in(cx) let mut value = UndefinedValue());
if !JS_GetPendingException(cx, value.handle_mut()) { if !JS_GetPendingException(cx, value.handle_mut()) {
JS_ClearPendingException(cx); JS_ClearPendingException(cx);

View file

@ -426,7 +426,8 @@ impl EventTarget {
if !rv || handler.get().is_null() { if !rv || handler.get().is_null() {
// Step 1.8.2 // Step 1.8.2
unsafe { unsafe {
report_pending_exception(cx, self.reflector().get_jsobject().get()); let _ac = JSAutoCompartment::new(cx, self.reflector().get_jsobject().get());
report_pending_exception(cx);
} }
// Step 1.8.1 / 1.8.3 // Step 1.8.1 / 1.8.3
return None; return None;

View file

@ -952,7 +952,7 @@ impl<'a, T: Reflectable> ScriptHelpers for &'a T {
code.len() as libc::size_t, code.len() as libc::size_t,
rval) { rval) {
debug!("error evaluating JS string"); debug!("error evaluating JS string");
report_pending_exception(cx, globalhandle.get()); report_pending_exception(cx);
} }
} }

View file

@ -20,7 +20,7 @@ use dom::window::{base64_atob, base64_btoa};
use dom::workerlocation::WorkerLocation; use dom::workerlocation::WorkerLocation;
use dom::workernavigator::WorkerNavigator; use dom::workernavigator::WorkerNavigator;
use ipc_channel::ipc::IpcSender; use ipc_channel::ipc::IpcSender;
use js::jsapi::{HandleValue, JSContext, JSRuntime}; use js::jsapi::{HandleValue, JSAutoCompartment, JSContext, JSRuntime};
use js::jsval::UndefinedValue; use js::jsval::UndefinedValue;
use js::rust::Runtime; use js::rust::Runtime;
use msg::constellation_msg::{PipelineId, ReferrerPolicy}; use msg::constellation_msg::{PipelineId, ReferrerPolicy};
@ -382,8 +382,9 @@ impl WorkerGlobalScope {
// https://github.com/servo/servo/issues/6422 // https://github.com/servo/servo/issues/6422
println!("evaluate_script failed"); println!("evaluate_script failed");
unsafe { unsafe {
report_pending_exception( let _ac = JSAutoCompartment::new(self.runtime.cx(),
self.runtime.cx(), self.reflector().get_jsobject().get()); self.reflector().get_jsobject().get());
report_pending_exception(self.runtime.cx());
} }
} }
} }