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
{
17 NS_DECL_ISUPPORTS_INHERITED
18 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(CallbackDebuggerNotification
,
21 CallbackDebuggerNotification(nsIGlobalObject
* aDebuggeeGlobal
,
22 DebuggerNotificationType aType
,
23 CallbackDebuggerNotificationPhase aPhase
,
24 nsIGlobalObject
* aOwnerGlobal
= nullptr)
25 : DebuggerNotification(aDebuggeeGlobal
, aType
, aOwnerGlobal
),
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
; }
38 ~CallbackDebuggerNotification() = default;
40 CallbackDebuggerNotificationPhase mPhase
;
43 class MOZ_RAII CallbackDebuggerNotificationGuard final
{
45 MOZ_CAN_RUN_SCRIPT
CallbackDebuggerNotificationGuard(
46 nsIGlobalObject
* aDebuggeeGlobal
, DebuggerNotificationType aType
)
47 : mDebuggeeGlobal(aDebuggeeGlobal
), mType(aType
) {
48 Dispatch(CallbackDebuggerNotificationPhase::Pre
);
50 CallbackDebuggerNotificationGuard(const CallbackDebuggerNotificationGuard
&) =
52 CallbackDebuggerNotificationGuard(CallbackDebuggerNotificationGuard
&&) =
54 CallbackDebuggerNotificationGuard
& operator=(
55 const CallbackDebuggerNotificationGuard
&) = delete;
56 CallbackDebuggerNotificationGuard
& operator=(
57 CallbackDebuggerNotificationGuard
&&) = delete;
59 MOZ_CAN_RUN_SCRIPT
~CallbackDebuggerNotificationGuard() {
60 Dispatch(CallbackDebuggerNotificationPhase::Post
);
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