Title: [223849] trunk
Revision
223849
Author
[email protected]
Date
2017-10-23 12:36:24 -0700 (Mon, 23 Oct 2017)

Log Message

Drop confusing Event::dispatched() method
https://bugs.webkit.org/show_bug.cgi?id=178670

Reviewed by Youenn Fablet.

Source/WebCore:

Drop confusing Event::dispatched() method. What the call sites want to do is check
that the Event's "dispatch" flag is set:
- https://dom.spec.whatwg.org/#dispatch-flag

This flag gets set at the beginning of dispatchEvent() and unset at the end of
dispatchEvent():
- https://dom.spec.whatwg.org/#ref-for-dispatch-flag③

See as an example event.initEvent():
- https://dom.spec.whatwg.org/#dom-event-initevent

The right way to check the Event's "dispatch" flag is the Event::isBeingDispatched()
method, so use this instead. One side effect of this change is that it is now
possible to call the init*Event() method on events that have already been dispatched
in order to dispatch them again, as per the specification.

Test: fast/events/initEvent-after-dispatching.html

* dom/CompositionEvent.cpp:
(WebCore::CompositionEvent::initCompositionEvent):
* dom/DeviceMotionEvent.cpp:
(WebCore::DeviceMotionEvent::initDeviceMotionEvent):
* dom/DeviceOrientationEvent.cpp:
(WebCore::DeviceOrientationEvent::initDeviceOrientationEvent):
* dom/Event.h:
* dom/HashChangeEvent.h:
* dom/KeyboardEvent.cpp:
(WebCore::KeyboardEvent::initKeyboardEvent):
* dom/MessageEvent.cpp:
(WebCore::MessageEvent::initMessageEvent):
* dom/MouseEvent.cpp:
(WebCore::MouseEvent::initMouseEvent):
* dom/OverflowEvent.cpp:
(WebCore::OverflowEvent::initOverflowEvent):
* dom/TextEvent.cpp:
(WebCore::TextEvent::initTextEvent):
* dom/TouchEvent.cpp:
(WebCore::TouchEvent::initTouchEvent):
* dom/UIEvent.cpp:
(WebCore::UIEvent::initUIEvent):
* dom/WheelEvent.cpp:
(WebCore::WheelEvent::initWheelEvent):
* storage/StorageEvent.cpp:
(WebCore::StorageEvent::initStorageEvent):

LayoutTests:

Add layout test coverage.

* fast/events/initEvent-after-dispatching-expected.txt: Added.
* fast/events/initEvent-after-dispatching.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (223848 => 223849)


--- trunk/LayoutTests/ChangeLog	2017-10-23 18:59:06 UTC (rev 223848)
+++ trunk/LayoutTests/ChangeLog	2017-10-23 19:36:24 UTC (rev 223849)
@@ -1,3 +1,15 @@
+2017-10-23  Chris Dumez  <[email protected]>
+
+        Drop confusing Event::dispatched() method
+        https://bugs.webkit.org/show_bug.cgi?id=178670
+
+        Reviewed by Youenn Fablet.
+
+        Add layout test coverage.
+
+        * fast/events/initEvent-after-dispatching-expected.txt: Added.
+        * fast/events/initEvent-after-dispatching.html: Added.
+
 2017-10-23  Antti Koivisto  <[email protected]>
 
         Remember previous child renderer during render tree update

Added: trunk/LayoutTests/fast/events/initEvent-after-dispatching-expected.txt (0 => 223849)


