Changeset 269500 in webkit


Ignore:
Timestamp:
Nov 5, 2020 6:05:47 PM (21 months ago)
Author:
Chris Dumez
Message:

window.event should not be affected by nodes moving post-dispatch
https://bugs.webkit.org/show_bug.cgi?id=218635

Reviewed by Geoffrey Garen.

LayoutTests/imported/w3c:

Rebaseline test now that it is fully passing.

  • web-platform-tests/dom/events/event-global-extra.window-expected.txt:

Source/WebCore:

window.event should not be affected by nodes moving post-dispatch:

In particular, window.event should not get set when the event target was inside
a shadow tree initially when dispatchEvent() got called, even if the event target
gets moved out of the shadow tree during the execution of the event listeners.

Previously, our code was checking if the node was in a shadow tree at the point
of calling each event listener, instead of doing that check very initially when
dispatchEvent() is called.

No new tests, rebaselined existing test.

  • bindings/js/JSEventListener.cpp:

(WebCore::JSEventListener::handleEvent):

  • dom/Event.cpp:

(WebCore::Event::setCurrentTarget):
(WebCore::Event::resetAfterDispatch):

  • dom/Event.h:

(WebCore::Event::currentTargetIsInShadowTree const):

  • dom/EventContext.cpp:

(WebCore::EventContext::handleLocalEvents const):

  • dom/EventContext.h:

(WebCore::EventContext::isCurrentTargetInShadowTree const):

  • dom/EventPath.cpp:

