make report_pending_exception safe and adjust callers (#35351)

Signed-off-by: Nolen Scaife <nolen@scaife.org>
This commit is contained in:
Nolen Scaife 2025-02-08 15:22:44 -07:00 committed by GitHub
parent 827012fc08
commit df73d02932
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 42 additions and 44 deletions

View file

@ -271,31 +271,35 @@ impl ErrorInfo {
///
/// The `dispatch_event` argument is temporary and non-standard; passing false
/// prevents dispatching the `error` event.
pub(crate) unsafe fn report_pending_exception(
cx: *mut JSContext,
pub(crate) fn report_pending_exception(
cx: SafeJSContext,
dispatch_event: bool,
realm: InRealm,
can_gc: CanGc,
) {
let cx = SafeJSContext::from_ptr(cx);
if !JS_IsExceptionPending(*cx) {
return;
unsafe {
if !JS_IsExceptionPending(*cx) {
return;
}
}
rooted!(in(*cx) let mut value = UndefinedValue());
if !JS_GetPendingException(*cx, value.handle_mut()) {
JS_ClearPendingException(*cx);
error!("Uncaught exception: JS_GetPendingException failed");
return;
}
JS_ClearPendingException(*cx);
unsafe {
if !JS_GetPendingException(*cx, value.handle_mut()) {
JS_ClearPendingException(*cx);
error!("Uncaught exception: JS_GetPendingException failed");
return;
}
JS_ClearPendingException(*cx);
}
let error_info = ErrorInfo::from_value(value.handle(), cx);
error!(
"Error at {}:{}:{} {}",
error_info.filename, error_info.lineno, error_info.column, error_info.message
);
#[cfg(feature = "js_backtrace")]
{
LAST_EXCEPTION_BACKTRACE.with(|backtrace| {