diff options
Diffstat (limited to 'src/components/script/dom/bindings/error.rs')
-rw-r--r-- | src/components/script/dom/bindings/error.rs | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/components/script/dom/bindings/error.rs b/src/components/script/dom/bindings/error.rs index f204dc5859a..cef1de163fd 100644 --- a/src/components/script/dom/bindings/error.rs +++ b/src/components/script/dom/bindings/error.rs @@ -6,10 +6,12 @@ use dom::bindings::conversions::ToJSValConvertible; use dom::bindings::global::GlobalRef; use dom::domexception::DOMException; -use js::jsapi::{JSContext, JSBool}; -use js::jsapi::{JS_IsExceptionPending, JS_SetPendingException}; +use js::jsapi::{JSContext, JSBool, JSObject}; +use js::jsapi::{JS_IsExceptionPending, JS_SetPendingException, JS_ReportPendingException}; use js::jsapi::{JS_ReportErrorNumber, JSErrorFormatString, JSEXN_TYPEERR}; +use js::jsapi::{JS_SaveFrameChain, JS_RestoreFrameChain}; use js::glue::{ReportError}; +use js::rust::with_compartment; use libc; use std::ptr; @@ -46,6 +48,20 @@ pub fn throw_dom_exception(cx: *mut JSContext, global: &GlobalRef, } } +pub fn report_pending_exception(cx: *mut JSContext, obj: *mut JSObject) { + unsafe { + if JS_IsExceptionPending(cx) != 0 { + let saved = JS_SaveFrameChain(cx); + with_compartment(cx, obj, || { + JS_ReportPendingException(cx); + }); + if saved != 0 { + JS_RestoreFrameChain(cx); + } + } + } +} + pub fn throw_not_in_union(cx: *mut JSContext, names: &'static str) -> JSBool { assert!(unsafe { JS_IsExceptionPending(cx) } == 0); let message = format!("argument could not be converted to any of: {}", names); |