diff options
author | Luke Wilde <lukew@serenityos.org> | 2021-12-10 19:48:51 +0000 |
---|---|---|
committer | Idan Horowitz <idan.horowitz@gmail.com> | 2021-12-10 23:05:36 +0200 |
commit | 1a5bf15b4da25e4b9362519439ed1bc2b021bc24 (patch) | |
tree | 4ca1e3887969d68a5abc4cdc96ee67cf2ff1da25 /Userland | |
parent | 64040c136e06c63e5c8139240915d86d29dd3dd7 (diff) | |
download | serenity-1a5bf15b4da25e4b9362519439ed1bc2b021bc24.zip |
LibWeb: Implement AbortSignal.throwIfAborted
See: https://github.com/whatwg/dom/commit/cfe2f1e
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/AbortSignal.cpp | 16 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/AbortSignal.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/AbortSignal.idl | 1 |
3 files changed, 19 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/DOM/AbortSignal.cpp b/Userland/Libraries/LibWeb/DOM/AbortSignal.cpp index f86bd74c57..1cb2e23cc7 100644 --- a/Userland/Libraries/LibWeb/DOM/AbortSignal.cpp +++ b/Userland/Libraries/LibWeb/DOM/AbortSignal.cpp @@ -73,6 +73,22 @@ HTML::EventHandler AbortSignal::onabort() return event_handler_attribute(HTML::EventNames::abort); } +// https://dom.spec.whatwg.org/#dom-abortsignal-throwifaborted +JS::ThrowCompletionOr<void> AbortSignal::throw_if_aborted() const +{ + auto& global_object = wrapper()->global_object(); + auto& vm = global_object.vm(); + + // The throwIfAborted() method steps are to throw thisโs abort reason, if this is aborted. + if (!aborted()) + return {}; + + // FIXME: Remove this once VM::exception() has been removed. + vm.throw_exception(global_object, m_abort_reason); + + return JS::throw_completion(m_abort_reason); +} + void AbortSignal::visit_edges(JS::Cell::Visitor& visitor) { visitor.visit(m_abort_reason); diff --git a/Userland/Libraries/LibWeb/DOM/AbortSignal.h b/Userland/Libraries/LibWeb/DOM/AbortSignal.h index fbbb83bb5c..300c7758bd 100644 --- a/Userland/Libraries/LibWeb/DOM/AbortSignal.h +++ b/Userland/Libraries/LibWeb/DOM/AbortSignal.h @@ -53,6 +53,8 @@ public: // https://dom.spec.whatwg.org/#dom-abortsignal-reason JS::Value reason() const { return m_abort_reason; } + JS::ThrowCompletionOr<void> throw_if_aborted() const; + void visit_edges(JS::Cell::Visitor&); // ^EventTarget diff --git a/Userland/Libraries/LibWeb/DOM/AbortSignal.idl b/Userland/Libraries/LibWeb/DOM/AbortSignal.idl index d28ef8a5d5..902626de92 100644 --- a/Userland/Libraries/LibWeb/DOM/AbortSignal.idl +++ b/Userland/Libraries/LibWeb/DOM/AbortSignal.idl @@ -4,6 +4,7 @@ interface AbortSignal : EventTarget { readonly attribute boolean aborted; readonly attribute any reason; + undefined throwIfAborted(); attribute EventHandler onabort; }; |