From aff38cdbd05fed82a34ed03090c68d4962e742a0 Mon Sep 17 00:00:00 2001 From: Taym Haddadi Date: Wed, 4 Jun 2025 13:48:25 +0200 Subject: [PATCH] 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 --- components/script/dom/abortsignal.rs | 14 ++++++++++++-- 1 file 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 for AbortSignal { /// #[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, + ) + }; + } } //