Bug 1874684 - Part 6: Limit day length calculations to safe integers. r=mgaudet
[gecko.git] / dom / debugger / DebuggerNotificationManager.cpp
blob773fdc0c5aa318869024af4bac292838e81a6a51
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 #include "DebuggerNotificationManager.h"
9 #include "nsIGlobalObject.h"
11 namespace mozilla::dom {
13 NS_IMPL_CYCLE_COLLECTION(DebuggerNotificationManager, mDebuggeeGlobal,
14 mNotificationObservers)
16 NS_IMPL_CYCLE_COLLECTING_ADDREF(DebuggerNotificationManager)
17 NS_IMPL_CYCLE_COLLECTING_RELEASE(DebuggerNotificationManager)
19 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DebuggerNotificationManager)
20 NS_INTERFACE_MAP_ENTRY(nsISupports)
21 NS_INTERFACE_MAP_END
23 NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(DebuggerNotificationManager)
24 NS_IMPL_CYCLE_COLLECTION_TRACE_END
26 bool DebuggerNotificationManager::Attach(
27 DebuggerNotificationObserver* aObserver) {
28 RefPtr<DebuggerNotificationObserver> ptr(aObserver);
30 if (mNotificationObservers.Contains(ptr)) {
31 return false;
34 mNotificationObservers.AppendElement(ptr);
35 return true;
37 bool DebuggerNotificationManager::Detach(
38 DebuggerNotificationObserver* aObserver) {
39 RefPtr<DebuggerNotificationObserver> ptr(aObserver);
41 return mNotificationObservers.RemoveElement(ptr);
44 bool DebuggerNotificationManager::HasListeners() {
45 const auto [begin, end] = mNotificationObservers.NonObservingRange();
46 return std::any_of(begin, end, [](const auto& observer) {
47 return observer->HasListeners();
48 });
51 void DebuggerNotificationManager::NotifyListeners(
52 DebuggerNotification* aNotification) {
53 for (RefPtr<DebuggerNotificationObserver> observer :
54 mNotificationObservers.ForwardRange()) {
55 observer->NotifyListeners(aNotification);
59 } // namespace mozilla::dom