Commit 8b5caa03 authored by Alexandre Poirot's avatar Alexandre Poirot
Browse files

Bug 1819767 - [devtools] Avoid instantiating...

Bug 1819767 - [devtools] Avoid instantiating EventCallbackDebuggerNotificationGuard when DevTools aren't opened at all. r=smaug

Note that it may still be instantiated if DevTools are debugging another document/context.
Enabling this codepath only if the related document is debugged by devtools
would require checking BrowsingContext.isWatchedByDevTools.

Differential Revision: https://phabricator.services.mozilla.com/D173439
parent 61c0a76c
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -51,7 +51,7 @@ class EventCallbackDebuggerNotification : public CallbackDebuggerNotification {


class MOZ_RAII EventCallbackDebuggerNotificationGuard final {
class MOZ_RAII EventCallbackDebuggerNotificationGuard final {
 public:
 public:
  MOZ_CAN_RUN_SCRIPT explicit EventCallbackDebuggerNotificationGuard(
  MOZ_CAN_RUN_SCRIPT_BOUNDARY explicit EventCallbackDebuggerNotificationGuard(
      mozilla::dom::EventTarget* aEventTarget, mozilla::dom::Event* aEvent)
      mozilla::dom::EventTarget* aEventTarget, mozilla::dom::Event* aEvent)
      : mDebuggeeGlobal(aEventTarget ? aEventTarget->GetOwnerGlobal()
      : mDebuggeeGlobal(aEventTarget ? aEventTarget->GetOwnerGlobal()
                                     : nullptr),
                                     : nullptr),
@@ -68,7 +68,7 @@ class MOZ_RAII EventCallbackDebuggerNotificationGuard final {
  EventCallbackDebuggerNotificationGuard& operator=(
  EventCallbackDebuggerNotificationGuard& operator=(
      EventCallbackDebuggerNotificationGuard&&) = delete;
      EventCallbackDebuggerNotificationGuard&&) = delete;


  MOZ_CAN_RUN_SCRIPT ~EventCallbackDebuggerNotificationGuard() {
  MOZ_CAN_RUN_SCRIPT_BOUNDARY ~EventCallbackDebuggerNotificationGuard() {
    Dispatch(CallbackDebuggerNotificationPhase::Post);
    Dispatch(CallbackDebuggerNotificationPhase::Post);
  }
  }


+5 −1
Original line number Original line Diff line number Diff line
@@ -36,6 +36,7 @@
#include "mozilla/TimelineConsumers.h"
#include "mozilla/TimelineConsumers.h"
#include "mozilla/EventTimelineMarker.h"
#include "mozilla/EventTimelineMarker.h"
#include "mozilla/TimeStamp.h"
#include "mozilla/TimeStamp.h"
#include "mozilla/dom/ChromeUtils.h"


#include "EventListenerService.h"
#include "EventListenerService.h"
#include "nsCOMPtr.h"
#include "nsCOMPtr.h"
@@ -1299,7 +1300,10 @@ nsresult EventListenerManager::HandleEventSubType(Listener* aListener,
  }
  }


  if (NS_SUCCEEDED(result)) {
  if (NS_SUCCEEDED(result)) {
    EventCallbackDebuggerNotificationGuard dbgGuard(aCurrentTarget, aDOMEvent);
    Maybe<EventCallbackDebuggerNotificationGuard> dbgGuard;
    if (dom::ChromeUtils::IsDevToolsOpened()) {
      dbgGuard.emplace(aCurrentTarget, aDOMEvent);
    }
    nsAutoMicroTask mt;
    nsAutoMicroTask mt;


    // Event::currentTarget is set in EventDispatcher.
    // Event::currentTarget is set in EventDispatcher.