Skip to content

Commit

Permalink
Bug 1819767 - [devtools] Avoid instantiating EventCallbackDebuggerNot…
Browse files Browse the repository at this point in the history
…ificationGuard 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
  • Loading branch information
ochameau committed Mar 30, 2023
1 parent db486d2 commit 175040d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions dom/debugger/EventCallbackDebuggerNotification.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class EventCallbackDebuggerNotification : public CallbackDebuggerNotification {

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

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

Expand Down
6 changes: 5 additions & 1 deletion dom/events/EventListenerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "mozilla/TimelineConsumers.h"
#include "mozilla/EventTimelineMarker.h"
#include "mozilla/TimeStamp.h"
#include "mozilla/dom/ChromeUtils.h"

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

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

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

0 comments on commit 175040d

Please sign in to comment.