--- trunk/LayoutTests/fast/events/initEvent-after-dispatching-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/events/initEvent-after-dispatching-expected.txt	2017-10-23 19:36:24 UTC (rev 223849)
@@ -0,0 +1,107 @@
+Tests that the various init*Event() functions work on an event that has already been dispatched.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+* CompositionEvent.prototype.initCompositionEvent()
+testEvent = document.createEvent(createEventString)
+PASS testEvent.__proto__ is window[eventType].prototype
+testEvent[initMethodName]('firstType', true, true)
+PASS testEvent.type is "firstType"
+PASS testEvent.bubbles is true
+PASS testEvent.cancelable is true
+PASS document.body.dispatchEvent(testEvent) is true
+testEvent[initMethodName]('secondType', false, false)
+PASS testEvent.type is "secondType"
+PASS testEvent.bubbles is false
+PASS testEvent.cancelable is false
+PASS document.body.dispatchEvent(testEvent) is true
+
+* HashChangeEvent.prototype.initHashChangeEvent()
+testEvent = document.createEvent(createEventString)
+PASS testEvent.__proto__ is window[eventType].prototype
+testEvent[initMethodName]('firstType', true, true)
+PASS testEvent.type is "firstType"
+PASS testEvent.bubbles is true
+PASS testEvent.cancelable is true
+PASS document.body.dispatchEvent(testEvent) is true
+testEvent[initMethodName]('secondType', false, false)
+PASS testEvent.type is "secondType"
+PASS testEvent.bubbles is false
+PASS testEvent.cancelable is false
+PASS document.body.dispatchEvent(testEvent) is true
+
+* KeyboardEvent.prototype.initKeyboardEvent()
+testEvent = document.createEvent(createEventString)
+PASS testEvent.__proto__ is window[eventType].prototype
+testEvent[initMethodName]('firstType', true, true)
+PASS testEvent.type is "firstType"
+PASS testEvent.bubbles is true
+PASS testEvent.cancelable is true
+PASS document.body.dispatchEvent(testEvent) is true
+testEvent[initMethodName]('secondType', false, false)
+PASS testEvent.type is "secondType"
+PASS testEvent.bubbles is false
+PASS testEvent.cancelable is false
+PASS document.body.dispatchEvent(testEvent) is true
+
+* MessageEvent.prototype.initMessageEvent()
+testEvent = document.createEvent(createEventString)
+PASS testEvent.__proto__ is window[eventType].prototype
+testEvent[initMethodName]('firstType', true, true)
+PASS testEvent.type is "firstType"
+PASS testEvent.bubbles is true
+PASS testEvent.cancelable is true
+PASS document.body.dispatchEvent(testEvent) is true
+testEvent[initMethodName]('secondType', false, false)
+PASS testEvent.type is "secondType"
+PASS testEvent.bubbles is false
+PASS testEvent.cancelable is false
+PASS document.body.dispatchEvent(testEvent) is true
+
+* TextEvent.prototype.initTextEvent()
+testEvent = document.createEvent(createEventString)
+PASS testEvent.__proto__ is window[eventType].prototype
+testEvent[initMethodName]('firstType', true, true)
+PASS testEvent.type is "firstType"
+PASS testEvent.bubbles is true
+PASS testEvent.cancelable is true
+PASS document.body.dispatchEvent(testEvent) is true
+testEvent[initMethodName]('secondType', false, false)
+PASS testEvent.type is "secondType"
+PASS testEvent.bubbles is false
+PASS testEvent.cancelable is false
+PASS document.body.dispatchEvent(testEvent) is true
+
+* UIEvent.prototype.initUIEvent()
+testEvent = document.createEvent(createEventString)
+PASS testEvent.__proto__ is window[eventType].prototype
+testEvent[initMethodName]('firstType', true, true)
+PASS testEvent.type is "firstType"
+PASS testEvent.bubbles is true
+PASS testEvent.cancelable is true
+PASS document.body.dispatchEvent(testEvent) is true
+testEvent[initMethodName]('secondType', false, false)
+PASS testEvent.type is "secondType"
+PASS testEvent.bubbles is false
+PASS testEvent.cancelable is false
+PASS document.body.dispatchEvent(testEvent) is true
+
+* StorageEvent.prototype.initStorageEvent()
+testEvent = document.createEvent(createEventString)
+PASS testEvent.__proto__ is window[eventType].prototype
+testEvent[initMethodName]('firstType', true, true)
+PASS testEvent.type is "firstType"
+PASS testEvent.bubbles is true
+PASS testEvent.cancelable is true
+PASS document.body.dispatchEvent(testEvent) is true
+testEvent[initMethodName]('secondType', false, false)
+PASS testEvent.type is "secondType"
+PASS testEvent.bubbles is false
+PASS testEvent.cancelable is false
+PASS document.body.dispatchEvent(testEvent) is true
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/events/initEvent-after-dispatching.html (0 => 223849)


