Bug 1892041 - Part 1: Update test262 features. r=spidermonkey-reviewers,dminor
[gecko.git] / dom / debugger / EventCallbackDebuggerNotification.h
blobb4f85e5624591dcadb73a0f035904466a6b474d7
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_EventCallbackDebuggerNotification_h
8 #define mozilla_dom_EventCallbackDebuggerNotification_h
10 #include "CallbackDebuggerNotification.h"
11 #include "DebuggerNotificationManager.h"
12 #include "mozilla/dom/Event.h"
13 #include "mozilla/RefPtr.h"
15 namespace mozilla::dom {
17 class EventCallbackDebuggerNotification : public CallbackDebuggerNotification {
18 public:
19 NS_DECL_ISUPPORTS_INHERITED
20 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(EventCallbackDebuggerNotification,
21 CallbackDebuggerNotification)
23 EventCallbackDebuggerNotification(
24 nsIGlobalObject* aDebuggeeGlobal, DebuggerNotificationType aType,
25 Event* aEvent, EventCallbackDebuggerNotificationType aTargetType,
26 CallbackDebuggerNotificationPhase aPhase,
27 nsIGlobalObject* aOwnerGlobal = nullptr)
28 : CallbackDebuggerNotification(aDebuggeeGlobal, aType, aPhase,
29 aOwnerGlobal),
30 mEvent(aEvent),
31 mTargetType(aTargetType) {}
33 // nsWrapperCache
34 virtual JSObject* WrapObject(JSContext* aCx,
35 JS::Handle<JSObject*> aGivenProto) override;
37 already_AddRefed<DebuggerNotification> CloneInto(
38 nsIGlobalObject* aNewOwner) const override;
40 mozilla::dom::Event* Event() const { return mEvent; }
41 EventCallbackDebuggerNotificationType TargetType() const {
42 return mTargetType;
45 private:
46 ~EventCallbackDebuggerNotification() = default;
48 RefPtr<mozilla::dom::Event> mEvent;
49 EventCallbackDebuggerNotificationType mTargetType;
52 class MOZ_RAII EventCallbackDebuggerNotificationGuard final {
53 public:
54 MOZ_CAN_RUN_SCRIPT_BOUNDARY explicit EventCallbackDebuggerNotificationGuard(
55 mozilla::dom::EventTarget* aEventTarget, mozilla::dom::Event* aEvent)
56 : mDebuggeeGlobal(aEventTarget ? aEventTarget->GetOwnerGlobal()
57 : nullptr),
58 mEventTarget(aEventTarget),
59 mEvent(aEvent) {
60 Dispatch(CallbackDebuggerNotificationPhase::Pre);
62 EventCallbackDebuggerNotificationGuard(
63 const EventCallbackDebuggerNotificationGuard&) = delete;
64 EventCallbackDebuggerNotificationGuard(
65 EventCallbackDebuggerNotificationGuard&&) = delete;
66 EventCallbackDebuggerNotificationGuard& operator=(
67 const EventCallbackDebuggerNotificationGuard&) = delete;
68 EventCallbackDebuggerNotificationGuard& operator=(
69 EventCallbackDebuggerNotificationGuard&&) = delete;
71 MOZ_CAN_RUN_SCRIPT_BOUNDARY ~EventCallbackDebuggerNotificationGuard() {
72 Dispatch(CallbackDebuggerNotificationPhase::Post);
75 private:
76 MOZ_CAN_RUN_SCRIPT void Dispatch(CallbackDebuggerNotificationPhase aPhase) {
77 auto manager = DebuggerNotificationManager::ForDispatch(mDebuggeeGlobal);
78 if (MOZ_UNLIKELY(manager)) {
79 DispatchToManager(manager, aPhase);
83 MOZ_CAN_RUN_SCRIPT void DispatchToManager(
84 const RefPtr<DebuggerNotificationManager>& aManager,
85 CallbackDebuggerNotificationPhase aPhase);
87 nsIGlobalObject* mDebuggeeGlobal;
88 mozilla::dom::EventTarget* mEventTarget;
89 mozilla::dom::Event* mEvent;
92 } // namespace mozilla::dom
94 #endif // mozilla_dom_EventCallbackDebuggerNotification_h