Dom: Implement AbortSignal ThrowIfAborted method

Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com>
This commit is contained in:
Taym Haddadi 2025-06-04 11:25:32 +01:00
parent e0d96163c7
commit cc5bdc855d
No known key found for this signature in database

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>