aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/script_runtime.rs
diff options
context:
space:
mode:
authorJosh Matthews <josh@joshmatthews.net>2016-06-20 13:25:42 -0400
committerJosh Matthews <josh@joshmatthews.net>2016-06-22 09:35:19 -0400
commitb8853554dbe595dedf3d68532af66bbf0c329b42 (patch)
tree7a31274c6141630bd876a44972b799d6b56cb2d0 /components/script/script_runtime.rs
parenta74ce64539e29cfef96d03e87490c9454b61f3e1 (diff)
downloadservo-b8853554dbe595dedf3d68532af66bbf0c329b42.tar.gz
servo-b8853554dbe595dedf3d68532af66bbf0c329b42.zip
Wrap executions of Rust code called from JS in catch_unwind. Propagate the interrupted panic to the origin of the JS execution via TLS before resuming. Fix #6462.
Diffstat (limited to 'components/script/script_runtime.rs')
-rw-r--r--components/script/script_runtime.rs18
1 files changed, 17 insertions, 1 deletions
diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs
index 25fdcb579cb..a2677526e0b 100644
--- a/components/script/script_runtime.rs
+++ b/components/script/script_runtime.rs
@@ -19,7 +19,8 @@ use js::jsapi::{JSObject, RuntimeOptionsRef, SetPreserveWrapperCallback};
use js::rust::Runtime;
use profile_traits::mem::{Report, ReportKind, ReportsChan};
use script_thread::{Runnable, STACK_ROOTS, trace_thread};
-use std::cell::Cell;
+use std::any::Any;
+use std::cell::{RefCell, Cell};
use std::io::{Write, stdout};
use std::marker::PhantomData;
use std::os;
@@ -321,6 +322,21 @@ pub fn get_reports(cx: *mut JSContext, path_seg: String) -> Vec<Report> {
reports
}
+thread_local!(static PANIC_RESULT: RefCell<Option<Box<Any + Send>>> = RefCell::new(None));
+
+pub fn store_panic_result(error: Box<Any + Send>) {
+ PANIC_RESULT.with(|result| {
+ assert!(result.borrow().is_none());
+ *result.borrow_mut() = Some(error);
+ });
+}
+
+pub fn maybe_take_panic_result() -> Option<Box<Any + Send>> {
+ PANIC_RESULT.with(|result| {
+ result.borrow_mut().take()
+ })
+}
+
thread_local!(static GC_CYCLE_START: Cell<Option<Tm>> = Cell::new(None));
thread_local!(static GC_SLICE_START: Cell<Option<Tm>> = Cell::new(None));