Dom: Implement AbortSignal ThrowIfAborted method (#37245)

Implement the ThrowIfAborted method of AbortSignal; part of
https://github.com/servo/servo/issues/36935.

Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com>
This commit is contained in:
Taym Haddadi 2025-06-04 13:48:25 +02:00 committed by GitHub
parent 39ee27eea6
commit aff38cdbd0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -6,7 +6,7 @@ use std::cell::RefCell;
use std::mem; use std::mem;
use dom_struct::dom_struct; use dom_struct::dom_struct;
use js::jsapi::Heap; use js::jsapi::{ExceptionStackBehavior, Heap, JS_SetPendingException};
use js::jsval::{JSVal, UndefinedValue}; use js::jsval::{JSVal, UndefinedValue};
use js::rust::{HandleObject, HandleValue, MutableHandleValue}; use js::rust::{HandleObject, HandleValue, MutableHandleValue};
use script_bindings::inheritance::Castable; use script_bindings::inheritance::Castable;
@ -139,7 +139,17 @@ impl AbortSignalMethods<crate::DomTypeHolder> for AbortSignal {
/// <https://dom.spec.whatwg.org/#dom-abortsignal-throwifaborted> /// <https://dom.spec.whatwg.org/#dom-abortsignal-throwifaborted>
#[allow(unsafe_code)] #[allow(unsafe_code)]
fn ThrowIfAborted(&self) { fn ThrowIfAborted(&self) {
// TODO // The throwIfAborted() method steps are to throw thiss abort reason, if this is aborted.
if self.aborted() {
let cx = GlobalScope::get_cx();
unsafe {
JS_SetPendingException(
*cx,
self.abort_reason.handle(),
ExceptionStackBehavior::Capture,
)
};
}
} }
// <https://dom.spec.whatwg.org/#dom-abortsignal-onabort> // <https://dom.spec.whatwg.org/#dom-abortsignal-onabort>