- Revision
- 269500
- Author
- [email protected]
- Date
- 2020-11-05 18:05:47 -0800 (Thu, 05 Nov 2020)
Log 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:
- https://dom.spec.whatwg.org/#concept-event-listener-invoke
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):
Modified Paths
Diff
Modified: trunk/LayoutTests/imported/w3c/ChangeLog (269499 => 269500)
--- trunk/LayoutTests/imported/w3c/ChangeLog 2020-11-06 02:02:41 UTC (rev 269499)
+++ trunk/LayoutTests/imported/w3c/ChangeLog 2020-11-06 02:05:47 UTC (rev 269500)
@@ -1,3 +1,14 @@
+2020-11-05 Chris Dumez <[email protected]>
+
+ window.event should not be affected by nodes moving post-dispatch
+ https://bugs.webkit.org/show_bug.cgi?id=218635
+
+ Reviewed by Geoffrey Garen.
+
+ Rebaseline test now that it is fully passing.
+
+ * web-platform-tests/dom/events/event-global-extra.window-expected.txt:
+
2020-11-05 Alex Christensen <[email protected]>
Align GBK and gb18030 encoder and decoder with specification and other browsers
Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/dom/events/event-global-extra.window-expected.txt (269499 => 269500)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/dom/events/event-global-extra.window-expected.txt 2020-11-06 02:02:41 UTC (rev 269499)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/dom/events/event-global-extra.window-expected.txt 2020-11-06 02:05:47 UTC (rev 269500)
@@ -3,6 +3,6 @@
PASS window.event for constructors from another global: XMLHttpRequest
PASS window.event and element from another document
PASS window.event and moving an element post-dispatch
-FAIL window.event should not be affected by nodes moving post-dispatch assert_equals: expected (undefined) undefined but got (object) object "[object Event]"
+PASS window.event should not be affected by nodes moving post-dispatch
PASS Listener from a different global
Modified: trunk/Source/WebCore/ChangeLog (269499 => 269500)
--- trunk/Source/WebCore/ChangeLog 2020-11-06 02:02:41 UTC (rev 269499)
+++ trunk/Source/WebCore/ChangeLog 2020-11-06 02:05:47 UTC (rev 269500)
@@ -1,3 +1,37 @@
+2020-11-05 Chris Dumez <[email protected]>
+
+ window.event should not be affected by nodes moving post-dispatch
+ https://bugs.webkit.org/show_bug.cgi?id=218635
+
+ Reviewed by Geoffrey Garen.
+
+ window.event should not be affected by nodes moving post-dispatch:
+ - https://dom.spec.whatwg.org/#concept-event-listener-invoke
+
+ 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):
+
2020-11-05 Alex Christensen <[email protected]>
Align GBK and gb18030 encoder and decoder with specification and other browsers
Modified: trunk/Source/WebCore/bindings/js/JSEventListener.cpp (269499 => 269500)
--- trunk/Source/WebCore/bindings/js/JSEventListener.cpp 2020-11-06 02:02:41 UTC (rev 269499)
+++ trunk/Source/WebCore/bindings/js/JSEventListener.cpp 2020-11-06 02:05:47 UTC (rev 269500)
@@ -169,8 +169,7 @@
savedEvent = jsFunctionWindow->currentEvent();
// window.event should not be set when the target is inside a shadow tree, as per the DOM specification.
- bool isTargetInsideShadowTree = is<Node>(event.currentTarget()) && downcast<Node>(*event.currentTarget()).isInShadowTree();
- if (!isTargetInsideShadowTree)
+ if (!event.currentTargetIsInShadowTree())
jsFunctionWindow->setCurrentEvent(&event);
}
Modified: trunk/Source/WebCore/dom/Event.cpp (269499 => 269500)
--- trunk/Source/WebCore/dom/Event.cpp 2020-11-06 02:02:41 UTC (rev 269499)
+++ trunk/Source/WebCore/dom/Event.cpp 2020-11-06 02:05:47 UTC (rev 269500)
@@ -50,6 +50,7 @@
, m_isDefaultEventHandlerIgnored { false }
, m_isTrusted { isTrusted == IsTrusted::Yes }
, m_isExecutingPassiveEventListener { false }
+ , m_currentTargetIsInShadowTree { false }
, m_eventPhase { NONE }
, m_type { type }
, m_createTime { createTime }
@@ -127,9 +128,10 @@
receivedTarget();
}
-void Event::setCurrentTarget(EventTarget* currentTarget)
+void Event::setCurrentTarget(EventTarget* currentTarget, Optional<bool> isInShadowTree)
{
m_currentTarget = currentTarget;
+ m_currentTargetIsInShadowTree = isInShadowTree ? *isInShadowTree : (is<Node>(currentTarget) && downcast<Node>(*currentTarget).isInShadowTree());
}
Vector<EventTarget*> Event::composedPath() const
@@ -171,7 +173,7 @@
void Event::resetAfterDispatch()
{
m_eventPath = nullptr;
- m_currentTarget = nullptr;
+ setCurrentTarget(nullptr);
m_eventPhase = NONE;
m_propagationStopped = false;
m_immediatePropagationStopped = false;
Modified: trunk/Source/WebCore/dom/Event.h (269499 => 269500)
--- trunk/Source/WebCore/dom/Event.h 2020-11-06 02:02:41 UTC (rev 269499)
+++ trunk/Source/WebCore/dom/Event.h 2020-11-06 02:05:47 UTC (rev 269500)
@@ -70,7 +70,8 @@
void setTarget(RefPtr<EventTarget>&&);
EventTarget* currentTarget() const { return m_currentTarget.get(); }
- void setCurrentTarget(EventTarget*);
+ void setCurrentTarget(EventTarget*, Optional<bool> isInShadowTree = WTF::nullopt);
+ bool currentTargetIsInShadowTree() const { return m_currentTargetIsInShadowTree; }
unsigned short eventPhase() const { return m_eventPhase; }
void setEventPhase(PhaseType phase) { m_eventPhase = phase; }
@@ -167,6 +168,7 @@
unsigned m_isDefaultEventHandlerIgnored : 1;
unsigned m_isTrusted : 1;
unsigned m_isExecutingPassiveEventListener : 1;
+ unsigned m_currentTargetIsInShadowTree : 1;
unsigned m_eventPhase : 2;
Modified: trunk/Source/WebCore/dom/EventContext.cpp (269499 => 269500)
--- trunk/Source/WebCore/dom/EventContext.cpp 2020-11-06 02:02:41 UTC (rev 269499)
+++ trunk/Source/WebCore/dom/EventContext.cpp 2020-11-06 02:05:47 UTC (rev 269500)
@@ -40,6 +40,7 @@
, m_currentTarget { currentTarget }
, m_target { target }
, m_closedShadowDepth { closedShadowDepth }
+ , m_currentTargetIsInShadowTree { is<Node>(currentTarget) && downcast<Node>(*currentTarget).isInShadowTree() }
{
ASSERT(!isUnreachableNode(m_target.get()));
}
@@ -49,7 +50,7 @@
void EventContext::handleLocalEvents(Event& event, EventInvokePhase phase) const
{
event.setTarget(m_target.get());
- event.setCurrentTarget(m_currentTarget.get());
+ event.setCurrentTarget(m_currentTarget.get(), m_currentTargetIsInShadowTree);
// FIXME: Consider merging handleLocalEvents and fireEventListeners.
if (m_node)
m_node->handleLocalEvents(event, phase);
Modified: trunk/Source/WebCore/dom/EventContext.h (269499 => 269500)
--- trunk/Source/WebCore/dom/EventContext.h 2020-11-06 02:02:41 UTC (rev 269499)
+++ trunk/Source/WebCore/dom/EventContext.h 2020-11-06 02:05:47 UTC (rev 269500)
@@ -43,6 +43,7 @@
Node* node() const { return m_node.get(); }
EventTarget* currentTarget() const { return m_currentTarget.get(); }
+ bool isCurrentTargetInShadowTree() const { return m_currentTargetIsInShadowTree; }
EventTarget* target() const { return m_target.get(); }
int closedShadowDepth() const { return m_closedShadowDepth; }
@@ -60,6 +61,7 @@
RefPtr<EventTarget> m_currentTarget;
RefPtr<EventTarget> m_target;
int m_closedShadowDepth { 0 };
+ bool m_currentTargetIsInShadowTree { false };
};
class MouseOrFocusEventContext final : public EventContext {
Modified: trunk/Source/WebCore/dom/EventPath.cpp (269499 => 269500)
--- trunk/Source/WebCore/dom/EventPath.cpp 2020-11-06 02:02:41 UTC (rev 269499)
+++ trunk/Source/WebCore/dom/EventPath.cpp 2020-11-06 02:05:47 UTC (rev 269500)
@@ -50,7 +50,7 @@
void WindowEventContext::handleLocalEvents(Event& event, EventInvokePhase phase) const
{
event.setTarget(m_target.get());
- event.setCurrentTarget(m_currentTarget.get());
+ event.setCurrentTarget(m_currentTarget.get(), m_currentTargetIsInShadowTree);
m_currentTarget->fireEventListeners(event, phase);
}