diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /dom/abort/AbortFollower.h | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/abort/AbortFollower.h')
-rw-r--r-- | dom/abort/AbortFollower.h | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/dom/abort/AbortFollower.h b/dom/abort/AbortFollower.h new file mode 100644 index 0000000000..9599960390 --- /dev/null +++ b/dom/abort/AbortFollower.h @@ -0,0 +1,90 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef mozilla_dom_AbortFollower_h +#define mozilla_dom_AbortFollower_h + +#include "jsapi.h" +#include "nsISupportsImpl.h" +#include "nsTObserverArray.h" +#include "mozilla/WeakPtr.h" + +namespace mozilla::dom { + +class AbortSignal; +class AbortSignalImpl; + +// This class must be implemented by objects who want to follow an +// AbortSignalImpl. +class AbortFollower : public nsISupports { + public: + virtual void RunAbortAlgorithm() = 0; + + // This adds strong reference to this follower on the signal, which means + // you'll need to call Unfollow() to prevent your object from living + // needlessly longer. + void Follow(AbortSignalImpl* aSignal); + + // Explicitly call this to let garbage collection happen sooner when the + // follower finished its work and cannot be aborted anymore. + void Unfollow(); + + bool IsFollowing() const; + + AbortSignalImpl* Signal() const { return mFollowingSignal; } + + protected: + virtual ~AbortFollower(); + + friend class AbortSignalImpl; + + WeakPtr<AbortSignalImpl> mFollowingSignal; +}; + +class AbortSignalImpl : public nsISupports, public SupportsWeakPtr { + public: + explicit AbortSignalImpl(bool aAborted, JS::Handle<JS::Value> aReason); + + bool Aborted() const; + + // Web IDL Layer + void GetReason(JSContext* aCx, JS::MutableHandle<JS::Value> aReason); + // Helper for other DOM code + JS::Value RawReason() const; + + virtual void SignalAbort(JS::Handle<JS::Value> aReason); + + protected: + // Subclasses of this class must call these Traverse and Unlink functions + // during corresponding cycle collection operations. + static void Traverse(AbortSignalImpl* aSignal, + nsCycleCollectionTraversalCallback& cb); + + static void Unlink(AbortSignalImpl* aSignal); + + virtual ~AbortSignalImpl() { UnlinkFollowers(); } + + JS::Heap<JS::Value> mReason; + + private: + friend class AbortFollower; + + void MaybeAssignAbortError(JSContext* aCx); + + void UnlinkFollowers(); + + // Raw pointers. |AbortFollower::Follow| adds to this array, and + // |AbortFollower::Unfollow| (also called by the destructor) will remove + // from this array. Finally, calling |SignalAbort()| will (after running all + // abort algorithms) empty this and make all contained followers |Unfollow()|. + nsTObserverArray<RefPtr<AbortFollower>> mFollowers; + + bool mAborted; +}; + +} // namespace mozilla::dom + +#endif // mozilla_dom_AbortFollower_h |