Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/mozilla/dom/Timeout.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_timeout_h
8
#define mozilla_dom_timeout_h
9
10
#include "mozilla/LinkedList.h"
11
#include "mozilla/TimeStamp.h"
12
#include "nsCOMPtr.h"
13
#include "nsCycleCollectionParticipant.h"
14
#include "nsGlobalWindow.h"
15
#include "nsITimeoutHandler.h"
16
17
class nsIEventTarget;
18
class nsIPrincipal;
19
class nsIEventTarget;
20
21
namespace mozilla {
22
namespace dom {
23
24
/*
25
 * Timeout struct that holds information about each script
26
 * timeout.  Holds a strong reference to an nsITimeoutHandler, which
27
 * abstracts the language specific cruft.
28
 */
29
class Timeout final
30
  : public LinkedListElement<RefPtr<Timeout>>
31
{
32
public:
33
  Timeout();
34
35
  NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(Timeout)
36
  NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(Timeout)
37
38
  enum class Reason : uint8_t
39
  {
40
    eTimeoutOrInterval,
41
    eIdleCallbackTimeout,
42
  };
43
44
  void SetWhenOrTimeRemaining(const TimeStamp& aBaseTime,
45
                              const TimeDuration& aDelay);
46
47
  // Can only be called when not frozen.
48
  const TimeStamp& When() const;
49
50
  // Can only be called when frozen.
51
  const TimeDuration& TimeRemaining() const;
52
53
private:
54
  // mWhen and mTimeRemaining can't be in a union, sadly, because they
55
  // have constructors.
56
  // Nominal time to run this timeout.  Use only when timeouts are not
57
  // frozen.
58
  TimeStamp mWhen;
59
60
  // Remaining time to wait.  Used only when timeouts are frozen.
61
  TimeDuration mTimeRemaining;
62
63
0
  ~Timeout() = default;
64
65
public:
66
  // Public member variables in this section.  Please don't add to this list
67
  // or mix methods with these.  The interleaving public/private sections
68
  // is necessary as we migrate members to private while still trying to
69
  // keep decent binary packing.
70
71
  // Window for which this timeout fires
72
  RefPtr<nsGlobalWindowInner> mWindow;
73
74
  // The language-specific information about the callback.
75
  nsCOMPtr<nsITimeoutHandler> mScriptHandler;
76
77
  // Interval
78
  TimeDuration mInterval;
79
80
  // Returned as value of setTimeout()
81
  uint32_t mTimeoutId;
82
83
  // Identifies which firing level this Timeout is being processed in
84
  // when sync loops trigger nested firing.
85
  uint32_t mFiringId;
86
87
  // The popup state at timeout creation time if not created from
88
  // another timeout
89
  PopupControlState mPopupState;
90
91
  // Used to allow several reasons for setting a timeout, where each
92
  // 'Reason' value is using a possibly overlapping set of id:s.
93
  Reason mReason;
94
95
  // Between 0 and DOM_CLAMP_TIMEOUT_NESTING_LEVEL.  Currently we don't
96
  // care about nesting levels beyond that value.
97
  uint8_t mNestingLevel;
98
99
  // True if the timeout was cleared
100
  bool mCleared;
101
102
  // True if this is one of the timeouts that are currently running
103
  bool mRunning;
104
105
  // True if this is a repeating/interval timer
106
  bool mIsInterval;
107
108
  // True if this is a timeout coming from a tracking script
109
  bool mIsTracking;
110
};
111
112
} // namespace dom
113
} // namespace mozilla
114
115
#endif // mozilla_dom_timeout_h