Bug 1874684 - Part 6: Limit day length calculations to safe integers. r=mgaudet
[gecko.git] / dom / debugger / CallbackDebuggerNotification.h
blob8059ac9ed44d12f7862c3bf09f71bb52ad702ea6
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_CallbackDebuggerNotification_h
8 #define mozilla_dom_CallbackDebuggerNotification_h
10 #include "DebuggerNotification.h"
11 #include "DebuggerNotificationManager.h"
13 namespace mozilla::dom {
15 class CallbackDebuggerNotification : public DebuggerNotification {
16 public:
17 NS_DECL_ISUPPORTS_INHERITED
18 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(CallbackDebuggerNotification,
19 DebuggerNotification)
21 CallbackDebuggerNotification(nsIGlobalObject* aDebuggeeGlobal,
22 DebuggerNotificationType aType,
23 CallbackDebuggerNotificationPhase aPhase,
24 nsIGlobalObject* aOwnerGlobal = nullptr)
25 : DebuggerNotification(aDebuggeeGlobal, aType, aOwnerGlobal),
26 mPhase(aPhase) {}
28 // nsWrapperCache
29 virtual JSObject* WrapObject(JSContext* aCx,
30 JS::Handle<JSObject*> aGivenProto) override;
32 already_AddRefed<DebuggerNotification> CloneInto(
33 nsIGlobalObject* aNewOwner) const override;
35 CallbackDebuggerNotificationPhase Phase() const { return mPhase; }
37 protected:
38 ~CallbackDebuggerNotification() = default;
40 CallbackDebuggerNotificationPhase mPhase;
43 class MOZ_RAII CallbackDebuggerNotificationGuard final {
44 public:
45 MOZ_CAN_RUN_SCRIPT CallbackDebuggerNotificationGuard(
46 nsIGlobalObject* aDebuggeeGlobal, DebuggerNotificationType aType)
47 : mDebuggeeGlobal(aDebuggeeGlobal), mType(aType) {
48 Dispatch(CallbackDebuggerNotificationPhase::Pre);
50 CallbackDebuggerNotificationGuard(const CallbackDebuggerNotificationGuard&) =
51 delete;
52 CallbackDebuggerNotificationGuard(CallbackDebuggerNotificationGuard&&) =
53 delete;
54 CallbackDebuggerNotificationGuard& operator=(
55 const CallbackDebuggerNotificationGuard&) = delete;
56 CallbackDebuggerNotificationGuard& operator=(
57 CallbackDebuggerNotificationGuard&&) = delete;
59 MOZ_CAN_RUN_SCRIPT ~CallbackDebuggerNotificationGuard() {
60 Dispatch(CallbackDebuggerNotificationPhase::Post);
63 private:
64 MOZ_CAN_RUN_SCRIPT void Dispatch(CallbackDebuggerNotificationPhase aPhase) {
65 auto manager = DebuggerNotificationManager::ForDispatch(mDebuggeeGlobal);
66 if (MOZ_UNLIKELY(manager)) {
67 manager->Dispatch<CallbackDebuggerNotification>(mType, aPhase);
71 nsIGlobalObject* mDebuggeeGlobal;
72 DebuggerNotificationType mType;
75 } // namespace mozilla::dom
77 #endif // mozilla_dom_CallbackDebuggerNotification_h