Stop passing a PassRefPtr to dispatchEvent()
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 12 Nov 2015 07:28:57 +0000 (07:28 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 12 Nov 2015 07:28:57 +0000 (07:28 +0000)
https://bugs.webkit.org/show_bug.cgi?id=151158

Reviewed by Alex Christensen.

Stop passing a PassRefPtr to dispatchEvent() because:
1. PassRefPtr is legacy and should no longer be used
2. We don't actually transfer ownership of the Event to the callee

Pass a C++ reference instead.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@192354 268f45cc-cd09-0410-ab3c-d52691b4dbfc

86 files changed:
Source/WebCore/ChangeLog
Source/WebCore/Modules/battery/BatteryController.cpp
Source/WebCore/Modules/battery/BatteryManager.cpp
Source/WebCore/Modules/battery/BatteryManager.h
Source/WebCore/Modules/indexeddb/IDBEventDispatcher.cpp
Source/WebCore/Modules/indexeddb/IDBEventDispatcher.h
Source/WebCore/Modules/indexeddb/client/IDBDatabaseImpl.cpp
Source/WebCore/Modules/indexeddb/client/IDBRequestImpl.cpp
Source/WebCore/Modules/indexeddb/client/IDBRequestImpl.h
Source/WebCore/Modules/indexeddb/client/IDBTransactionImpl.cpp
Source/WebCore/Modules/indexeddb/client/IDBTransactionImpl.h
Source/WebCore/Modules/indexeddb/legacy/LegacyDatabase.cpp
Source/WebCore/Modules/indexeddb/legacy/LegacyDatabase.h
Source/WebCore/Modules/indexeddb/legacy/LegacyOpenDBRequest.cpp
Source/WebCore/Modules/indexeddb/legacy/LegacyOpenDBRequest.h
Source/WebCore/Modules/indexeddb/legacy/LegacyRequest.cpp
Source/WebCore/Modules/indexeddb/legacy/LegacyRequest.h
Source/WebCore/Modules/indexeddb/legacy/LegacyTransaction.cpp
Source/WebCore/Modules/indexeddb/legacy/LegacyTransaction.h
Source/WebCore/Modules/mediastream/MediaStream.cpp
Source/WebCore/Modules/mediastream/MediaStream.h
Source/WebCore/Modules/mediastream/RTCDTMFSender.cpp
Source/WebCore/Modules/mediastream/RTCDTMFSender.h
Source/WebCore/Modules/mediastream/RTCDataChannel.cpp
Source/WebCore/Modules/mediastream/RTCDataChannel.h
Source/WebCore/Modules/mediastream/RTCPeerConnection.cpp
Source/WebCore/Modules/mediastream/RTCPeerConnection.h
Source/WebCore/Modules/plugins/QuickTimePluginReplacement.mm
Source/WebCore/Modules/proximity/DeviceProximityController.cpp
Source/WebCore/Modules/proximity/DeviceProximityController.h
Source/WebCore/Modules/websockets/WebSocket.cpp
Source/WebCore/css/FontLoader.cpp
Source/WebCore/css/FontLoader.h
Source/WebCore/dom/DeviceMotionController.cpp
Source/WebCore/dom/DeviceMotionController.h
Source/WebCore/dom/DeviceOrientationController.cpp
Source/WebCore/dom/DeviceOrientationController.h
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/Document.h
Source/WebCore/dom/DocumentEventQueue.cpp
Source/WebCore/dom/DocumentEventQueue.h
Source/WebCore/dom/Element.cpp
Source/WebCore/dom/Event.cpp
Source/WebCore/dom/Event.h
Source/WebCore/dom/EventDispatcher.cpp
Source/WebCore/dom/EventDispatcher.h
Source/WebCore/dom/EventQueue.h
Source/WebCore/dom/EventTarget.cpp
Source/WebCore/dom/EventTarget.h
Source/WebCore/dom/GenericEventQueue.cpp
Source/WebCore/dom/MessagePort.cpp
Source/WebCore/dom/Node.cpp
Source/WebCore/dom/Node.h
Source/WebCore/dom/ScopedEventQueue.cpp
Source/WebCore/dom/ScopedEventQueue.h
Source/WebCore/dom/ScriptExecutionContext.cpp
Source/WebCore/editing/AlternativeTextController.cpp
Source/WebCore/editing/Editor.cpp
Source/WebCore/editing/ReplaceSelectionCommand.cpp
Source/WebCore/editing/TextInsertionBaseCommand.cpp
Source/WebCore/html/HTMLMediaElement.cpp
Source/WebCore/html/HTMLMediaElement.h
Source/WebCore/html/HTMLTrackElement.cpp
Source/WebCore/html/MediaController.cpp
Source/WebCore/html/MediaController.h
Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp
Source/WebCore/html/parser/HTMLScriptRunner.cpp
Source/WebCore/html/track/TextTrackCue.cpp
Source/WebCore/html/track/TextTrackCue.h
Source/WebCore/loader/FrameLoader.cpp
Source/WebCore/loader/appcache/ApplicationCacheHost.cpp
Source/WebCore/page/DOMWindow.cpp
Source/WebCore/page/DOMWindow.h
Source/WebCore/page/DeviceController.cpp
Source/WebCore/page/DeviceController.h
Source/WebCore/page/DragController.cpp
Source/WebCore/page/EventHandler.cpp
Source/WebCore/page/EventHandler.h
Source/WebCore/page/EventSource.cpp
Source/WebCore/page/EventSource.h
Source/WebCore/page/FrameView.cpp
Source/WebCore/rendering/RenderBlock.cpp
Source/WebCore/workers/WorkerEventQueue.cpp
Source/WebCore/workers/WorkerEventQueue.h
Source/WebCore/xml/XMLHttpRequestProgressEventThrottle.cpp
Source/WebCore/xml/XMLHttpRequestProgressEventThrottle.h

index 4000f92..82b2d31 100644 (file)
@@ -1,5 +1,18 @@
 2015-11-11  Chris Dumez  <cdumez@apple.com>
 
+        Stop passing a PassRefPtr to dispatchEvent()
+        https://bugs.webkit.org/show_bug.cgi?id=151158
+
+        Reviewed by Alex Christensen.
+
+        Stop passing a PassRefPtr to dispatchEvent() because:
+        1. PassRefPtr is legacy and should no longer be used
+        2. We don't actually transfer ownership of the Event to the callee
+
+        Pass a C++ reference instead.
+
+2015-11-11  Chris Dumez  <cdumez@apple.com>
+
         Fix leaks in idbKeyFromInspectorObject()
         https://bugs.webkit.org/show_bug.cgi?id=151179
 
index cf82a35..25215c9 100644 (file)
@@ -84,7 +84,7 @@ void BatteryController::updateBatteryStatus(PassRefPtr<BatteryStatus> batterySta
 
 void BatteryController::didChangeBatteryStatus(const AtomicString& eventType, PassRefPtr<BatteryStatus> batteryStatus)
 {
-    RefPtr<Event> event = Event::create(eventType, false, false);
+    Ref<Event> event = Event::create(eventType, false, false);
     RefPtr<BatteryStatus> battery = batteryStatus;
     for (auto& listener : m_listeners)
         listener->didChangeBatteryStatus(event, battery);
index 3c1ea77..d6d180e 100644 (file)
@@ -77,7 +77,7 @@ double BatteryManager::level()
     return m_batteryStatus ? m_batteryStatus->level() : 1;
 }
 
-void BatteryManager::didChangeBatteryStatus(PassRefPtr<Event> event, PassRefPtr<BatteryStatus> batteryStatus)
+void BatteryManager::didChangeBatteryStatus(Event& event, PassRefPtr<BatteryStatus> batteryStatus)
 {
     updateBatteryStatus(batteryStatus);
     dispatchEvent(event);
index 79a01f9..d4e3d26 100644 (file)
@@ -46,7 +46,7 @@ public:
     double dischargingTime();
     double level();
 
-    void didChangeBatteryStatus(PassRefPtr<Event>, PassRefPtr<BatteryStatus>);
+    void didChangeBatteryStatus(Event&, PassRefPtr<BatteryStatus>);
     void updateBatteryStatus(PassRefPtr<BatteryStatus>);
     void batteryControllerDestroyed() { m_batteryController = nullptr; }
 
index b88ede5..f81f365 100644 (file)
 
 namespace WebCore {
 
-bool IDBEventDispatcher::dispatch(Event* event, Vector<RefPtr<EventTarget>>& eventTargets)
+bool IDBEventDispatcher::dispatch(Event& event, Vector<RefPtr<EventTarget>>& eventTargets)
 {
     size_t size = eventTargets.size();
     ASSERT(size);
 
-    event->setEventPhase(Event::CAPTURING_PHASE);
+    event.setEventPhase(Event::CAPTURING_PHASE);
     for (size_t i = size - 1; i; --i) { // Don't do the first element.
-        event->setCurrentTarget(eventTargets[i].get());
+        event.setCurrentTarget(eventTargets[i].get());
         eventTargets[i]->fireEventListeners(event);
-        if (event->propagationStopped())
+        if (event.propagationStopped())
             goto doneDispatching;
     }
 
-    event->setEventPhase(Event::AT_TARGET);
-    event->setCurrentTarget(eventTargets[0].get());
+    event.setEventPhase(Event::AT_TARGET);
+    event.setCurrentTarget(eventTargets[0].get());
     eventTargets[0]->fireEventListeners(event);
-    if (event->propagationStopped() || !event->bubbles() || event->cancelBubble())
+    if (event.propagationStopped() || !event.bubbles() || event.cancelBubble())
         goto doneDispatching;
 
-    event->setEventPhase(Event::BUBBLING_PHASE);
+    event.setEventPhase(Event::BUBBLING_PHASE);
     for (size_t i = 1; i < size; ++i) { // Don't do the first element.
-        event->setCurrentTarget(eventTargets[i].get());
+        event.setCurrentTarget(eventTargets[i].get());
         eventTargets[i]->fireEventListeners(event);
-        if (event->propagationStopped() || event->cancelBubble())
+        if (event.propagationStopped() || event.cancelBubble())
             goto doneDispatching;
     }
 
@@ -82,9 +82,9 @@ bool IDBEventDispatcher::dispatch(Event* event, Vector<RefPtr<EventTarget>>& eve
     //        event on the window until that has been implemented)." -- Jonas Sicking
 
 doneDispatching:
-    event->setCurrentTarget(nullptr);
-    event->setEventPhase(0);
-    return !event->defaultPrevented();
+    event.setCurrentTarget(nullptr);
+    event.setEventPhase(0);
+    return !event.defaultPrevented();
 }
 
 } // namespace WebCore
index a46393e..ed59597 100644 (file)
@@ -41,7 +41,7 @@ class EventTarget;
 
 class IDBEventDispatcher {
 public:
-    static bool dispatch(Event*, Vector<RefPtr<EventTarget>>&); // The target first and then its ancestors in order of how the event bubbles.
+    static bool dispatch(Event&, Vector<RefPtr<EventTarget>>&); // The target first and then its ancestors in order of how the event bubbles.
 
 private:
     IDBEventDispatcher();
index dbe000f..61b177c 100644 (file)
@@ -331,7 +331,7 @@ void IDBDatabase::fireVersionChangeEvent(uint64_t requestedVersion)
     
     Ref<Event> event = IDBVersionChangeEvent::create(currentVersion, requestedVersion, eventNames().versionchangeEvent);
     event->setTarget(this);
-    scriptExecutionContext()->eventQueue().enqueueEvent(adoptRef(&event.leakRef()));
+    scriptExecutionContext()->eventQueue().enqueueEvent(WTF::move(event));
 }
 
 void IDBDatabase::didCreateIndexInfo(const IDBIndexInfo& info)
index 75b965d..98aead5 100644 (file)
@@ -194,16 +194,14 @@ void IDBRequest::enqueueEvent(Ref<Event>&& event)
         return;
 
     event->setTarget(this);
-    scriptExecutionContext()->eventQueue().enqueueEvent(&event.get());
+    scriptExecutionContext()->eventQueue().enqueueEvent(WTF::move(event));
 }
 
-bool IDBRequest::dispatchEvent(PassRefPtr<Event> prpEvent)
+bool IDBRequest::dispatchEvent(Event& event)
 {
-    LOG(IndexedDB, "IDBRequest::dispatchEvent - %s", prpEvent->type().characters8());
+    LOG(IndexedDB, "IDBRequest::dispatchEvent - %s", event.type().characters8());
 
-    RefPtr<Event> event = prpEvent;
-
-    if (event->type() != eventNames().blockedEvent)
+    if (event.type() != eventNames().blockedEvent)
         m_readyState = IDBRequestReadyState::Done;
 
     Vector<RefPtr<EventTarget>> targets;
@@ -217,7 +215,7 @@ bool IDBRequest::dispatchEvent(PassRefPtr<Event> prpEvent)
     bool dontPreventDefault;
     {
         TransactionActivator activator(m_transaction.get());
-        dontPreventDefault = IDBEventDispatcher::dispatch(event.get(), targets);
+        dontPreventDefault = IDBEventDispatcher::dispatch(event, targets);
     }
 
     m_hasPendingActivity = false;
index a42b17b..290e39c 100644 (file)
@@ -78,7 +78,7 @@ public:
     using RefCounted<IDBRequest>::deref;
 
     void enqueueEvent(Ref<Event>&&);
-    virtual bool dispatchEvent(PassRefPtr<Event>) override final;
+    virtual bool dispatchEvent(Event&) override final;
 
     IDBConnectionToServer& connection() { return m_connection; }
 
index 0dc1c4f..4a47194 100644 (file)
@@ -346,7 +346,7 @@ void IDBTransaction::fireOnAbort()
     enqueueEvent(Event::create(eventNames().abortEvent, true, false));
 }
 
-void IDBTransaction::enqueueEvent(Ref<Event> event)
+void IDBTransaction::enqueueEvent(Ref<Event>&& event)
 {
     ASSERT(m_state != IndexedDB::TransactionState::Finished);
 
@@ -354,22 +354,22 @@ void IDBTransaction::enqueueEvent(Ref<Event> event)
         return;
 
     event->setTarget(this);
-    scriptExecutionContext()->eventQueue().enqueueEvent(&event.get());
+    scriptExecutionContext()->eventQueue().enqueueEvent(WTF::move(event));
 }
 
-bool IDBTransaction::dispatchEvent(PassRefPtr<Event> event)
+bool IDBTransaction::dispatchEvent(Event& event)
 {
     LOG(IndexedDB, "IDBTransaction::dispatchEvent");
 
     ASSERT(scriptExecutionContext());
-    ASSERT(event->target() == this);
-    ASSERT(event->type() == eventNames().completeEvent || event->type() == eventNames().abortEvent);
+    ASSERT(event.target() == this);
+    ASSERT(event.type() == eventNames().completeEvent || event.type() == eventNames().abortEvent);
 
     Vector<RefPtr<EventTarget>> targets;
     targets.append(this);
     targets.append(db());
 
-    return IDBEventDispatcher::dispatch(event.get(), targets);
+    return IDBEventDispatcher::dispatch(event, targets);
 }
 
 Ref<IDBObjectStore> IDBTransaction::createObjectStore(const IDBObjectStoreInfo& info)
index b3d7b3c..0436195 100644 (file)
@@ -71,7 +71,7 @@ public:
     virtual void refEventTarget() override final { ref(); }
     virtual void derefEventTarget() override final { deref(); }
     using EventTarget::dispatchEvent;
-    virtual bool dispatchEvent(PassRefPtr<Event>) override final;
+    virtual bool dispatchEvent(Event&) override final;
 
     virtual const char* activeDOMObjectName() const override final;
     virtual bool canSuspendForPageCache() const override final;
@@ -128,7 +128,7 @@ private:
 
     void fireOnComplete();
     void fireOnAbort();
-    void enqueueEvent(Ref<Event>);
+    void enqueueEvent(Ref<Event>&&);
 
     Ref<IDBRequest> requestIndexRecord(ScriptExecutionContext&, IDBIndex&, IndexedDB::IndexRecordType, const IDBKeyRangeData&);
 
index b014e66..d03f128 100644 (file)
@@ -92,7 +92,7 @@ LegacyDatabase::~LegacyDatabase()
         // connection called setVersion, but the frontend connection is being
         // closed before they could fire.
         for (auto& event : m_enqueuedEvents)
-            context->eventQueue().cancelEvent(*event);
+            context->eventQueue().cancelEvent(event);
     }
 }
 
@@ -321,7 +321,7 @@ void LegacyDatabase::closeConnection()
     // connection called setVersion, but the frontend connection is being
     // closed before they could fire.
     for (auto& event : m_enqueuedEvents) {
-        bool removed = eventQueue.cancelEvent(*event);
+        bool removed = eventQueue.cancelEvent(event);
         ASSERT_UNUSED(removed, removed);
     }
 
@@ -341,25 +341,25 @@ void LegacyDatabase::onVersionChange(uint64_t oldVersion, uint64_t newVersion)
     enqueueEvent(LegacyVersionChangeEvent::create(oldVersion, newVersion, eventNames().versionchangeEvent));
 }
 
