Bug 1560374 - Set testharness and reftest web-platform-tests to Tier-1; r=jmaher...
[gecko.git] / dom / abort / AbortSignal.h
blobe7663bb111cc53f9fa633bfe023f1f30300982e3
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"
13 namespace mozilla {
14 namespace dom {
16 class AbortSignal;
17 class AbortSignalImpl;
19 // This class must be implemented by objects who want to follow a
20 // AbortSignalImpl.
21 class AbortFollower {
22 public:
23 virtual void Abort() = 0;
25 void Follow(AbortSignalImpl* aSignal);
27 void Unfollow();
29 bool IsFollowing() const;
31 protected:
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 {
42 public:
43 explicit AbortSignalImpl(bool aAborted);
45 bool Aborted() const;
47 void Abort() override;
49 void AddFollower(AbortFollower* aFollower);
51 void RemoveFollower(AbortFollower* aFollower);
53 protected:
54 virtual ~AbortSignalImpl() = default;
56 private:
57 // Raw pointers. AbortFollower unregisters itself in the DTOR.
58 nsTObserverArray<AbortFollower*> mFollowers;
60 bool mAborted;
63 class AbortSignal final : public DOMEventTargetHelper, public AbortSignalImpl {
64 public:
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;
77 private:
78 ~AbortSignal() = default;
81 } // namespace dom
82 } // namespace mozilla
84 #endif // mozilla_dom_AbortSignal_h