Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/abort/AbortSignal.h
Line
Count
Source (jump to first uncovered line)
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/. */
6
7
#ifndef mozilla_dom_AbortSignal_h
8
#define mozilla_dom_AbortSignal_h
9
10
#include "mozilla/DOMEventTargetHelper.h"
11
#include "nsTObserverArray.h"
12
13
namespace mozilla {
14
namespace dom {
15
16
class AbortSignal;
17
class AbortSignalImpl;
18
19
// This class must be implemented by objects who want to follow a
20
// AbortSignalImpl.
21
class AbortFollower
22
{
23
public:
24
  virtual void Abort() = 0;
25
26
  void
27
  Follow(AbortSignalImpl* aSignal);
28
29
  void
30
  Unfollow();
31
32
  bool
33
  IsFollowing() const;
34
35
protected:
36
  virtual ~AbortFollower();
37
38
  // Subclasses of AbortFollower must Traverse this member and call
39
  // Unfollow() when Unlinking.
40
  RefPtr<AbortSignalImpl> mFollowingSignal;
41
};
42
43
// Any subclass of this class must Traverse mFollowingSignal and call
44
// Unfollow() when Unlinking.
45
class AbortSignalImpl : public AbortFollower
46
                      , public nsISupports
47
{
48
public:
49
  explicit AbortSignalImpl(bool aAborted);
50
51
  bool
52
  Aborted() const;
53
54
  void
55
  Abort() override;
56
57
  void
58
  AddFollower(AbortFollower* aFollower);
59
60
  void
61
  RemoveFollower(AbortFollower* aFollower);
62
63
protected:
64
0
  virtual ~AbortSignalImpl() = default;
65
66
private:
67
  // Raw pointers. AbortFollower unregisters itself in the DTOR.
68
  nsTObserverArray<AbortFollower*> mFollowers;
69
70
  bool mAborted;
71
};
72
73
class AbortSignal final : public DOMEventTargetHelper
74
                        , public AbortSignalImpl
75
{
76
public:
77
  NS_DECL_ISUPPORTS_INHERITED
78
  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(AbortSignal, DOMEventTargetHelper)
79
80
  AbortSignal(nsIGlobalObject* aGlobalObject, bool aAborted);
81
82
  JSObject*
83
  WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
84
85
  IMPL_EVENT_HANDLER(abort);
86
87
  void
88
  Abort() override;
89
90
private:
91
0
  ~AbortSignal() = default;
92
};
93
94
} // dom namespace
95
} // mozilla namespace
96
97
#endif // mozilla_dom_AbortSignal_h