-void LegacyDatabase::enqueueEvent(PassRefPtr<Event> event)
+void LegacyDatabase::enqueueEvent(Ref<Event>&& event)
 {
     ASSERT(!m_contextStopped);
     ASSERT(!m_isClosed);
     ASSERT(scriptExecutionContext());
     event->setTarget(this);
-    scriptExecutionContext()->eventQueue().enqueueEvent(event.get());
-    m_enqueuedEvents.append(event);
+    scriptExecutionContext()->eventQueue().enqueueEvent(event.copyRef());
+    m_enqueuedEvents.append(WTF::move(event));
 }
 
-bool LegacyDatabase::dispatchEvent(PassRefPtr<Event> event)
+bool LegacyDatabase::dispatchEvent(Event& event)
 {
     LOG(StorageAPI, "LegacyDatabase::dispatchEvent");
-    ASSERT(event->type() == eventNames().versionchangeEvent);
+    ASSERT(event.type() == eventNames().versionchangeEvent);
     for (size_t i = 0; i < m_enqueuedEvents.size(); ++i) {
-        if (m_enqueuedEvents[i].get() == event.get())
+        if (m_enqueuedEvents[i].ptr() == &event)
             m_enqueuedEvents.remove(i);
     }
-    return EventTarget::dispatchEvent(event.get());
+    return EventTarget::dispatchEvent(event);
 }
 
 int64_t LegacyDatabase::findObjectStoreId(const String& name) const
index 1137e5e..ea1eb5f 100644 (file)
@@ -84,10 +84,10 @@ public:
     bool isClosePending() const { return m_closePending; }
     void forceClose();
     const IDBDatabaseMetadata metadata() const { return m_metadata; }
-    void enqueueEvent(PassRefPtr<Event>);
+    void enqueueEvent(Ref<Event>&&);
 
     using EventTarget::dispatchEvent;
-    virtual bool dispatchEvent(PassRefPtr<Event>) override;
+    virtual bool dispatchEvent(Event&) override;
 
     int64_t findObjectStoreId(const String& name) const;
     bool containsObjectStore(const String& name) const
@@ -130,7 +130,7 @@ private:
 
     // Keep track of the versionchange events waiting to be fired on this
     // database so that we can cancel them if the database closes.
-    Vector<RefPtr<Event>> m_enqueuedEvents;
+    Vector<Ref<Event>> m_enqueuedEvents;
 
     RefPtr<IDBDatabaseCallbacks> m_databaseCallbacks;
 };
index 3290c50..7217bc3 100644 (file)
@@ -138,11 +138,11 @@ bool LegacyOpenDBRequest::shouldEnqueueEvent() const
     return true;
 }
 
-bool LegacyOpenDBRequest::dispatchEvent(PassRefPtr<Event> event)
+bool LegacyOpenDBRequest::dispatchEvent(Event& event)
 {
     // If the connection closed between onUpgradeNeeded and the delivery of the "success" event,
     // an "error" event should be fired instead.
-    if (event->type() == eventNames().successEvent && m_result->type() == IDBAny::Type::IDBDatabase && m_result->legacyDatabase()->isClosePending()) {
+    if (event.type() == eventNames().successEvent && m_result->type() == IDBAny::Type::IDBDatabase && m_result->legacyDatabase()->isClosePending()) {
         m_result = nullptr;
         onError(IDBDatabaseError::create(IDBDatabaseException::AbortError, "The connection was closed."));
         return false;
index 5a593b5..64f66c4 100644 (file)
@@ -48,7 +48,7 @@ public:
 
     // EventTarget
     virtual EventTargetInterface eventTargetInterface() const override final;
-    virtual bool dispatchEvent(PassRefPtr<Event>) override final;
+    virtual bool dispatchEvent(Event&) override final;
 
 protected:
     virtual bool shouldEnqueueEvent() const override;
index a3c2020..2c747a5 100644 (file)
@@ -166,7 +166,7 @@ void LegacyRequest::abort()
 
     EventQueue& eventQueue = scriptExecutionContext()->eventQueue();
     for (auto& event : m_enqueuedEvents) {
-        bool removed = eventQueue.cancelEvent(*event);
+        bool removed = eventQueue.cancelEvent(event);
         ASSERT_UNUSED(removed, removed);
     }
     m_enqueuedEvents.clear();
@@ -262,7 +262,7 @@ void LegacyRequest::onError(PassRefPtr<IDBDatabaseError> error)
     enqueueEvent(Event::create(eventNames().errorEvent, true, true));
 }
 
-static PassRefPtr<Event> createSuccessEvent()
+static Ref<Event> createSuccessEvent()
 {
     return Event::create(eventNames().successEvent, false, false);
 }
@@ -466,7 +466,7 @@ EventTargetInterface LegacyRequest::eventTargetInterface() const
     return IDBRequestEventTargetInterfaceType;
 }
 
-bool LegacyRequest::dispatchEvent(PassRefPtr<Event> event)
+bool LegacyRequest::dispatchEvent(Event& event)
 {
     LOG(StorageAPI, "LegacyRequest::dispatchEvent");
     ASSERT(m_readyState == IDBRequestReadyState::Pending);
@@ -474,16 +474,16 @@ bool LegacyRequest::dispatchEvent(PassRefPtr<Event> event)
     ASSERT(m_hasPendingActivity);
     ASSERT(m_enqueuedEvents.size());
     ASSERT(scriptExecutionContext());
-    ASSERT(event->target() == this);
-    ASSERT_WITH_MESSAGE(m_readyState < IDBRequestReadyState::Done, "When dispatching event %s, m_readyState < DONE(%d), was %d", event->type().string().utf8().data(), static_cast<int>(IDBRequestReadyState::Done), static_cast<int>(m_readyState));
+    ASSERT(event.target() == this);
+    ASSERT_WITH_MESSAGE(m_readyState < IDBRequestReadyState::Done, "When dispatching event %s, m_readyState < DONE(%d), was %d", event.type().string().utf8().data(), static_cast<int>(IDBRequestReadyState::Done), static_cast<int>(m_readyState));
 
     DOMRequestState::Scope scope(m_requestState);
 
-    if (event->type() != eventNames().blockedEvent)
+    if (event.type() != eventNames().blockedEvent)
         m_readyState = IDBRequestReadyState::Done;
 
     for (size_t i = 0; i < m_enqueuedEvents.size(); ++i) {
-        if (m_enqueuedEvents[i].get() == event.get())
+        if (m_enqueuedEvents[i].ptr() == &event)
             m_enqueuedEvents.remove(i);
     }
 
@@ -500,7 +500,7 @@ bool LegacyRequest::dispatchEvent(PassRefPtr<Event> event)
 
     // Cursor properties should not updated until the success event is being dispatched.
     RefPtr<LegacyCursor> cursorToNotify;
-    if (event->type() == eventNames().successEvent) {
+    if (event.type() == eventNames().successEvent) {
         cursorToNotify = getResultCursor();
         if (cursorToNotify) {
             cursorToNotify->setValueReady(requestState(), m_cursorKey.release(), m_cursorPrimaryKey.release(), m_cursorValue);
@@ -508,19 +508,19 @@ bool LegacyRequest::dispatchEvent(PassRefPtr<Event> event)
         }
     }
 
-    if (event->type() == eventNames().upgradeneededEvent) {
+    if (event.type() == eventNames().upgradeneededEvent) {
         ASSERT(!m_didFireUpgradeNeededEvent);
         m_didFireUpgradeNeededEvent = true;
     }
 
     // FIXME: When we allow custom event dispatching, this will probably need to change.
-    ASSERT_WITH_MESSAGE(event->type() == eventNames().successEvent || event->type() == eventNames().errorEvent || event->type() == eventNames().blockedEvent || event->type() == eventNames().upgradeneededEvent, "event type was %s", event->type().string().utf8().data());
-    const bool setTransactionActive = m_transaction && (event->type() == eventNames().successEvent || event->type() == eventNames().upgradeneededEvent || (event->type() == eventNames().errorEvent && m_errorCode != IDBDatabaseException::AbortError));
+    ASSERT_WITH_MESSAGE(event.type() == eventNames().successEvent || event.type() == eventNames().errorEvent || event.type() == eventNames().blockedEvent || event.type() == eventNames().upgradeneededEvent, "event type was %s", event.type().string().utf8().data());
+    const bool setTransactionActive = m_transaction && (event.type() == eventNames().successEvent || event.type() == eventNames().upgradeneededEvent || (event.type() == eventNames().errorEvent && m_errorCode != IDBDatabaseException::AbortError));
 
     if (setTransactionActive)
         m_transaction->setActive(true);
 
-    bool dontPreventDefault = IDBEventDispatcher::dispatch(event.get(), targets);
+    bool dontPreventDefault = IDBEventDispatcher::dispatch(event, targets);
 
     if (m_transaction) {
         if (m_readyState == IDBRequestReadyState::Done)
@@ -528,7 +528,7 @@ bool LegacyRequest::dispatchEvent(PassRefPtr<Event> event)
 
         // Possibly abort the transaction. This must occur after unregistering (so this request
         // doesn't receive a second error) and before deactivating (which might trigger commit).
-        if (event->type() == eventNames().errorEvent && dontPreventDefault && !m_requestAborted) {
+        if (event.type() == eventNames().errorEvent && dontPreventDefault && !m_requestAborted) {
             m_transaction->setError(m_error, m_errorMessage);
             m_transaction->abort(IGNORE_EXCEPTION);
         }
@@ -541,7 +541,7 @@ bool LegacyRequest::dispatchEvent(PassRefPtr<Event> event)
     if (cursorToNotify)
         cursorToNotify->postSuccessHandlerCallback();
 
-    if (m_readyState == IDBRequestReadyState::Done && (!cursorToNotify || m_cursorFinished) && event->type() != eventNames().upgradeneededEvent)
+    if (m_readyState == IDBRequestReadyState::Done && (!cursorToNotify || m_cursorFinished) && event.type() != eventNames().upgradeneededEvent)
         m_hasPendingActivity = false;
 
     return dontPreventDefault;
@@ -565,7 +565,7 @@ void LegacyRequest::transactionDidFinishAndDispatch()
     m_readyState = IDBRequestReadyState::Pending;
 }
 
-void LegacyRequest::enqueueEvent(PassRefPtr<Event> event)
+void LegacyRequest::enqueueEvent(Ref<Event>&& event)
 {
     ASSERT(m_readyState == IDBRequestReadyState::Pending || m_readyState == IDBRequestReadyState::Done);
 
@@ -576,8 +576,8 @@ void LegacyRequest::enqueueEvent(PassRefPtr<Event> event)
 
     event->setTarget(this);
 
-    if (scriptExecutionContext()->eventQueue().enqueueEvent(event.get()))
-        m_enqueuedEvents.append(event);
+    if (scriptExecutionContext()->eventQueue().enqueueEvent(event.copyRef()))
+        m_enqueuedEvents.append(WTF::move(event));
 }
 
 } // namespace WebCore
index 5aefb11..eb1fbae 100644 (file)
@@ -92,7 +92,7 @@ public:
     virtual void uncaughtExceptionInEventHandler() override final;
 
     using EventTarget::dispatchEvent;
-    virtual bool dispatchEvent(PassRefPtr<Event>) override;
+    virtual bool dispatchEvent(Event&) override;
 
     void transactionDidFinishAndDispatch();
 
@@ -108,7 +108,7 @@ public:
 
 protected:
     LegacyRequest(ScriptExecutionContext*, PassRefPtr<LegacyAny> source, IDBDatabaseBackend::TaskType, LegacyTransaction*);
-    void enqueueEvent(PassRefPtr<Event>);
+    void enqueueEvent(Ref<Event>&&);
     virtual bool shouldEnqueueEvent() const;
     void onSuccessInternal(PassRefPtr<SerializedScriptValue>);
     void onSuccessInternal(const Deprecated::ScriptValue&);
@@ -139,7 +139,7 @@ private:
     const IDBDatabaseBackend::TaskType m_taskType;
 
     bool m_hasPendingActivity;
-    Vector<RefPtr<Event>> m_enqueuedEvents;
+    Vector<Ref<Event>> m_enqueuedEvents;
 
     // Only used if the result type will be a cursor.
     IndexedDB::CursorType m_cursorType;
index f0b34a0..ce849fd 100644 (file)
@@ -306,13 +306,13 @@ bool LegacyTransaction::hasPendingActivity() const
     return m_hasPendingActivity && !m_contextStopped;
 }
 
-bool LegacyTransaction::dispatchEvent(PassRefPtr<Event> event)
+bool LegacyTransaction::dispatchEvent(Event& event)
 {
     LOG(StorageAPI, "LegacyTransaction::dispatchEvent");
     ASSERT(m_state != Finished);
     ASSERT(m_hasPendingActivity);
     ASSERT(scriptExecutionContext());
-    ASSERT(event->target() == this);
+    ASSERT(event.target() == this);
     m_state = Finished;
 
     // Break reference cycles.
@@ -328,8 +328,8 @@ bool LegacyTransaction::dispatchEvent(PassRefPtr<Event> event)
     targets.append(db());
 
     // FIXME: When we allow custom event dispatching, this will probably need to change.
-    ASSERT(event->type() == eventNames().completeEvent || event->type() == eventNames().abortEvent);
-    bool returnValue = IDBEventDispatcher::dispatch(event.get(), targets);
+    ASSERT(event.type() == eventNames().completeEvent || event.type() == eventNames().abortEvent);
+    bool returnValue = IDBEventDispatcher::dispatch(event, targets);
     // FIXME: Try to construct a test where |this| outlives openDBRequest and we
     // get a crash.
     if (m_openDBRequest) {
@@ -359,14 +359,14 @@ const char* LegacyTransaction::activeDOMObjectName() const
     return "LegacyTransaction";
 }
 
-void LegacyTransaction::enqueueEvent(PassRefPtr<Event> event)
+void LegacyTransaction::enqueueEvent(Ref<Event>&& event)
 {
     ASSERT_WITH_MESSAGE(m_state != Finished, "A finished transaction tried to enqueue an event of type %s.", event->type().string().utf8().data());
     if (m_contextStopped || !scriptExecutionContext())
         return;
 
     event->setTarget(this);
-    scriptExecutionContext()->eventQueue().enqueueEvent(event);
+    scriptExecutionContext()->eventQueue().enqueueEvent(WTF::move(event));
 }
 
 IDBDatabaseBackend* LegacyTransaction::backendDB() const
index 83b7971..f79dec3 100644 (file)
@@ -96,7 +96,7 @@ public:
     virtual ScriptExecutionContext* scriptExecutionContext() const override final { return ActiveDOMObject::scriptExecutionContext(); }
 
     using EventTarget::dispatchEvent;
-    virtual bool dispatchEvent(PassRefPtr<Event>) override final;
+    virtual bool dispatchEvent(Event&) override final;
 
     // ActiveDOMObject
     virtual bool hasPendingActivity() const override final;
@@ -104,7 +104,7 @@ public:
 private:
     LegacyTransaction(ScriptExecutionContext*, int64_t, const Vector<String>&, IndexedDB::TransactionMode, LegacyDatabase*, LegacyOpenDBRequest*, const IDBDatabaseMetadata&);
 
-    void enqueueEvent(PassRefPtr<Event>);
+    void enqueueEvent(Ref<Event>&&);
     void closeOpenCursors();
 
     void registerOpenCursor(LegacyCursor*);
index c3cc381..044340f 100644 (file)
@@ -299,13 +299,11 @@ void MediaStream::scheduleActiveStateChange()
 
 void MediaStream::activityEventTimerFired()
 {
-    Vector<RefPtr<Event>> events;
+    Vector<Ref<Event>> events;
     events.swap(m_scheduledActivityEvents);
 
     for (auto& event : events)
-        dispatchEvent(event.release());
-
-    events.clear();
+        dispatchEvent(event);
 }
 
 URLRegistry& MediaStream::registry() const
index 31a4618..1a45647 100644 (file)
@@ -128,7 +128,7 @@ private:
     HashMap<String, RefPtr<MediaStreamTrack>> m_trackSet;
 
     Timer m_activityEventTimer;
-    Vector<RefPtr<Event>> m_scheduledActivityEvents;
+    Vector<Ref<Event>> m_scheduledActivityEvents;
 
     Vector<Observer*> m_observers;
 };
index 527b5d1..c9e2cca 100644 (file)
@@ -145,9 +145,9 @@ bool RTCDTMFSender::canSuspendForPageCache() const
     return false;
 }
 
-void RTCDTMFSender::scheduleDispatchEvent(PassRefPtr<Event> event)
+void RTCDTMFSender::scheduleDispatchEvent(Ref<Event>&& event)
 {
-    m_scheduledEvents.append(event);
+    m_scheduledEvents.append(WTF::move(event));
 
     if (!m_scheduledEventTimer.isActive())
         m_scheduledEventTimer.startOneShot(0);
@@ -158,11 +158,11 @@ void RTCDTMFSender::scheduledEventTimerFired()
     if (m_stopped)
         return;
 
-    Vector<RefPtr<Event>> events;
+    Vector<Ref<Event>> events;
     events.swap(m_scheduledEvents);
 
     for (auto& event : events)
-        dispatchEvent(event.release());
+        dispatchEvent(event);
 }
 
 } // namespace WebCore
index 023e827..aa5dda9 100644 (file)
@@ -71,7 +71,7 @@ private:
     const char* activeDOMObjectName() const override;
     bool canSuspendForPageCache() const override;
 
-    void scheduleDispatchEvent(PassRefPtr<Event>);
+    void scheduleDispatchEvent(Ref<Event>&&);
     void scheduledEventTimerFired();
 
     // EventTarget
@@ -90,7 +90,7 @@ private:
     bool m_stopped;
 
     Timer m_scheduledEventTimer;
-    Vector<RefPtr<Event>> m_scheduledEvents;
+    Vector<Ref<Event>> m_scheduledEvents;
 };
 
 } // namespace WebCore
