servo: Merge #12272 - Reuse report_pending_exception in CallSetup (from Ms2ger:report); r=jdm
authorMs2ger <Ms2ger@gmail.com>
Wed, 06 Jul 2016 20:49:54 -0700
changeset 339228 0fae6524fcb2f0996cf5de598b4954de18a85bda
parent 339227 166868446ad200adbad776513046219f128c3064
child 339229 f60fe1b78695a78eeafe6fdd14897a35d3df812e
push id31307
push usergszorc@mozilla.com
push dateSat, 04 Feb 2017 00:59:06 +0000
treeherdermozilla-central@94079d43835f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdm
servo: Merge #12272 - Reuse report_pending_exception in CallSetup (from Ms2ger:report); r=jdm Source-Repo: https://github.com/servo/servo Source-Revision: 4fafcb121f807c31593bd2f8731358c68b3b7810
servo/components/script/dom/bindings/callback.rs
--- a/servo/components/script/dom/bindings/callback.rs
+++ b/servo/components/script/dom/bindings/callback.rs
@@ -1,23 +1,22 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 //! Base classes to work with IDL callbacks.
 
-use dom::bindings::error::{Error, Fallible};
+use dom::bindings::error::{Error, Fallible, report_pending_exception};
 use dom::bindings::global::global_root_from_object;
 use dom::bindings::reflector::Reflectable;
 use js::jsapi::GetGlobalForObjectCrossCompartment;
-use js::jsapi::JSAutoCompartment;
+use js::jsapi::JS_GetProperty;
 use js::jsapi::{Heap, MutableHandleObject, RootedObject};
 use js::jsapi::{IsCallable, JSContext, JSObject, JS_WrapObject};
 use js::jsapi::{JSCompartment, JS_EnterCompartment, JS_LeaveCompartment};
-use js::jsapi::{JS_GetProperty, JS_IsExceptionPending, JS_ReportPendingException};
 use js::jsval::{JSVal, UndefinedValue};
 use js::rust::RootedGuard;
 use std::default::Default;
 use std::ffi::CString;
 use std::ptr;
 use std::rc::Rc;
 
 /// The exception handling used for a call.
@@ -184,19 +183,14 @@ impl<'a> CallSetup<'a> {
         self.cx
     }
 }
 
 impl<'a> Drop for CallSetup<'a> {
     fn drop(&mut self) {
         unsafe {
             JS_LeaveCompartment(self.cx, self.old_compartment);
-        }
-        let need_to_deal_with_exception = self.handling == ExceptionHandling::Report &&
-                                          unsafe { JS_IsExceptionPending(self.cx) };
-        if need_to_deal_with_exception {
-            unsafe {
-                let _ac = JSAutoCompartment::new(self.cx, *self.exception_compartment);
-                JS_ReportPendingException(self.cx);
+            if self.handling == ExceptionHandling::Report {
+                report_pending_exception(self.cx, *self.exception_compartment);
             }
         }
     }
 }