Bug 1449631 part 6. Remove nsIDOMEventTarget::DispatchEvent. r=smaug
authorBoris Zbarsky <bzbarsky@mit.edu>
Thu, 05 Apr 2018 13:42:41 -0400
changeset 412013 caa5bef6848122d106ad47fc7b2bf104d2d8ce3d
parent 412012 d05e92371389bf5992a4c96a243b4e3d26fe7e1f
child 412014 433dba4e710415a040ca047a5f0cbcb94eeaf2d0
push id33781
push userapavel@mozilla.com
push dateFri, 06 Apr 2018 14:39:11 +0000
treeherdermozilla-central@6792eee0c9c5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1449631
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1449631 part 6. Remove nsIDOMEventTarget::DispatchEvent. r=smaug MozReview-Commit-ID: 8YMgmMwZkAL
dom/abort/AbortSignal.cpp
dom/base/DOMRequest.cpp
dom/base/EventSource.cpp
dom/base/nsContentUtils.cpp
dom/base/nsDOMDataChannel.cpp
dom/base/nsDOMWindowUtils.cpp
dom/base/nsFrameLoader.cpp
dom/base/nsGlobalWindowInner.cpp
dom/base/nsGlobalWindowInner.h
dom/base/nsGlobalWindowOuter.cpp
dom/base/nsGlobalWindowOuter.h
dom/base/nsINode.cpp
dom/base/nsINode.h
dom/base/nsPluginArray.cpp
dom/base/nsWindowRoot.cpp
dom/base/nsWindowRoot.h
dom/broadcastchannel/BroadcastChannelChild.cpp
dom/canvas/WebGLContext.cpp
dom/clients/manager/ClientSource.cpp
dom/events/AsyncEventDispatcher.cpp
dom/events/DOMEventTargetHelper.cpp
dom/events/DOMEventTargetHelper.h
dom/events/EventTarget.cpp
dom/events/EventTarget.h
dom/events/PointerEventHandler.cpp
dom/fetch/FetchObserver.cpp
dom/file/FileReader.cpp
dom/gamepad/GamepadManager.cpp
dom/indexedDB/ActorsChild.cpp
dom/indexedDB/IDBEvents.cpp
dom/indexedDB/IDBEvents.h
dom/indexedDB/IDBFileHandle.cpp
dom/indexedDB/IDBRequest.cpp
dom/indexedDB/IDBTransaction.cpp
dom/interfaces/events/nsIDOMEventTarget.idl
dom/ipc/TabParent.cpp
dom/media/MediaRecorder.cpp
dom/media/webspeech/recognition/SpeechRecognition.cpp
dom/messagechannel/MessagePort.cpp
dom/network/TCPServerSocket.cpp
dom/network/TCPSocket.cpp
dom/notification/Notification.cpp
dom/offline/nsDOMOfflineResourceList.cpp
dom/offline/nsDOMOfflineResourceList.h
dom/payments/PaymentRequest.cpp
dom/performance/Performance.cpp
dom/performance/PerformanceMainThread.cpp
dom/presentation/PresentationConnection.cpp
dom/security/nsCSPContext.cpp
dom/serviceworkers/ServiceWorkerPrivate.cpp
dom/system/nsDeviceSensors.cpp
dom/websocket/WebSocket.cpp
dom/workers/MessageEventRunnable.cpp
dom/workers/SharedWorker.cpp
dom/workers/SharedWorker.h
dom/workers/WorkerDebugger.cpp
dom/workers/WorkerError.cpp
dom/workers/WorkerPrivate.cpp
dom/xhr/XMLHttpRequestMainThread.cpp
dom/xhr/XMLHttpRequestWorker.cpp
dom/xml/nsXMLPrettyPrinter.cpp
layout/base/nsRefreshDriver.cpp
layout/base/nsRefreshDriver.h
layout/style/MediaQueryList.cpp
toolkit/components/extensions/webrequest/ChannelWrapper.cpp
toolkit/components/extensions/webrequest/StreamFilter.cpp
toolkit/components/satchel/nsFormFillController.cpp
toolkit/components/windowwatcher/nsAutoWindowStateHelper.cpp
widget/cocoa/nsMenuItemX.mm
widget/cocoa/nsMenuUtilsX.mm
xpfe/appshell/nsXULWindow.cpp
--- a/dom/abort/AbortSignal.cpp
+++ b/dom/abort/AbortSignal.cpp
@@ -68,18 +68,17 @@ AbortSignal::Abort()
   EventInit init;
   init.mBubbles = false;
   init.mCancelable = false;
 
   RefPtr<Event> event =
     Event::Constructor(this, NS_LITERAL_STRING("abort"), init);
   event->SetTrusted(true);
 