index d7708ca..55f5086 100644 (file)
@@ -304,9 +304,9 @@ void RTCDataChannel::stop()
     m_scriptExecutionContext = nullptr;
 }
 
-void RTCDataChannel::scheduleDispatchEvent(PassRefPtr<Event> event)
+void RTCDataChannel::scheduleDispatchEvent(Ref<Event>&& event)
 {
-    m_scheduledEvents.append(event);
+    m_scheduledEvents.append(WTF::move(event));
 
     if (!m_scheduledEventTimer.isActive())
         m_scheduledEventTimer.startOneShot(0);
@@ -317,11 +317,11 @@ void RTCDataChannel::scheduledEventTimerFired()
     if (m_stopped)
         return;
 
-    Vector<RefPtr<Event>> events;
+    Vector<Ref<Event>> events;
     events.swap(m_scheduledEvents);
 
     for (auto& event : events)
-        dispatchEvent(event.release());
+        dispatchEvent(event);
 }
 
 } // namespace WebCore
index 88e74ae..4a7a5af 100644 (file)
@@ -83,7 +83,7 @@ public:
 private:
     RTCDataChannel(ScriptExecutionContext*, std::unique_ptr<RTCDataChannelHandler>);
 
-    void scheduleDispatchEvent(PassRefPtr<Event>);
+    void scheduleDispatchEvent(Ref<Event>&&);
     void scheduledEventTimerFired();
 
     // EventTarget
@@ -110,7 +110,7 @@ private:
     BinaryType m_binaryType;
 
     Timer m_scheduledEventTimer;
-    Vector<RefPtr<Event>> m_scheduledEvents;
+    Vector<Ref<Event>> m_scheduledEvents;
 };
 
 } // namespace WebCore
index dd4641e..c6af12b 100644 (file)
@@ -725,9 +725,9 @@ void RTCPeerConnection::changeIceConnectionState(IceConnectionState iceConnectio
     }
 }
 
-void RTCPeerConnection::scheduleDispatchEvent(PassRefPtr<Event> event)
+void RTCPeerConnection::scheduleDispatchEvent(Ref<Event>&& event)
 {
-    m_scheduledEvents.append(event);
+    m_scheduledEvents.append(WTF::move(event));
 
     if (!m_scheduledEventTimer.isActive())
         m_scheduledEventTimer.startOneShot(0);
@@ -738,11 +738,11 @@ void RTCPeerConnection::scheduledEventTimerFired()
     if (m_stopped)
         return;
 
-    Vector<RefPtr<Event>> events;
+    Vector<Ref<Event>> events;
     events.swap(m_scheduledEvents);
 
     for (auto& event : events)
-        dispatchEvent(event.release());
+        dispatchEvent(event);
 
     events.clear();
 }
index 52dc793..e754c7b 100644 (file)
@@ -127,7 +127,7 @@ private:
     RTCPeerConnection(ScriptExecutionContext&, PassRefPtr<RTCConfiguration>, ExceptionCode&);
 
     static RefPtr<RTCConfiguration> parseConfiguration(const Dictionary& configuration, ExceptionCode&);
-    void scheduleDispatchEvent(PassRefPtr<Event>);
+    void scheduleDispatchEvent(Ref<Event>&&);
     void scheduledEventTimerFired();
     bool hasLocalStreamWithTrackId(const String& trackId);
 
@@ -159,7 +159,7 @@ private:
     std::unique_ptr<RTCPeerConnectionHandler> m_peerHandler;
 
     Timer m_scheduledEventTimer;
-    Vector<RefPtr<Event>> m_scheduledEvents;
+    Vector<Ref<Event>> m_scheduledEvents;
 
     RefPtr<RTCConfiguration> m_configuration;
 
index e4532c8..6c83edc 100644 (file)
@@ -243,8 +243,8 @@ unsigned long long QuickTimePluginReplacement::movieSize() const
 void QuickTimePluginReplacement::postEvent(const String& eventName)
 {
     Ref<HTMLPlugInElement> protect(*m_parentElement);
-    RefPtr<Event> event = Event::create(eventName, false, true);
-    m_parentElement->dispatchEvent(event.get());
+    Ref<Event> event = Event::create(eventName, false, true);
+    m_parentElement->dispatchEvent(event);
 }
 
 #if PLATFORM(IOS)
index 6078f37..68ea296 100644 (file)
@@ -57,7 +57,7 @@ bool DeviceProximityController::hasLastData()
     return deviceProximityClient()->hasLastData();
 }
 
-PassRefPtr<Event> DeviceProximityController::getLastEvent()
+RefPtr<Event> DeviceProximityController::getLastEvent()
 {
     return DeviceProximityEvent::create(eventNames().webkitdeviceproximityEvent, deviceProximityClient()->value(), deviceProximityClient()->min(), deviceProximityClient()->max());
 }
index 40ddfb7..89cf054 100644 (file)
@@ -43,7 +43,7 @@ public:
     DeviceProximityClient* deviceProximityClient();
 
     virtual bool hasLastData();
-    virtual PassRefPtr<Event> getLastEvent();
+    virtual RefPtr<Event> getLastEvent();
 
     static const char* supplementName();
     static DeviceProximityController* from(Page*);
index 6465840..41eb109 100644 (file)
@@ -648,7 +648,7 @@ void WebSocket::dispatchOrQueueEvent(Ref<Event>&& event)
     if (m_shouldDelayEventFiring)
         m_pendingEvents.append(WTF::move(event));
     else
-        dispatchEvent(WTF::move(event));
+        dispatchEvent(event);
 }
 
 }  // namespace WebCore
index dde133c..c907460 100644 (file)
@@ -166,9 +166,9 @@ bool FontLoader::canSuspendForPageCache() const
     return !m_numLoadingFromCSS && !m_numLoadingFromJS;
 }
 
-void FontLoader::scheduleEvent(PassRefPtr<Event> event)
+void FontLoader::scheduleEvent(Ref<Event>&& event)
 {
-    m_pendingEvents.append(event);
+    m_pendingEvents.append(WTF::move(event));
     if (!m_pendingEventsTimer.isActive())
         m_pendingEventsTimer.startOneShot(0);
 }
@@ -178,17 +178,17 @@ void FontLoader::firePendingEvents()
     if (m_pendingEvents.isEmpty() && !m_loadingDoneEvent && !m_callbacks.isEmpty())
         return;
 
-    Vector<RefPtr<Event>> pendingEvents;
+    Vector<Ref<Event>> pendingEvents;
     m_pendingEvents.swap(pendingEvents);
 
     bool loadingDone = false;
     if (m_loadingDoneEvent) {
-        pendingEvents.append(m_loadingDoneEvent.release());
+        pendingEvents.append(m_loadingDoneEvent.releaseNonNull());
         loadingDone = true;
     }
 
     for (size_t index = 0; index < pendingEvents.size(); ++index)
-        dispatchEvent(pendingEvents[index].release());
+        dispatchEvent(pendingEvents[index]);
 
     if (loadingDone && !m_callbacks.isEmpty()) {
         Vector<RefPtr<VoidCallback>> callbacks;
index dfc501a..3344594 100644 (file)
@@ -99,7 +99,7 @@ private:
     EventTargetData m_eventTargetData;
     unsigned m_numLoadingFromCSS;
     unsigned m_numLoadingFromJS;
-    Vector<RefPtr<Event>> m_pendingEvents;
+    Vector<Ref<Event>> m_pendingEvents;
     Vector<RefPtr<VoidCallback>> m_callbacks;
     RefPtr<Event> m_loadingDoneEvent;
     Timer m_pendingEventsTimer;
index 1151bd1..93092bc 100644 (file)
@@ -72,7 +72,7 @@ bool DeviceMotionController::hasLastData()
     return deviceMotionClient()->lastMotion();
 }
 
-PassRefPtr<Event> DeviceMotionController::getLastEvent()
+RefPtr<Event> DeviceMotionController::getLastEvent()
 {
     return DeviceMotionEvent::create(eventNames().devicemotionEvent, deviceMotionClient()->lastMotion());
 }
index 7d72d51..14dc744 100644 (file)
@@ -52,7 +52,7 @@ public:
     DeviceMotionClient* deviceMotionClient();
 
     virtual bool hasLastData() override;
-    virtual PassRefPtr<Event> getLastEvent() override;
+    virtual RefPtr<Event> getLastEvent() override;
 
     static const char* supplementName();
     static DeviceMotionController* from(Page*);
index ace3b2b..396bf8c 100644 (file)
@@ -79,7 +79,7 @@ bool DeviceOrientationController::hasLastData()
     return deviceOrientationClient()->lastOrientation();
 }
 
-PassRefPtr<Event> DeviceOrientationController::getLastEvent()
+RefPtr<Event> DeviceOrientationController::getLastEvent()
 {
     return DeviceOrientationEvent::create(eventNames().deviceorientationEvent, deviceOrientationClient()->lastOrientation());
 }
index 1183063..b01f8d1 100644 (file)
@@ -53,7 +53,7 @@ public:
     void resumeUpdates();
 #else
     virtual bool hasLastData() override;
-    virtual PassRefPtr<Event> getLastEvent() override;
+    virtual RefPtr<Event> getLastEvent() override;
 #endif
 
     static const char* supplementName();
index 1e493b8..f5fbeb4 100644 (file)
@@ -4050,7 +4050,7 @@ EventListener* Document::getWindowAttributeEventListener(const AtomicString& eve
     return m_domWindow->getAttributeEventListener(eventType);
 }
 
-void Document::dispatchWindowEvent(PassRefPtr<Event> event,  PassRefPtr<EventTarget> target)
+void Document::dispatchWindowEvent(Event& event, EventTarget* target)
 {
     ASSERT_WITH_SECURITY_IMPLICATION(!NoEventDispatchAssertion::isEventDispatchForbidden());
     if (!m_domWindow)
@@ -4068,21 +4068,21 @@ void Document::dispatchWindowLoadEvent()
     m_cachedResourceLoader->documentDidFinishLoadEvent();
 }
 
-void Document::enqueueWindowEvent(PassRefPtr<Event> event)
+void Document::enqueueWindowEvent(Ref<Event>&& event)
 {
     event->setTarget(m_domWindow.get());
-    m_eventQueue.enqueueEvent(event);
+    m_eventQueue.enqueueEvent(WTF::move(event));
 }
 
