aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/script/dom/bindings/error.rs
diff options
context:
space:
mode:
authorMatt Brubeck <mbrubeck@limpet.net>2014-07-18 15:40:10 -0700
committerMatt Brubeck <mbrubeck@limpet.net>2014-07-18 15:40:10 -0700
commitd43db3df3069bed4b52b50e6efdc26f7834b9dda (patch)
treeb2a6bfe9817fbc11ededabc8d143a2331480a2fe /src/components/script/dom/bindings/error.rs
parent45379a6a6191f65cb227ce8e80c1ad73f16ebcf8 (diff)
parentd20b216e31edaf9dcf98d3647a6155b8a3b6091b (diff)
downloadservo-d43db3df3069bed4b52b50e6efdc26f7834b9dda.tar.gz
servo-d43db3df3069bed4b52b50e6efdc26f7834b9dda.zip
Merge pull request #2863 from mbrubeck/2862-null-fun
Don't fail on invalid JS syntax in event handlers. r=Ms2ger
Diffstat (limited to 'src/components/script/dom/bindings/error.rs')
-rw-r--r--src/components/script/dom/bindings/error.rs20
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);