-  bool dummy;
-  DispatchEvent(event, &dummy);
+  DispatchEvent(*event);
 }
 
 void
 AbortSignal::AddFollower(AbortFollower* aFollower)
 {
   MOZ_DIAGNOSTIC_ASSERT(aFollower);
   if (!mFollowers.Contains(aFollower)) {
     mFollowers.AppendElement(aFollower);
--- a/dom/base/DOMRequest.cpp
+++ b/dom/base/DOMRequest.cpp
@@ -191,18 +191,17 @@ DOMRequest::FireEvent(const nsAString& a
   if (NS_FAILED(CheckInnerWindowCorrectness())) {
     return;
   }
 
   RefPtr<Event> event = NS_NewDOMEvent(this, nullptr, nullptr);
   event->InitEvent(aType, aBubble, aCancelable);
   event->SetTrusted(true);
 
-  bool dummy;
-  DispatchEvent(event, &dummy);
+  DispatchEvent(*event);
 }
 
 void
 DOMRequest::RootResultVal()
 {
   mozilla::HoldJSObjects(this);
 }
 
--- a/dom/base/EventSource.cpp
+++ b/dom/base/EventSource.cpp
@@ -1519,19 +1519,19 @@ EventSourceImpl::DispatchAllMessageEvent
     RefPtr<MessageEvent> event = new MessageEvent(mEventSource, nullptr,
                                                   nullptr);
 
     event->InitMessageEvent(nullptr, message->mEventName, false, false, jsData,
                             mOrigin, message->mLastEventID, nullptr,
                             Sequence<OwningNonNull<MessagePort>>());
     event->SetTrusted(true);
 
-    bool dummy;
-    rv = mEventSource->DispatchEvent(static_cast<Event*>(event), &dummy);
-    if (NS_FAILED(rv)) {
+    IgnoredErrorResult err;
+    mEventSource->DispatchEvent(*event, err);
+    if (err.Failed()) {
       NS_WARNING("Failed to dispatch the message event!!!");
       return;
     }
 
     mLastEventID.Assign(message->mLastEventID);
     if (IsClosed() || IsFrozen()) {
       return;
     }
@@ -1941,18 +1941,19 @@ EventSource::~EventSource()
 
 nsresult
 EventSource::CreateAndDispatchSimpleEvent(const nsAString& aName)
 {
   RefPtr<Event> event = NS_NewDOMEvent(this, nullptr, nullptr);
   // it doesn't bubble, and it isn't cancelable
   event->InitEvent(aName, false, false);
   event->SetTrusted(true);
-  bool dummy;
-  return DispatchEvent(event, &dummy);
+  ErrorResult rv;
+  DispatchEvent(*event, rv);
+  return rv.StealNSResult();
 }
 
 /* static */ already_AddRefed<EventSource>
 EventSource::Constructor(const GlobalObject& aGlobal, const nsAString& aURL,
                          const EventSourceInit& aEventSourceInitDict,
                          ErrorResult& aRv)
 {
   nsCOMPtr<nsPIDOMWindowInner> ownerWindow =
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -4414,17 +4414,17 @@ nsContentUtils::GetEventMessageAndAtomFo
   // now updated sStringEventTable.
   return GetEventMessageAndAtomForListener(aName, aOnName);
 }
 
 static
 nsresult GetEventAndTarget(nsIDocument* aDoc, nsISupports* aTarget,
                            const nsAString& aEventName,
                            bool aCanBubble, bool aCancelable,
-                           bool aTrusted, nsIDOMEvent** aEvent,
+                           bool aTrusted, Event** aEvent,
                            EventTarget** aTargetOut)
 {
   nsCOMPtr<EventTarget> target(do_QueryInterface(aTarget));
   NS_ENSURE_TRUE(aDoc && target, NS_ERROR_INVALID_ARG);
 
   ErrorResult err;
   RefPtr<Event> event = aDoc->CreateEvent(NS_LITERAL_STRING("Events"),
                                           CallerType::System, err);
@@ -4468,26 +4468,30 @@ nsContentUtils::DispatchUntrustedEvent(n
 // static
 nsresult
 nsContentUtils::DispatchEvent(nsIDocument* aDoc, nsISupports* aTarget,
                               const nsAString& aEventName,
                               bool aCanBubble, bool aCancelable,
                               bool aTrusted, bool* aDefaultAction,
                               bool aOnlyChromeDispatch)
 {
-  nsCOMPtr<nsIDOMEvent> event;
+  RefPtr<Event> event;
   nsCOMPtr<EventTarget> target;
   nsresult rv = GetEventAndTarget(aDoc, aTarget, aEventName, aCanBubble,
                                   aCancelable, aTrusted, getter_AddRefs(event),
                                   getter_AddRefs(target));
   NS_ENSURE_SUCCESS(rv, rv);
   event->WidgetEventPtr()->mFlags.mOnlyChromeDispatch = aOnlyChromeDispatch;
 
-  bool dummy;
-  return target->DispatchEvent(event, aDefaultAction ? aDefaultAction : &dummy);
+  ErrorResult err;
+  bool doDefault = target->DispatchEvent(*event, CallerType::System, err);
+  if (aDefaultAction) {
+    *aDefaultAction = doDefault;
+  }
+  return err.StealNSResult();
 }
 
 // static
 nsresult
 nsContentUtils::DispatchEvent(nsIDocument* aDoc, nsISupports* aTarget,
                               WidgetEvent& aEvent,
                               EventMessage aEventMessage,
                               bool aCanBubble, bool aCancelable,
@@ -4522,37 +4526,38 @@ nsContentUtils::DispatchEvent(nsIDocumen
 nsresult
 nsContentUtils::DispatchChromeEvent(nsIDocument *aDoc,
                                     nsISupports *aTarget,
                                     const nsAString& aEventName,
                                     bool aCanBubble, bool aCancelable,
                                     bool* aDefaultAction)
 {
 
-  nsCOMPtr<nsIDOMEvent> event;
+  RefPtr<Event> event;
   nsCOMPtr<EventTarget> target;
   nsresult rv = GetEventAndTarget(aDoc, aTarget, aEventName, aCanBubble,
                                   aCancelable, true, getter_AddRefs(event),
                                   getter_AddRefs(target));
   NS_ENSURE_SUCCESS(rv, rv);
 
   NS_ASSERTION(aDoc, "GetEventAndTarget lied?");
   if (!aDoc->GetWindow())
     return NS_ERROR_INVALID_ARG;
 
   EventTarget* piTarget = aDoc->GetWindow()->GetParentTarget();
   if (!piTarget)
     return NS_ERROR_INVALID_ARG;
 
-  bool defaultActionEnabled;
-  rv = piTarget->DispatchEvent(event, &defaultActionEnabled);
+  ErrorResult err;
+  bool defaultActionEnabled =
+    piTarget->DispatchEvent(*event, CallerType::System, err);
   if (aDefaultAction) {
     *aDefaultAction = defaultActionEnabled;
   }
-  return rv;
+  return err.StealNSResult();
 }
 
 /* static */
 nsresult
 nsContentUtils::DispatchFocusChromeEvent(nsPIDOMWindowOuter* aWindow)
 {
   MOZ_ASSERT(aWindow);
 
@@ -6580,20 +6585,19 @@ nsContentUtils::DispatchXULCommand(nsICo
                                aInputSource, IgnoreErrors());
 
   if (aShell) {
     nsEventStatus status = nsEventStatus_eIgnore;
     nsCOMPtr<nsIPresShell> kungFuDeathGrip = aShell;
     return aShell->HandleDOMEventWithTarget(aTarget, xulCommand, &status);
   }
 
-  nsCOMPtr<EventTarget> target = do_QueryInterface(aTarget);
-  NS_ENSURE_STATE(target);
-  bool dummy;
-  return target->DispatchEvent(xulCommand, &dummy);
+  ErrorResult rv;
+  aTarget->DispatchEvent(*xulCommand, rv);
+  return rv.StealNSResult();
 }
 
 // static
 nsresult
 nsContentUtils::WrapNative(JSContext *cx, nsISupports *native,
                            nsWrapperCache *cache, const nsIID* aIID,
                            JS::MutableHandle<JS::Value> vp, bool aAllowWrapping)
 {
--- a/dom/base/nsDOMDataChannel.cpp
+++ b/dom/base/nsDOMDataChannel.cpp
@@ -329,22 +329,22 @@ nsDOMDataChannel::DoOnMessageAvailable(c
   RefPtr<MessageEvent> event = new MessageEvent(this, nullptr, nullptr);
 
   event->InitMessageEvent(nullptr, NS_LITERAL_STRING("message"), false, false,
                           jsData, mOrigin, EmptyString(), nullptr,
                           Sequence<OwningNonNull<MessagePort>>());
   event->SetTrusted(true);
 
   LOG(("%p(%p): %s - Dispatching\n",this,(void*)mDataChannel,__FUNCTION__));
-  bool dummy;
-  rv = DispatchEvent(static_cast<Event*>(event), &dummy);
-  if (NS_FAILED(rv)) {
+  ErrorResult err;
+  DispatchEvent(*event, err);
+  if (err.Failed()) {
     NS_WARNING("Failed to dispatch the message event!!!");
   }
-  return rv;
+  return err.StealNSResult();
 }
 
 nsresult
 nsDOMDataChannel::OnMessageAvailable(nsISupports* aContext,
                                      const nsACString& aMessage)
 {
   MOZ_ASSERT(NS_IsMainThread());
   return DoOnMessageAvailable(aMessage, false);
@@ -368,18 +368,19 @@ nsDOMDataChannel::OnSimpleEvent(nsISuppo
     return NS_OK;
   }
 
   RefPtr<Event> event = NS_NewDOMEvent(this, nullptr, nullptr);
 
   event->InitEvent(aName, false, false);
   event->SetTrusted(true);
 
-  bool dummy;
-  return DispatchEvent(event, &dummy);
+  ErrorResult err;
+  DispatchEvent(*event, err);
+  return err.StealNSResult();
 }
 
 nsresult
 nsDOMDataChannel::OnChannelConnected(nsISupports* aContext)
 {
   LOG(("%p(%p): %s - Dispatching\n",this,(void*)mDataChannel,__FUNCTION__));
 
   return OnSimpleEvent(aContext, NS_LITERAL_STRING("open"));
--- a/dom/base/nsDOMWindowUtils.cpp
+++ b/dom/base/nsDOMWindowUtils.cpp
@@ -3707,17 +3707,18 @@ nsDOMWindowUtils::GetPaintFlashing(bool*
 NS_IMETHODIMP
 nsDOMWindowUtils::DispatchEventToChromeOnly(nsIDOMEventTarget* aTarget,
                                             nsIDOMEvent* aEvent,
                                             bool* aRetVal)
 {
   *aRetVal = false;
   NS_ENSURE_STATE(aTarget && aEvent);
   aEvent->WidgetEventPtr()->mFlags.mOnlyChromeDispatch = true;
-  aTarget->DispatchEvent(aEvent, aRetVal);
+  *aRetVal = EventTarget::From(aTarget)->
+    DispatchEvent(*aEvent->InternalDOMEvent(), CallerType::System, IgnoreErrors());
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMWindowUtils::RequestCompositorProperty(const nsAString& property,
                                             float* aResult)
 {
   if (nsIWidget* widget = GetWidget()) {
--- a/dom/base/nsFrameLoader.cpp
+++ b/dom/base/nsFrameLoader.cpp
@@ -374,18 +374,17 @@ nsFrameLoader::SwapBrowsersAndNotify(nsF
   eventInit.mBubbles = true;
   eventInit.mCancelable= false;
   eventInit.mOtherBrowser = secondaryContent;
   RefPtr<GroupedHistoryEvent> event =
     GroupedHistoryEvent::Constructor(primaryContent,
                                      NS_LITERAL_STRING("BrowserChangedProcess"),
                                      eventInit);
   event->SetTrusted(true);
-  bool dummy;
-  primaryContent->DispatchEvent(event, &dummy);
+  primaryContent->DispatchEvent(*event);
 
   return true;
 }
 
 already_AddRefed<Promise>
 nsFrameLoader::FireWillChangeProcessEvent()
 {
   AutoJSAPI jsapi;
@@ -406,18 +405,17 @@ nsFrameLoader::FireWillChangeProcessEven
   eventInit.mBubbles = true;
   eventInit.mCancelable = false;
   eventInit.mOtherBrowser = nullptr;
   RefPtr<GroupedHistoryEvent> event =
     GroupedHistoryEvent::Constructor(mOwnerContent,
                                      NS_LITERAL_STRING("BrowserWillChangeProcess"),
                                      eventInit);
   event->SetTrusted(true);
-  bool dummy;
-  mOwnerContent->DispatchEvent(event, &dummy);
+  mOwnerContent->DispatchEvent(*event);
 
   mBrowserChangingProcessBlockers = nullptr;
 
   ErrorResult rv;
   RefPtr<Promise> allPromise = Promise::All(global, blockers, rv);
   return allPromise.forget();
 }
 
--- a/dom/base/nsGlobalWindowInner.cpp
+++ b/dom/base/nsGlobalWindowInner.cpp
@@ -4470,38 +4470,44 @@ nsGlobalWindowInner::Btoa(const nsAStrin
 //*****************************************************************************
 
 nsPIDOMWindowOuter*
 nsGlobalWindowInner::GetOwnerGlobalForBindings()
 {
   return nsPIDOMWindowOuter::GetFromCurrentInner(this);
 }
 
-NS_IMETHODIMP
-nsGlobalWindowInner::DispatchEvent(nsIDOMEvent* aEvent, bool* aRetVal)
+bool
+nsGlobalWindowInner::DispatchEvent(Event& aEvent,
+                                   CallerType aCallerType,
+                                   ErrorResult& aRv)
 {
   if (!IsCurrentInnerWindow()) {
     NS_WARNING("DispatchEvent called on non-current inner window, dropping. "
                "Please check the window in the caller instead.");
-    return NS_ERROR_FAILURE;
+    aRv.Throw(NS_ERROR_FAILURE);
+    return false;
   }
 
   if (!mDoc) {
-    return NS_ERROR_FAILURE;
+    aRv.Throw(NS_ERROR_FAILURE);
+    return false;
   }
 
   // Obtain a presentation shell
   RefPtr<nsPresContext> presContext = mDoc->GetPresContext();
 
   nsEventStatus status = nsEventStatus_eIgnore;
   nsresult rv = EventDispatcher::DispatchDOMEvent(ToSupports(this), nullptr,
-                                                  aEvent, presContext, &status);
-
-  *aRetVal = (status != nsEventStatus_eConsumeNoDefault);
-  return rv;
+                                                  &aEvent, presContext, &status);
+  bool retval = !aEvent.DefaultPrevented(aCallerType);
+  if (NS_FAILED(rv)) {
+    aRv.Throw(rv);
+  }
+  return retval;
 }
 
 NS_IMETHODIMP
 nsGlobalWindowInner::AddEventListener(const nsAString& aType,
                                       nsIDOMEventListener *aListener,
                                       bool aUseCapture, bool aWantsUntrusted,
                                       uint8_t aOptionalArgc)
 {
@@ -4879,18 +4885,19 @@ nsGlobalWindowInner::FireHashchange(cons
   init.mOldURL = aOldURL;
 
   RefPtr<HashChangeEvent> event =
     HashChangeEvent::Constructor(this, NS_LITERAL_STRING("hashchange"),
                                  init);
 
   event->SetTrusted(true);
 
-  bool dummy;
-  return DispatchEvent(event, &dummy);
+  ErrorResult rv;
+  DispatchEvent(*event, rv);
+  return rv.StealNSResult();
 }
 
 nsresult
 nsGlobalWindowInner::DispatchSyncPopState()
 {
   NS_ASSERTION(nsContentUtils::IsSafeToRunScript(),
                "Must be safe to run script here.");
 
@@ -4924,18 +4931,19 @@ nsGlobalWindowInner::DispatchSyncPopStat
   init.mState = stateJSValue;
 
   RefPtr<PopStateEvent> event =
     PopStateEvent::Constructor(this, NS_LITERAL_STRING("popstate"),
                                init);
   event->SetTrusted(true);
   event->SetTarget(this);
 
-  bool dummy; // default action
-  return DispatchEvent(event, &dummy);
+  ErrorResult err;
+  DispatchEvent(*event, err);
+  return err.StealNSResult();
 }
 
 // Find an nsICanvasFrame under aFrame.  Only search the principal
 // child lists.  aFrame must be non-null.
 static nsCanvasFrame*
 FindCanvasFrame(nsIFrame* aFrame)
 {
     nsCanvasFrame* canvasFrame = do_QueryFrame(aFrame);
@@ -5959,18 +5967,19 @@ nsGlobalWindowInner::Observe(nsISupports
     if (!IsCurrentInnerWindow()) {
       return NS_OK;
     }
 
     RefPtr<Event> event = NS_NewDOMEvent(this, nullptr, nullptr);
     event->InitEvent(NS_LITERAL_STRING("languagechange"), false, false);
     event->SetTrusted(true);
 
-    bool dummy;
-    return DispatchEvent(event, &dummy);
+    ErrorResult rv;
+    DispatchEvent(*event, rv);
+    return rv.StealNSResult();
   }
 
   NS_WARNING("unrecognized topic in nsGlobalWindowInner::Observe");
   return NS_ERROR_FAILURE;
 }
 
 void
 nsGlobalWindowInner::ObserveStorageNotification(StorageEvent* aEvent,
@@ -6058,18 +6067,17 @@ nsGlobalWindowInner::ObserveStorageNotif
 
   clonedEvent->SetTrusted(true);
 
   if (fireMozStorageChanged) {
     WidgetEvent* internalEvent = clonedEvent->WidgetEventPtr();
     internalEvent->mFlags.mOnlyChromeDispatch = true;
   }
 
-  bool defaultActionEnabled;
-  DispatchEvent(clonedEvent, &defaultActionEnabled);
+  DispatchEvent(*clonedEvent);
 }
 
 already_AddRefed<StorageEvent>
 nsGlobalWindowInner::CloneStorageEvent(const nsAString& aType,
                                        const RefPtr<StorageEvent>& aEvent,
                                        ErrorResult& aRv)
 {
   StorageEventInit dict;
@@ -7158,22 +7166,21 @@ nsGlobalWindowInner::DispatchVRDisplayAc
       RefPtr<VRDisplayEvent> event =
         VRDisplayEvent::Constructor(this,
                                     NS_LITERAL_STRING("vrdisplayactivate"),
                                     init);
       // vrdisplayactivate is a trusted event, allowing VRDisplay.requestPresent
       // to be used in response to link traversal, user request (chrome UX), and
       // HMD mounting detection sensors.
       event->SetTrusted(true);
-      bool defaultActionEnabled;
       // VRDisplay.requestPresent normally requires a user gesture; however, an
       // exception is made to allow it to be called in response to vrdisplayactivate
       // during VR link traversal.
       display->StartHandlingVRNavigationEvent();
-      Unused << DispatchEvent(event, &defaultActionEnabled);
+      DispatchEvent(*event);
       display->StopHandlingVRNavigationEvent();
       // Once we dispatch the event, we must not access any members as an event
       // listener can do anything, including closing windows.
       return;
     }
   }
 }
 
@@ -7197,18 +7204,17 @@ nsGlobalWindowInner::DispatchVRDisplayDe
       init.mDisplay = display;
       init.mReason.Construct(aReason);
 
       RefPtr<VRDisplayEvent> event =
         VRDisplayEvent::Constructor(this,
                                     NS_LITERAL_STRING("vrdisplaydeactivate"),
                                     init);
       event->SetTrusted(true);
-      bool defaultActionEnabled;
-      Unused << DispatchEvent(event, &defaultActionEnabled);
+      DispatchEvent(*event);
       // Once we dispatch the event, we must not access any members as an event
       // listener can do anything, including closing windows.
       return;
     }
   }
 }
 
 void
@@ -7228,18 +7234,17 @@ nsGlobalWindowInner::DispatchVRDisplayCo
       init.mDisplay = display;
       // VRDisplayEvent.reason is not set for vrdisplayconnect
 
       RefPtr<VRDisplayEvent> event =
         VRDisplayEvent::Constructor(this,
                                     NS_LITERAL_STRING("vrdisplayconnect"),
                                     init);
       event->SetTrusted(true);
-      bool defaultActionEnabled;
-      Unused << DispatchEvent(event, &defaultActionEnabled);
+      DispatchEvent(*event);
       // Once we dispatch the event, we must not access any members as an event
       // listener can do anything, including closing windows.
       return;
     }
   }
 }
 
 void
@@ -7259,18 +7264,17 @@ nsGlobalWindowInner::DispatchVRDisplayDi
       init.mDisplay = display;
       // VRDisplayEvent.reason is not set for vrdisplaydisconnect
 
       RefPtr<VRDisplayEvent> event =
         VRDisplayEvent::Constructor(this,
                                     NS_LITERAL_STRING("vrdisplaydisconnect"),
                                     init);
       event->SetTrusted(true);
-      bool defaultActionEnabled;
-      Unused << DispatchEvent(event, &defaultActionEnabled);
+      DispatchEvent(*event);
       // Once we dispatch the event, we must not access any members as an event
       // listener can do anything, including closing windows.
       return;
     }
   }
 }
 
 void
@@ -7289,18 +7293,17 @@ nsGlobalWindowInner::DispatchVRDisplayPr
       init.mCancelable = false;
       init.mDisplay = display;
       // VRDisplayEvent.reason is not set for vrdisplaypresentchange
       RefPtr<VRDisplayEvent> event =
         VRDisplayEvent::Constructor(this,
                                     NS_LITERAL_STRING("vrdisplaypresentchange"),
                                     init);
       event->SetTrusted(true);
-      bool defaultActionEnabled;
-      Unused << DispatchEvent(event, &defaultActionEnabled);
+      DispatchEvent(*event);
       // Once we dispatch the event, we must not access any members as an event
       // listener can do anything, including closing windows.
       return;
     }
   }
 }
 
 enum WindowState {
--- a/dom/base/nsGlobalWindowInner.h
+++ b/dom/base/nsGlobalWindowInner.h
@@ -328,16 +328,21 @@ public:
                                 mozilla::dom::EventListener* aListener,
                                 const mozilla::dom::AddEventListenerOptionsOrBoolean& aOptions,
                                 const mozilla::dom::Nullable<bool>& aWantsUntrusted,
                                 mozilla::ErrorResult& aRv) override;
   virtual nsPIDOMWindowOuter* GetOwnerGlobalForBindings() override;
 
   virtual nsIGlobalObject* GetOwnerGlobal() const override;
 
+  using mozilla::dom::EventTarget::DispatchEvent;
+  bool DispatchEvent(mozilla::dom::Event& aEvent,
+                     mozilla::dom::CallerType aCallerType,
+                     mozilla::ErrorResult& aRv) override;
+
   nsresult PostHandleEvent(mozilla::EventChainPostVisitor& aVisitor) override;
 
   // nsPIDOMWindow
   virtual nsPIDOMWindowOuter* GetPrivateRoot() override;
 
   // Outer windows only.
   virtual bool IsTopLevelWindowActive() override;
 
--- a/dom/base/nsGlobalWindowOuter.cpp
+++ b/dom/base/nsGlobalWindowOuter.cpp
@@ -3880,20 +3880,17 @@ nsGlobalWindowOuter::DispatchResizeEvent
                                detailValue);
 
   domEvent->SetTrusted(true);
   domEvent->WidgetEventPtr()->mFlags.mOnlyChromeDispatch = true;
 
   nsCOMPtr<EventTarget> target = do_QueryInterface(GetOuterWindow());
   domEvent->SetTarget(target);
 