-void Document::enqueueDocumentEvent(PassRefPtr<Event> event)
+void Document::enqueueDocumentEvent(Ref<Event>&& event)
 {
     event->setTarget(this);
-    m_eventQueue.enqueueEvent(event);
+    m_eventQueue.enqueueEvent(WTF::move(event));
 }
 
-void Document::enqueueOverflowEvent(PassRefPtr<Event> event)
+void Document::enqueueOverflowEvent(Ref<Event>&& event)
 {
-    m_eventQueue.enqueueEvent(event);
+    m_eventQueue.enqueueEvent(WTF::move(event));
 }
 
 RefPtr<Event> Document::createEvent(const String& eventType, ExceptionCode& ec)
@@ -5980,24 +5980,24 @@ void Document::sendWillRevealEdgeEventsIfNeeded(const IntPoint& oldPosition, con
     // Bottom edge.
     if (newPosition.y() >= willRevealBottomNotificationPoint && newPosition.y() > oldPosition.y()
         && willRevealBottomNotificationPoint >= oldPosition.y()) {
-        RefPtr<Event> willRevealEvent = Event::create(eventNames().webkitwillrevealbottomEvent, false, false);
+        Ref<Event> willRevealEvent = Event::create(eventNames().webkitwillrevealbottomEvent, false, false);
         if (!target)
-            enqueueWindowEvent(willRevealEvent.release());
+            enqueueWindowEvent(WTF::move(willRevealEvent));
         else {
             willRevealEvent->setTarget(target);
-            m_eventQueue.enqueueEvent(willRevealEvent.release());
+            m_eventQueue.enqueueEvent(WTF::move(willRevealEvent));
         }
     }
 
     // Top edge.
     if (newPosition.y() <= willRevealTopNotificationPoint && newPosition.y() < oldPosition.y()
         && willRevealTopNotificationPoint <= oldPosition.y()) {
-        RefPtr<Event> willRevealEvent = Event::create(eventNames().webkitwillrevealtopEvent, false, false);
+        Ref<Event> willRevealEvent = Event::create(eventNames().webkitwillrevealtopEvent, false, false);
         if (!target)
-            enqueueWindowEvent(willRevealEvent.release());
+            enqueueWindowEvent(WTF::move(willRevealEvent));
         else {
             willRevealEvent->setTarget(target);
-            m_eventQueue.enqueueEvent(willRevealEvent.release());
+            m_eventQueue.enqueueEvent(WTF::move(willRevealEvent));
         }
     }
 
@@ -6007,24 +6007,24 @@ void Document::sendWillRevealEdgeEventsIfNeeded(const IntPoint& oldPosition, con
     // Right edge.
     if (newPosition.x() >= willRevealRightNotificationPoint && newPosition.x() > oldPosition.x()
         && willRevealRightNotificationPoint >= oldPosition.x()) {
-        RefPtr<Event> willRevealEvent = Event::create(eventNames().webkitwillrevealrightEvent, false, false);
+        Ref<Event> willRevealEvent = Event::create(eventNames().webkitwillrevealrightEvent, false, false);
         if (!target)
-            enqueueWindowEvent(willRevealEvent.release());
+            enqueueWindowEvent(WTF::move(willRevealEvent));
         else {
             willRevealEvent->setTarget(target);
-            m_eventQueue.enqueueEvent(willRevealEvent.release());
+            m_eventQueue.enqueueEvent(WTF::move(willRevealEvent));
         }
     }
 
     // Left edge.
     if (newPosition.x() <= willRevealLeftNotificationPoint && newPosition.x() < oldPosition.x()
         && willRevealLeftNotificationPoint <= oldPosition.x()) {
-        RefPtr<Event> willRevealEvent = Event::create(eventNames().webkitwillrevealleftEvent, false, false);
+        Ref<Event> willRevealEvent = Event::create(eventNames().webkitwillrevealleftEvent, false, false);
         if (!target)
-            enqueueWindowEvent(willRevealEvent.release());
+            enqueueWindowEvent(WTF::move(willRevealEvent));
         else {
             willRevealEvent->setTarget(target);
-            m_eventQueue.enqueueEvent(willRevealEvent.release());
+            m_eventQueue.enqueueEvent(WTF::move(willRevealEvent));
         }
     }
 #else
index 03d0b45..b5ff3d4 100644 (file)
@@ -788,7 +788,7 @@ public:
     void setWindowAttributeEventListener(const AtomicString& eventType, const QualifiedName& attributeName, const AtomicString& value);
     void setWindowAttributeEventListener(const AtomicString& eventType, PassRefPtr<EventListener>);
     EventListener* getWindowAttributeEventListener(const AtomicString& eventType);
-    WEBCORE_EXPORT void dispatchWindowEvent(PassRefPtr<Event>, PassRefPtr<EventTarget> = nullptr);
+    WEBCORE_EXPORT void dispatchWindowEvent(Event&, EventTarget* = nullptr);
     void dispatchWindowLoadEvent();
 
     RefPtr<Event> createEvent(const String& eventType, ExceptionCode&);
@@ -1092,9 +1092,9 @@ public:
     virtual bool isContextThread() const override final;
     virtual bool isJSExecutionForbidden() const override final { return false; }
 
-    void enqueueWindowEvent(PassRefPtr<Event>);
-    void enqueueDocumentEvent(PassRefPtr<Event>);
-    void enqueueOverflowEvent(PassRefPtr<Event>);
+    void enqueueWindowEvent(Ref<Event>&&);
+    void enqueueDocumentEvent(Ref<Event>&&);
+    void enqueueOverflowEvent(Ref<Event>&&);
     void enqueuePageshowEvent(PageshowEventPersistence);
     void enqueueHashchangeEvent(const String& oldURL, const String& newURL);
     void enqueuePopstateEvent(PassRefPtr<SerializedScriptValue> stateObject);
index a7bb5df..8ea5ec0 100644 (file)
@@ -68,15 +68,15 @@ DocumentEventQueue::~DocumentEventQueue()
 {
 }
 
-bool DocumentEventQueue::enqueueEvent(PassRefPtr<Event> event)
+bool DocumentEventQueue::enqueueEvent(Ref<Event>&& event)
 {
     ASSERT(event->target());
-    ASSERT(!m_queuedEvents.contains(event.get()));
+    ASSERT(!m_queuedEvents.contains(event.ptr()));
 
     if (m_isClosed)
         return false;
 
-    m_queuedEvents.add(event);
+    m_queuedEvents.add(event.ptr());
     if (!m_pendingEventTimer->isActive())
         m_pendingEventTimer->startOneShot(0);
     return true;
@@ -99,9 +99,9 @@ void DocumentEventQueue::enqueueOrDispatchScrollEvent(Node& target)
     bool bubbles = target.isDocumentNode();
     bool cancelable = false;
 
-    RefPtr<Event> scrollEvent = Event::create(eventNames().scrollEvent, bubbles, cancelable);
+    Ref<Event> scrollEvent = Event::create(eventNames().scrollEvent, bubbles, cancelable);
     scrollEvent->setTarget(&target);
-    enqueueEvent(scrollEvent.release());
+    enqueueEvent(WTF::move(scrollEvent));
 }
 
 bool DocumentEventQueue::cancelEvent(Event& event)
@@ -146,9 +146,9 @@ void DocumentEventQueue::dispatchEvent(Event& event)
     // Why do we have this special case here instead of a virtual function on EventTarget?
     EventTarget& eventTarget = *event.target();
     if (DOMWindow* window = eventTarget.toDOMWindow())
-        window->dispatchEvent(&event, 0);
+        window->dispatchEvent(event, nullptr);
     else
-        eventTarget.dispatchEvent(&event);
+        eventTarget.dispatchEvent(event);
 }
 
 }
index 9825ed2..7d111d2 100644 (file)
@@ -44,7 +44,7 @@ public:
     explicit DocumentEventQueue(Document&);
     virtual ~DocumentEventQueue();
 
-    virtual bool enqueueEvent(PassRefPtr<Event>) override;
+    virtual bool enqueueEvent(Ref<Event>&&) override;
     virtual bool cancelEvent(Event&) override;
     virtual void close() override;
 
index 98a610f..3d73dea 100644 (file)
@@ -253,7 +253,7 @@ bool Element::dispatchMouseEvent(const PlatformMouseEvent& platformEvent, const
     if (isForceEvent(platformEvent) && !document().hasListenerTypeForEventType(platformEvent.type()))
         return false;
 
-    RefPtr<MouseEvent> mouseEvent = MouseEvent::create(eventType, document().defaultView(), platformEvent, detail, relatedTarget);
+    Ref<MouseEvent> mouseEvent = MouseEvent::create(eventType, document().defaultView(), platformEvent, detail, relatedTarget);
 
     if (mouseEvent->type().isEmpty())
         return true; // Shouldn't happen.
@@ -265,7 +265,7 @@ bool Element::dispatchMouseEvent(const PlatformMouseEvent& platformEvent, const
         // Special case: If it's a double click event, we also send the dblclick event. This is not part
         // of the DOM specs, but is used for compatibility with the ondblclick="" attribute. This is treated
         // as a separate event in other DOM-compliant browsers like Firefox, and so we do the same.
-        RefPtr<MouseEvent> doubleClickEvent = MouseEvent::create();
+        Ref<MouseEvent> doubleClickEvent = MouseEvent::create();
         doubleClickEvent->initMouseEvent(eventNames().dblclickEvent,
             mouseEvent->bubbles(), mouseEvent->cancelable(), mouseEvent->view(), mouseEvent->detail(),
             mouseEvent->screenX(), mouseEvent->screenY(), mouseEvent->clientX(), mouseEvent->clientY(),
@@ -285,7 +285,7 @@ bool Element::dispatchMouseEvent(const PlatformMouseEvent& platformEvent, const
 
 bool Element::dispatchWheelEvent(const PlatformWheelEvent& event)
 {
-    RefPtr<WheelEvent> wheelEvent = WheelEvent::create(event, document().defaultView());
+    Ref<WheelEvent> wheelEvent = WheelEvent::create(event, document().defaultView());
 
     // Events with no deltas are important because they convey platform information about scroll gestures
     // and momentum beginning or ending. However, those events should not be sent to the DOM since some
@@ -300,9 +300,9 @@ bool Element::dispatchWheelEvent(const PlatformWheelEvent& event)
 
 bool Element::dispatchKeyEvent(const PlatformKeyboardEvent& platformEvent)
 {
-    RefPtr<KeyboardEvent> event = KeyboardEvent::create(platformEvent, document().defaultView());
+    Ref<KeyboardEvent> event = KeyboardEvent::create(platformEvent, document().defaultView());
     if (Frame* frame = document().frame()) {
-        if (frame->eventHandler().accessibilityPreventsEventPropogation(event.get()))
+        if (frame->eventHandler().accessibilityPreventsEventPropogation(event))
             event->stopPropagation();
     }
     return EventDispatcher::dispatchEvent(this, event) && !event->defaultHandled();
@@ -2324,7 +2324,7 @@ bool Element::dispatchMouseForceWillBegin()
         return false;
 
     PlatformMouseEvent platformMouseEvent(frame->eventHandler().lastKnownMousePosition(), frame->eventHandler().lastKnownMouseGlobalPosition(), NoButton, PlatformEvent::NoType, 1, false, false, false, false, WTF::currentTime(), ForceAtClick);
-    RefPtr<MouseEvent> mouseForceWillBeginEvent =  MouseEvent::create(eventNames().webkitmouseforcewillbeginEvent, document().defaultView(), platformMouseEvent, 0, nullptr);
+    Ref<MouseEvent> mouseForceWillBeginEvent =  MouseEvent::create(eventNames().webkitmouseforcewillbeginEvent, document().defaultView(), platformMouseEvent, 0, nullptr);
     mouseForceWillBeginEvent->setTarget(this);
     dispatchEvent(mouseForceWillBeginEvent);
 
index 596dd85..5c1e6fe 100644 (file)
@@ -162,12 +162,12 @@ PassRefPtr<Event> Event::cloneFor(HTMLIFrameElement*) const
     return Event::create(type(), bubbles(), cancelable());
 }
 
-void Event::setTarget(PassRefPtr<EventTarget> target)
+void Event::setTarget(RefPtr<EventTarget>&& target)
 {
     if (m_target == target)
         return;
 
-    m_target = target;
+    m_target = WTF::move(target);
     if (m_target)
         receivedTarget();
 }
index 09e778d..0ccce10 100644 (file)
@@ -106,7 +106,7 @@ public:
     void setType(const AtomicString& type) { m_type = type; }
     
     EventTarget* target() const { return m_target.get(); }
-    void setTarget(PassRefPtr<EventTarget>);
+    void setTarget(RefPtr<EventTarget>&&);
 
     EventTarget* currentTarget() const { return m_currentTarget; }
     void setCurrentTarget(EventTarget* currentTarget) { m_currentTarget = currentTarget; }
index 2bdc350..341847f 100644 (file)
@@ -70,9 +70,9 @@ bool WindowEventContext::handleLocalEvents(Event& event)
     if (!m_window)
         return false;
 
-    event.setTarget(m_target.get());
+    event.setTarget(m_target.copyRef());
     event.setCurrentTarget(m_window.get());
-    m_window->fireEventListeners(&event);
+    m_window->fireEventListeners(event);
     return true;
 }
 
@@ -201,10 +201,10 @@ inline EventTarget* eventTargetRespectingTargetRules(Node& referenceNode)
     return &referenceNode;
 }
 
-void EventDispatcher::dispatchScopedEvent(Node& node, PassRefPtr<Event> event)
+void EventDispatcher::dispatchScopedEvent(Node& node, Event& event)
 {
     // We need to set the target here because it can go away by the time we actually fire the event.
-    event->setTarget(eventTargetRespectingTargetRules(node));
+    event.setTarget(eventTargetRespectingTargetRules(node));
     ScopedEventQueue::singleton().enqueueEvent(event);
 }
 
@@ -300,23 +300,19 @@ static void dispatchEventInDOM(Event& event, const EventPath& path, WindowEventC
     }
 }
 
-bool EventDispatcher::dispatchEvent(Node* origin, PassRefPtr<Event> prpEvent)
+bool EventDispatcher::dispatchEvent(Node* origin, Event& event)
 {
     ASSERT_WITH_SECURITY_IMPLICATION(!NoEventDispatchAssertion::isEventDispatchForbidden());
-    if (!prpEvent)
-        return true;
-
     ASSERT(origin);
     RefPtr<Node> node(origin);
-    RefPtr<Event> event(prpEvent);
     RefPtr<FrameView> view = node->document().view();
-    EventPath eventPath(*node, *event);
+    EventPath eventPath(*node, event);
 
-    if (EventTarget* relatedTarget = event->relatedTarget())
+    if (EventTarget* relatedTarget = event.relatedTarget())
         eventPath.setRelatedTarget(*node, *relatedTarget);
 #if ENABLE(TOUCH_EVENTS) && !PLATFORM(IOS)
-    if (is<TouchEvent>(*event)) {
-        if (!eventPath.updateTouchLists(downcast<TouchEvent>(*event)))
+    if (is<TouchEvent>(event)) {
+        if (!eventPath.updateTouchLists(downcast<TouchEvent>(event)))
             return true;
     }
 #endif
@@ -324,8 +320,8 @@ bool EventDispatcher::dispatchEvent(Node* origin, PassRefPtr<Event> prpEvent)
     ChildNodesLazySnapshot::takeChildNodesLazySnapshot();
 
     EventTarget* target = eventTargetRespectingTargetRules(*node);
-    event->setTarget(target);
-    if (!event->target())
+    event.setTarget(target);
+    if (!event.target())
         return true;
 
     ASSERT_WITH_SECURITY_IMPLICATION(!NoEventDispatchAssertion::isEventDispatchForbidden());
@@ -334,30 +330,30 @@ bool EventDispatcher::dispatchEvent(Node* origin, PassRefPtr<Event> prpEvent)
 
     InputElementClickState clickHandlingState;
     if (is<HTMLInputElement>(*node))
-        downcast<HTMLInputElement>(*node).willDispatchEvent(*event, clickHandlingState);
+        downcast<HTMLInputElement>(*node).willDispatchEvent(event, clickHandlingState);
 
-    if (!event->propagationStopped() && !eventPath.isEmpty())
-        dispatchEventInDOM(*event, eventPath, windowEventContext);
+    if (!event.propagationStopped() && !eventPath.isEmpty())
+        dispatchEventInDOM(event, eventPath, windowEventContext);
 
-    event->setTarget(eventTargetRespectingTargetRules(*node));
-    event->setCurrentTarget(nullptr);
-    event->setEventPhase(0);
+    event.setTarget(eventTargetRespectingTargetRules(*node));
+    event.setCurrentTarget(nullptr);
+    event.setEventPhase(0);
 
     if (clickHandlingState.stateful)
-        downcast<HTMLInputElement>(*node).didDispatchClickEvent(*event, clickHandlingState);
+        downcast<HTMLInputElement>(*node).didDispatchClickEvent(event, clickHandlingState);
 
     // Call default event handlers. While the DOM does have a concept of preventing
     // default handling, the detail of which handlers are called is an internal
     // implementation detail and not part of the DOM.
-    if (!event->defaultPrevented() && !event->defaultHandled())
-        callDefaultEventHandlersInTheBubblingOrder(*event, eventPath);
+    if (!event.defaultPrevented() && !event.defaultHandled())
+        callDefaultEventHandlersInTheBubblingOrder(event, eventPath);
 
     // Ensure that after event dispatch, the event's target object is the
     // outermost shadow DOM boundary.
-    event->setTarget(windowEventContext.target());
-    event->setCurrentTarget(nullptr);
+    event.setTarget(windowEventContext.target());
+    event.setCurrentTarget(nullptr);
 
-    return !event->defaultPrevented();
+    return !event.defaultPrevented();
 }
 
 static inline bool shouldEventCrossShadowBoundary(Event& event, ShadowRoot& shadowRoot, EventTarget& target)
index 64040dd..f189d7a 100644 (file)
@@ -38,11 +38,11 @@ class Node;
 
 namespace EventDispatcher {
 
-bool dispatchEvent(Node*, PassRefPtr<Event>);
-void dispatchScopedEvent(Node&, PassRefPtr<Event>);
+bool dispatchEvent(Node*, Event&);
+void dispatchScopedEvent(Node&, Event&);
 void dispatchSimulatedClick(Element*, Event* underlyingEvent, SimulatedClickMouseEventOptions, SimulatedClickVisualOptions);
 
-};
+}
 
 }
 
index e9934c5..ac39ec6 100644 (file)
@@ -36,7 +36,7 @@ class Event;
 class EventQueue {
 public:
     virtual ~EventQueue() { }
-    virtual bool enqueueEvent(PassRefPtr<Event>) = 0;
+    virtual bool enqueueEvent(Ref<Event>&&) = 0;
     virtual bool cancelEvent(Event&) = 0;
     virtual void close() = 0; // Discard accumulated events and all future events. No events will be dispatched after this.
 };
index 762a6a5..ffddea9 100644 (file)
@@ -134,7 +134,7 @@ bool EventTarget::clearAttributeEventListener(const AtomicString& eventType)
     return removeEventListener(eventType, listener, false);
 }
 
