Skip to content

Commit

Permalink
Get rid of downcast>() in ScopedEventQueue::enqueueEvent()
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=270371

Reviewed by Ryosuke Niwa.

* Source/WebCore/dom/EventDispatcher.cpp:
(WebCore::EventDispatcher::dispatchScopedEvent):
* Source/WebCore/dom/ScopedEventQueue.cpp:
(WebCore::ScopedEventQueue::enqueueEvent):
* Source/WebCore/dom/ScopedEventQueue.h:

Canonical link: https://commits.webkit.org/275576@main
  • Loading branch information
cdumez committed Mar 1, 2024
1 parent 3c4f36a commit 81d1596
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
6 changes: 4 additions & 2 deletions Source/WebCore/dom/EventDispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ namespace WebCore {
void EventDispatcher::dispatchScopedEvent(Node& node, Event& event)
{
// Need to set the target here so the scoped event queue knows which node to dispatch to.
event.setTarget(RefPtr { EventPath::eventTargetRespectingTargetRules(node) });
ScopedEventQueue::singleton().enqueueEvent(event);
RefPtr target = EventPath::eventTargetRespectingTargetRules(node);
ASSERT(target);
event.setTarget(target.copyRef());
ScopedEventQueue::singleton().enqueueEvent({ event, *target });
}

static void callDefaultEventHandlersInBubblingOrder(Event& event, const EventPath& path)
Expand Down
9 changes: 3 additions & 6 deletions Source/WebCore/dom/ScopedEventQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,12 @@ ScopedEventQueue& ScopedEventQueue::singleton()
return scopedEventQueue;
}

void ScopedEventQueue::enqueueEvent(Ref<Event>&& event)
void ScopedEventQueue::enqueueEvent(ScopedEvent&& event)
{
ASSERT(event->target());
auto& target = downcast<Node>(*event->target());
ScopedEvent scopedEvent = { WTFMove(event), target };
if (m_scopingLevel)
m_queuedEvents.append(WTFMove(scopedEvent));
m_queuedEvents.append(WTFMove(event));
else
dispatchEvent(scopedEvent);
dispatchEvent(event);
}

void ScopedEventQueue::dispatchEvent(const ScopedEvent& event) const
Expand Down
10 changes: 5 additions & 5 deletions Source/WebCore/dom/ScopedEventQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ class ScopedEventQueue {
WTF_MAKE_NONCOPYABLE(ScopedEventQueue); WTF_MAKE_FAST_ALLOCATED;
public:
static ScopedEventQueue& singleton();
void enqueueEvent(Ref<Event>&&);

private:
ScopedEventQueue() = default;
~ScopedEventQueue() = delete;

struct ScopedEvent {
Ref<Event> event;
GCReachableRef<Node> target;
};
void enqueueEvent(ScopedEvent&&);

private:
ScopedEventQueue() = default;
~ScopedEventQueue() = delete;

void dispatchEvent(const ScopedEvent&) const;
void dispatchAllEvents();
Expand Down

0 comments on commit 81d1596

Please sign in to comment.