aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/bindings/error.rs
diff options
context:
space:
mode:
authormarmeladema <xademax@gmail.com>2019-07-27 19:36:21 +0100
committermarmeladema <xademax@gmail.com>2019-08-09 00:43:28 +0100
commit0703a1ad6d736796d467f5a028e5ab3c6d876268 (patch)
tree8c8d3abf018339a38f40df2ce4d090a3f31ee4d6 /components/script/dom/bindings/error.rs
parent6c26518f61f016bf2a0bac9dced9d222880fbaec (diff)
downloadservo-0703a1ad6d736796d467f5a028e5ab3c6d876268.tar.gz
servo-0703a1ad6d736796d467f5a028e5ab3c6d876268.zip
Use safe JSContext as first argument for throw_dom_exception
Diffstat (limited to 'components/script/dom/bindings/error.rs')
-rw-r--r--components/script/dom/bindings/error.rs35
1 files changed, 19 insertions, 16 deletions
diff --git a/components/script/dom/bindings/error.rs b/components/script/dom/bindings/error.rs
index 40d690ff8d0..b0b6ca1f685 100644
--- a/components/script/dom/bindings/error.rs
+++ b/components/script/dom/bindings/error.rs
@@ -15,6 +15,7 @@ use crate::dom::bindings::conversions::{
use crate::dom::bindings::str::USVString;
use crate::dom::domexception::{DOMErrorName, DOMException};
use crate::dom::globalscope::GlobalScope;
+use crate::script_runtime::JSContext as SafeJSContext;
#[cfg(feature = "js_backtrace")]
use backtrace::Backtrace;
use js::error::{throw_range_error, throw_type_error};
@@ -104,10 +105,10 @@ pub type Fallible<T> = Result<T, Error>;
pub type ErrorResult = Fallible<()>;
/// Set a pending exception for the given `result` on `cx`.
-pub unsafe fn throw_dom_exception(cx: *mut JSContext, global: &GlobalScope, result: Error) {
+pub fn throw_dom_exception(cx: SafeJSContext, global: &GlobalScope, result: Error) {
#[cfg(feature = "js_backtrace")]
{
- capture_stack!(in(cx) let stack);
+ capture_stack!(in(*cx) let stack);
let js_stack = stack.and_then(|s| s.as_string(None));
let rust_stack = Backtrace::new();
LAST_EXCEPTION_BACKTRACE.with(|backtrace| {
@@ -139,27 +140,29 @@ pub unsafe fn throw_dom_exception(cx: *mut JSContext, global: &GlobalScope, resu
Error::InvalidModification => DOMErrorName::InvalidModificationError,
Error::NotReadable => DOMErrorName::NotReadableError,
Error::Operation => DOMErrorName::OperationError,
- Error::Type(message) => {
- assert!(!JS_IsExceptionPending(cx));
- throw_type_error(cx, &message);
+ Error::Type(message) => unsafe {
+ assert!(!JS_IsExceptionPending(*cx));
+ throw_type_error(*cx, &message);
return;
},
- Error::Range(message) => {
- assert!(!JS_IsExceptionPending(cx));
- throw_range_error(cx, &message);
+ Error::Range(message) => unsafe {
+ assert!(!JS_IsExceptionPending(*cx));
+ throw_range_error(*cx, &message);
return;
},
- Error::JSFailed => {
- assert!(JS_IsExceptionPending(cx));
+ Error::JSFailed => unsafe {
+ assert!(JS_IsExceptionPending(*cx));
return;
},
};
- assert!(!JS_IsExceptionPending(cx));
- let exception = DOMException::new(global, code);
- rooted!(in(cx) let mut thrown = UndefinedValue());
- exception.to_jsval(cx, thrown.handle_mut());
- JS_SetPendingException(cx, thrown.handle());
+ unsafe {
+ assert!(!JS_IsExceptionPending(*cx));
+ let exception = DOMException::new(global, code);
+ rooted!(in(*cx) let mut thrown = UndefinedValue());
+ exception.to_jsval(*cx, thrown.handle_mut());
+ JS_SetPendingException(*cx, thrown.handle());
+ }
}
/// A struct encapsulating information about a runtime script error.
@@ -310,7 +313,7 @@ impl Error {
Error::JSFailed => (),
_ => assert!(!JS_IsExceptionPending(cx)),
}
- throw_dom_exception(cx, global, self);
+ throw_dom_exception(SafeJSContext::from_ptr(cx), global, self);
assert!(JS_IsExceptionPending(cx));
assert!(JS_GetPendingException(cx, rval));
JS_ClearPendingException(cx);