-bool EventTarget::dispatchEvent(PassRefPtr<Event> event, ExceptionCode& ec)
+bool EventTarget::dispatchEvent(Event* event, ExceptionCode& ec)
 {
     if (!event) {
         ec = TypeError;
@@ -149,16 +149,19 @@ bool EventTarget::dispatchEvent(PassRefPtr<Event> event, ExceptionCode& ec)
     if (!scriptExecutionContext())
         return false;
 
-    return dispatchEvent(event);
+    return dispatchEvent(*event);
 }
 
-bool EventTarget::dispatchEvent(PassRefPtr<Event> event)
+bool EventTarget::dispatchEvent(Event& event)
 {
-    event->setTarget(this);
-    event->setCurrentTarget(this);
-    event->setEventPhase(Event::AT_TARGET);
-    bool defaultPrevented = fireEventListeners(event.get());
-    event->setEventPhase(0);
+    ASSERT(event.isInitialized());
+    ASSERT(!event.isBeingDispatched());
+
+    event.setTarget(this);
+    event.setCurrentTarget(this);
+    event.setEventPhase(Event::AT_TARGET);
+    bool defaultPrevented = fireEventListeners(event);
+    event.setEventPhase(0);
     return defaultPrevented;
 }
 
@@ -166,30 +169,30 @@ void EventTarget::uncaughtExceptionInEventHandler()
 {
 }
 
-static const AtomicString& legacyType(const Event* event)
+static const AtomicString& legacyType(const Event& event)
 {
-    if (event->type() == eventNames().animationendEvent)
+    if (event.type() == eventNames().animationendEvent)
         return eventNames().webkitAnimationEndEvent;
 
-    if (event->type() == eventNames().animationstartEvent)
+    if (event.type() == eventNames().animationstartEvent)
         return eventNames().webkitAnimationStartEvent;
 
-    if (event->type() == eventNames().animationiterationEvent)
+    if (event.type() == eventNames().animationiterationEvent)
         return eventNames().webkitAnimationIterationEvent;
 
-    if (event->type() == eventNames().transitionendEvent)
+    if (event.type() == eventNames().transitionendEvent)
         return eventNames().webkitTransitionEndEvent;
 
-    if (event->type() == eventNames().wheelEvent)
+    if (event.type() == eventNames().wheelEvent)
         return eventNames().mousewheelEvent;
 
     return emptyAtom;
 }
 
-bool EventTarget::fireEventListeners(Event* event)
+bool EventTarget::fireEventListeners(Event& event)
 {
     ASSERT_WITH_SECURITY_IMPLICATION(!NoEventDispatchAssertion::isEventDispatchForbidden());
-    ASSERT(event && event->isInitialized());
+    ASSERT(event.isInitialized());
 
     EventTargetData* d = eventTargetData();
     if (!d)
@@ -200,21 +203,21 @@ bool EventTarget::fireEventListeners(Event* event)
     if (!legacyTypeName.isEmpty())
         legacyListenersVector = d->eventListenerMap.find(legacyTypeName);
 
-    EventListenerVector* listenersVector = d->eventListenerMap.find(event->type());
+    EventListenerVector* listenersVector = d->eventListenerMap.find(event.type());
 
     if (listenersVector)
         fireEventListeners(event, d, *listenersVector);
     else if (legacyListenersVector) {
-        AtomicString typeName = event->type();
-        event->setType(legacyTypeName);
+        AtomicString typeName = event.type();
+        event.setType(legacyTypeName);
         fireEventListeners(event, d, *legacyListenersVector);
-        event->setType(typeName);
+        event.setType(typeName);
     }
 
-    return !event->defaultPrevented();
+    return !event.defaultPrevented();
 }
         
-void EventTarget::fireEventListeners(Event* event, EventTargetData* d, EventListenerVector& entry)
+void EventTarget::fireEventListeners(Event& event, EventTargetData* d, EventListenerVector& entry)
 {
     Ref<EventTarget> protect(*this);
 
@@ -226,32 +229,32 @@ void EventTarget::fireEventListeners(Event* event, EventTargetData* d, EventList
     size_t size = entry.size();
     if (!d->firingEventIterators)
         d->firingEventIterators = std::make_unique<FiringEventIteratorVector>();
-    d->firingEventIterators->append(FiringEventIterator(event->type(), i, size));
+    d->firingEventIterators->append(FiringEventIterator(event.type(), i, size));
 
     ScriptExecutionContext* context = scriptExecutionContext();
     Document* document = nullptr;
     InspectorInstrumentationCookie willDispatchEventCookie;
     if (is<Document>(context)) {
         document = downcast<Document>(context);
-        willDispatchEventCookie = InspectorInstrumentation::willDispatchEvent(*document, *event, size > 0);
+        willDispatchEventCookie = InspectorInstrumentation::willDispatchEvent(*document, event, size > 0);
     }
 
     for (; i < size; ++i) {
         RegisteredEventListener& registeredListener = entry[i];
-        if (event->eventPhase() == Event::CAPTURING_PHASE && !registeredListener.useCapture)
+        if (event.eventPhase() == Event::CAPTURING_PHASE && !registeredListener.useCapture)
             continue;
-        if (event->eventPhase() == Event::BUBBLING_PHASE && registeredListener.useCapture)
+        if (event.eventPhase() == Event::BUBBLING_PHASE && registeredListener.useCapture)
             continue;
 
         // If stopImmediatePropagation has been called, we just break out immediately, without
         // handling any more events on this target.
-        if (event->immediatePropagationStopped())
+        if (event.immediatePropagationStopped())
             break;
 
-        InspectorInstrumentationCookie cookie = InspectorInstrumentation::willHandleEvent(context, *event);
+        InspectorInstrumentationCookie cookie = InspectorInstrumentation::willHandleEvent(context, event);
         // To match Mozilla, the AT_TARGET phase fires both capturing and bubbling
         // event listeners, even though that violates some versions of the DOM spec.
-        registeredListener.listener->handleEvent(context, event);
+        registeredListener.listener->handleEvent(context, &event);
         InspectorInstrumentation::didHandleEvent(cookie);
     }
     d->firingEventIterators->removeLast();
index 688e6ff..7077774 100644 (file)
@@ -123,8 +123,8 @@ public:
     virtual bool addEventListener(const AtomicString& eventType, RefPtr<EventListener>&&, bool useCapture);
     virtual bool removeEventListener(const AtomicString& eventType, EventListener*, bool useCapture);
     virtual void removeAllEventListeners();
-    virtual bool dispatchEvent(PassRefPtr<Event>);
-    bool dispatchEvent(PassRefPtr<Event>, ExceptionCode&); // DOM API
+    virtual bool dispatchEvent(Event&);
+    bool dispatchEvent(Event*, ExceptionCode&); // DOM API
     virtual void uncaughtExceptionInEventHandler();
 
     // Used for legacy "onEvent" attribute APIs.
@@ -137,7 +137,7 @@ public:
     bool hasCapturingEventListeners(const AtomicString& eventType);
     const EventListenerVector& getEventListeners(const AtomicString& eventType);
 
-    bool fireEventListeners(Event*);
+    bool fireEventListeners(Event&);
     bool isFiringEventListeners();
 
     void visitJSEventListeners(JSC::SlotVisitor&);
@@ -153,7 +153,7 @@ private:
     virtual void refEventTarget() = 0;
     virtual void derefEventTarget() = 0;
     
-    void fireEventListeners(Event*, EventTargetData*, EventListenerVector&);
+    void fireEventListeners(Event&, EventTargetData*, EventListenerVector&);
 
     friend class EventListenerIterator;
 };
index 72dd0fe..dba8527 100644 (file)
@@ -100,7 +100,7 @@ void GenericEventQueue::dispatchOneEvent()
     Ref<EventTarget> protect(m_owner);
     RefPtr<Event> event = m_pendingEvents.takeFirst();
     EventTarget& target = event->target() ? *event->target() : m_owner;
-    target.dispatchEvent(event.release());
+    target.dispatchEvent(*event);
 }
 
 void GenericEventQueue::close()
index c325684..a3ab896 100644 (file)
@@ -160,9 +160,8 @@ void MessagePort::dispatchMessages()
             return;
 
         std::unique_ptr<MessagePortArray> ports = MessagePort::entanglePorts(*m_scriptExecutionContext, WTF::move(channels));
-        RefPtr<Event> evt = MessageEvent::create(WTF::move(ports), message.release());
-
-        dispatchEvent(evt.release(), ASSERT_NO_EXCEPTION);
+        Ref<Event> event = MessageEvent::create(WTF::move(ports), message.release());
+        dispatchEvent(event);
     }
 }
 
index 387caeb..08fa024 100644 (file)
@@ -2090,19 +2090,19 @@ void Node::handleLocalEvents(Event& event)
     if (is<Element>(*this) && downcast<Element>(*this).isDisabledFormControl() && event.isMouseEvent())
         return;
 
-    fireEventListeners(&event);
+    fireEventListeners(event);
 }
 
-void Node::dispatchScopedEvent(PassRefPtr<Event> event)
+void Node::dispatchScopedEvent(Event& event)
 {
     EventDispatcher::dispatchScopedEvent(*this, event);
 }
 
-bool Node::dispatchEvent(PassRefPtr<Event> event)
+bool Node::dispatchEvent(Event& event)
 {
 #if ENABLE(TOUCH_EVENTS) && !PLATFORM(IOS)
-    if (is<TouchEvent>(*event))
-        return dispatchTouchEvent(adoptRef(downcast<TouchEvent>(event.leakRef())));
+    if (is<TouchEvent>(event))
+        return dispatchTouchEvent(downcast<TouchEvent>(event));
 #endif
     return EventDispatcher::dispatchEvent(this, event);
 }
@@ -2126,24 +2126,24 @@ void Node::dispatchSubtreeModifiedEvent()
 bool Node::dispatchDOMActivateEvent(int detail, PassRefPtr<Event> underlyingEvent)
 {
     ASSERT_WITH_SECURITY_IMPLICATION(!NoEventDispatchAssertion::isEventDispatchForbidden());
-    RefPtr<UIEvent> event = UIEvent::create(eventNames().DOMActivateEvent, true, true, document().defaultView(), detail);
+    Ref<UIEvent> event = UIEvent::create(eventNames().DOMActivateEvent, true, true, document().defaultView(), detail);
     event->setUnderlyingEvent(underlyingEvent);
     dispatchScopedEvent(event);
     return event->defaultHandled();
 }
 
 #if ENABLE(TOUCH_EVENTS) && !PLATFORM(IOS)
-bool Node::dispatchTouchEvent(PassRefPtr<TouchEvent> event)
+bool Node::dispatchTouchEvent(TouchEvent& event)
 {
     return EventDispatcher::dispatchEvent(this, event);
 }
 #endif
 
 #if ENABLE(INDIE_UI)
-bool Node::dispatchUIRequestEvent(PassRefPtr<UIRequestEvent> event)
+bool Node::dispatchUIRequestEvent(UIRequestEvent& event)
 {
     EventDispatcher::dispatchEvent(this, event);
-    return event->defaultHandled() || event->defaultPrevented();
+    return event.defaultHandled() || event.defaultPrevented();
 }
 #endif
     