--- trunk/LayoutTests/fast/events/initEvent-after-dispatching.html	                        (rev 0)
+++ trunk/LayoutTests/fast/events/initEvent-after-dispatching.html	2017-10-23 19:36:24 UTC (rev 223849)
@@ -0,0 +1,40 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src=""
+<script>
+description("Tests that the various init*Event() functions work on an event that has already been dispatched.");
+
+function testEventInitFunction(_createEventString, _eventType, _initMethodName)
+{
+    createEventString = _createEventString;
+    eventType = _eventType;
+    initMethodName = _initMethodName;
+
+    debug("* " + eventType + ".prototype." + initMethodName + "()");
+    evalAndLog("testEvent = document.createEvent(createEventString)");
+    shouldBe("testEvent.__proto__", "window[eventType].prototype");
+    evalAndLog("testEvent[initMethodName]('firstType', true, true)");
+    shouldBeEqualToString("testEvent.type", "firstType");
+    shouldBeTrue("testEvent.bubbles");
+    shouldBeTrue("testEvent.cancelable");
+    shouldBeTrue("document.body.dispatchEvent(testEvent)");
+    evalAndLog("testEvent[initMethodName]('secondType', false, false)");
+    shouldBeEqualToString("testEvent.type", "secondType");
+    shouldBeFalse("testEvent.bubbles");
+    shouldBeFalse("testEvent.cancelable");
+    shouldBeTrue("document.body.dispatchEvent(testEvent)");
+    debug("");
+}
+
+testEventInitFunction("compositionevent", "CompositionEvent", "initCompositionEvent");
+testEventInitFunction("hashchangeevent", "HashChangeEvent", "initHashChangeEvent");
+testEventInitFunction("keyboardevent", "KeyboardEvent", "initKeyboardEvent");
+testEventInitFunction("messageevent", "MessageEvent", "initMessageEvent");
+testEventInitFunction("textevent", "TextEvent", "initTextEvent");
+testEventInitFunction("uievent", "UIEvent", "initUIEvent");
+testEventInitFunction("storageevent", "StorageEvent", "initStorageEvent");
+
+</script>
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (223848 => 223849)


--- trunk/Source/WebCore/ChangeLog	2017-10-23 18:59:06 UTC (rev 223848)
+++ trunk/Source/WebCore/ChangeLog	2017-10-23 19:36:24 UTC (rev 223849)
@@ -1,3 +1,55 @@
+2017-10-23  Chris Dumez  <[email protected]>
+
+        Drop confusing Event::dispatched() method
+        https://bugs.webkit.org/show_bug.cgi?id=178670
+
+        Reviewed by Youenn Fablet.
+
+        Drop confusing Event::dispatched() method. What the call sites want to do is check
+        that the Event's "dispatch" flag is set:
+        - https://dom.spec.whatwg.org/#dispatch-flag
+
+        This flag gets set at the beginning of dispatchEvent() and unset at the end of
+        dispatchEvent():
+        - https://dom.spec.whatwg.org/#ref-for-dispatch-flag③
+
+        See as an example event.initEvent():
+        - https://dom.spec.whatwg.org/#dom-event-initevent
+
+        The right way to check the Event's "dispatch" flag is the Event::isBeingDispatched()
+        method, so use this instead. One side effect of this change is that it is now
+        possible to call the init*Event() method on events that have already been dispatched
+        in order to dispatch them again, as per the specification.
+
+        Test: fast/events/initEvent-after-dispatching.html
+
+        * dom/CompositionEvent.cpp:
+        (WebCore::CompositionEvent::initCompositionEvent):
+        * dom/DeviceMotionEvent.cpp:
+        (WebCore::DeviceMotionEvent::initDeviceMotionEvent):
+        * dom/DeviceOrientationEvent.cpp:
+        (WebCore::DeviceOrientationEvent::initDeviceOrientationEvent):
+        * dom/Event.h:
+        * dom/HashChangeEvent.h:
+        * dom/KeyboardEvent.cpp:
+        (WebCore::KeyboardEvent::initKeyboardEvent):
+        * dom/MessageEvent.cpp:
+        (WebCore::MessageEvent::initMessageEvent):
+        * dom/MouseEvent.cpp:
+        (WebCore::MouseEvent::initMouseEvent):
+        * dom/OverflowEvent.cpp:
+        (WebCore::OverflowEvent::initOverflowEvent):
+        * dom/TextEvent.cpp:
+        (WebCore::TextEvent::initTextEvent):
+        * dom/TouchEvent.cpp:
+        (WebCore::TouchEvent::initTouchEvent):
+        * dom/UIEvent.cpp:
+        (WebCore::UIEvent::initUIEvent):
+        * dom/WheelEvent.cpp:
+        (WebCore::WheelEvent::initWheelEvent):
+        * storage/StorageEvent.cpp:
+        (WebCore::StorageEvent::initStorageEvent):
+
 2017-10-23  Antti Koivisto  <[email protected]>
 
         Remember previous child renderer during render tree update