-  bool defaultActionEnabled = true;
-  target->DispatchEvent(domEvent, &defaultActionEnabled);
-
-  return defaultActionEnabled;
+  return target->DispatchEvent(*domEvent, CallerType::System, IgnoreErrors());
 }
 
 static already_AddRefed<nsIDocShellTreeItem>
 GetCallerDocShellTreeItem()
 {
   nsCOMPtr<nsIWebNavigation> callerWebNav = do_GetInterface(GetEntryGlobal());
   nsCOMPtr<nsIDocShellTreeItem> callerItem = do_QueryInterface(callerWebNav);
 
@@ -5424,18 +5421,17 @@ nsGlobalWindowOuter::FirePopupBlockedEve
 
   RefPtr<PopupBlockedEvent> event =
     PopupBlockedEvent::Constructor(aDoc,
                                    NS_LITERAL_STRING("DOMPopupBlocked"),
                                    init);
 
   event->SetTrusted(true);
 
-  bool defaultActionEnabled;
-  aDoc->DispatchEvent(event, &defaultActionEnabled);
+  aDoc->DispatchEvent(*event);
 }
 
 // static
 bool
 nsGlobalWindowOuter::CanSetProperty(const char *aPrefName)
 {
   // Chrome can set any property.
   if (nsContentUtils::LegacyIsCallerChromeOrNativeCode()) {
@@ -6215,18 +6211,17 @@ nsGlobalWindowOuter::LeaveModalState()
     inner->mLastDialogQuitTime = TimeStamp::Now();
   }
 
   if (topWin->mModalStateDepth == 0) {
     RefPtr<Event> event = NS_NewDOMEvent(inner, nullptr, nullptr);
     event->InitEvent(NS_LITERAL_STRING("endmodalstate"), true, false);
     event->SetTrusted(true);
     event->WidgetEventPtr()->mFlags.mOnlyChromeDispatch = true;
-    bool dummy;
-    topWin->DispatchEvent(event, &dummy);
+    topWin->DispatchEvent(*event);
   }
 }
 
 bool
 nsGlobalWindowOuter::IsInModalState()
 {
   nsGlobalWindowOuter *topWin = GetScriptableTopInternal();
 
@@ -6464,20 +6459,22 @@ nsGlobalWindowOuter::FindOuter(const nsA
 //*****************************************************************************
 
 nsPIDOMWindowOuter*
 nsGlobalWindowOuter::GetOwnerGlobalForBindings()
 {
   return this;
 }
 
-NS_IMETHODIMP
-nsGlobalWindowOuter::DispatchEvent(nsIDOMEvent* aEvent, bool* aRetVal)
-{
-  FORWARD_TO_INNER(DispatchEvent, (aEvent, aRetVal), NS_OK);
+bool
+nsGlobalWindowOuter::DispatchEvent(Event& aEvent,
+                                   CallerType aCallerType,
+                                   ErrorResult& aRv)
+{
+  FORWARD_TO_INNER(DispatchEvent, (aEvent, aCallerType, aRv), false);
 }
 
 NS_IMETHODIMP
 nsGlobalWindowOuter::AddEventListener(const nsAString& aType,
                                       nsIDOMEventListener *aListener,
                                       bool aUseCapture, bool aWantsUntrusted,
                                       uint8_t aOptionalArgc)
 {
--- a/dom/base/nsGlobalWindowOuter.h
+++ b/dom/base/nsGlobalWindowOuter.h
@@ -285,16 +285,21 @@ public:
                                 mozilla::dom::EventListener* aListener,
                                 const mozilla::dom::AddEventListenerOptionsOrBoolean& aOptions,
                                 const mozilla::dom::Nullable<bool>& aWantsUntrusted,
                                 mozilla::ErrorResult& aRv) override;
   virtual nsPIDOMWindowOuter* GetOwnerGlobalForBindings() override;
 
   virtual nsIGlobalObject* GetOwnerGlobal() const override;
 
+  using mozilla::dom::EventTarget::DispatchEvent;
+  bool DispatchEvent(mozilla::dom::Event& aEvent,
+                     mozilla::dom::CallerType aCallerType,
+                     mozilla::ErrorResult& aRv) override;
+
   nsresult PostHandleEvent(mozilla::EventChainPostVisitor& aVisitor) override;
 
   // nsPIDOMWindow
   virtual nsPIDOMWindowOuter* GetPrivateRoot() override;
 
   // Outer windows only.
   virtual void ActivateOrDeactivate(bool aActivate) override;
   virtual void SetActive(bool aActive) override;
--- a/dom/base/nsINode.cpp
+++ b/dom/base/nsINode.cpp
@@ -1134,37 +1134,39 @@ nsINode::ConvertPointFromNode(const DOMP
                               const ConvertCoordinateOptions& aOptions,
                               CallerType aCallerType,
                               ErrorResult& aRv)
 {
   return mozilla::ConvertPointFromNode(this, aPoint, aFrom, aOptions,
                                        aCallerType, aRv);
 }
 
-nsresult
-nsINode::DispatchEvent(nsIDOMEvent *aEvent, bool* aRetVal)
+bool
+nsINode::DispatchEvent(Event& aEvent, CallerType aCallerType, ErrorResult& aRv)
 {
   // XXX sXBL/XBL2 issue -- do we really want the owner here?  What
   // if that's the XBL document?  Would we want its presshell?  Or what?
   nsCOMPtr<nsIDocument> document = OwnerDoc();
 
   // Do nothing if the element does not belong to a document
   if (!document) {
-    *aRetVal = true;
-    return NS_OK;
+    return true;
   }
 
   // Obtain a presentation shell
   RefPtr<nsPresContext> context = document->GetPresContext();
 
   nsEventStatus status = nsEventStatus_eIgnore;
   nsresult rv =
-    EventDispatcher::DispatchDOMEvent(this, nullptr, aEvent, context, &status);
-  *aRetVal = (status != nsEventStatus_eConsumeNoDefault);
-  return rv;
+    EventDispatcher::DispatchDOMEvent(this, nullptr, &aEvent, context, &status);
+  bool retval = !aEvent.DefaultPrevented(aCallerType);
+  if (NS_FAILED(rv)) {
+    aRv.Throw(rv);
+  }
+  return retval;
 }
 
 nsresult
 nsINode::PostHandleEvent(EventChainPostVisitor& /*aVisitor*/)
 {
   return NS_OK;
 }
 
--- a/dom/base/nsINode.h
+++ b/dom/base/nsINode.h
@@ -1037,16 +1037,21 @@ public:
                                 mozilla::ErrorResult& aRv) override;
   using nsIDOMEventTarget::AddSystemEventListener;
 
   virtual bool IsApzAware() const override;
 
   virtual nsPIDOMWindowOuter* GetOwnerGlobalForBindings() override;
   virtual nsIGlobalObject* GetOwnerGlobal() const override;
 
+  using mozilla::dom::EventTarget::DispatchEvent;
+  bool DispatchEvent(mozilla::dom::Event& aEvent,
+                     mozilla::dom::CallerType aCallerType,
+                     mozilla::ErrorResult& aRv) override;
+
   nsresult PostHandleEvent(mozilla::EventChainPostVisitor& aVisitor) override;
 
   /**
    * Adds a mutation observer to be notified when this node, or any of its
    * descendants, are modified. The node will hold a weak reference to the
    * observer, which means that it is the responsibility of the observer to
    * remove itself in case it dies before the node.  If an observer is added
    * while observers are being notified, it may also be notified.  In general,
--- a/dom/base/nsPluginArray.cpp
+++ b/dom/base/nsPluginArray.cpp
@@ -254,18 +254,17 @@ void nsPluginArray::NotifyHiddenPluginTo
   HiddenPluginEventInit init;
   init.mTag = aHiddenElement->PluginTag();
   nsCOMPtr<nsIDocument> doc = aHiddenElement->GetParentObject()->GetDoc();
   RefPtr<HiddenPluginEvent> event =
     HiddenPluginEvent::Constructor(doc, NS_LITERAL_STRING("HiddenPlugin"), init);
   event->SetTarget(doc);
   event->SetTrusted(true);
   event->WidgetEventPtr()->mFlags.mOnlyChromeDispatch = true;
-  bool dummy;
-  doc->DispatchEvent(event, &dummy);
+  doc->DispatchEvent(*event);
 }
 
 uint32_t
 nsPluginArray::Length(CallerType aCallerType)
 {
   if (!AllowPlugins() || nsContentUtils::ResistFingerprinting(aCallerType)) {
     return 0;
   }
--- a/dom/base/nsWindowRoot.cpp
+++ b/dom/base/nsWindowRoot.cpp
@@ -67,24 +67,28 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(
   NS_INTERFACE_MAP_ENTRY(mozilla::dom::EventTarget)
 NS_INTERFACE_MAP_END
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF(nsWindowRoot)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(nsWindowRoot)
 
 NS_IMPL_DOMTARGET_DEFAULTS(nsWindowRoot)
 
-NS_IMETHODIMP
-nsWindowRoot::DispatchEvent(nsIDOMEvent* aEvt, bool *aRetVal)
+bool
+nsWindowRoot::DispatchEvent(Event& aEvent, CallerType aCallerType,
+                            ErrorResult& aRv)
 {
   nsEventStatus status = nsEventStatus_eIgnore;
   nsresult rv =  EventDispatcher::DispatchDOMEvent(
-    static_cast<EventTarget*>(this), nullptr, aEvt, nullptr, &status);
-  *aRetVal = (status != nsEventStatus_eConsumeNoDefault);
-  return rv;
+    static_cast<EventTarget*>(this), nullptr, &aEvent, nullptr, &status);
+  bool retval = !aEvent.DefaultPrevented(aCallerType);
+  if (NS_FAILED(rv)) {
+    aRv.Throw(rv);
+  }
+  return retval;
 }
 
 NS_IMETHODIMP
 nsWindowRoot::AddEventListener(const nsAString& aType,
                                nsIDOMEventListener *aListener,
                                bool aUseCapture, bool aWantsUntrusted,
                                uint8_t aOptionalArgc)
 {
--- a/dom/base/nsWindowRoot.h
+++ b/dom/base/nsWindowRoot.h
@@ -33,16 +33,20 @@ public:
     GetOrCreateListenerManager() override;
 
   virtual void AddEventListener(const nsAString& aType,
                                 mozilla::dom::EventListener* aListener,
                                 const mozilla::dom::AddEventListenerOptionsOrBoolean& aOptions,
                                 const mozilla::dom::Nullable<bool>& aWantsUntrusted,
                                 mozilla::ErrorResult& aRv) override;
 
+  bool DispatchEvent(mozilla::dom::Event& aEvent,
+                     mozilla::dom::CallerType aCallerType,
+                     mozilla::ErrorResult& aRv) override;
+
   nsresult PostHandleEvent(mozilla::EventChainPostVisitor& aVisitor) override;
 
   // nsPIWindowRoot
 
   virtual nsPIDOMWindowOuter* GetWindow() override;
 
   virtual nsresult GetControllers(bool aForVisibleWindow,
                                   nsIControllers** aResult) override;
--- a/dom/broadcastchannel/BroadcastChannelChild.cpp
+++ b/dom/broadcastchannel/BroadcastChannelChild.cpp
@@ -91,18 +91,17 @@ BroadcastChannelChild::RecvNotify(const 
   init.mOrigin = mOrigin;
   init.mData = value;
 
   RefPtr<MessageEvent> event =
     MessageEvent::Constructor(mBC, NS_LITERAL_STRING("message"), init);
 
   event->SetTrusted(true);
 
-  bool status;
-  mBC->DispatchEvent(static_cast<Event*>(event.get()), &status);
+  mBC->DispatchEvent(*event);
 
   return IPC_OK();
 }
 
 void
 BroadcastChannelChild::ActorDestroy(ActorDestroyReason aWhy)
 {
   mActorDestroyed = true;
@@ -115,14 +114,13 @@ BroadcastChannelChild::DispatchError(JSC
   init.mBubbles = false;
   init.mCancelable = false;
   init.mOrigin = mOrigin;
 
   RefPtr<Event> event =
     MessageEvent::Constructor(mBC, NS_LITERAL_STRING("messageerror"), init);
   event->SetTrusted(true);
 
-  bool dummy;
-  mBC->DispatchEvent(event, &dummy);
+  mBC->DispatchEvent(*event);
 }
 
 } // namespace dom
 } // namespace mozilla
--- a/dom/canvas/WebGLContext.cpp
+++ b/dom/canvas/WebGLContext.cpp
@@ -816,18 +816,17 @@ WebGLContext::ThrowEvent_WebGLContextCre
     // eventInit.mCancelable = true; // The spec says this, but it's silly.
     eventInit.mStatusMessage = NS_ConvertASCIItoUTF16(text);
 
     const RefPtr<WebGLContextEvent> event = WebGLContextEvent::Constructor(target,
                                                                            kEventName,
                                                                            eventInit);
     event->SetTrusted(true);
 
-    bool didPreventDefault;
-    target->DispatchEvent(event, &didPreventDefault);
+    target->DispatchEvent(*event);
 
     //////
 
     GenerateWarning("Failed to create WebGL context: %s", text.BeginReading());
 }
 
 NS_IMETHODIMP
 WebGLContext::SetDimensions(int32_t signedWidth, int32_t signedHeight)
@@ -1792,17 +1791,19 @@ WebGLContext::UpdateContextLossStatus()
                 kCanBubble,
                 kIsCancelable,
                 &useDefaultHandler);
         } else {
             // OffscreenCanvas case
             RefPtr<Event> event = new Event(mOffscreenCanvas, nullptr, nullptr);
             event->InitEvent(kEventName, kCanBubble, kIsCancelable);
             event->SetTrusted(true);
-            mOffscreenCanvas->DispatchEvent(event, &useDefaultHandler);
+            useDefaultHandler =
+                mOffscreenCanvas->DispatchEvent(*event, CallerType::System,
+                                                IgnoreErrors());
         }
 
         // We sent the callback, so we're just 'regular lost' now.
         mContextStatus = ContextLost;
         // If we're told to use the default handler, it means the script
         // didn't bother to handle the event. In this case, we shouldn't
         // auto-restore the context.
         if (useDefaultHandler)
@@ -1858,18 +1859,17 @@ WebGLContext::UpdateContextLossStatus()
                 static_cast<nsIContent*>(mCanvasElement),
                 NS_LITERAL_STRING("webglcontextrestored"),
                 true,
                 true);
         } else {
             RefPtr<Event> event = new Event(mOffscreenCanvas, nullptr, nullptr);
             event->InitEvent(NS_LITERAL_STRING("webglcontextrestored"), true, true);
             event->SetTrusted(true);
-            bool unused;
-            mOffscreenCanvas->DispatchEvent(event, &unused);
+            mOffscreenCanvas->DispatchEvent(*event);
         }
 
         mEmitContextLostErrorOnce = true;
         return;
     }
 }
 
 void
--- a/dom/clients/manager/ClientSource.cpp
+++ b/dom/clients/manager/ClientSource.cpp
@@ -593,20 +593,19 @@ ClientSource::PostMessage(const ClientPo
       init.mSource.SetValue().SetAsServiceWorker() = instance;
     }
   }
 
   RefPtr<MessageEvent> event =
     MessageEvent::Constructor(target, NS_LITERAL_STRING("message"), init);
   event->SetTrusted(true);
 
-  bool preventDefaultCalled = false;
-  rv = target->DispatchEvent(static_cast<dom::Event*>(event.get()),
-                             &preventDefaultCalled);
-  if (NS_FAILED(rv)) {
+  target->DispatchEvent(*event, result);
+  if (result.Failed()) {
+    result.SuppressException();
     ref = ClientOpPromise::CreateAndReject(NS_ERROR_FAILURE, __func__);
     return ref.forget();
   }
 
   ref = ClientOpPromise::CreateAndResolve(NS_OK, __func__);
   return ref.forget();
 }
 
--- a/dom/events/AsyncEventDispatcher.cpp
+++ b/dom/events/AsyncEventDispatcher.cpp
@@ -61,18 +61,17 @@ AsyncEventDispatcher::Run()
     event = NS_NewDOMEvent(mTarget, nullptr, nullptr);
     event->InitEvent(mEventType, mBubbles, false);
     event->SetTrusted(true);
   }
   if (mOnlyChromeDispatch) {
     MOZ_ASSERT(event->IsTrusted());
     event->WidgetEventPtr()->mFlags.mOnlyChromeDispatch = true;
   }
-  bool dummy;
-  mTarget->DispatchEvent(event, &dummy);
+  mTarget->DispatchEvent(*event);
   return NS_OK;
 }
 
 nsresult
 AsyncEventDispatcher::Cancel()
 {
   mCanceled = true;
   return NS_OK;
--- a/dom/events/DOMEventTargetHelper.cpp
+++ b/dom/events/DOMEventTargetHelper.cpp
@@ -241,43 +241,47 @@ DOMEventTargetHelper::AddSystemEventList
     nsresult rv = WantsUntrusted(&aWantsUntrusted);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   return NS_AddSystemEventListener(this, aType, aListener, aUseCapture,
                                    aWantsUntrusted);
 }
 
-NS_IMETHODIMP
-DOMEventTargetHelper::DispatchEvent(nsIDOMEvent* aEvent, bool* aRetVal)
+bool
+DOMEventTargetHelper::DispatchEvent(Event& aEvent, CallerType aCallerType,
+                                    ErrorResult& aRv)
 {
   nsEventStatus status = nsEventStatus_eIgnore;
   nsresult rv =
-    EventDispatcher::DispatchDOMEvent(this, nullptr, aEvent, nullptr, &status);
-
-  *aRetVal = (status != nsEventStatus_eConsumeNoDefault);
-  return rv;
+    EventDispatcher::DispatchDOMEvent(this, nullptr, &aEvent, nullptr, &status);
+  bool retval = !aEvent.DefaultPrevented(aCallerType);
+  if (NS_FAILED(rv)) {
+    aRv.Throw(rv);
+  }
+  return retval;
 }
 
 nsresult
 DOMEventTargetHelper::DispatchTrustedEvent(const nsAString& aEventName)
 {
   RefPtr<Event> event = NS_NewDOMEvent(this, nullptr, nullptr);
   event->InitEvent(aEventName, false, false);
 
   return DispatchTrustedEvent(event);
 }
 
 nsresult
 DOMEventTargetHelper::DispatchTrustedEvent(nsIDOMEvent* event)
 {
   event->SetTrusted(true);
 
-  bool dummy;
-  return DispatchEvent(event, &dummy);
+  ErrorResult rv;
+  DispatchEvent(*event->InternalDOMEvent(), rv);
+  return rv.StealNSResult();
 }
 
 nsresult
 DOMEventTargetHelper::GetEventTargetParent(EventChainPreVisitor& aVisitor)
 {
   aVisitor.mCanHandle = true;
   aVisitor.SetParentTarget(nullptr, false);
   return NS_OK;
--- a/dom/events/DOMEventTargetHelper.h
+++ b/dom/events/DOMEventTargetHelper.h
@@ -75,16 +75,20 @@ public:
 
   using EventTarget::AddEventListener;
   virtual void AddEventListener(const nsAString& aType,
                                 dom::EventListener* aListener,
                                 const dom::AddEventListenerOptionsOrBoolean& aOptions,
                                 const dom::Nullable<bool>& aWantsUntrusted,
                                 ErrorResult& aRv) override;
 
+  using EventTarget::DispatchEvent;
+  bool DispatchEvent(dom::Event& aEvent, dom::CallerType aCallerType,
+                     ErrorResult& aRv) override;
+
   nsresult PostHandleEvent(EventChainPostVisitor& aVisitor) override;
 
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_DOMEVENTTARGETHELPER_IID)
 
   void GetParentObject(nsIScriptGlobalObject **aParentObject)
   {
     if (mParentObject) {
       CallQueryInterface(mParentObject, aParentObject);
--- a/dom/events/EventTarget.cpp
+++ b/dom/events/EventTarget.cpp
@@ -113,20 +113,26 @@ EventTarget::HasNonPassiveNonSystemGroup
 
 bool
 EventTarget::IsApzAware() const
 {
   EventListenerManager* elm = GetExistingListenerManager();
   return elm && elm->HasApzAwareListeners();
 }
 
-bool
-EventTarget::DispatchEvent(Event& aEvent,
-                           CallerType aCallerType,
-                           ErrorResult& aRv)
+void
+EventTarget::DispatchEvent(Event& aEvent)
 {
-  bool result = false;
-  aRv = DispatchEvent(&aEvent, &result);
-  return !aEvent.DefaultPrevented(aCallerType);
+  // The caller type doesn't really matter if we don't care about the
+  // return value, but let's be safe and pass NonSystem.
+  Unused << DispatchEvent(aEvent, CallerType::NonSystem, IgnoreErrors());
+}
+
+void
+EventTarget::DispatchEvent(Event& aEvent, ErrorResult& aRv)
+{
+  // The caller type doesn't really matter if we don't care about the
+  // return value, but let's be safe and pass NonSystem.
+  Unused << DispatchEvent(aEvent, CallerType::NonSystem, IgnoreErrors());
 }
 
 } // namespace dom
 } // namespace mozilla
--- a/dom/events/EventTarget.h
+++ b/dom/events/EventTarget.h
@@ -40,21 +40,25 @@ template <class T> struct Nullable;
   { 0xb1, 0x3d, 0x67, 0xb9, 0x40, 0xfc, 0x82, 0xe4 } }
 
 class EventTarget : public nsIDOMEventTarget,
                     public nsWrapperCache
 {
 public:
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_EVENTTARGET_IID)
 
+  static EventTarget* From(nsIDOMEventTarget* aTarget)
+  {
+    return static_cast<EventTarget*>(aTarget);
+  }
+
   // WebIDL API
   static already_AddRefed<EventTarget> Constructor(const GlobalObject& aGlobal,
                                                    ErrorResult& aRv);
   using nsIDOMEventTarget::AddEventListener;
-  using nsIDOMEventTarget::DispatchEvent;
   virtual void AddEventListener(const nsAString& aType,
                                 EventListener* aCallback,
                                 const AddEventListenerOptionsOrBoolean& aOptions,
                                 const Nullable<bool>& aWantsUntrusted,
                                 ErrorResult& aRv) = 0;
   void RemoveEventListener(const nsAString& aType,
                            EventListener* aCallback,
                            const EventListenerOptionsOrBoolean& aOptions,
@@ -70,17 +74,33 @@ public:
   /**
    * RemoveSystemEventListener() should be used if you have used
    * AddSystemEventListener().
    */
   void RemoveSystemEventListener(const nsAString& aType,
                                  nsIDOMEventListener* aListener,
                                  bool aUseCapture);
 
-  bool DispatchEvent(Event& aEvent, CallerType aCallerType, ErrorResult& aRv);
+  /**
+   * The most general DispatchEvent method.  This is the one the bindings call.
+   */
+  virtual bool DispatchEvent(Event& aEvent, CallerType aCallerType,
+                             ErrorResult& aRv) = 0;
+
+  /**
+   * A version of DispatchEvent you can use if you really don't care whether it
+   * succeeds or not and whether default is prevented or not.
+   */
+  void DispatchEvent(Event& aEvent);
+
+  /**
+   * A version of DispatchEvent you can use if you really don't care whether
+   * default is prevented or not.
+   */
+  void DispatchEvent(Event& aEvent, ErrorResult& aRv);
 
   nsIGlobalObject* GetParentObject() const
   {
     return GetOwnerGlobal();
   }
 
   // Note, this takes the type in onfoo form!
   EventHandlerNonNull* GetEventHandler(const nsAString& aType)
--- a/dom/events/PointerEventHandler.cpp
+++ b/dom/events/PointerEventHandler.cpp
@@ -640,18 +640,17 @@ PointerEventHandler::DispatchGotOrLostPo
     init.mBubbles = true;
     init.mComposed = true;
     ConvertPointerTypeToString(aPointerEvent->inputSource, init.mPointerType);
     init.mIsPrimary = aPointerEvent->mIsPrimary;
     RefPtr<PointerEvent> event;
     event = PointerEvent::Constructor(aCaptureTarget,
                                       NS_LITERAL_STRING("lostpointercapture"),
                                       init);
-    bool dummy;
-    targetDoc->DispatchEvent(event->InternalDOMEvent(), &dummy);
+    targetDoc->DispatchEvent(*event->InternalDOMEvent());
     return;
   }
   nsEventStatus status = nsEventStatus_eIgnore;
   WidgetPointerEvent localEvent(aPointerEvent->IsTrusted(),
                                 aIsGotCapture ? ePointerGotCapture :
                                                 ePointerLostCapture,
                                 aPointerEvent->mWidget);
 
--- a/dom/fetch/FetchObserver.cpp
+++ b/dom/fetch/FetchObserver.cpp
@@ -85,14 +85,13 @@ FetchObserver::SetState(FetchState aStat
   init.mCancelable = false;
 
   // TODO which kind of event should we dispatch here?
 
   RefPtr<Event> event =
     Event::Constructor(this, NS_LITERAL_STRING("statechange"), init);
   event->SetTrusted(true);
 
-  bool dummy;
-  DispatchEvent(event, &dummy);
+  DispatchEvent(*event);
 }
 
 } // dom namespace
 } // mozilla namespace