(WebCore::WindowEventContext::handleLocalEvents const):

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r269499 r269500  
     12020-11-05  Chris Dumez  <cdumez@apple.com>
     2
     3        window.event should not be affected by nodes moving post-dispatch
     4        https://bugs.webkit.org/show_bug.cgi?id=218635
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        Rebaseline test now that it is fully passing.
     9
     10        * web-platform-tests/dom/events/event-global-extra.window-expected.txt:
     11
    1122020-11-05  Alex Christensen  <achristensen@webkit.org>
    213
  • trunk/LayoutTests/imported/w3c/web-platform-tests/dom/events/event-global-extra.window-expected.txt

    r269414 r269500  
    44PASS window.event and element from another document
    55PASS window.event and moving an element post-dispatch
    6 FAIL window.event should not be affected by nodes moving post-dispatch assert_equals: expected (undefined) undefined but got (object) object "[object Event]"
     6PASS window.event should not be affected by nodes moving post-dispatch
    77PASS Listener from a different global
    88
  • trunk/Source/WebCore/ChangeLog

    r269499 r269500  
     12020-11-05  Chris Dumez  <cdumez@apple.com>
     2
     3        window.event should not be affected by nodes moving post-dispatch
     4        https://bugs.webkit.org/show_bug.cgi?id=218635
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        window.event should not be affected by nodes moving post-dispatch:
     9        - https://dom.spec.whatwg.org/#concept-event-listener-invoke
     10
     11        In particular, window.event should not get set when the event target was inside
     12        a shadow tree initially when dispatchEvent() got called, even if the event target
     13        gets moved out of the shadow tree during the execution of the event listeners.
     14
     15        Previously, our code was checking if the node was in a shadow tree at the point
     16        of calling each event listener, instead of doing that check very initially when
     17        dispatchEvent() is called.
     18
     19        No new tests, rebaselined existing test.
     20
     21        * bindings/js/JSEventListener.cpp:
     22        (WebCore::JSEventListener::handleEvent):
     23        * dom/Event.cpp:
     24        (WebCore::Event::setCurrentTarget):
     25        (WebCore::Event::resetAfterDispatch):
     26        * dom/Event.h:
     27        (WebCore::Event::currentTargetIsInShadowTree const):
     28        * dom/EventContext.cpp:
     29        (WebCore::EventContext::handleLocalEvents const):
     30        * dom/EventContext.h:
     31        (WebCore::EventContext::isCurrentTargetInShadowTree const):
     32        * dom/EventPath.cpp:
     33        (WebCore::WindowEventContext::handleLocalEvents const):
     34
    1352020-11-05  Alex Christensen  <achristensen@webkit.org>
    236
  • trunk/Source/WebCore/bindings/js/JSEventListener.cpp

    r269414 r269500  
    170170
    171171        // window.event should not be set when the target is inside a shadow tree, as per the DOM specification.
    172         bool isTargetInsideShadowTree = is<Node>(event.currentTarget()) && downcast<Node>(*event.currentTarget()).isInShadowTree();
    173         if (!isTargetInsideShadowTree)
     172        if (!event.currentTargetIsInShadowTree())
    174173            jsFunctionWindow->setCurrentEvent(&event);
    175174    }
  • trunk/Source/WebCore/dom/Event.cpp

    r250060 r269500  
    5151    , m_isTrusted { isTrusted == IsTrusted::Yes }
    5252    , m_isExecutingPassiveEventListener { false }
     53    , m_currentTargetIsInShadowTree { false }
    5354    , m_eventPhase { NONE }
    5455    , m_type { type }
     
    128129}
    129130
    130 void Event::setCurrentTarget(EventTarget* currentTarget)
     131void Event::setCurrentTarget(EventTarget* currentTarget, Optional<bool> isInShadowTree)
    131132{
    132133    m_currentTarget = currentTarget;
     134    m_currentTargetIsInShadowTree = isInShadowTree ? *isInShadowTree : (is<Node>(currentTarget) && downcast<Node>(*currentTarget).isInShadowTree());
    133135}
    134136
     
    172174{
    173175    m_eventPath = nullptr;
    174     m_currentTarget = nullptr;
     176    setCurrentTarget(nullptr);
    175177    m_eventPhase = NONE;
    176178    m_propagationStopped = false;
  • trunk/Source/WebCore/dom/Event.h

    r250060 r269500  
    7171
    7272    EventTarget* currentTarget() const { return m_currentTarget.get(); }
    73     void setCurrentTarget(EventTarget*);
     73    void setCurrentTarget(EventTarget*, Optional<bool> isInShadowTree = WTF::nullopt);
     74    bool currentTargetIsInShadowTree() const { return m_currentTargetIsInShadowTree; }
    7475
    7576    unsigned short eventPhase() const { return m_eventPhase; }
     
    168169    unsigned m_isTrusted : 1;
    169170    unsigned m_isExecutingPassiveEventListener : 1;
     171    unsigned m_currentTargetIsInShadowTree : 1;
    170172
    171173    unsigned m_eventPhase : 2;
  • trunk/Source/WebCore/dom/EventContext.cpp

    r254087 r269500  
    4141    , m_target { target }
    4242    , m_closedShadowDepth { closedShadowDepth }
     43    , m_currentTargetIsInShadowTree { is<Node>(currentTarget) && downcast<Node>(*currentTarget).isInShadowTree() }
    4344{
    4445    ASSERT(!isUnreachableNode(m_target.get()));
     
    5051{
    5152    event.setTarget(m_target.get());
    52     event.setCurrentTarget(m_currentTarget.get());
     53    event.setCurrentTarget(m_currentTarget.get(), m_currentTargetIsInShadowTree);
    5354    // FIXME: Consider merging handleLocalEvents and fireEventListeners.
    5455    if (m_node)
  • trunk/Source/WebCore/dom/EventContext.h

    r254087 r269500  
    4444    Node* node() const { return m_node.get(); }
    4545    EventTarget* currentTarget() const { return m_currentTarget.get(); }
     46    bool isCurrentTargetInShadowTree() const { return m_currentTargetIsInShadowTree; }
    4647    EventTarget* target() const { return m_target.get(); }
    4748    int closedShadowDepth() const { return m_closedShadowDepth; }
     
    6162    RefPtr<EventTarget> m_target;
    6263    int m_closedShadowDepth { 0 };
     64    bool m_currentTargetIsInShadowTree { false };
    6365};
    6466
  • trunk/Source/WebCore/dom/EventPath.cpp

    r261028 r269500  
    5151{
    5252    event.setTarget(m_target.get());
    53     event.setCurrentTarget(m_currentTarget.get());
     53    event.setCurrentTarget(m_currentTarget.get(), m_currentTargetIsInShadowTree);
    5454    m_currentTarget->fireEventListeners(event, phase);
    5555}
Note: See TracChangeset for help on using the changeset viewer.