1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_AbortSignal_h
8 #define mozilla_dom_AbortSignal_h
10 #include "mozilla/DOMEventTargetHelper.h"
11 #include "nsTObserverArray.h"
17 class AbortSignalImpl
;
19 // This class must be implemented by objects who want to follow a
23 virtual void Abort() = 0;
25 void Follow(AbortSignalImpl
* aSignal
);
29 bool IsFollowing() const;
32 virtual ~AbortFollower();
34 // Subclasses of AbortFollower must Traverse this member and call
35 // Unfollow() when Unlinking.
36 RefPtr
<AbortSignalImpl
> mFollowingSignal
;
39 // Any subclass of this class must Traverse mFollowingSignal and call
40 // Unfollow() when Unlinking.
41 class AbortSignalImpl
: public AbortFollower
, public nsISupports
{
43 explicit AbortSignalImpl(bool aAborted
);
47 void Abort() override
;
49 void AddFollower(AbortFollower
* aFollower
);
51 void RemoveFollower(AbortFollower
* aFollower
);
54 virtual ~AbortSignalImpl() = default;
57 // Raw pointers. AbortFollower unregisters itself in the DTOR.
58 nsTObserverArray
<AbortFollower
*> mFollowers
;
63 class AbortSignal final
: public DOMEventTargetHelper
, public AbortSignalImpl
{
65 NS_DECL_ISUPPORTS_INHERITED
66 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(AbortSignal
, DOMEventTargetHelper
)
68 AbortSignal(nsIGlobalObject
* aGlobalObject
, bool aAborted
);
70 JSObject
* WrapObject(JSContext
* aCx
,
71 JS::Handle
<JSObject
*> aGivenProto
) override
;
73 IMPL_EVENT_HANDLER(abort
);
75 void Abort() override
;
78 ~AbortSignal() = default;
82 } // namespace mozilla
84 #endif // mozilla_dom_AbortSignal_h