--- a/dom/file/FileReader.cpp
+++ b/dom/file/FileReader.cpp
@@ -617,18 +617,19 @@ FileReader::DispatchProgressEvent(const 
   } else {
     init.mLengthComputable = false;
     init.mTotal = 0;
   }
   RefPtr<ProgressEvent> event =
     ProgressEvent::Constructor(this, aType, init);
   event->SetTrusted(true);
 
-  bool dummy;
-  return DispatchEvent(event, &dummy);
+  ErrorResult rv;
+  DispatchEvent(*event, rv);
+  return rv.StealNSResult();
 }
 
 // nsITimerCallback
 NS_IMETHODIMP
 FileReader::Notify(nsITimer* aTimer)
 {
   nsresult rv;
   mTimerIsActive = false;
--- a/dom/gamepad/GamepadManager.cpp
+++ b/dom/gamepad/GamepadManager.cpp
@@ -295,18 +295,17 @@ GamepadManager::FireButtonEvent(EventTar
   init.mCancelable = false;
   init.mGamepad = aGamepad;
   init.mButton = aButton;
   RefPtr<GamepadButtonEvent> event =
     GamepadButtonEvent::Constructor(aTarget, name, init);
 
   event->SetTrusted(true);
 
-  bool defaultActionEnabled = true;
-  aTarget->DispatchEvent(event, &defaultActionEnabled);
+  aTarget->DispatchEvent(*event);
 }
 
 void
 GamepadManager::FireAxisMoveEvent(EventTarget* aTarget,
                                   Gamepad* aGamepad,
                                   uint32_t aAxis,
                                   double aValue)
 {
@@ -318,18 +317,17 @@ GamepadManager::FireAxisMoveEvent(EventT
   init.mValue = aValue;
   RefPtr<GamepadAxisMoveEvent> event =
     GamepadAxisMoveEvent::Constructor(aTarget,
                                       NS_LITERAL_STRING("gamepadaxismove"),
                                       init);
 
   event->SetTrusted(true);
 
-  bool defaultActionEnabled = true;
-  aTarget->DispatchEvent(event, &defaultActionEnabled);
+  aTarget->DispatchEvent(*event);
 }
 
 void
 GamepadManager::NewConnectionEvent(uint32_t aIndex, bool aConnected)
 {
   // Do not fire gamepadconnected and gamepaddisconnected events when
   // privacy.resistFingerprinting is true.
   if (nsContentUtils::ShouldResistFingerprinting()) {
@@ -403,18 +401,17 @@ GamepadManager::FireConnectionEvent(Even
   init.mBubbles = false;
   init.mCancelable = false;
   init.mGamepad = aGamepad;
   RefPtr<GamepadEvent> event =
     GamepadEvent::Constructor(aTarget, name, init);
 
   event->SetTrusted(true);
 
-  bool defaultActionEnabled = true;
-  aTarget->DispatchEvent(event, &defaultActionEnabled);
+  aTarget->DispatchEvent(*event);
 }
 
 void
 GamepadManager::SyncGamepadState(uint32_t aIndex, Gamepad* aGamepad)
 {
   if (mShuttingDown || !mEnabled || nsContentUtils::ShouldResistFingerprinting()) {
     return;
   }
--- a/dom/indexedDB/ActorsChild.cpp
+++ b/dom/indexedDB/ActorsChild.cpp
@@ -733,17 +733,17 @@ DispatchErrorEvent(IDBRequest* aRequest,
 
   AUTO_PROFILER_LABEL("IndexedDB:DispatchErrorEvent", STORAGE);
 
   RefPtr<IDBRequest> request = aRequest;
   RefPtr<IDBTransaction> transaction = aTransaction;
 
   request->SetError(aErrorCode);
 
-  nsCOMPtr<nsIDOMEvent> errorEvent;
+  RefPtr<Event> errorEvent;
   if (!aEvent) {
     // Make an error event and fire it at the target.
     errorEvent = CreateGenericEvent(request,
                                     nsDependentString(kErrorEventType),
                                     eDoesBubble,
                                     eCancelable);
     MOZ_ASSERT(errorEvent);
 
@@ -769,19 +769,20 @@ DispatchErrorEvent(IDBRequest* aRequest,
                    "Firing %s event with error 0x%x",
                  "IndexedDB %s: C R[%llu]: %s (0x%x)",
                  IDB_LOG_ID_STRING(),
                  request->LoggingSerialNumber(),
                  IDB_LOG_STRINGIFY(aEvent, kErrorEventType),
                  aErrorCode);
   }
 
-  bool doDefault;
-  nsresult rv = request->DispatchEvent(aEvent, &doDefault);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
+  IgnoredErrorResult rv;
+  bool doDefault = request->DispatchEvent(*aEvent->InternalDOMEvent(),
+                                          CallerType::System, rv);
+  if (NS_WARN_IF(rv.Failed())) {
     return;
   }
 
   MOZ_ASSERT(!transaction || transaction->IsOpen() || transaction->IsAborted());
 
   // Do not abort the transaction here if this request is failed due to the
   // abortion of its transaction to ensure that the correct error cause of
   // the abort event be set in IDBTransaction::FireCompleteOrAbortEvents() later.
@@ -812,17 +813,17 @@ DispatchSuccessEvent(ResultHelper* aResu
 
   RefPtr<IDBTransaction> transaction = aResultHelper->Transaction();
 
   if (transaction && transaction->IsAborted()) {
     DispatchErrorEvent(request, transaction->AbortCode(), transaction);
     return;
   }
 
-  nsCOMPtr<nsIDOMEvent> successEvent;
+  RefPtr<Event> successEvent;
   if (!aEvent) {
     successEvent = CreateGenericEvent(request,
                                       nsDependentString(kSuccessEventType),
                                       eDoesNotBubble,
                                       eNotCancelable);
     MOZ_ASSERT(successEvent);
 
     aEvent = successEvent;
@@ -847,19 +848,19 @@ DispatchSuccessEvent(ResultHelper* aResu
                  IDB_LOG_ID_STRING(),
                  request->LoggingSerialNumber(),
                  IDB_LOG_STRINGIFY(aEvent, kSuccessEventType));
   }
 
   MOZ_ASSERT_IF(transaction,
                 transaction->IsOpen() && !transaction->IsAborted());
 
-  bool dummy;
-  nsresult rv = request->DispatchEvent(aEvent, &dummy);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
+  IgnoredErrorResult rv;
+  request->DispatchEvent(*aEvent->InternalDOMEvent(), rv);
+  if (NS_WARN_IF(rv.Failed())) {
     return;
   }
 
   WidgetEvent* internalEvent = aEvent->WidgetEventPtr();
   MOZ_ASSERT(internalEvent);
 
   if (transaction &&
       transaction->IsOpen()) {
@@ -2009,17 +2010,17 @@ BackgroundFactoryRequestChild::RecvBlock
 {
   AssertIsOnOwningThread();
   MOZ_ASSERT(mRequest);
 
   MaybeCollectGarbageOnIPCMessage();
 
   const nsDependentString type(kBlockedEventType);
 
-  nsCOMPtr<nsIDOMEvent> blockedEvent;
+  RefPtr<Event> blockedEvent;
   if (mIsDeleteOp) {
     blockedEvent =
       IDBVersionChangeEvent::Create(mRequest, type, aCurrentVersion);
     MOZ_ASSERT(blockedEvent);
   } else {
     blockedEvent =
       IDBVersionChangeEvent::Create(mRequest,
                                     type,
@@ -2030,18 +2031,19 @@ BackgroundFactoryRequestChild::RecvBlock
 
   RefPtr<IDBRequest> kungFuDeathGrip = mRequest;
 
   IDB_LOG_MARK("IndexedDB %s: Child  Request[%llu]: Firing \"blocked\" event",
                "IndexedDB %s: C R[%llu]: \"blocked\"",
                IDB_LOG_ID_STRING(),
                kungFuDeathGrip->LoggingSerialNumber());
 
-  bool dummy;
-  if (NS_FAILED(kungFuDeathGrip->DispatchEvent(blockedEvent, &dummy))) {
+  IgnoredErrorResult rv;
+  kungFuDeathGrip->DispatchEvent(*blockedEvent, rv);
+  if (rv.Failed()) {
     NS_WARNING("Failed to dispatch event!");
   }
 
   return IPC_OK();
 }
 
 /*******************************************************************************
  * BackgroundDatabaseChild
@@ -2343,17 +2345,17 @@ BackgroundDatabaseChild::RecvVersionChan
       kungFuDeathGrip->Close();
       return IPC_OK();
     }
   }
 
   // Otherwise fire a versionchange event.
   const nsDependentString type(kVersionChangeEventType);
 
-  nsCOMPtr<nsIDOMEvent> versionChangeEvent;
+  RefPtr<Event> versionChangeEvent;
 
   switch (aNewVersion.type()) {
     case NullableVersion::Tnull_t:
       versionChangeEvent =
         IDBVersionChangeEvent::Create(kungFuDeathGrip, type, aOldVersion);
       MOZ_ASSERT(versionChangeEvent);
       break;
 
@@ -2369,18 +2371,19 @@ BackgroundDatabaseChild::RecvVersionChan
     default:
       MOZ_CRASH("Should never get here!");
   }
 
   IDB_LOG_MARK("IndexedDB %s: Child : Firing \"versionchange\" event",
                "IndexedDB %s: C: IDBDatabase \"versionchange\" event",
                IDB_LOG_ID_STRING());
 
-  bool dummy;
-  if (NS_FAILED(kungFuDeathGrip->DispatchEvent(versionChangeEvent, &dummy))) {
+  IgnoredErrorResult rv;
+  kungFuDeathGrip->DispatchEvent(*versionChangeEvent, rv);
+  if (rv.Failed()) {
     NS_WARNING("Failed to dispatch event!");
   }
 
   if (!kungFuDeathGrip->IsClosed()) {
     SendBlocked();
   }
 
   return IPC_OK();
--- a/dom/indexedDB/IDBEvents.cpp
+++ b/dom/indexedDB/IDBEvents.cpp
@@ -23,17 +23,17 @@ const char16_t* kAbortEventType = u"abor
 const char16_t* kBlockedEventType = u"blocked";
 const char16_t* kCompleteEventType = u"complete";
 const char16_t* kErrorEventType = u"error";
 const char16_t* kSuccessEventType = u"success";
 const char16_t* kUpgradeNeededEventType = u"upgradeneeded";
 const char16_t* kVersionChangeEventType = u"versionchange";
 const char16_t* kCloseEventType = u"close";
 
-already_AddRefed<nsIDOMEvent>
+already_AddRefed<Event>
 CreateGenericEvent(EventTarget* aOwner,
                    const nsDependentString& aType,
                    Bubbles aBubbles,
                    Cancelable aCancelable)
 {
   RefPtr<Event> event = new Event(aOwner, nullptr, nullptr);
 
   event->InitEvent(aType,
--- a/dom/indexedDB/IDBEvents.h
+++ b/dom/indexedDB/IDBEvents.h
@@ -42,17 +42,17 @@ extern const char16_t* kAbortEventType;
 extern const char16_t* kBlockedEventType;
 extern const char16_t* kCompleteEventType;
 extern const char16_t* kErrorEventType;
 extern const char16_t* kSuccessEventType;
 extern const char16_t* kUpgradeNeededEventType;
 extern const char16_t* kVersionChangeEventType;
 extern const char16_t* kCloseEventType;
 
-already_AddRefed<nsIDOMEvent>
+already_AddRefed<Event>
 CreateGenericEvent(EventTarget* aOwner,
                    const nsDependentString& aType,
                    Bubbles aBubbles,
                    Cancelable aCancelable);
 
 } // namespace indexedDB
 
 class IDBVersionChangeEvent final : public Event
--- a/dom/indexedDB/IDBFileHandle.cpp
+++ b/dom/indexedDB/IDBFileHandle.cpp
@@ -207,30 +207,31 @@ IDBFileHandle::FireCompleteOrAbortEvents
   MOZ_ASSERT(!mFiredCompleteOrAbort);
 
   mReadyState = DONE;
 
 #ifdef DEBUG
   mFiredCompleteOrAbort = true;
 #endif
 
-  nsCOMPtr<nsIDOMEvent> event;
+  RefPtr<Event> event;
   if (aAborted) {
     event = CreateGenericEvent(this, nsDependentString(kAbortEventType),
                                eDoesBubble, eNotCancelable);
   } else {
     event = CreateGenericEvent(this, nsDependentString(kCompleteEventType),
                                eDoesNotBubble, eNotCancelable);
   }
   if (NS_WARN_IF(!event)) {
     return;
   }
 
-  bool dummy;
-  if (NS_FAILED(DispatchEvent(event, &dummy))) {
+  IgnoredErrorResult rv;
+  DispatchEvent(*event, rv);
+  if (rv.Failed()) {
     NS_WARNING("DispatchEvent failed!");
   }
 }
 
 bool
 IDBFileHandle::IsOpen() const
 {
   AssertIsOnOwningThread();
--- a/dom/indexedDB/IDBRequest.cpp
+++ b/dom/indexedDB/IDBRequest.cpp
@@ -564,25 +564,26 @@ IDBOpenDBRequest::DispatchNonTransaction
 
   // The actor failed to initiate, decrease the number of active IDBOpenRequests
   // here since NoteComplete won't be called.
   MaybeDecreaseActiveDatabaseCount();
 
   SetError(aErrorCode);
 
   // Make an error event and fire it at the target.
-  nsCOMPtr<nsIDOMEvent> event =
+  RefPtr<Event> event =
     CreateGenericEvent(this,
                        nsDependentString(kErrorEventType),
                        eDoesBubble,
                        eCancelable);
   MOZ_ASSERT(event);
 
-  bool ignored;
-  if (NS_FAILED(DispatchEvent(event, &ignored))) {
+  IgnoredErrorResult rv;
+  DispatchEvent(*event, rv);
+  if (rv.Failed()) {
     NS_WARNING("Failed to dispatch event!");
   }
 }
 
 void
 IDBOpenDBRequest::NoteComplete()
 {
   AssertIsOnOwningThread();
--- a/dom/indexedDB/IDBTransaction.cpp
+++ b/dom/indexedDB/IDBTransaction.cpp
@@ -818,17 +818,17 @@ IDBTransaction::FireCompleteOrAbortEvent
 
 #ifdef DEBUG
   mFiredCompleteOrAbort = true;
 #endif
 
   // Make sure we drop the WorkerHolder when this function completes.
   nsAutoPtr<WorkerHolder> workerHolder = Move(mWorkerHolder);
 
-  nsCOMPtr<nsIDOMEvent> event;
+  RefPtr<Event> event;
   if (NS_SUCCEEDED(aResult)) {
     event = CreateGenericEvent(this,
                                nsDependentString(kCompleteEventType),
                                eDoesNotBubble,
                                eNotCancelable);
     MOZ_ASSERT(event);
   } else {
     if (aResult == NS_ERROR_DOM_INDEXEDDB_QUOTA_ERR) {
@@ -856,18 +856,19 @@ IDBTransaction::FireCompleteOrAbortEvent
     IDB_LOG_MARK("IndexedDB %s: Child  Transaction[%lld]: "
                    "Firing 'abort' event with error 0x%x",
                  "IndexedDB %s: C T[%lld]: IDBTransaction 'abort' event (0x%x)",
                  IDB_LOG_ID_STRING(),
                  mLoggingSerialNumber,
                  mAbortCode);
   }
 
-  bool dummy;
-  if (NS_FAILED(DispatchEvent(event, &dummy))) {
+  IgnoredErrorResult rv;
+  DispatchEvent(*event, rv);
+  if (rv.Failed()) {
     NS_WARNING("DispatchEvent failed!");
   }
 
   // Normally, we note inactive transaction here instead of
   // IDBTransaction::ClearBackgroundActor() because here is the earliest place
   // to know that it becomes non-blocking to allow the scheduler to start the
   // preemption as soon as it can.
   // Note: If the IDBTransaction object is held by the script,
--- a/dom/interfaces/events/nsIDOMEventTarget.idl
+++ b/dom/interfaces/events/nsIDOMEventTarget.idl
@@ -133,37 +133,16 @@ interface nsIDOMEventTarget : nsISupport
                                   bool aWantsUntrusted)
   {
     return AddSystemEventListener(aType, aListener, aUseCapture,
                                   aWantsUntrusted, 2);
   }
 %}
 
   /**
-   * This method allows the dispatch of events into the implementations 
-   * event model. Events dispatched in this manner will have the same 
-   * capturing and bubbling behavior as events dispatched directly by the 
-   * implementation. The target of the event is the EventTarget on which 
-   * dispatchEvent is called.
-   *
-   * @param   evt Specifies the event type, behavior, and contextual 
-   *              information to be used in processing the event.
-   * @return  Indicates whether any of the listeners which handled the 
-   *          event called preventDefault. If preventDefault was called 
-   *          the value is false, else the value is true.
-   * @throws  INVALID_STATE_ERR: Raised if the Event's type was 
-   *              not specified by initializing the event before 
-   *              dispatchEvent was called. Specification of the Event's 
-   *              type as null or an empty string will also trigger this 
-   *              exception.
-   */
-  boolean                  dispatchEvent(in nsIDOMEvent evt)
-                                               raises(DOMException);
-
-  /**
    * Returns the nsIDOMEventTarget object which should be used as the target
    * of DOMEvents.
    * Usually |this| is returned, but for example global object returns
    * the outer object.
    */
    [notxpcom, nostdcall] EventTargetPtr GetTargetForDOMEvent();
 
   /**
--- a/dom/ipc/TabParent.cpp
+++ b/dom/ipc/TabParent.cpp
@@ -576,18 +576,17 @@ TabParent::RecvEvent(const RemoteDOMEven
   nsCOMPtr<nsIDOMEvent> event = do_QueryInterface(aEvent.mEvent);
   NS_ENSURE_TRUE(event, IPC_OK());
 
   nsCOMPtr<mozilla::dom::EventTarget> target = do_QueryInterface(mFrameElement);
   NS_ENSURE_TRUE(target, IPC_OK());
 
   event->SetOwner(target);
 
-  bool dummy;
-  target->DispatchEvent(event, &dummy);
+  target->DispatchEvent(*event->InternalDOMEvent());
   return IPC_OK();
 }
 
 bool
 TabParent::SendLoadRemoteScript(const nsString& aURL,
                                 const bool& aRunInGlobalScope)
 {
   if (mCreatingWindow) {
@@ -3063,18 +3062,17 @@ TabParent::LayerTreeUpdate(uint64_t aEpo
   if (aActive) {
     mHasPresented = true;
     event->InitEvent(NS_LITERAL_STRING("MozLayerTreeReady"), true, false);
   } else {
     event->InitEvent(NS_LITERAL_STRING("MozLayerTreeCleared"), true, false);
   }
   event->SetTrusted(true);
   event->WidgetEventPtr()->mFlags.mOnlyChromeDispatch = true;
-  bool dummy;
-  mFrameElement->DispatchEvent(event, &dummy);
+  mFrameElement->DispatchEvent(*event);
 }
 
 mozilla::ipc::IPCResult
 TabParent::RecvForcePaintNoOp(const uint64_t& aLayerObserverEpoch)
 {
   // We sent a ForcePaint message when layers were already visible. In this
   // case, we should act as if an update occurred even though we already have
   // the layers.
@@ -3090,18 +3088,17 @@ TabParent::RecvRemotePaintIsReady()
     NS_WARNING("Could not locate target for MozAfterRemotePaint message.");
     return IPC_OK();
   }
 
   RefPtr<Event> event = NS_NewDOMEvent(mFrameElement, nullptr, nullptr);
   event->InitEvent(NS_LITERAL_STRING("MozAfterRemotePaint"), false, false);
   event->SetTrusted(true);
   event->WidgetEventPtr()->mFlags.mOnlyChromeDispatch = true;
-  bool dummy;
-  mFrameElement->DispatchEvent(event, &dummy);
+  mFrameElement->DispatchEvent(*event);
   return IPC_OK();
 }
 
 mozilla::ipc::IPCResult
 TabParent::RecvRemoteIsReadyToHandleInputEvents()
 {
   // When enabling input event prioritization, input events may preempt other
   // normal priority IPC messages. To prevent the input events preempt
--- a/dom/media/MediaRecorder.cpp
+++ b/dom/media/MediaRecorder.cpp
@@ -1610,36 +1610,37 @@ MediaRecorder::CreateAndDispatchBlobEven
   init.mCancelable = false;
   init.mData = aBlob;
 
   RefPtr<BlobEvent> event =
     BlobEvent::Constructor(this,
                            NS_LITERAL_STRING("dataavailable"),
                            init);
   event->SetTrusted(true);
-  bool dummy;
-  return DispatchEvent(event, &dummy);
+  ErrorResult rv;
+  DispatchEvent(*event, rv);
+  return rv.StealNSResult();
 }
 
 void
 MediaRecorder::DispatchSimpleEvent(const nsAString & aStr)
 {
   MOZ_ASSERT(NS_IsMainThread(), "Not running on main thread");
   nsresult rv = CheckInnerWindowCorrectness();
   if (NS_FAILED(rv)) {
     return;
   }
 
   RefPtr<Event> event = NS_NewDOMEvent(this, nullptr, nullptr);
   event->InitEvent(aStr, false, false);
   event->SetTrusted(true);
 
-  bool dummy;
-  rv = DispatchEvent(event, &dummy);
-  if (NS_FAILED(rv)) {
+  IgnoredErrorResult res;
+  DispatchEvent(*event, res);
+  if (res.Failed()) {
     NS_ERROR("Failed to dispatch the event!!!");
     return;
   }
 }
 
 void
 MediaRecorder::NotifyError(nsresult aRv)
 {
@@ -1673,19 +1674,19 @@ MediaRecorder::NotifyError(nsresult aRv)
         "mUnknownDomException being fired for aRv: %X", uint32_t(aRv)));
       init.mError = mUnknownDomException.forget();
   }
 
   RefPtr<MediaRecorderErrorEvent> event = MediaRecorderErrorEvent::Constructor(
     this, NS_LITERAL_STRING("error"), init);
   event->SetTrusted(true);
 
-  bool dummy;
-  rv = DispatchEvent(event, &dummy);
-  if (NS_FAILED(rv)) {
+  IgnoredErrorResult res;
+  DispatchEvent(*event, res);
+  if (res.Failed()) {
     NS_ERROR("Failed to dispatch the error event!!!");
   }
 }
 
 void
 MediaRecorder::RemoveSession(Session* aSession)
 {
   LOG(LogLevel::Debug, ("MediaRecorder.RemoveSession (%p)", aSession));
--- a/dom/media/webspeech/recognition/SpeechRecognition.cpp
+++ b/dom/media/webspeech/recognition/SpeechRecognition.cpp
@@ -524,18 +524,17 @@ SpeechRecognition::NotifyFinalResult(Spe
   init.mResults = aEvent->mRecognitionResultList;
   init.mInterpretation = JS::NullValue();
   // init.mEmma = nullptr;
 
   RefPtr<SpeechRecognitionEvent> event = SpeechRecognitionEvent::Constructor(
     this, NS_LITERAL_STRING("result"), init);
   event->SetTrusted(true);
 
-  bool defaultActionEnabled;
-  this->DispatchEvent(event, &defaultActionEnabled);
+  DispatchEvent(*event);
 }
 
 void
 SpeechRecognition::DoNothing(SpeechEvent* aEvent)
 {
 }
 
 void
@@ -559,18 +558,17 @@ SpeechRecognition::AbortError(SpeechEven
   NotifyError(aEvent);
 }
 
 void
 SpeechRecognition::NotifyError(SpeechEvent* aEvent)
 {
   aEvent->mError->SetTrusted(true);
 
-  bool defaultActionEnabled;
-  this->DispatchEvent(aEvent->mError, &defaultActionEnabled);
+  DispatchEvent(*aEvent->mError);
 }
 
 /**************************************
  * Event triggers and other functions *
  **************************************/
 NS_IMETHODIMP
 SpeechRecognition::StartRecording(DOMMediaStream* aDOMStream)
 {
--- a/dom/messagechannel/MessagePort.cpp
+++ b/dom/messagechannel/MessagePort.cpp
@@ -151,18 +151,17 @@ private:
     }
 
     event->InitMessageEvent(nullptr, NS_LITERAL_STRING("message"),
                             false /* non-bubbling */,
                             false /* cancelable */, value, EmptyString(),
                             EmptyString(), nullptr, ports);
     event->SetTrusted(true);
 
-    bool dummy;
-    mPort->DispatchEvent(static_cast<dom::Event*>(event.get()), &dummy);
+    mPort->DispatchEvent(*event);
 
     return NS_OK;
   }
 
 private:
   ~PostMessageRunnable()
   {}
 
@@ -949,14 +948,13 @@ MessagePort::DispatchError()
   RootedDictionary<MessageEventInit> init(jsapi.cx());
   init.mBubbles = false;
   init.mCancelable = false;
 
   RefPtr<Event> event =
     MessageEvent::Constructor(this, NS_LITERAL_STRING("messageerror"), init);
   event->SetTrusted(true);
 
-  bool dummy;
-  DispatchEvent(event, &dummy);
+  DispatchEvent(*event);
 }
 
 } // namespace dom
 } // namespace mozilla
--- a/dom/network/TCPServerSocket.cpp
+++ b/dom/network/TCPServerSocket.cpp
@@ -131,18 +131,17 @@ TCPServerSocket::FireEvent(const nsAStri
   TCPServerSocketEventInit init;
   init.mBubbles = false;
   init.mCancelable = false;
   init.mSocket = aSocket;
 
   RefPtr<TCPServerSocketEvent> event =
       TCPServerSocketEvent::Constructor(this, aType, init);
   event->SetTrusted(true);
-  bool dummy;
-  DispatchEvent(event, &dummy);
+  DispatchEvent(*event);
 
   if (mServerBridgeParent) {
     mServerBridgeParent->OnConnect(event);
   }
 }
 
 NS_IMETHODIMP
 TCPServerSocket::OnSocketAccepted(nsIServerSocket* aServer, nsISocketTransport* aTransport)
@@ -155,18 +154,17 @@ TCPServerSocket::OnSocketAccepted(nsISer
 
 NS_IMETHODIMP
 TCPServerSocket::OnStopListening(nsIServerSocket* aServer, nsresult aStatus)
 {
   if (aStatus != NS_BINDING_ABORTED) {
     RefPtr<Event> event = new Event(GetOwner());
     event->InitEvent(NS_LITERAL_STRING("error"), false, false);
     event->SetTrusted(true);
-    bool dummy;
-    DispatchEvent(event, &dummy);
+    DispatchEvent(*event);
 
     NS_WARNING("Server socket was closed by unexpected reason.");
     return NS_ERROR_FAILURE;
   }
   mServerSocket = nullptr;
   return NS_OK;
 }
 
--- a/dom/network/TCPSocket.cpp
+++ b/dom/network/TCPSocket.cpp
@@ -487,18 +487,17 @@ TCPSocket::FireErrorEvent(const nsAStrin
   init.mCancelable = false;
   init.mName = aName;
   init.mMessage = aType;
 
   RefPtr<TCPSocketErrorEvent> event =
     TCPSocketErrorEvent::Constructor(this, NS_LITERAL_STRING("error"), init);
   MOZ_ASSERT(event);
   event->SetTrusted(true);
-  bool dummy;
-  DispatchEvent(event, &dummy);
+  DispatchEvent(*event);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 TCPSocket::FireEvent(const nsAString& aType)
 {
   if (mSocketBridgeParent) {
     mSocketBridgeParent->FireEvent(aType, mReadyState);
@@ -557,18 +556,17 @@ TCPSocket::FireDataEvent(JSContext* aCx,
   RootedDictionary<TCPSocketEventInit> init(aCx);
   init.mBubbles = false;
   init.mCancelable = false;
   init.mData = aData;
 
   RefPtr<TCPSocketEvent> event =
     TCPSocketEvent::Constructor(this, aType, init);
   event->SetTrusted(true);
-  bool dummy;
-  DispatchEvent(event, &dummy);
+  DispatchEvent(*event);
   return NS_OK;
 }
 
 JSObject*
 TCPSocket::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
 {
   return TCPSocketBinding::Wrap(aCx, this, aGivenProto);
 }
--- a/dom/notification/Notification.cpp
+++ b/dom/notification/Notification.cpp
@@ -1296,35 +1296,32 @@ Notification::DispatchNotificationClickE
                                    options,
                                    result);
   if (NS_WARN_IF(result.Failed())) {
     return false;
   }
 
   event->SetTrusted(true);
   WantsPopupControlCheck popupControlCheck(event);
-  bool dummy;
-  target->DispatchEvent(event, &dummy);
+  target->DispatchEvent(*event);
   // We always return false since in case of dispatching on the serviceworker,
   // there is no well defined window to focus. The script may use the
   // Client.focus() API if it wishes.
   return false;
 }
 
 bool
 Notification::DispatchClickEvent()
 {
   AssertIsOnTargetThread();
   RefPtr<Event> event = NS_NewDOMEvent(this, nullptr, nullptr);
   event->InitEvent(NS_LITERAL_STRING("click"), false, true);
   event->SetTrusted(true);
   WantsPopupControlCheck popupControlCheck(event);
-  bool doDefaultAction = true;
-  DispatchEvent(event, &doDefaultAction);
-  return doDefaultAction;
+  return DispatchEvent(*event, CallerType::System, IgnoreErrors());
 }
 
 // Overrides dispatch and run handlers so we can directly dispatch from main
 // thread to child workers.
 class NotificationClickWorkerRunnable final : public NotificationWorkerRunnable
 {
   Notification* mNotification;
   // Optional window that gets focused if click event is not
--- a/dom/offline/nsDOMOfflineResourceList.cpp
+++ b/dom/offline/nsDOMOfflineResourceList.cpp
@@ -519,19 +519,18 @@ nsDOMOfflineResourceList::SwapCache()
 //
 // nsDOMOfflineResourceList::nsIDOMEventTarget
 //
 
 void
 nsDOMOfflineResourceList::FirePendingEvents()
 {
   for (int32_t i = 0; i < mPendingEvents.Count(); ++i) {
-    bool dummy;
-    nsCOMPtr<nsIDOMEvent> event = mPendingEvents[i];
-    DispatchEvent(event, &dummy);
+    RefPtr<Event> event = mPendingEvents[i];
+    DispatchEvent(*event);
   }
   mPendingEvents.Clear();
 }
 
 nsresult
 nsDOMOfflineResourceList::SendEvent(const nsAString &aEventName)
 {
   // Don't send events to closed windows
@@ -551,18 +550,17 @@ nsDOMOfflineResourceList::SendEvent(cons
 
   // If the window is frozen or we're still catching up on events that were
   // queued while frozen, save the event for later.
   if (GetOwner()->IsFrozen() || mPendingEvents.Count() > 0) {
     mPendingEvents.AppendObject(event);
     return NS_OK;
   }
 
-  bool dummy;
-  DispatchEvent(event, &dummy);
+  DispatchEvent(*event);
 
   return NS_OK;
 }
 
 
 //
 // nsDOMOfflineResourceList::nsIObserver
 //
--- a/dom/offline/nsDOMOfflineResourceList.h
+++ b/dom/offline/nsDOMOfflineResourceList.h
@@ -25,16 +25,17 @@
 #include "nsCycleCollectionParticipant.h"
 #include "nsPIDOMWindow.h"
 #include "mozilla/DOMEventTargetHelper.h"
 #include "mozilla/ErrorResult.h"
 
 namespace mozilla {
 namespace dom {
 class DOMStringList;
+class Event;
 } // namespace dom
 } // namespace mozilla
 
 class nsDOMOfflineResourceList final : public mozilla::DOMEventTargetHelper,
                                        public nsIDOMOfflineResourceList,
                                        public nsIObserver,
                                        public nsIOfflineCacheUpdateObserver,
                                        public nsSupportsWeakReference
@@ -160,12 +161,12 @@ private:
   nsCOMPtr<nsIOfflineCacheUpdate> mCacheUpdate;
   bool mExposeCacheUpdateStatus;
   uint16_t mStatus;
 
   // The set of dynamic keys for this application cache object.
   char **mCachedKeys;
   uint32_t mCachedKeysCount;
 
-  nsCOMArray<nsIDOMEvent> mPendingEvents;
+  nsCOMArray<mozilla::dom::Event> mPendingEvents;
 };
 
 #endif
--- a/dom/payments/PaymentRequest.cpp
+++ b/dom/payments/PaymentRequest.cpp
@@ -931,18 +931,19 @@ PaymentRequest::DispatchUpdateEvent(cons
   init.mBubbles = false;
   init.mCancelable = false;
 
   RefPtr<PaymentRequestUpdateEvent> event =
     PaymentRequestUpdateEvent::Constructor(this, aType, init);
   event->SetTrusted(true);
   event->SetRequest(this);
 
-  bool dummy;
-  return DispatchEvent(event, &dummy);
+  ErrorResult rv;
+  DispatchEvent(*event, rv);
+  return rv.StealNSResult();
 }
 
 already_AddRefed<PaymentAddress>
 PaymentRequest::GetShippingAddress() const
 {
   RefPtr<PaymentAddress> address = mShippingAddress;
   return address.forget();
 }
--- a/dom/performance/Performance.cpp
+++ b/dom/performance/Performance.cpp
@@ -384,18 +384,17 @@ Performance::TimingNotification(Performa
   init.mEpoch = aEpoch;
   init.mOrigin = NS_ConvertUTF8toUTF16(aOwner.BeginReading());
 
   RefPtr<PerformanceEntryEvent> perfEntryEvent =
     PerformanceEntryEvent::Constructor(this, NS_LITERAL_STRING("performanceentry"), init);
 
   nsCOMPtr<EventTarget> et = do_QueryInterface(GetOwner());
   if (et) {
-    bool dummy = false;
-    et->DispatchEvent(perfEntryEvent, &dummy);
+    et->DispatchEvent(*perfEntryEvent);
   }
 }
 
 void
 Performance::InsertUserEntry(PerformanceEntry* aEntry)
 {
   mUserEntries.InsertElementSorted(aEntry,
                                    PerformanceEntryComparator());
--- a/dom/performance/PerformanceMainThread.cpp
+++ b/dom/performance/PerformanceMainThread.cpp
@@ -89,18 +89,17 @@ PerformanceMainThread::Timing()
 
 void
 PerformanceMainThread::DispatchBufferFullEvent()
 {
   RefPtr<Event> event = NS_NewDOMEvent(this, nullptr, nullptr);
   // it bubbles, and it isn't cancelable
   event->InitEvent(NS_LITERAL_STRING("resourcetimingbufferfull"), true, false);
   event->SetTrusted(true);
-  bool dummy;
-  DispatchEvent(event, &dummy);
+  DispatchEvent(*event);
 }
 
 PerformanceNavigation*
 PerformanceMainThread::Navigation()
 {
   if (!mNavigation) {
     mNavigation = new PerformanceNavigation(this);
   }
--- a/dom/presentation/PresentationConnection.cpp
+++ b/dom/presentation/PresentationConnection.cpp
@@ -610,18 +610,19 @@ PresentationConnection::DispatchConnecti
 
   RefPtr<PresentationConnectionCloseEvent> closedEvent =
     PresentationConnectionCloseEvent::Constructor(this,
                                                    NS_LITERAL_STRING("close"),
                                                    init);
   closedEvent->SetTrusted(true);
 
   if (aDispatchNow) {
-    bool ignore;
-    return DOMEventTargetHelper::DispatchEvent(closedEvent, &ignore);
+    ErrorResult rv;
+    DispatchEvent(*closedEvent, rv);
+    return rv.StealNSResult();
   }
 
   RefPtr<AsyncEventDispatcher> asyncDispatcher =
     new AsyncEventDispatcher(this, static_cast<Event*>(closedEvent));
   return asyncDispatcher->PostDOMEvent();
 }
 
 nsresult
--- a/dom/security/nsCSPContext.cpp
+++ b/dom/security/nsCSPContext.cpp
@@ -1193,18 +1193,19 @@ nsCSPContext::FireViolationEvent(
 
   RefPtr<mozilla::dom::Event> event =
     mozilla::dom::SecurityPolicyViolationEvent::Constructor(
       doc,
       NS_LITERAL_STRING("securitypolicyviolation"),
       aViolationEventInit);
   event->SetTrusted(true);
 
-  bool rv;
-  return doc->DispatchEvent(event, &rv);
+  ErrorResult rv;
+  doc->DispatchEvent(*event, rv);
+  return rv.StealNSResult();
 }
 
 /**
  * Dispatched from the main thread to send reports for one CSP violation.
  */
 class CSPReportSenderRunnable final : public Runnable
 {
   public:
--- a/dom/serviceworkers/ServiceWorkerPrivate.cpp
+++ b/dom/serviceworkers/ServiceWorkerPrivate.cpp
@@ -472,18 +472,17 @@ public:
       return NS_ERROR_FAILURE;
     }
 
     // This must always be set *before* dispatching the event, otherwise
     // waitUntil calls will fail.
     aEvent->SetKeepAliveHandler(keepAliveHandler);
 
     ErrorResult result;
-    bool dummy;
-    result = aWorkerScope->DispatchEvent(aEvent, &dummy);
+    aWorkerScope->DispatchEvent(*aEvent, result);
     if (NS_WARN_IF(result.Failed())) {
       result.SuppressException();
       return NS_ERROR_FAILURE;
     }
 
     // [[ If e’s extend lifetime promises is empty, unset e’s extensions allowed
     //    flag and abort these steps. ]]
     keepAliveHandler->MaybeDone();
--- a/dom/system/nsDeviceSensors.cpp
+++ b/dom/system/nsDeviceSensors.cpp
@@ -413,18 +413,17 @@ nsDeviceSensors::FireDOMLightEvent(mozil
   init.mBubbles = true;
   init.mCancelable = false;
   init.mValue = round(aValue);
   RefPtr<DeviceLightEvent> event =
     DeviceLightEvent::Constructor(aTarget, NS_LITERAL_STRING("devicelight"), init);
 
   event->SetTrusted(true);
 
-  bool defaultActionEnabled;
-  aTarget->DispatchEvent(event, &defaultActionEnabled);
+  aTarget->DispatchEvent(*event);
 }
 
 void
 nsDeviceSensors::FireDOMProximityEvent(mozilla::dom::EventTarget* aTarget,
                                        double aValue,
                                        double aMin,
                                        double aMax)
 {
@@ -435,18 +434,17 @@ nsDeviceSensors::FireDOMProximityEvent(m
   init.mMin = aMin;
   init.mMax = aMax;
   RefPtr<DeviceProximityEvent> event =
     DeviceProximityEvent::Constructor(aTarget,
                                       NS_LITERAL_STRING("deviceproximity"),
                                       init);
   event->SetTrusted(true);
 
-  bool defaultActionEnabled;
-  aTarget->DispatchEvent(event, &defaultActionEnabled);
+  aTarget->DispatchEvent(*event);
 
   // Some proximity sensors only support a binary near or
   // far measurement. In this case, the sensor should report
   // its maximum range value in the far state and a lesser
   // value in the near state.
 
   bool near = (aValue < aMax);
   if (mIsUserProximityNear != near) {
@@ -465,18 +463,17 @@ nsDeviceSensors::FireDOMUserProximityEve
   init.mNear = aNear;
   RefPtr<UserProximityEvent> event =
     UserProximityEvent::Constructor(aTarget,
                                     NS_LITERAL_STRING("userproximity"),
                                     init);
 
   event->SetTrusted(true);
 
-  bool defaultActionEnabled;
-  aTarget->DispatchEvent(event, &defaultActionEnabled);
+  aTarget->DispatchEvent(*event);
 }
 
 void
 nsDeviceSensors::FireDOMOrientationEvent(EventTarget* aTarget,
                                          double aAlpha,
                                          double aBeta,
                                          double aGamma,
                                          bool aIsAbsolute)
@@ -489,18 +486,17 @@ nsDeviceSensors::FireDOMOrientationEvent
   init.mGamma.SetValue(aGamma);
   init.mAbsolute = aIsAbsolute;
 
   auto Dispatch = [&](EventTarget* aEventTarget, const nsAString& aType)
   {
     RefPtr<DeviceOrientationEvent> event =
       DeviceOrientationEvent::Constructor(aEventTarget, aType, init);
     event->SetTrusted(true);
-    bool dummy;
-    aEventTarget->DispatchEvent(event, &dummy);
+    aEventTarget->DispatchEvent(*event);
   };
 
   Dispatch(aTarget, aIsAbsolute ? NS_LITERAL_STRING("absolutedeviceorientation") :
                                   NS_LITERAL_STRING("deviceorientation"));
 
   // This is used to determine whether relative events have been dispatched
   // during the current session, in which case we don't dispatch the additional
   // compatibility events.
@@ -592,18 +588,17 @@ nsDeviceSensors::FireDOMMotionEvent(nsID
                             *mLastAcceleration,
                             *mLastAccelerationIncludingGravity,
                             *mLastRotationRate,
                             Nullable<double>(DEFAULT_SENSOR_POLL),
                             Nullable<uint64_t>(timestamp));
 
   event->SetTrusted(true);
 
-  bool defaultActionEnabled = true;
-  target->DispatchEvent(event, &defaultActionEnabled);
+  target->DispatchEvent(*event);
 
   mLastRotationRate.reset();
   mLastAccelerationIncludingGravity.reset();
   mLastAcceleration.reset();
   mLastDOMMotionEventTime = TimeStamp::Now();
 }
 
 bool
--- a/dom/websocket/WebSocket.cpp
+++ b/dom/websocket/WebSocket.cpp
@@ -1919,18 +1919,19 @@ WebSocket::CreateAndDispatchSimpleEvent(
   }
 
   RefPtr<Event> event = NS_NewDOMEvent(this, nullptr, nullptr);
 
   // it doesn't bubble, and it isn't cancelable
   event->InitEvent(aName, false, false);
   event->SetTrusted(true);
 
-  bool dummy;
-  return DispatchEvent(event, &dummy);
+  ErrorResult err;
+  DispatchEvent(*event, err);
+  return err.StealNSResult();
 }
 
 nsresult
 WebSocket::CreateAndDispatchMessageEvent(const nsACString& aData,
                                          bool aIsBinary)
 {
   MOZ_ASSERT(mImpl);
   AssertIsOnTargetThread();
@@ -2003,18 +2004,19 @@ WebSocket::CreateAndDispatchMessageEvent
 
   RefPtr<MessageEvent> event = new MessageEvent(this, nullptr, nullptr);
 
   event->InitMessageEvent(nullptr, MESSAGE_EVENT_STRING, false, false,
                           jsData, mImpl->mUTF16Origin, EmptyString(), nullptr,
                           Sequence<OwningNonNull<MessagePort>>());
   event->SetTrusted(true);
 
-  bool dummy;
-  return DispatchEvent(static_cast<Event*>(event), &dummy);
+  ErrorResult err;
+  DispatchEvent(*event, err);
+  return err.StealNSResult();
 }
 
 nsresult
 WebSocket::CreateAndDispatchCloseEvent(bool aWasClean,
                                        uint16_t aCode,
                                        const nsAString& aReason)
 {
   AssertIsOnTargetThread();
@@ -2038,18 +2040,19 @@ WebSocket::CreateAndDispatchCloseEvent(b
   init.mWasClean = aWasClean;
   init.mCode = aCode;
   init.mReason = aReason;
 
   RefPtr<CloseEvent> event =
     CloseEvent::Constructor(this, CLOSE_EVENT_STRING, init);
   event->SetTrusted(true);
 
-  bool dummy;
-  return DispatchEvent(event, &dummy);
+  ErrorResult err;
+  DispatchEvent(*event, err);
+  return err.StealNSResult();
 }
 
 nsresult
 WebSocketImpl::ParseURL(const nsAString& aURL)
 {
   AssertIsOnMainThread();
   NS_ENSURE_TRUE(!aURL.IsEmpty(), NS_ERROR_DOM_SYNTAX_ERR);
 
--- a/dom/workers/MessageEventRunnable.cpp
+++ b/dom/workers/MessageEventRunnable.cpp
@@ -81,33 +81,30 @@ MessageEventRunnable::DispatchDOMEvent(J
   }
 
   Sequence<OwningNonNull<MessagePort>> ports;
   if (!TakeTransferredPortsAsSequence(ports)) {
     DispatchError(aCx, aTarget);
     return false;
   }
 
-  nsCOMPtr<nsIDOMEvent> domEvent;
   RefPtr<MessageEvent> event = new MessageEvent(aTarget, nullptr, nullptr);
   event->InitMessageEvent(nullptr,
                           NS_LITERAL_STRING("message"),
                           false /* non-bubbling */,
                           false /* cancelable */,
                           messageData,
                           EmptyString(),
                           EmptyString(),
                           nullptr,
                           ports);
-  domEvent = do_QueryObject(event);
 
-  domEvent->SetTrusted(true);
+  event->SetTrusted(true);
 
-  bool dummy;
-  aTarget->DispatchEvent(domEvent, &dummy);
+  aTarget->DispatchEvent(*event);
 
   return true;
 }
 
 bool
 MessageEventRunnable::WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate)
 {
   if (mBehavior == ParentThreadUnchangedBusyCount) {
@@ -144,14 +141,13 @@ MessageEventRunnable::DispatchError(JSCo
   RootedDictionary<MessageEventInit> init(aCx);
   init.mBubbles = false;
   init.mCancelable = false;
 
   RefPtr<Event> event =
     MessageEvent::Constructor(aTarget, NS_LITERAL_STRING("messageerror"), init);
   event->SetTrusted(true);
 
-  bool dummy;
-  aTarget->DispatchEvent(event, &dummy);
+  aTarget->DispatchEvent(*event);
 }
 
 } // dom namespace
 } // mozilla namespace
--- a/dom/workers/SharedWorker.cpp
+++ b/dom/workers/SharedWorker.cpp
@@ -5,23 +5,24 @@
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "SharedWorker.h"
 
 #include "nsPIDOMWindow.h"
 
 #include "mozilla/EventDispatcher.h"
 #include "mozilla/Preferences.h"
+#include "mozilla/dom/Event.h"
+#include "mozilla/dom/EventTarget.h"
 #include "mozilla/dom/MessagePort.h"
 #include "mozilla/dom/SharedWorkerBinding.h"
 #include "mozilla/dom/WorkerBinding.h"
 #include "mozilla/Telemetry.h"
 #include "nsContentUtils.h"
 #include "nsIClassInfoImpl.h"
-#include "nsIDOMEvent.h"
 
 #include "RuntimeService.h"
 #include "WorkerPrivate.h"
 
 #ifdef XP_WIN
 #undef PostMessage
 #endif
 
@@ -104,38 +105,35 @@ void
 SharedWorker::Thaw()
 {
   AssertIsOnMainThread();
   MOZ_ASSERT(IsFrozen());
 
   mFrozen = false;
 
   if (!mFrozenEvents.IsEmpty()) {
-    nsTArray<nsCOMPtr<nsIDOMEvent>> events;
+    nsTArray<RefPtr<Event>> events;
     mFrozenEvents.SwapElements(events);
 
     for (uint32_t index = 0; index < events.Length(); index++) {
-      nsCOMPtr<nsIDOMEvent>& event = events[index];
+      RefPtr<Event>& event = events[index];
       MOZ_ASSERT(event);
 
-      nsCOMPtr<nsIDOMEventTarget> target;
-      if (NS_SUCCEEDED(event->GetTarget(getter_AddRefs(target)))) {
-        bool ignored;
-        if (NS_FAILED(target->DispatchEvent(event, &ignored))) {
-          NS_WARNING("Failed to dispatch event!");
-        }
-      } else {
-        NS_WARNING("Failed to get target!");
+      RefPtr<EventTarget> target = event->GetTarget();
+      ErrorResult rv;
+      target->DispatchEvent(*event, rv);
+      if (rv.Failed()) {
+        NS_WARNING("Failed to dispatch event!");
       }
     }
   }
 }
 
 void
-SharedWorker::QueueEvent(nsIDOMEvent* aEvent)
+SharedWorker::QueueEvent(Event* aEvent)
 {
   AssertIsOnMainThread();
   MOZ_ASSERT(aEvent);
   MOZ_ASSERT(IsFrozen());
 
   mFrozenEvents.AppendElement(aEvent);
 }
 
@@ -197,17 +195,17 @@ SharedWorker::GetEventTargetParent(Event
   if (IsFrozen()) {
     nsCOMPtr<nsIDOMEvent> event = aVisitor.mDOMEvent;
     if (!event) {
       event = EventDispatcher::CreateEvent(aVisitor.mEvent->mOriginalTarget,
                                            aVisitor.mPresContext,
                                            aVisitor.mEvent, EmptyString());
     }
 
-    QueueEvent(event);
+    QueueEvent(event->InternalDOMEvent());
 
     aVisitor.mCanHandle = false;
     aVisitor.SetParentTarget(nullptr, false);
     return NS_OK;
   }
 
   return DOMEventTargetHelper::GetEventTargetParent(aVisitor);
 }
--- a/dom/workers/SharedWorker.h
+++ b/dom/workers/SharedWorker.h
@@ -11,41 +11,41 @@
 
 #include "mozilla/dom/BindingDeclarations.h"
 #include "mozilla/DOMEventTargetHelper.h"
 
 #ifdef XP_WIN
 #undef PostMessage
 #endif
 
-class nsIDOMEvent;
 class nsPIDOMWindowInner;
 
 namespace mozilla {
 class EventChainPreVisitor;
 
 namespace dom {
 class MessagePort;
 class StringOrWorkerOptions;
 class WorkerPrivate;
+class Event;
 
 namespace workerinternals {
 class RuntimeService;
 }
 
 class SharedWorker final : public DOMEventTargetHelper
 {
   friend class workerinternals::RuntimeService;
 
   typedef mozilla::ErrorResult ErrorResult;
   typedef mozilla::dom::GlobalObject GlobalObject;
 
   RefPtr<WorkerPrivate> mWorkerPrivate;
   RefPtr<MessagePort> mMessagePort;
-  nsTArray<nsCOMPtr<nsIDOMEvent>> mFrozenEvents;
+  nsTArray<RefPtr<Event>> mFrozenEvents;
   bool mFrozen;
 
 public:
   static already_AddRefed<SharedWorker>
   Constructor(const GlobalObject& aGlobal, const nsAString& aScriptURL,
               const StringOrWorkerOptions& aOptions, ErrorResult& aRv);
 
   MessagePort*
@@ -59,17 +59,17 @@ public:
 
   void
   Freeze();
 
   void
   Thaw();
 
   void
-  QueueEvent(nsIDOMEvent* aEvent);
+  QueueEvent(Event* aEvent);
 
   void
   Close();
 
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(SharedWorker, DOMEventTargetHelper)
 
   IMPL_EVENT_HANDLER(error)
--- a/dom/workers/WorkerDebugger.cpp
+++ b/dom/workers/WorkerDebugger.cpp
@@ -62,19 +62,17 @@ private:
                             true, // cancelable
                             data,
                             EmptyString(),
                             EmptyString(),
                             nullptr,
                             Sequence<OwningNonNull<MessagePort>>());
     event->SetTrusted(true);
 
-    nsCOMPtr<nsIDOMEvent> domEvent = do_QueryObject(event);
-    bool dummy;
-    globalScope->DispatchEvent(domEvent, &dummy);
+    globalScope->DispatchEvent(*event);
     return true;
   }
 };
 
 class CompileDebuggerScriptRunnable final : public WorkerDebuggerRunnable
 {
   nsString mScriptURL;
 
--- a/dom/workers/WorkerError.cpp
+++ b/dom/workers/WorkerError.cpp
@@ -63,19 +63,18 @@ public:
       init.mCancelable = true;
       init.mBubbles = false;
 
       if (aTarget) {
         RefPtr<ErrorEvent> event =
           ErrorEvent::Constructor(aTarget, NS_LITERAL_STRING("error"), init);
         event->SetTrusted(true);
 
-        bool defaultActionEnabled;
-        aTarget->DispatchEvent(event, &defaultActionEnabled);
-
+        bool defaultActionEnabled =
+          aTarget->DispatchEvent(*event, CallerType::System, IgnoreErrors());
         if (!defaultActionEnabled) {
           return;
         }
       }
 
       // Now fire an event at the global object, but don't do that if the error
       // code is too much recursion and this is the same script threw the error.
       // XXXbz the interaction of this with worker errors seems kinda broken.
@@ -318,19 +317,18 @@ WorkerErrorReport::ReportError(JSContext
     init.mCancelable = true;
     init.mBubbles = false;
 
     if (aTarget) {
       RefPtr<ErrorEvent> event =
         ErrorEvent::Constructor(aTarget, NS_LITERAL_STRING("error"), init);
       event->SetTrusted(true);
 
-      bool defaultActionEnabled;
-      aTarget->DispatchEvent(event, &defaultActionEnabled);
-
+      bool defaultActionEnabled =
+        aTarget->DispatchEvent(*event, CallerType::System, IgnoreErrors());
       if (!defaultActionEnabled) {
         return;
       }
     }
 
     // Now fire an event at the global object, but don't do that if the error
     // code is too much recursion and this is the same script threw the error.
     // XXXbz the interaction of this with worker errors seems kinda broken.
--- a/dom/workers/WorkerPrivate.cpp
+++ b/dom/workers/WorkerPrivate.cpp
@@ -388,18 +388,17 @@ private:
 
     RefPtr<mozilla::dom::EventTarget> parentEventTarget =
       aWorkerPrivate->ParentEventTargetRef();
     RefPtr<Event> event =
       Event::Constructor(parentEventTarget, NS_LITERAL_STRING("error"),
                          EventInit());
     event->SetTrusted(true);
 
-    bool dummy;
-    parentEventTarget->DispatchEvent(event, &dummy);
+    parentEventTarget->DispatchEvent(*event);
     return true;
   }
 };
 
 class CompileScriptRunnable final : public WorkerRunnable
 {
   nsString mScriptURL;
 
@@ -2103,18 +2102,17 @@ WorkerPrivate::OfflineStatusChangeEventI
     eventType.AssignLiteral("online");
   }
 
   RefPtr<Event> event = NS_NewDOMEvent(globalScope, nullptr, nullptr);
 
   event->InitEvent(eventType, false, false);
   event->SetTrusted(true);
 
-  bool dummy;
-  globalScope->DispatchEvent(event, &dummy);
+  globalScope->DispatchEvent(*event);
 }
 
 void
 WorkerPrivate::MemoryPressure(bool aDummy)
 {
   AssertIsOnParentThread();
 
   RefPtr<MemoryPressureRunnable> runnable = new MemoryPressureRunnable(this);
@@ -2203,20 +2201,21 @@ WorkerPrivate::BroadcastErrorToSharedWor
 
     if (!event) {
       ThrowAndReport(window, NS_ERROR_UNEXPECTED);
       continue;
     }
 
     event->SetTrusted(true);
 
-    bool defaultActionEnabled;
-    nsresult rv = sharedWorker->DispatchEvent(event, &defaultActionEnabled);
-    if (NS_FAILED(rv)) {
-      ThrowAndReport(window, rv);
+    ErrorResult res;
+    bool defaultActionEnabled =
+      sharedWorker->DispatchEvent(*event, CallerType::System, res);
+    if (res.Failed()) {
+      ThrowAndReport(window, res.StealNSResult());
       continue;
     }
 
     if (!aIsErrorEvent) {
       continue;
     }
 
     if (defaultActionEnabled) {
@@ -5091,20 +5090,17 @@ WorkerPrivate::ConnectMessagePort(JSCont
   }
 
   RefPtr<MessageEvent> event =
     MessageEvent::Constructor(globalObject,
                               NS_LITERAL_STRING("connect"), init, rv);
 
   event->SetTrusted(true);
 
-  nsCOMPtr<nsIDOMEvent> domEvent = do_QueryObject(event);
-
-  bool dummy;
-  globalScope->DispatchEvent(domEvent, &dummy);
+  globalScope->DispatchEvent(*event);
 
   return true;
 }
 
 WorkerGlobalScope*
 WorkerPrivate::GetOrCreateGlobalScope(JSContext* aCx)
 {
   AssertIsOnWorkerThread();
--- a/dom/xhr/XMLHttpRequestMainThread.cpp
+++ b/dom/xhr/XMLHttpRequestMainThread.cpp
@@ -1331,18 +1331,17 @@ XMLHttpRequestMainThread::DispatchOrStor
 
   if (mEventDispatchingSuspended) {
     PendingEvent* event = mPendingEvents.AppendElement();
     event->mTarget = aTarget;
     event->mEvent = aEvent;
     return;
   }
 
-  bool dummy;
-  aTarget->DispatchEvent(aEvent, &dummy);
+  aTarget->DispatchEvent(*aEvent);
 }
 
 void
 XMLHttpRequestMainThread::SuspendEventDispatching()
 {
   MOZ_ASSERT(!mEventDispatchingSuspended);
   mEventDispatchingSuspended = true;
 }
@@ -1356,18 +1355,17 @@ XMLHttpRequestMainThread::ResumeEventDis
   nsTArray<PendingEvent> pendingEvents;
   pendingEvents.SwapElements(mPendingEvents);
 
   if (NS_FAILED(CheckInnerWindowCorrectness())) {
     return;
   }
 
   for (uint32_t i = 0; i < pendingEvents.Length(); ++i) {
-    bool dummy;
-    pendingEvents[i].mTarget->DispatchEvent(pendingEvents[i].mEvent, &dummy);
+    pendingEvents[i].mTarget->DispatchEvent(*pendingEvents[i].mEvent);
   }
 }
 
 already_AddRefed<nsIHttpChannel>
 XMLHttpRequestMainThread::GetCurrentHttpChannel()
 {
   nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(mChannel);
   return httpChannel.forget();
--- a/dom/xhr/XMLHttpRequestWorker.cpp
+++ b/dom/xhr/XMLHttpRequestWorker.cpp
@@ -1347,18 +1347,17 @@ EventRunnable::WorkerRun(JSContext* aCx,
   }
 
   if (!event) {
     return false;
   }
 
   event->SetTrusted(true);
 
-  bool dummy;
-  target->DispatchEvent(event, &dummy);
+  target->DispatchEvent(*event);
 
   // After firing the event set mResponse to JSVAL_NULL for chunked response
   // types.
   if (StringBeginsWith(mResponseType, NS_LITERAL_STRING("moz-chunked-"))) {
     xhr->NullResponseText();
   }
 
   return true;
@@ -1761,18 +1760,17 @@ XMLHttpRequestWorker::DispatchPrematureA
 
   if (!event) {
     aRv.Throw(NS_ERROR_FAILURE);
     return;
   }
 
   event->SetTrusted(true);
 
-  bool dummy;
-  aTarget->DispatchEvent(event, &dummy);
+  aTarget->DispatchEvent(*event);
 }
 
 void
 XMLHttpRequestWorker::Unpin()
 {
   mWorkerPrivate->AssertIsOnWorkerThread();
 
   MOZ_ASSERT(mRooted, "Mismatched calls to Unpin!");
--- a/dom/xml/nsXMLPrettyPrinter.cpp
+++ b/dom/xml/nsXMLPrettyPrinter.cpp
@@ -180,19 +180,20 @@ nsXMLPrettyPrinter::PrettyPrint(nsIDocum
     if (!ToJSValue(cx, resultFragment, &detail)) {
         return NS_ERROR_UNEXPECTED;
     }
     event->InitCustomEvent(cx, NS_LITERAL_STRING("prettyprint-dom-created"),
                            /* bubbles = */ false, /* cancelable = */ false,
                            detail);
 
     event->SetTrusted(true);
-    bool dummy;
-    rv = rootElement->DispatchEvent(event, &dummy);
-    NS_ENSURE_SUCCESS(rv, rv);
+    rootElement->DispatchEvent(*event, err);
+    if (NS_WARN_IF(err.Failed())) {
+        return err.StealNSResult();
+    }
 
     // Observe the document so we know when to switch to "normal" view
     aDocument->AddObserver(this);
     mDocument = aDocument;
 
     NS_ADDREF_THIS();
 
     return NS_OK;
--- a/layout/base/nsRefreshDriver.cpp
+++ b/layout/base/nsRefreshDriver.cpp
@@ -42,16 +42,17 @@
 #include "nsIXULRuntime.h"
 #include "jsapi.h"
 #include "nsContentUtils.h"
 #include "mozilla/PendingAnimationTracker.h"
 #include "mozilla/Preferences.h"
 #include "nsViewManager.h"
 #include "GeckoProfiler.h"
 #include "nsNPAPIPluginInstance.h"
+#include "mozilla/dom/Event.h"
 #include "mozilla/dom/Performance.h"
 #include "mozilla/dom/Selection.h"
 #include "mozilla/dom/WindowBinding.h"
 #include "mozilla/RestyleManager.h"
 #include "mozilla/RestyleManagerInlines.h"
 #include "Layers.h"
 #include "imgIContainer.h"
 #include "mozilla/dom/ScriptSettings.h"
@@ -64,17 +65,16 @@
 #include "mozilla/ipc/PBackgroundChild.h"
 #include "mozilla/layout/VsyncChild.h"
 #include "VsyncSource.h"
 #include "mozilla/VsyncDispatcher.h"
 #include "nsThreadUtils.h"
 #include "mozilla/Unused.h"
 #include "mozilla/TimelineConsumers.h"
 #include "nsAnimationManager.h"
-#include "nsIDOMEvent.h"
 #include "nsDisplayList.h"
 #include "nsTransitionManager.h"
 
 #ifdef MOZ_XUL
 #include "nsXULPopupManager.h"
 #endif
 
 using namespace mozilla;
@@ -1593,18 +1593,17 @@ TakeFrameRequestCallbacksFrom(nsIDocumen
 }
 
 void
 nsRefreshDriver::DispatchPendingEvents()
 {
   // Swap out the current pending events
   nsTArray<PendingEvent> pendingEvents(Move(mPendingEvents));
   for (PendingEvent& event : pendingEvents) {
-    bool dummy;
-    event.mTarget->DispatchEvent(event.mEvent, &dummy);
+    event.mTarget->DispatchEvent(*event.mEvent);
   }
 }
 
 void
 nsRefreshDriver::UpdateIntersectionObservations()
 {
   AutoTArray<nsCOMPtr<nsIDocument>, 32> documents;
 
@@ -2369,17 +2368,17 @@ nsRefreshDriver::RevokeFrameRequestCallb
 {
   mFrameRequestCallbackDocs.RemoveElement(aDocument);
   mThrottledFrameRequestCallbackDocs.RemoveElement(aDocument);
   // No need to worry about restarting our timer in slack mode if it's already
   // running; that will happen automatically when it fires.
 }
 
 void
-nsRefreshDriver::ScheduleEventDispatch(nsINode* aTarget, nsIDOMEvent* aEvent)
+nsRefreshDriver::ScheduleEventDispatch(nsINode* aTarget, dom::Event* aEvent)
 {
   mPendingEvents.AppendElement(PendingEvent{aTarget, aEvent});
   // make sure that the timer is running
   EnsureTimerStarted();
 }
 
 void
 nsRefreshDriver::CancelPendingEvents(nsIDocument* aDocument)
--- a/layout/base/nsRefreshDriver.h
+++ b/layout/base/nsRefreshDriver.h
@@ -26,26 +26,31 @@
 #include "mozilla/Attributes.h"
 #include "mozilla/Maybe.h"
 #include "mozilla/layers/TransactionIdAllocator.h"
 
 class nsPresContext;
 class nsIPresShell;
 class nsIDocument;
 class imgIRequest;
-class nsIDOMEvent;
 class nsINode;
 class nsIRunnable;
 
 namespace mozilla {
 class RefreshDriverTimer;
 class Runnable;
+
 namespace layout {
 class VsyncChild;
 } // namespace layout
+
+namespace dom {
+class Event;
+} // namespace dom
+
 } // namespace mozilla
 
 /**
  * An abstract base class to be implemented by callers wanting to be
  * notified at refresh times.  When nothing needs to be painted, callers
  * may not be notified.
  */
 class nsARefreshObserver {
@@ -235,17 +240,17 @@ public:
   /**
    * Remove a document for which we have FrameRequestCallbacks
    */
   void RevokeFrameRequestCallbacks(nsIDocument* aDocument);
 
   /**
    * Queue a new event to dispatch in next tick before the style flush
    */
-  void ScheduleEventDispatch(nsINode* aTarget, nsIDOMEvent* aEvent);
+  void ScheduleEventDispatch(nsINode* aTarget, mozilla::dom::Event* aEvent);
 
   /**
    * Cancel all pending events scheduled by ScheduleEventDispatch which
    * targets any node in aDocument.
    */
   void CancelPendingEvents(nsIDocument* aDocument);
 
   /**
@@ -503,17 +508,17 @@ private:
   ObserverArray mObservers[4];
   RequestTable mRequests;
   ImageStartTable mStartTable;
   AutoTArray<nsCOMPtr<nsIRunnable>, 16> mEarlyRunners;
   ScrollEventArray mScrollEvents;
 
   struct PendingEvent {
     nsCOMPtr<nsINode> mTarget;
-    nsCOMPtr<nsIDOMEvent> mEvent;
+    RefPtr<mozilla::dom::Event> mEvent;
   };
 
   AutoTArray<nsIPresShell*, 16> mResizeEventFlushObservers;
   AutoTArray<nsIPresShell*, 16> mStyleFlushObservers;
   AutoTArray<nsIPresShell*, 16> mLayoutFlushObservers;
   // nsTArray on purpose, because we want to be able to swap.
   nsTArray<nsIDocument*> mFrameRequestCallbackDocs;
   nsTArray<nsIDocument*> mThrottledFrameRequestCallbackDocs;
--- a/layout/style/MediaQueryList.cpp
+++ b/layout/style/MediaQueryList.cpp
@@ -192,14 +192,13 @@ MediaQueryList::MaybeNotify()
   init.mCancelable = false;
   init.mMatches = mMatches;
   mMediaList->GetText(init.mMedia);
 
   RefPtr<MediaQueryListEvent> event =
     MediaQueryListEvent::Constructor(this, ONCHANGE_STRING, init);
   event->SetTrusted(true);
 
-  bool dummy;
-  DispatchEvent(event, &dummy);
+  DispatchEvent(*event);
 }
 
 } // namespace dom
 } // namespace mozilla
--- a/toolkit/components/extensions/webrequest/ChannelWrapper.cpp
+++ b/toolkit/components/extensions/webrequest/ChannelWrapper.cpp
@@ -982,18 +982,17 @@ ChannelWrapper::FireEvent(const nsAStrin
 {
   EventInit init;
   init.mBubbles = false;
   init.mCancelable = false;
 
   RefPtr<Event> event = Event::Constructor(this, aType, init);
   event->SetTrusted(true);
 
-  bool defaultPrevented;
-  DispatchEvent(event, &defaultPrevented);
+  DispatchEvent(*event);
 }
 
 void
 ChannelWrapper::CheckEventListeners()
 {
   if (!mAddedStreamListener && (HasListenersFor(nsGkAtoms::onerror) ||
                                 HasListenersFor(nsGkAtoms::onstart) ||
                                 HasListenersFor(nsGkAtoms::onstop) ||
--- a/toolkit/components/extensions/webrequest/StreamFilter.cpp
+++ b/toolkit/components/extensions/webrequest/StreamFilter.cpp
@@ -239,18 +239,17 @@ StreamFilter::FireEvent(const nsAString&
 {
   EventInit init;
   init.mBubbles = false;
   init.mCancelable = false;
 
   RefPtr<Event> event = Event::Constructor(this, aType, init);
   event->SetTrusted(true);
 
-  bool defaultPrevented;
-  DispatchEvent(event, &defaultPrevented);
+  DispatchEvent(*event);
 }
 
 void
 StreamFilter::FireDataEvent(const nsTArray<uint8_t>& aData)
 {
   AutoEntryScript aes(mParent, "StreamFilter data event");
   JSContext* cx = aes.cx();
 
@@ -266,18 +265,17 @@ StreamFilter::FireDataEvent(const nsTArr
   }
 
   init.mData.Init(buffer);
 
   RefPtr<StreamFilterDataEvent> event =
     StreamFilterDataEvent::Constructor(this, NS_LITERAL_STRING("data"), init);
   event->SetTrusted(true);
 
-  bool defaultPrevented;
-  DispatchEvent(event, &defaultPrevented);
+  DispatchEvent(*event);
 }
 
 void
 StreamFilter::FireErrorEvent(const nsAString& aError)
 {
   MOZ_ASSERT(mError.IsEmpty());
 
   mError = aError;
--- a/toolkit/components/satchel/nsFormFillController.cpp
+++ b/toolkit/components/satchel/nsFormFillController.cpp
@@ -658,18 +658,18 @@ nsFormFillController::OnTextEntered(nsID
 
   event->InitEvent(NS_LITERAL_STRING("DOMAutoComplete"), true, true);
 
   // XXXjst: We mark this event as a trusted event, it's up to the
   // callers of this to ensure that it's only called from trusted
   // code.
   event->SetTrusted(true);
 
-  bool defaultActionEnabled;
-  mFocusedInput->DispatchEvent(event, &defaultActionEnabled);
+  bool defaultActionEnabled =
+    mFocusedInput->DispatchEvent(*event, CallerType::System, IgnoreErrors());
   *aPrevent = !defaultActionEnabled;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsFormFillController::OnTextReverted(bool *_retval)
 {
   return NS_OK;
--- a/toolkit/components/windowwatcher/nsAutoWindowStateHelper.cpp
+++ b/toolkit/components/windowwatcher/nsAutoWindowStateHelper.cpp
@@ -63,12 +63,12 @@ nsAutoWindowStateHelper::DispatchEventTo
     rv.SuppressException();
     return false;
   }
   event->InitEvent(NS_ConvertASCIItoUTF16(aEventName), true, true);
   event->SetTrusted(true);
   event->WidgetEventPtr()->mFlags.mOnlyChromeDispatch = true;
 
   nsCOMPtr<EventTarget> target = do_QueryInterface(mWindow);
-  bool defaultActionEnabled;
-  target->DispatchEvent(event, &defaultActionEnabled);
+  bool defaultActionEnabled =
+    target->DispatchEvent(*event, CallerType::System, IgnoreErrors());
   return defaultActionEnabled;
 }
--- a/widget/cocoa/nsMenuItemX.mm
+++ b/widget/cocoa/nsMenuItemX.mm
@@ -189,20 +189,21 @@ nsresult nsMenuItemX::DispatchDOMEvent(c
     return rv.StealNSResult();
   }
   event->InitEvent(eventName, true, true);
 
   // mark DOM event as trusted
   event->SetTrusted(true);
 
   // send DOM event
-  nsresult err = mContent->DispatchEvent(event, preventDefaultCalled);
-  if (NS_FAILED(err)) {
+  *preventDefaultCalled =
+    mContent->DispatchEvent(*event, CallerType::System, rv);
+  if (rv.Failed()) {
     NS_WARNING("Failed to send DOM event via EventTarget");
-    return err;
+    return rv.StealNSResult();
   }
 
   return NS_OK;
 }
 
 // Walk the sibling list looking for nodes with the same name and
 // uncheck them all.
 void nsMenuItemX::UncheckRadioSiblings(nsIContent* inCheckedContent)
--- a/widget/cocoa/nsMenuUtilsX.mm
+++ b/widget/cocoa/nsMenuUtilsX.mm
@@ -36,18 +36,17 @@ void nsMenuUtilsX::DispatchCommandTo(nsI
                             true, true,
                             nsGlobalWindowInner::Cast(doc->GetInnerWindow()),
                             0, false, false, false,
                             false, nullptr, 0, rv);
     // FIXME: Should probably figure out how to init this with the actual
     // pressed keys, but this is a big old edge case anyway. -dwh
     if (!rv.Failed()) {
       event->SetTrusted(true);
-      bool dummy;
-      aTargetContent->DispatchEvent(event, &dummy);
+      aTargetContent->DispatchEvent(*event);
     }
   }
 }
 
 NSString* nsMenuUtilsX::GetTruncatedCocoaLabel(const nsString& itemLabel)
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
 
--- a/xpfe/appshell/nsXULWindow.cpp
+++ b/xpfe/appshell/nsXULWindow.cpp
@@ -236,18 +236,17 @@ NS_IMETHODIMP nsXULWindow::SetZLevel(uin
       RefPtr<dom::Event> event =
         doc->CreateEvent(NS_LITERAL_STRING("Events"), dom::CallerType::System,
                          rv);
       if (event) {
         event->InitEvent(NS_LITERAL_STRING("windowZLevel"), true, false);
 
         event->SetTrusted(true);
 
-        bool defaultActionEnabled;
-        doc->DispatchEvent(event, &defaultActionEnabled);
+        doc->DispatchEvent(*event);
       }
     }
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP nsXULWindow::GetChromeFlags(uint32_t *aChromeFlags)
 {