@@ -2153,8 +2153,8 @@ bool Node::dispatchBeforeLoadEvent(const String& sourceURL)
         return true;
 
     Ref<Node> protect(*this);
-    RefPtr<BeforeLoadEvent> beforeLoadEvent = BeforeLoadEvent::create(sourceURL);
-    dispatchEvent(beforeLoadEvent.get());
+    Ref<BeforeLoadEvent> beforeLoadEvent = BeforeLoadEvent::create(sourceURL);
+    dispatchEvent(beforeLoadEvent);
     return !beforeLoadEvent->defaultPrevented();
 }
 
index eff086a..7b58f4f 100644 (file)
@@ -519,9 +519,9 @@ public:
     virtual bool removeEventListener(const AtomicString& eventType, EventListener*, bool useCapture) override;
 
     using EventTarget::dispatchEvent;
-    virtual bool dispatchEvent(PassRefPtr<Event>) override;
+    virtual bool dispatchEvent(Event&) override;
 
-    void dispatchScopedEvent(PassRefPtr<Event>);
+    void dispatchScopedEvent(Event&);
 
     virtual void handleLocalEvents(Event&);
 
@@ -533,10 +533,10 @@ public:
 #endif
 
 #if ENABLE(TOUCH_EVENTS) && !PLATFORM(IOS)
-    bool dispatchTouchEvent(PassRefPtr<TouchEvent>);
+    bool dispatchTouchEvent(TouchEvent&);
 #endif
 #if ENABLE(INDIE_UI)
-    bool dispatchUIRequestEvent(PassRefPtr<UIRequestEvent>);
+    bool dispatchUIRequestEvent(UIRequestEvent&);
 #endif
 
     bool dispatchBeforeLoadEvent(const String& sourceURL);
index 20f18cd..9350132 100644 (file)
@@ -43,27 +43,27 @@ ScopedEventQueue& ScopedEventQueue::singleton()
     return scopedEventQueue;
 }
 
-void ScopedEventQueue::enqueueEvent(PassRefPtr<Event> event)
+void ScopedEventQueue::enqueueEvent(Ref<Event>&& event)
 {
     if (m_scopingLevel)
-        m_queuedEvents.append(event);
+        m_queuedEvents.append(WTF::move(event));
     else
         dispatchEvent(event);
 }
 
-void ScopedEventQueue::dispatchEvent(PassRefPtr<Event> event) const
+void ScopedEventQueue::dispatchEvent(Event& event) const
 {
-    ASSERT(event->target());
+    ASSERT(event.target());
     // Store the target in a local variable to avoid possibly dereferencing a nullified PassRefPtr after it's passed on.
-    Node* node = event->target()->toNode();
+    Node* node = event.target()->toNode();
     EventDispatcher::dispatchEvent(node, event);
 }
 
 void ScopedEventQueue::dispatchAllEvents()
 {
-    Vector<RefPtr<Event>> queuedEvents = WTF::move(m_queuedEvents);
+    Vector<Ref<Event>> queuedEvents = WTF::move(m_queuedEvents);
     for (auto& queuedEvent : queuedEvents)
-        dispatchEvent(queuedEvent.release());
+        dispatchEvent(queuedEvent);
 }
 
 void ScopedEventQueue::incrementScopingLevel()
