diff options
author | Stephen Muss <stephenmuss@gmail.com> | 2025-02-11 10:47:31 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-02-10 23:47:31 +0000 |
commit | cb588bab6a78e19b2b406cb1b22b134bb35363dc (patch) | |
tree | 90d0f4fe02418d32a4ab512e5aad2ff0c57d3084 /components/script/dom/bindings | |
parent | 8486e585f567ba1b0a908ef77648dbbfd6cff04d (diff) | |
download | servo-cb588bab6a78e19b2b406cb1b22b134bb35363dc.tar.gz servo-cb588bab6a78e19b2b406cb1b22b134bb35363dc.zip |
script: make Error::to_jsval safe (#35411)
Signed-off-by: Stephen Muss <stephenmuss@gmail.com>
Diffstat (limited to 'components/script/dom/bindings')
-rw-r--r-- | components/script/dom/bindings/error.rs | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/components/script/dom/bindings/error.rs b/components/script/dom/bindings/error.rs index ac7951e4d4d..931c34eabdb 100644 --- a/components/script/dom/bindings/error.rs +++ b/components/script/dom/bindings/error.rs @@ -11,9 +11,7 @@ use backtrace::Backtrace; use js::error::{throw_range_error, throw_type_error}; #[cfg(feature = "js_backtrace")] use js::jsapi::StackFormat as JSStackFormat; -use js::jsapi::{ - ExceptionStackBehavior, JSContext, JS_ClearPendingException, JS_IsExceptionPending, -}; +use js::jsapi::{ExceptionStackBehavior, JS_ClearPendingException, JS_IsExceptionPending}; use js::jsval::UndefinedValue; use js::rust::wrappers::{JS_ErrorFromException, JS_GetPendingException, JS_SetPendingException}; use js::rust::{HandleObject, HandleValue, MutableHandleValue}; @@ -341,19 +339,21 @@ pub(crate) fn throw_constructor_without_new(cx: SafeJSContext, name: &str) { impl Error { /// Convert this error value to a JS value, consuming it in the process. #[allow(clippy::wrong_self_convention)] - pub(crate) unsafe fn to_jsval( + pub(crate) fn to_jsval( self, - cx: *mut JSContext, + cx: SafeJSContext, global: &GlobalScope, rval: MutableHandleValue, ) { match self { Error::JSFailed => (), - _ => assert!(!JS_IsExceptionPending(cx)), + _ => unsafe { assert!(!JS_IsExceptionPending(*cx)) }, + } + throw_dom_exception(cx, global, self); + unsafe { + assert!(JS_IsExceptionPending(*cx)); + assert!(JS_GetPendingException(*cx, rval)); + JS_ClearPendingException(*cx); } - throw_dom_exception(SafeJSContext::from_ptr(cx), global, self); - assert!(JS_IsExceptionPending(cx)); - assert!(JS_GetPendingException(cx, rval)); - JS_ClearPendingException(cx); } } |