Modified: trunk/Source/WebCore/dom/CompositionEvent.cpp (223848 => 223849)


--- trunk/Source/WebCore/dom/CompositionEvent.cpp	2017-10-23 18:59:06 UTC (rev 223848)
+++ trunk/Source/WebCore/dom/CompositionEvent.cpp	2017-10-23 19:36:24 UTC (rev 223849)
@@ -47,7 +47,7 @@
 
 void CompositionEvent::initCompositionEvent(const AtomicString& type, bool canBubble, bool cancelable, DOMWindow* view, const String& data)
 {
-    if (dispatched())
+    if (isBeingDispatched())
         return;
 
     initUIEvent(type, canBubble, cancelable, view, 0);

Modified: trunk/Source/WebCore/dom/DeviceMotionEvent.cpp (223848 => 223849)


--- trunk/Source/WebCore/dom/DeviceMotionEvent.cpp	2017-10-23 18:59:06 UTC (rev 223848)
+++ trunk/Source/WebCore/dom/DeviceMotionEvent.cpp	2017-10-23 19:36:24 UTC (rev 223849)
@@ -103,7 +103,7 @@
 
 void DeviceMotionEvent::initDeviceMotionEvent(const AtomicString& type, bool bubbles, bool cancelable, std::optional<DeviceMotionEvent::Acceleration>&& acceleration, std::optional<DeviceMotionEvent::Acceleration>&& accelerationIncludingGravity, std::optional<DeviceMotionEvent::RotationRate>&& rotationRate, std::optional<double> interval)
 {
-    if (dispatched())
+    if (isBeingDispatched())
         return;
 
     initEvent(type, bubbles, cancelable);

Modified: trunk/Source/WebCore/dom/DeviceOrientationEvent.cpp (223848 => 223849)


--- trunk/Source/WebCore/dom/DeviceOrientationEvent.cpp	2017-10-23 18:59:06 UTC (rev 223848)
+++ trunk/Source/WebCore/dom/DeviceOrientationEvent.cpp	2017-10-23 19:36:24 UTC (rev 223849)
@@ -72,7 +72,7 @@
 
 void DeviceOrientationEvent::initDeviceOrientationEvent(const AtomicString& type, bool bubbles, bool cancelable, std::optional<double> alpha, std::optional<double> beta, std::optional<double> gamma, std::optional<double> compassHeading, std::optional<double> compassAccuracy)
 {
-    if (dispatched())
+    if (isBeingDispatched())
         return;
 
     initEvent(type, bubbles, cancelable);
@@ -88,7 +88,7 @@
 
 void DeviceOrientationEvent::initDeviceOrientationEvent(const AtomicString& type, bool bubbles, bool cancelable, std::optional<double> alpha, std::optional<double> beta, std::optional<double> gamma, std::optional<bool> absolute)
 {
-    if (dispatched())
+    if (isBeingDispatched())
         return;
 
     initEvent(type, bubbles, cancelable);

Modified: trunk/Source/WebCore/dom/Event.h (223848 => 223849)


--- trunk/Source/WebCore/dom/Event.h	2017-10-23 18:59:06 UTC (rev 223848)
+++ trunk/Source/WebCore/dom/Event.h	2017-10-23 19:36:24 UTC (rev 223849)
@@ -165,6 +165,8 @@
     Event* underlyingEvent() const { return m_underlyingEvent.get(); }
     void setUnderlyingEvent(Event*);
 
+    // Returns true if the dispatch flag is set.
+    // https://dom.spec.whatwg.org/#dispatch-flag
     bool isBeingDispatched() const { return eventPhase(); }
 
     virtual EventTarget* relatedTarget() const { return nullptr; }
@@ -177,7 +179,6 @@
     Event(const AtomicString& type, const EventInit&, IsTrusted);
 
     virtual void receivedTarget();
-    bool dispatched() const { return m_target; }
 
 private:
     AtomicString m_type;

Modified: trunk/Source/WebCore/dom/HashChangeEvent.h (223848 => 223849)


--- trunk/Source/WebCore/dom/HashChangeEvent.h	2017-10-23 18:59:06 UTC (rev 223848)
+++ trunk/Source/WebCore/dom/HashChangeEvent.h	2017-10-23 19:36:24 UTC (rev 223849)
@@ -49,7 +49,7 @@
 
     void initHashChangeEvent(const AtomicString& eventType, bool canBubble, bool cancelable, const String& oldURL, const String& newURL)
     {
-        if (dispatched())
+        if (isBeingDispatched())
             return;
 
         initEvent(eventType, canBubble, cancelable);

Modified: trunk/Source/WebCore/dom/KeyboardEvent.cpp (223848 => 223849)


--- trunk/Source/WebCore/dom/KeyboardEvent.cpp	2017-10-23 18:59:06 UTC (rev 223848)
+++ trunk/Source/WebCore/dom/KeyboardEvent.cpp	2017-10-23 19:36:24 UTC (rev 223849)
@@ -152,7 +152,7 @@
                                       const String &keyIdentifier, unsigned location,
                                       bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, bool altGraphKey)
 {
-    if (dispatched())
+    if (isBeingDispatched())
         return;
 
     initUIEvent(type, canBubble, cancelable, view, 0);

Modified: trunk/Source/WebCore/dom/MessageEvent.cpp (223848 => 223849)


--- trunk/Source/WebCore/dom/MessageEvent.cpp	2017-10-23 18:59:06 UTC (rev 223848)
+++ trunk/Source/WebCore/dom/MessageEvent.cpp	2017-10-23 19:36:24 UTC (rev 223849)
@@ -135,7 +135,7 @@
 
 void MessageEvent::initMessageEvent(ExecState& state, const AtomicString& type, bool canBubble, bool cancelable, JSValue data, const String& origin, const String& lastEventId, std::optional<MessageEventSource>&& source, Vector<RefPtr<MessagePort>>&& ports)
 {
-    if (dispatched())
+    if (isBeingDispatched())
         return;
 
     initEvent(type, canBubble, cancelable);

Modified: trunk/Source/WebCore/dom/MouseEvent.cpp (223848 => 223849)


--- trunk/Source/WebCore/dom/MouseEvent.cpp	2017-10-23 18:59:06 UTC (rev 223848)
+++ trunk/Source/WebCore/dom/MouseEvent.cpp	2017-10-23 19:36:24 UTC (rev 223849)
@@ -129,7 +129,7 @@
 
 void MouseEvent::initMouseEvent(const AtomicString& type, bool canBubble, bool cancelable, DOMWindow* view, int detail, int screenX, int screenY, int clientX, int clientY, bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, unsigned short button, EventTarget* relatedTarget)
 {
-    if (dispatched())
+    if (isBeingDispatched())
         return;
 
     initUIEvent(type, canBubble, cancelable, view, detail);

Modified: trunk/Source/WebCore/dom/OverflowEvent.cpp (223848 => 223849)


--- trunk/Source/WebCore/dom/OverflowEvent.cpp	2017-10-23 18:59:06 UTC (rev 223848)
+++ trunk/Source/WebCore/dom/OverflowEvent.cpp	2017-10-23 19:36:24 UTC (rev 223849)
@@ -67,7 +67,7 @@
 
 void OverflowEvent::initOverflowEvent(unsigned short orient, bool horizontalOverflow, bool verticalOverflow)
 {
-    if (dispatched())
+    if (isBeingDispatched())
         return;
 
     initEvent(eventNames().overflowchangedEvent, false, false);

Modified: trunk/Source/WebCore/dom/TextEvent.cpp (223848 => 223849)


--- trunk/Source/WebCore/dom/TextEvent.cpp	2017-10-23 18:59:06 UTC (rev 223848)
+++ trunk/Source/WebCore/dom/TextEvent.cpp	2017-10-23 19:36:24 UTC (rev 223849)
@@ -107,7 +107,7 @@
 
 void TextEvent::initTextEvent(const AtomicString& type, bool canBubble, bool cancelable, DOMWindow* view, const String& data)
 {
-    if (dispatched())
+    if (isBeingDispatched())
         return;
 
     initUIEvent(type, canBubble, cancelable, view, 0);

Modified: trunk/Source/WebCore/dom/TouchEvent.cpp (223848 => 223849)


--- trunk/Source/WebCore/dom/TouchEvent.cpp	2017-10-23 18:59:06 UTC (rev 223848)
+++ trunk/Source/WebCore/dom/TouchEvent.cpp	2017-10-23 19:36:24 UTC (rev 223849)
@@ -67,7 +67,7 @@
         DOMWindow* view, int screenX, int screenY, int clientX, int clientY,
         bool ctrlKey, bool altKey, bool shiftKey, bool metaKey)
 {
-    if (dispatched())
+    if (isBeingDispatched())
         return;
 
     initUIEvent(type, true, true, view, 0);

Modified: trunk/Source/WebCore/dom/UIEvent.cpp (223848 => 223849)


--- trunk/Source/WebCore/dom/UIEvent.cpp	2017-10-23 18:59:06 UTC (rev 223848)
+++ trunk/Source/WebCore/dom/UIEvent.cpp	2017-10-23 19:36:24 UTC (rev 223849)
@@ -57,7 +57,7 @@
 
 void UIEvent::initUIEvent(const AtomicString& typeArg, bool canBubbleArg, bool cancelableArg, DOMWindow* viewArg, int detailArg)
 {
-    if (dispatched())
+    if (isBeingDispatched())
         return;
 
     initEvent(typeArg, canBubbleArg, cancelableArg);

Modified: trunk/Source/WebCore/dom/WheelEvent.cpp (223848 => 223849)


--- trunk/Source/WebCore/dom/WheelEvent.cpp	2017-10-23 18:59:06 UTC (rev 223848)
+++ trunk/Source/WebCore/dom/WheelEvent.cpp	2017-10-23 19:36:24 UTC (rev 223849)
@@ -66,7 +66,7 @@
 
 void WheelEvent::initWheelEvent(int rawDeltaX, int rawDeltaY, DOMWindow* view, int screenX, int screenY, int pageX, int pageY, bool ctrlKey, bool altKey, bool shiftKey, bool metaKey)
 {
-    if (dispatched())
+    if (isBeingDispatched())
         return;
     
     initUIEvent(eventNames().wheelEvent, true, true, view, 0);

Modified: trunk/Source/WebCore/storage/StorageEvent.cpp (223848 => 223849)


--- trunk/Source/WebCore/storage/StorageEvent.cpp	2017-10-23 18:59:06 UTC (rev 223848)
+++ trunk/Source/WebCore/storage/StorageEvent.cpp	2017-10-23 19:36:24 UTC (rev 223849)
@@ -71,7 +71,7 @@
 
 void StorageEvent::initStorageEvent(const AtomicString& type, bool canBubble, bool cancelable, const String& key, const String& oldValue, const String& newValue, const String& url, Storage* storageArea)
 {
-    if (dispatched())
+    if (isBeingDispatched())
         return;
 
     initEvent(type, canBubble, cancelable);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to