mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
make report_pending_exception safe and adjust callers (#35351)
Signed-off-by: Nolen Scaife <nolen@scaife.org>
This commit is contained in:
parent
827012fc08
commit
df73d02932
8 changed files with 42 additions and 44 deletions
|
@ -278,12 +278,12 @@ impl Drop for CallSetup {
|
|||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
LeaveRealm(*self.cx, self.old_realm);
|
||||
if self.handling == ExceptionHandling::Report {
|
||||
let ar = enter_realm(&*self.exception_global);
|
||||
report_pending_exception(*self.cx, true, InRealm::Entered(&ar), CanGc::note());
|
||||
}
|
||||
drop(self.incumbent_script.take());
|
||||
drop(self.entry_script.take().unwrap());
|
||||
}
|
||||
if self.handling == ExceptionHandling::Report {
|
||||
let ar = enter_realm(&*self.exception_global);
|
||||
report_pending_exception(self.cx, true, InRealm::Entered(&ar), CanGc::note());
|
||||
}
|
||||
drop(self.incumbent_script.take());
|
||||
drop(self.entry_script.take().unwrap());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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| {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue