aboutsummaryrefslogtreecommitdiffstats
path: root/components/script
diff options
context:
space:
mode:
authorTaym Haddadi <haddadi.taym@gmail.com>2025-06-04 13:48:25 +0200
committerGitHub <noreply@github.com>2025-06-04 11:48:25 +0000
commitaff38cdbd05fed82a34ed03090c68d4962e742a0 (patch)
tree60a21f3b845702dcd5109b61020a8f8b2e128434 /components/script
parent39ee27eea6cff2d8d04cbdeed7edf092be47c786 (diff)
downloadservo-aff38cdbd05fed82a34ed03090c68d4962e742a0.tar.gz
servo-aff38cdbd05fed82a34ed03090c68d4962e742a0.zip
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>
Diffstat (limited to 'components/script')
-rw-r--r--components/script/dom/abortsignal.rs14
1 files changed, 12 insertions, 2 deletions
diff --git a/components/script/dom/abortsignal.rs b/components/script/dom/abortsignal.rs
index 5cf867f8a0d..e93a7b64e90 100644
--- a/components/script/dom/abortsignal.rs
+++ b/components/script/dom/abortsignal.rs
@@ -6,7 +6,7 @@ use std::cell::RefCell;
use std::mem;
use dom_struct::dom_struct;
-use js::jsapi::Heap;
+use js::jsapi::{ExceptionStackBehavior, Heap, JS_SetPendingException};
use js::jsval::{JSVal, UndefinedValue};
use js::rust::{HandleObject, HandleValue, MutableHandleValue};
use script_bindings::inheritance::Castable;
@@ -139,7 +139,17 @@ impl AbortSignalMethods<crate::DomTypeHolder> for AbortSignal {
/// <https://dom.spec.whatwg.org/#dom-abortsignal-throwifaborted>
#[allow(unsafe_code)]
fn ThrowIfAborted(&self) {
- // TODO
+ // The throwIfAborted() method steps are to throw this’s 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>