index cf6b29c..78bbc65 100644 (file)
@@ -46,18 +46,18 @@ class ScopedEventQueue {
     WTF_MAKE_NONCOPYABLE(ScopedEventQueue); WTF_MAKE_FAST_ALLOCATED;
 public:
     static ScopedEventQueue& singleton();
-    void enqueueEvent(PassRefPtr<Event>);
+    void enqueueEvent(Ref<Event>&&);
 
 private:
     ScopedEventQueue() = default;
     ~ScopedEventQueue() = delete;
 
-    void dispatchEvent(PassRefPtr<Event>) const;
+    void dispatchEvent(Event&) const;
     void dispatchAllEvents();
     void incrementScopingLevel();
     void decrementScopingLevel();
 
-    Vector<RefPtr<Event>> m_queuedEvents;
+    Vector<Ref<Event>> m_queuedEvents;
     unsigned m_scopingLevel { 0 };
 
     friend class WTF::NeverDestroyed<WebCore::ScopedEventQueue>;
index 42f5e79..f052d86 100644 (file)
@@ -404,7 +404,7 @@ bool ScriptExecutionContext::dispatchErrorEvent(const String& errorMessage, int
 
     ASSERT(!m_inDispatchErrorEvent);
     m_inDispatchErrorEvent = true;
-    RefPtr<ErrorEvent> errorEvent = ErrorEvent::create(message, sourceName, line, column);
+    Ref<ErrorEvent> errorEvent = ErrorEvent::create(message, sourceName, line, column);
     target->dispatchEvent(errorEvent);
     m_inDispatchErrorEvent = false;
     return errorEvent->defaultPrevented();
index 6893770..b71f973 100644 (file)
@@ -682,10 +682,10 @@ bool AlternativeTextController::insertDictatedText(const String& text, const Vec
     if (FrameView* view = m_frame.view())
         view->disableLayerFlushThrottlingTemporarilyForInteraction();
 
-    RefPtr<TextEvent> event = TextEvent::createForDictation(m_frame.document()->domWindow(), text, dictationAlternatives);
+    Ref<TextEvent> event = TextEvent::createForDictation(m_frame.document()->domWindow(), text, dictationAlternatives);
     event->setUnderlyingEvent(triggeringEvent);
 
-    target->dispatchEvent(event, IGNORE_EXCEPTION);
+    target->dispatchEvent(event);
     return event->defaultHandled();
 }
 
index af5286d..cf1be2a 100644 (file)
@@ -461,7 +461,7 @@ void Editor::pasteAsPlainText(const String& pastingText, bool smartReplace)
     Node* target = findEventTargetFromSelection();
     if (!target)
         return;
-    target->dispatchEvent(TextEvent::createForPlainTextPaste(document().domWindow(), pastingText, smartReplace), IGNORE_EXCEPTION);
+    target->dispatchEvent(TextEvent::createForPlainTextPaste(document().domWindow(), pastingText, smartReplace));
 }
 
 void Editor::pasteAsFragment(PassRefPtr<DocumentFragment> pastingFragment, bool smartReplace, bool matchStyle, MailBlockquoteHandling respectsMailBlockquote)
@@ -469,7 +469,7 @@ void Editor::pasteAsFragment(PassRefPtr<DocumentFragment> pastingFragment, bool
     Node* target = findEventTargetFromSelection();
     if (!target)
         return;
-    target->dispatchEvent(TextEvent::createForFragmentPaste(document().domWindow(), pastingFragment, smartReplace, matchStyle, respectsMailBlockquote), IGNORE_EXCEPTION);
+    target->dispatchEvent(TextEvent::createForFragmentPaste(document().domWindow(), pastingFragment, smartReplace, matchStyle, respectsMailBlockquote));
 }
 
 void Editor::pasteAsPlainTextBypassingDHTML()
@@ -851,8 +851,8 @@ bool Editor::dispatchCPPEvent(const AtomicString& eventType, DataTransferAccessP
 
     RefPtr<DataTransfer> dataTransfer = DataTransfer::createForCopyAndPaste(policy);
 
-    RefPtr<Event> event = ClipboardEvent::create(eventType, true, true, dataTransfer);
-    target->dispatchEvent(event, IGNORE_EXCEPTION);
+    Ref<Event> event = ClipboardEvent::create(eventType, true, true, dataTransfer);
+    target->dispatchEvent(event);
     bool noDefaultProcessing = event->defaultPrevented();
     if (noDefaultProcessing && policy == DataTransferAccessPolicy::Writable) {
         auto pasteboard = Pasteboard::createForCopyAndPaste();
@@ -1012,9 +1012,9 @@ static void dispatchEditableContentChangedEvents(PassRefPtr<Element> prpStartRoo
     RefPtr<Element> startRoot = prpStartRoot;
     RefPtr<Element> endRoot = prpEndRoot;
     if (startRoot)
-        startRoot->dispatchEvent(Event::create(eventNames().webkitEditableContentChangedEvent, false, false), IGNORE_EXCEPTION);
+        startRoot->dispatchEvent(Event::create(eventNames().webkitEditableContentChangedEvent, false, false));
     if (endRoot && endRoot != startRoot)
-        endRoot->dispatchEvent(Event::create(eventNames().webkitEditableContentChangedEvent, false, false), IGNORE_EXCEPTION);
+        endRoot->dispatchEvent(Event::create(eventNames().webkitEditableContentChangedEvent, false, false));
 }
 
 void Editor::appliedEditing(PassRefPtr<CompositeEditCommand> cmd)
@@ -1720,8 +1720,8 @@ void Editor::setComposition(const String& text, SetCompositionMode mode)
     // We should send this event before sending a TextEvent as written in Section 6.2.2 and 6.2.3 of
     // the DOM Event specification.
     if (Element* target = document().focusedElement()) {
-        RefPtr<CompositionEvent> event = CompositionEvent::create(eventNames().compositionendEvent, document().domWindow(), text);
-        target->dispatchEvent(event.release(), IGNORE_EXCEPTION);
+        Ref<CompositionEvent> event = CompositionEvent::create(eventNames().compositionendEvent, document().domWindow(), text);
+        target->dispatchEvent(event);
     }
 
     // If text is empty, then delete the old composition here.  If text is non-empty, InsertTextCommand::input
@@ -1795,8 +1795,8 @@ void Editor::setComposition(const String& text, const Vector<CompositionUnderlin
             else
                 event = CompositionEvent::create(eventNames().compositionendEvent, document().domWindow(), text);
         }
-        if (event.get())
-            target->dispatchEvent(event, IGNORE_EXCEPTION);
+        if (event)
+            target->dispatchEvent(*event);
     }
 
     // If text is empty, then delete the old composition here.  If text is non-empty, InsertTextCommand::input
index 5b68f57..78972c7 100644 (file)
@@ -182,16 +182,16 @@ ReplacementFragment::ReplacementFragment(Document& document, DocumentFragment* f
     restoreAndRemoveTestRenderingNodesToFragment(holder.get());
 
     // Give the root a chance to change the text.
-    RefPtr<BeforeTextInsertedEvent> evt = BeforeTextInsertedEvent::create(text);
-    editableRoot->dispatchEvent(evt, ASSERT_NO_EXCEPTION);
-    if (text != evt->text() || !editableRoot->hasRichlyEditableStyle()) {
+    Ref<BeforeTextInsertedEvent> event = BeforeTextInsertedEvent::create(text);
+    editableRoot->dispatchEvent(event);
+    if (text != event->text() || !editableRoot->hasRichlyEditableStyle()) {
         restoreAndRemoveTestRenderingNodesToFragment(holder.get());
 
         RefPtr<Range> range = selection.toNormalizedRange();
         if (!range)
             return;
 
-        m_fragment = createFragmentFromText(*range, evt->text());
+        m_fragment = createFragmentFromText(*range, event->text());
         if (!m_fragment->firstChild())
             return;
 
index fd7219d..ccc3dde 100644 (file)
@@ -63,9 +63,9 @@ String dispatchBeforeTextInsertedEvent(const String& text, const VisibleSelectio
     if (Node* startNode = selectionForInsertion.start().containerNode()) {
         if (startNode->rootEditableElement()) {
             // Send BeforeTextInsertedEvent. The event handler will update text if necessary.
-            RefPtr<BeforeTextInsertedEvent> evt = BeforeTextInsertedEvent::create(text);
-            startNode->rootEditableElement()->dispatchEvent(evt, IGNORE_EXCEPTION);
-            newText = evt->text();
+            Ref<BeforeTextInsertedEvent> event = BeforeTextInsertedEvent::create(text);
+            startNode->rootEditableElement()->dispatchEvent(event);
+            newText = event->text();
         }
     }
     return newText;
@@ -77,8 +77,8 @@ bool canAppendNewLineFeedToSelection(const VisibleSelection& selection)
     if (!node)
         return false;
     
-    RefPtr<BeforeTextInsertedEvent> event = BeforeTextInsertedEvent::create(String("\n"));
-    node->dispatchEvent(event, IGNORE_EXCEPTION);
+    Ref<BeforeTextInsertedEvent> event = BeforeTextInsertedEvent::create(String("\n"));
+    node->dispatchEvent(event);
     return event->text().length();
 }
 
index 957a97e..0ad61f3 100644 (file)
@@ -5120,10 +5120,9 @@ void HTMLMediaElement::mediaPlayerCurrentPlaybackTargetIsWirelessChanged(MediaPl
     updateMediaState(UpdateMediaState::Asynchronously);
 }
 
-bool HTMLMediaElement::dispatchEvent(PassRefPtr<Event> prpEvent)
+bool HTMLMediaElement::dispatchEvent(Event& event)
 {
-    RefPtr<Event> event = prpEvent;
-    if (event->type() == eventNames().webkitcurrentplaybacktargetiswirelesschangedEvent)
+    if (event.type() == eventNames().webkitcurrentplaybacktargetiswirelesschangedEvent)
         scheduleDelayedAction(CheckPlaybackTargetCompatablity);
     return HTMLElement::dispatchEvent(event);
 }
index 050acb4..a03f2c4 100644 (file)
@@ -564,7 +564,7 @@ private:
     void enqueuePlaybackTargetAvailabilityChangedEvent();
 
     using EventTarget::dispatchEvent;
-    virtual bool dispatchEvent(PassRefPtr<Event>) override;
+    virtual bool dispatchEvent(Event&) override;
 #endif
 
 #if ENABLE(MEDIA_SESSION)
index d6b1f9a..b3eb3b8 100644 (file)
@@ -260,7 +260,7 @@ void HTMLTrackElement::didCompleteLoad(LoadStatus status)
 
     if (status == Failure) {
         setReadyState(HTMLTrackElement::TRACK_ERROR);
-        dispatchEvent(Event::create(eventNames().errorEvent, false, false), IGNORE_EXCEPTION);
+        dispatchEvent(Event::create(eventNames().errorEvent, false, false));
         return;
     }
 
@@ -271,7 +271,7 @@ void HTMLTrackElement::didCompleteLoad(LoadStatus status)
 
     //     2. If the file was successfully processed, fire a simple event named load at the 
     //        track element.
-    dispatchEvent(Event::create(eventNames().loadEvent, false, false), IGNORE_EXCEPTION);
+    dispatchEvent(Event::create(eventNames().loadEvent, false, false));
 }
 
 // NOTE: The values in the TextTrack::ReadinessState enum must stay in sync with those in HTMLTrackElement::ReadyState.
index 9637244..dbb02ab 100644 (file)
@@ -544,11 +544,11 @@ void MediaController::scheduleEvent(const AtomicString& eventName)
 
 void MediaController::asyncEventTimerFired()
 {
-    Vector<RefPtr<Event>> pendingEvents;
+    Vector<Ref<Event>> pendingEvents;
 
     m_pendingEvents.swap(pendingEvents);
     for (auto& pendingEvent : pendingEvents)
-        dispatchEvent(pendingEvent.release(), IGNORE_EXCEPTION);
+        dispatchEvent(pendingEvent);
 }
 
 void MediaController::clearPositionTimerFired()
index 7533b48..315eecd 100644 (file)
@@ -145,7 +145,7 @@ private:
     bool m_muted;
     ReadyState m_readyState;
     PlaybackState m_playbackState;
-    Vector<RefPtr<Event>> m_pendingEvents;
+    Vector<Ref<Event>> m_pendingEvents;
     Timer m_asyncEventTimer;
     mutable Timer m_clearPositionTimer;
     String m_mediaGroup;
index 330c950..ed3049d 100644 (file)
@@ -4766,7 +4766,7 @@ void WebGLRenderingContextBase::restoreStatesAfterVertexAttrib0Simulation()
 
 void WebGLRenderingContextBase::dispatchContextLostEvent()
 {
-    RefPtr<WebGLContextEvent> event = WebGLContextEvent::create(eventNames().webglcontextlostEvent, false, true, "");
+    Ref<WebGLContextEvent> event = WebGLContextEvent::create(eventNames().webglcontextlostEvent, false, true, "");
     canvas()->dispatchEvent(event);
     m_restoreAllowed = event->defaultPrevented();
     if (m_contextLostMode == RealLostContext && m_restoreAllowed)
index eea0ec7..edb0627 100644 (file)
@@ -81,7 +81,7 @@ static URL documentURLForScriptExecution(Document* document)
     return document->frame()->document()->url();
 }
 
-inline PassRefPtr<Event> createScriptLoadEvent()
+inline Ref<Event> createScriptLoadEvent()
 {
     return Event::create(eventNames().loadEvent, false, false);
 }
index c2458d2..a6b1dbb 100644 (file)
@@ -190,7 +190,7 @@ void TextTrackCue::invalidateCueIndex()
     m_cueIndex = invalidCueIndex;
 }
 
-bool TextTrackCue::dispatchEvent(PassRefPtr<Event> event)
+bool TextTrackCue::dispatchEvent(Event& event)
 {
     // When a TextTrack's mode is disabled: no cues are active, no events fired.
     if (!track() || track()->mode() == TextTrack::disabledKeyword())
index ec2ab22..64e6fd2 100644 (file)
@@ -79,7 +79,7 @@ public:
     void invalidateCueIndex();
 
     using EventTarget::dispatchEvent;
-    virtual bool dispatchEvent(PassRefPtr<Event>) override;
+    virtual bool dispatchEvent(Event&) override;
 
     bool isActive();
     virtual void setIsActive(bool);
index 784b3a3..1bae4a2 100644 (file)
@@ -2859,7 +2859,7 @@ void FrameLoader::dispatchUnloadEvents(UnloadEventPolicy unloadEventPolicy)
             // https://bugs.webkit.org/show_bug.cgi?id=116770
 
             if (!m_frame.document()->inPageCache()) {
-                RefPtr<Event> unloadEvent(Event::create(eventNames().unloadEvent, false, false));
+                Ref<Event> unloadEvent(Event::create(eventNames().unloadEvent, false, false));
                 // The DocumentLoader (and thus its DocumentLoadTiming) might get destroyed
                 // while dispatching the event, so protect it to prevent writing the end
                 // time into freed memory.
@@ -2905,18 +2905,18 @@ bool FrameLoader::dispatchBeforeUnloadEvent(Chrome& chrome, FrameLoader* frameLo
     if (!document->bodyOrFrameset())
         return true;
     
-    RefPtr<BeforeUnloadEvent> beforeUnloadEvent = BeforeUnloadEvent::create();
+    Ref<BeforeUnloadEvent> beforeUnloadEvent = BeforeUnloadEvent::create();
     m_pageDismissalEventBeingDispatched = PageDismissalType::BeforeUnload;
 
     {
         ForbidPromptsScope forbidPrompts(m_frame.page());
-        domWindow->dispatchEvent(beforeUnloadEvent.get(), domWindow->document());
+        domWindow->dispatchEvent(beforeUnloadEvent, domWindow->document());
     }
 
     m_pageDismissalEventBeingDispatched = PageDismissalType::None;
 
     if (!beforeUnloadEvent->defaultPrevented())
-        document->defaultEventHandler(beforeUnloadEvent.get());
+        document->defaultEventHandler(beforeUnloadEvent.ptr());
     if (beforeUnloadEvent->returnValue().isNull())
         return true;
 
index 9890994..88e7ee2 100644 (file)
@@ -350,7 +350,7 @@ void ApplicationCacheHost::dispatchDOMEvent(EventID id, int total, int done)
             event = ProgressEvent::create(eventType, true, done, total);
         else
             event = Event::create(eventType, false, false);
-        m_domApplicationCache->dispatchEvent(event, ASSERT_NO_EXCEPTION);
+        m_domApplicationCache->dispatchEvent(*event);
     }
 }
 
index 1efaeb4..f89e194 100644 (file)
@@ -156,7 +156,7 @@ public:
     {
     }
 
-    PassRefPtr<MessageEvent> event(ScriptExecutionContext* context)
+    Ref<MessageEvent> event(ScriptExecutionContext* context)
     {
         std::unique_ptr<MessagePortArray> messagePorts = MessagePort::entanglePorts(*context, WTF::move(m_channels));
         return MessageEvent::create(WTF::move(messagePorts), m_message, m_origin, String(), m_source);
@@ -928,7 +928,7 @@ void DOMWindow::postMessageTimerFired(PostMessageTimer& timer)
     dispatchMessageEventWithOriginCheck(timer.targetOrigin(), timer.event(document()), timer.stackTrace());
 }
 
-void DOMWindow::dispatchMessageEventWithOriginCheck(SecurityOrigin* intendedTargetOrigin, PassRefPtr<Event> event, PassRefPtr<ScriptCallStack> stackTrace)
+void DOMWindow::dispatchMessageEventWithOriginCheck(SecurityOrigin* intendedTargetOrigin, Event& event, PassRefPtr<ScriptCallStack> stackTrace)
 {
     if (intendedTargetOrigin) {
         // Check target origin now since the target document may have changed since the timer was scheduled.
@@ -1870,7 +1870,7 @@ bool DOMWindow::removeEventListener(const AtomicString& eventType, EventListener
 
 void DOMWindow::dispatchLoadEvent()
 {
-    RefPtr<Event> loadEvent(Event::create(eventNames().loadEvent, false, false));
+    Ref<Event> loadEvent = Event::create(eventNames().loadEvent, false, false);
     if (m_frame && m_frame->loader().documentLoader() && !m_frame->loader().documentLoader()->timing().loadEventStart()) {
         // The DocumentLoader (and thus its DocumentLoadTiming) might get destroyed while dispatching
         // the event, so protect it to prevent writing the end time into freed memory.
@@ -1892,34 +1892,33 @@ void DOMWindow::dispatchLoadEvent()
     InspectorInstrumentation::loadEventFired(frame());
 }
 
-bool DOMWindow::dispatchEvent(PassRefPtr<Event> prpEvent, PassRefPtr<EventTarget> prpTarget)
+bool DOMWindow::dispatchEvent(Event& event, EventTarget* target)
 {
     Ref<EventTarget> protect(*this);
-    RefPtr<Event> event = prpEvent;
 
     // Pausing a page may trigger pagehide and pageshow events. WebCore also implicitly fires these
     // events when closing a WebView. Here we keep track of the state of the page to prevent duplicate,
     // unbalanced events per the definition of the pageshow event:
     // <http://www.whatwg.org/specs/web-apps/current-work/multipage/history.html#event-pageshow>.
-    if (event->eventInterface() == PageTransitionEventInterfaceType) {
-        if (event->type() == eventNames().pageshowEvent) {
+    if (event.eventInterface() == PageTransitionEventInterfaceType) {
+        if (event.type() == eventNames().pageshowEvent) {
             if (m_lastPageStatus == PageStatusShown)
                 return true; // Event was previously dispatched; do not fire a duplicate event.
             m_lastPageStatus = PageStatusShown;
-        } else if (event->type() == eventNames().pagehideEvent) {
+        } else if (event.type() == eventNames().pagehideEvent) {
             if (m_lastPageStatus == PageStatusHidden)
                 return true; // Event was previously dispatched; do not fire a duplicate event.
             m_lastPageStatus = PageStatusHidden;
         }
     }
 
-    event->setTarget(prpTarget ? prpTarget : this);
-    event->setCurrentTarget(this);
-    event->setEventPhase(Event::AT_TARGET);
+    event.setTarget(target ? target : this);
+    event.setCurrentTarget(this);
+    event.setEventPhase(Event::AT_TARGET);
 
-    InspectorInstrumentationCookie cookie = InspectorInstrumentation::willDispatchEventOnWindow(frame(), *event, *this);
+    InspectorInstrumentationCookie cookie = InspectorInstrumentation::willDispatchEventOnWindow(frame(), event, *this);
 
-    bool result = fireEventListeners(event.get());
+    bool result = fireEventListeners(event);
 
     InspectorInstrumentation::didDispatchEventOnWindow(cookie);
 
index 0d8d953..b5001bc 100644 (file)
@@ -244,7 +244,7 @@ namespace WebCore {
         // Needed for Objective-C bindings (see bug 28774).
         void postMessage(PassRefPtr<SerializedScriptValue> message, MessagePort*, const String& targetOrigin, DOMWindow& source, ExceptionCode&);
         void postMessageTimerFired(PostMessageTimer&);
-        void dispatchMessageEventWithOriginCheck(SecurityOrigin* intendedTargetOrigin, PassRefPtr<Event>, PassRefPtr<Inspector::ScriptCallStack>);
+        void dispatchMessageEventWithOriginCheck(SecurityOrigin* intendedTargetOrigin, Event&, PassRefPtr<Inspector::ScriptCallStack>);
 
         void scrollBy(int x, int y) const;
         void scrollTo(int x, int y) const;
@@ -278,7 +278,7 @@ namespace WebCore {
         virtual void removeAllEventListeners() override;
 
         using EventTarget::dispatchEvent;
-        bool dispatchEvent(PassRefPtr<Event> prpEvent, PassRefPtr<EventTarget> prpTarget);
+        bool dispatchEvent(Event&, EventTarget*);
 
         void dispatchLoadEvent();
 
index 925754e..3c38430 100644 (file)
@@ -71,9 +71,8 @@ void DeviceController::removeAllDeviceEventListeners(DOMWindow* window)
         m_client->stopUpdating();
 }
 
-void DeviceController::dispatchDeviceEvent(PassRefPtr<Event> prpEvent)
+void DeviceController::dispatchDeviceEvent(Event& event)
 {
-    RefPtr<Event> event = prpEvent;
     Vector<RefPtr<DOMWindow>> listenerVector;
     copyToVector(m_listeners, listenerVector);
     for (auto& listener : listenerVector) {
@@ -93,8 +92,10 @@ void DeviceController::fireDeviceEvent()
     m_lastEventListeners.clear();
     for (auto& listener : listenerVector) {
         auto document = listener->document();
-        if (document && !document->activeDOMObjectsAreSuspended() && !document->activeDOMObjectsAreStopped())
-            listener->dispatchEvent(getLastEvent());
+        if (document && !document->activeDOMObjectsAreSuspended() && !document->activeDOMObjectsAreStopped()) {
+            if (auto lastEvent = getLastEvent())
+                listener->dispatchEvent(*lastEvent);
+        }
     }
 }
 
index fdf5d1d..21861f2 100644 (file)
@@ -48,12 +48,12 @@ public:
     void removeDeviceEventListener(DOMWindow*);
     void removeAllDeviceEventListeners(DOMWindow*);
 
-    void dispatchDeviceEvent(PassRefPtr<Event>);
+    void dispatchDeviceEvent(Event&);
     bool isActive() { return !m_listeners.isEmpty(); }
     DeviceClient* client() { return m_client; }
 
     virtual bool hasLastData() { return false; }
-    virtual PassRefPtr<Event> getLastEvent() { return 0; }
+    virtual RefPtr<Event> getLastEvent() { return nullptr; }
 
 protected:
     void fireDeviceEvent();
index 050b628..daa0f98 100644 (file)
@@ -446,7 +446,7 @@ bool DragController::dispatchTextInputEventFor(Frame* innerFrame, DragData& drag
     ASSERT(m_page.dragCaretController().hasCaret());
     String text = m_page.dragCaretController().isContentRichlyEditable() ? emptyString() : dragData.asPlainText();
     Node* target = innerFrame->editor().findEventTargetFrom(m_page.dragCaretController().caretPosition());
-    return target->dispatchEvent(TextEvent::createForDrop(innerFrame->document()->domWindow(), text), IGNORE_EXCEPTION);
+    return target->dispatchEvent(TextEvent::createForDrop(innerFrame->document()->domWindow(), text));
 }
 
 bool DragController::concludeEditDrag(DragData& dragData)
index 670e135..bf8fba7 100644 (file)
@@ -3012,13 +3012,13 @@ bool EventHandler::keyEvent(const PlatformKeyboardEvent& initialKeyEvent)
     PlatformKeyboardEvent keyDownEvent = initialKeyEvent;    
     if (keyDownEvent.type() != PlatformEvent::RawKeyDown)
         keyDownEvent.disambiguateKeyDownEvent(PlatformEvent::RawKeyDown, backwardCompatibilityMode);
-    RefPtr<KeyboardEvent> keydown = KeyboardEvent::create(keyDownEvent, m_frame.document()->defaultView());
+    Ref<KeyboardEvent> keydown = KeyboardEvent::create(keyDownEvent, m_frame.document()->defaultView());
     if (matchedAnAccessKey)
         keydown->setDefaultPrevented(true);
     keydown->setTarget(element);
 
     if (initialKeyEvent.type() == PlatformEvent::RawKeyDown) {
-        element->dispatchEvent(keydown, IGNORE_EXCEPTION);
+        element->dispatchEvent(keydown);
         // If frame changed as a result of keydown dispatch, then return true to avoid sending a subsequent keypress message to the new frame.
         bool changedFocusedFrame = m_frame.page() && &m_frame != &m_frame.page()->focusController().focusedOrMainFrame();
         return keydown->defaultHandled() || keydown->defaultPrevented() || changedFocusedFrame;
@@ -3029,7 +3029,7 @@ bool EventHandler::keyEvent(const PlatformKeyboardEvent& initialKeyEvent)
     // in order to match IE:
     // 1. preventing default handling of keydown and keypress events has no effect on IM input;
     // 2. if an input method handles the event, its keyCode is set to 229 in keydown event.
-    m_frame.editor().handleInputMethodKeydown(keydown.get());
+    m_frame.editor().handleInputMethodKeydown(keydown.ptr());
     
     bool handledByInputMethod = keydown->defaultHandled();
     
@@ -3040,10 +3040,10 @@ bool EventHandler::keyEvent(const PlatformKeyboardEvent& initialKeyEvent)
         keydown->setDefaultHandled();
     }
     
-    if (accessibilityPreventsEventPropogation(keydown.get()))
+    if (accessibilityPreventsEventPropogation(keydown))
         keydown->stopPropagation();
 
-    element->dispatchEvent(keydown, IGNORE_EXCEPTION);
+    element->dispatchEvent(keydown);
     // If frame changed as a result of keydown dispatch, then return early to avoid sending a subsequent keypress message to the new frame.
     bool changedFocusedFrame = m_frame.page() && &m_frame != &m_frame.page()->focusController().focusedOrMainFrame();
     bool keydownResult = keydown->defaultHandled() || keydown->defaultPrevented() || changedFocusedFrame;
@@ -3062,14 +3062,14 @@ bool EventHandler::keyEvent(const PlatformKeyboardEvent& initialKeyEvent)
     keyPressEvent.disambiguateKeyDownEvent(PlatformEvent::Char, backwardCompatibilityMode);
     if (keyPressEvent.text().isEmpty())
         return keydownResult;
-    RefPtr<KeyboardEvent> keypress = KeyboardEvent::create(keyPressEvent, m_frame.document()->defaultView());
+    Ref<KeyboardEvent> keypress = KeyboardEvent::create(keyPressEvent, m_frame.document()->defaultView());
     keypress->setTarget(element);
     if (keydownResult)
         keypress->setDefaultPrevented(true);
 #if PLATFORM(COCOA)
     keypress->keypressCommands() = keydown->keypressCommands();
 #endif
-    element->dispatchEvent(keypress, IGNORE_EXCEPTION);
+    element->dispatchEvent(keypress);
 
     return keydownResult || keypress->defaultPrevented() || keypress->defaultHandled();
 }
@@ -3186,7 +3186,7 @@ void EventHandler::handleKeyboardSelectionMovementForAccessibility(KeyboardEvent
     }
 }
 
-bool EventHandler::accessibilityPreventsEventPropogation(KeyboardEvent* event)
+bool EventHandler::accessibilityPreventsEventPropogation(KeyboardEvent& event)
 {
 #if PLATFORM(COCOA)
     if (!AXObjectCache::accessibilityEnhancedUserInterfaceEnabled())
@@ -3196,9 +3196,9 @@ bool EventHandler::accessibilityPreventsEventPropogation(KeyboardEvent* event)
         return false;
 
     // Check for key events that are relevant to accessibility: tab and arrows keys that change focus
-    if (event->keyIdentifier() == "U+0009")
+    if (event.keyIdentifier() == "U+0009")
         return true;
-    FocusDirection direction = focusDirectionForKey(event->keyIdentifier());
+    FocusDirection direction = focusDirectionForKey(event.keyIdentifier());
     if (direction != FocusDirectionNone)
         return true;
 #else
@@ -3494,10 +3494,10 @@ bool EventHandler::handleTextInputEvent(const String& text, Event* underlyingEve
     if (FrameView* view = m_frame.view())
         view->disableLayerFlushThrottlingTemporarilyForInteraction();
 
-    RefPtr<TextEvent> event = TextEvent::create(m_frame.document()->domWindow(), text, inputType);
+    Ref<TextEvent> event = TextEvent::create(m_frame.document()->domWindow(), text, inputType);
     event->setUnderlyingEvent(underlyingEvent);
 
-    target->dispatchEvent(event, IGNORE_EXCEPTION);
+    target->dispatchEvent(event);
     return event->defaultHandled();
 }
     
@@ -3899,11 +3899,11 @@ bool EventHandler::handleTouchEvent(const PlatformTouchEvent& event)
             RefPtr<TouchList> targetTouches(isTouchCancelEvent ? emptyList : touchesByTarget.get(touchEventTarget));
             ASSERT(targetTouches);
 
-            RefPtr<TouchEvent> touchEvent =
+            Ref<TouchEvent> touchEvent =
                 TouchEvent::create(effectiveTouches.get(), targetTouches.get(), changedTouches[state].m_touches.get(),
                     stateName, touchEventTarget->toNode()->document().defaultView(),
                     0, 0, 0, 0, event.ctrlKey(), event.altKey(), event.shiftKey(), event.metaKey());
-            touchEventTarget->toNode()->dispatchTouchEvent(touchEvent.get());
+            touchEventTarget->toNode()->dispatchTouchEvent(touchEvent);
             swallowedEvent = swallowedEvent || touchEvent->defaultPrevented() || touchEvent->defaultHandled();
         }
     }
index 3d57588..2435da0 100644 (file)
@@ -247,7 +247,7 @@ public:
     WEBCORE_EXPORT bool keyEvent(const PlatformKeyboardEvent&);
     void defaultKeyboardEventHandler(KeyboardEvent*);
 
-    bool accessibilityPreventsEventPropogation(KeyboardEvent*);
+    bool accessibilityPreventsEventPropogation(KeyboardEvent&);
     WEBCORE_EXPORT void handleKeyboardSelectionMovementForAccessibility(KeyboardEvent*);
 
     bool handleTextInputEvent(const String& text, Event* underlyingEvent = nullptr, TextEventInputType = TextEventInputKeyboard);
index 9f90b01..4a10151 100644 (file)
@@ -410,11 +410,11 @@ bool EventSource::canSuspendForPageCache() const
     return false;
 }
 
-PassRefPtr<MessageEvent> EventSource::createMessageEvent()
+Ref<MessageEvent> EventSource::createMessageEvent()
 {
-    RefPtr<MessageEvent> event = MessageEvent::create();
+    Ref<MessageEvent> event = MessageEvent::create();
     event->initMessageEvent(m_eventName.isEmpty() ? eventNames().messageEvent : AtomicString(m_eventName), false, false, SerializedScriptValue::create(String::adopt(m_data)), m_eventStreamOrigin, m_lastEventId, 0, 0);
-    return event.release();
+    return event;
 }
 
 } // namespace WebCore
index e49d68e..1d25458 100644 (file)
@@ -99,7 +99,7 @@ private:
     void abortConnectionAttempt();
     void parseEventStream();
     void parseEventStreamLine(unsigned pos, int fieldLength, int lineLength);
-    PassRefPtr<MessageEvent> createMessageEvent();
+    Ref<MessageEvent> createMessageEvent();
 
     URL m_url;
     bool m_withCredentials;
index 1e7fed7..31ac31e 100644 (file)
@@ -3184,14 +3184,14 @@ void FrameView::sendResizeEventIfNeeded()
     bool isMainFrame = frame().isMainFrame();
     bool canSendResizeEventSynchronously = isMainFrame && !m_shouldAutoSize;
 
-    RefPtr<Event> resizeEvent = Event::create(eventNames().resizeEvent, false, false);
+    Ref<Event> resizeEvent = Event::create(eventNames().resizeEvent, false, false);
     if (canSendResizeEventSynchronously)
-        frame().document()->dispatchWindowEvent(resizeEvent.release());
+        frame().document()->dispatchWindowEvent(resizeEvent);
     else {
         // FIXME: Queueing this event for an unpredictable time in the future seems
         // intrinsically racy. By the time this resize event fires, the frame might
         // be resized again, so we could end up with two resize events for the same size.
-        frame().document()->enqueueWindowEvent(resizeEvent.release());
+        frame().document()->enqueueWindowEvent(WTF::move(resizeEvent));
     }
 
     if (InspectorInstrumentation::hasFrontends() && isMainFrame) {
@@ -3377,11 +3377,11 @@ void FrameView::updateOverflowStatus(bool horizontalOverflow, bool verticalOverf
         m_horizontalOverflow = horizontalOverflow;
         m_verticalOverflow = verticalOverflow;
 
-        RefPtr<OverflowEvent> overflowEvent = OverflowEvent::create(horizontalOverflowChanged, horizontalOverflow,
+        Ref<OverflowEvent> overflowEvent = OverflowEvent::create(horizontalOverflowChanged, horizontalOverflow,
             verticalOverflowChanged, verticalOverflow);
         overflowEvent->setTarget(viewportRenderer->element());
 
-        frame().document()->enqueueOverflowEvent(overflowEvent.release());
+        frame().document()->enqueueOverflowEvent(WTF::move(overflowEvent));
     }
 }
 
index 93c706c..c61cc8b 100644 (file)
@@ -169,9 +169,9 @@ public:
         if (!horizontalLayoutOverflowChanged && !verticalLayoutOverflowChanged)
             return;
 
-        RefPtr<OverflowEvent> overflowEvent = OverflowEvent::create(horizontalLayoutOverflowChanged, hasHorizontalLayoutOverflow, verticalLayoutOverflowChanged, hasVerticalLayoutOverflow);
+        Ref<OverflowEvent> overflowEvent = OverflowEvent::create(horizontalLayoutOverflowChanged, hasHorizontalLayoutOverflow, verticalLayoutOverflowChanged, hasVerticalLayoutOverflow);
         overflowEvent->setTarget(m_block->element());
-        m_block->document().enqueueOverflowEvent(overflowEvent.release());
+        m_block->document().enqueueOverflowEvent(WTF::move(overflowEvent));
     }
 
 private:
index 0721076..7eb58a2 100644 (file)
@@ -49,8 +49,8 @@ WorkerEventQueue::~WorkerEventQueue()
 class WorkerEventQueue::EventDispatcher
 {
 public:
-    EventDispatcher(PassRefPtr<Event> event, WorkerEventQueue& eventQueue)
-        : m_event(event)
+    EventDispatcher(RefPtr<Event>&& event, WorkerEventQueue& eventQueue)
+        : m_event(WTF::move(event))
         , m_eventQueue(eventQueue)
         , m_isCancelled(false)
     {
@@ -67,7 +67,7 @@ public:
         if (m_isCancelled)
             return;
         m_eventQueue.m_eventDispatcherMap.remove(m_event.get());
-        m_event->target()->dispatchEvent(m_event);
+        m_event->target()->dispatchEvent(*m_event);
         m_event = nullptr;
     }
 
@@ -83,13 +83,13 @@ private:
     bool m_isCancelled;
 };
 
-bool WorkerEventQueue::enqueueEvent(PassRefPtr<Event> event)
+bool WorkerEventQueue::enqueueEvent(Ref<Event>&& event)
 {
     if (m_isClosed)
         return false;
 
-    EventDispatcher* eventDispatcherPtr = new EventDispatcher(event.get(), *this);
-    m_eventDispatcherMap.add(event, eventDispatcherPtr);
+    EventDispatcher* eventDispatcherPtr = new EventDispatcher(event.copyRef(), *this);
+    m_eventDispatcherMap.add(event.ptr(), eventDispatcherPtr);
     m_scriptExecutionContext.postTask([eventDispatcherPtr] (ScriptExecutionContext&) {
         std::unique_ptr<EventDispatcher> eventDispatcher(eventDispatcherPtr);
         eventDispatcher->dispatch();
index 9a05756..3dbf33d 100644 (file)
@@ -39,7 +39,7 @@ public:
     explicit WorkerEventQueue(ScriptExecutionContext&);
     virtual ~WorkerEventQueue();
 
-    virtual bool enqueueEvent(PassRefPtr<Event>) override;
+    virtual bool enqueueEvent(Ref<Event>&&) override;
     virtual bool cancelEvent(Event&) override;
     virtual void close() override;
 
index ab1708f..c3e1538 100644 (file)
@@ -81,25 +81,24 @@ void XMLHttpRequestProgressEventThrottle::dispatchThrottledProgressEvent(bool le
     m_hasThrottledProgressEvent = true;
 }
 
-void XMLHttpRequestProgressEventThrottle::dispatchReadyStateChangeEvent(RefPtr<Event>&& event, ProgressEventAction progressEventAction)
+void XMLHttpRequestProgressEventThrottle::dispatchReadyStateChangeEvent(Event& event, ProgressEventAction progressEventAction)
 {
     if (progressEventAction == FlushProgressEvent)
         flushProgressEvent();
 
-    dispatchEvent(WTF::move(event));
+    dispatchEvent(event);
 }
 
-void XMLHttpRequestProgressEventThrottle::dispatchEvent(RefPtr<Event>&& event)
+void XMLHttpRequestProgressEventThrottle::dispatchEvent(Event& event)
 {
-    ASSERT(event);
     if (m_deferEvents) {
-        if (m_deferredEvents.size() > 1 && event->type() == eventNames().readystatechangeEvent && event->type() == m_deferredEvents.last()->type()) {
+        if (m_deferredEvents.size() > 1 && event.type() == eventNames().readystatechangeEvent && event.type() == m_deferredEvents.last()->type()) {
             // Readystatechange events are state-less so avoid repeating two identical events in a row on resume.
             return;
         }
-        m_deferredEvents.append(WTF::move(event));
+        m_deferredEvents.append(event);
     } else
-        m_target->dispatchEvent(WTF::move(event));
+        m_target->dispatchEvent(event);
 }
 
 void XMLHttpRequestProgressEventThrottle::dispatchProgressEvent(const AtomicString& type)
@@ -120,8 +119,7 @@ void XMLHttpRequestProgressEventThrottle::flushProgressEvent()
 {
     if (m_deferEvents && m_deferredProgressEvent) {
         // Move the progress event to the queue, to get it in the right order on resume.
-        m_deferredEvents.append(m_deferredProgressEvent);
-        m_deferredProgressEvent = nullptr;
+        m_deferredEvents.append(m_deferredProgressEvent.releaseNonNull());
         return;
     }
 
@@ -144,16 +142,15 @@ void XMLHttpRequestProgressEventThrottle::dispatchDeferredEvents()
     // Take over the deferred events before dispatching them which can potentially add more.
     auto deferredEvents = WTF::move(m_deferredEvents);
 
-    RefPtr<Event> deferredProgressEvent = m_deferredProgressEvent;
-    m_deferredProgressEvent = nullptr;
+    RefPtr<Event> deferredProgressEvent = WTF::move(m_deferredProgressEvent);
 
     for (auto& deferredEvent : deferredEvents)
-        dispatchEvent(deferredEvent.release());
+        dispatchEvent(deferredEvent);
 
     // The progress event will be in the m_deferredEvents vector if the load was finished while suspended.
     // If not, just send the most up-to-date progress on resume.
     if (deferredProgressEvent)
-        dispatchEvent(WTF::move(deferredProgressEvent));
+        dispatchEvent(*deferredProgressEvent);
 }
 
 void XMLHttpRequestProgressEventThrottle::fired()
index 29f4d65..c1009e5 100644 (file)
@@ -49,7 +49,7 @@ public:
     virtual ~XMLHttpRequestProgressEventThrottle();
 
     void dispatchThrottledProgressEvent(bool lengthComputable, unsigned long long loaded, unsigned long long total);
-    void dispatchReadyStateChangeEvent(RefPtr<Event>&&, ProgressEventAction = DoNotFlushProgressEvent);
+    void dispatchReadyStateChangeEvent(Event&, ProgressEventAction = DoNotFlushProgressEvent);
     void dispatchProgressEvent(const AtomicString&);
 
     void suspend();
@@ -61,7 +61,7 @@ private:
     virtual void fired();
     void dispatchDeferredEvents();
     void flushProgressEvent();
-    void dispatchEvent(RefPtr<Event>&&);
+    void dispatchEvent(Event&);
 
     bool hasEventToDispatch() const;
 
@@ -75,7 +75,7 @@ private:
 
     bool m_deferEvents;
     RefPtr<Event> m_deferredProgressEvent;
-    Vector<RefPtr<Event>> m_deferredEvents;
+    Vector<Ref<Event>> m_deferredEvents;
     Timer m_dispatchDeferredEventsTimer;
 };