https://bugs.webkit.org/show_bug.cgi?id=148800
<rdar://problem/
22565782>
<rdar://problem/
22565485>
Reviewed by Geoffrey Garen.
Source/WebCore:
dispatchEvent() should throw an InvalidStateError if the event's
initialized flag is not set or its dispatch flag is set, and should
allow dispatching events with an empty type as long as it is
initialized:
https://dom.spec.whatwg.org/#dom-eventtarget-dispatchevent (step 1)
Previously, WebKit relied on the event type being empty to throw a
UNSPECIFIED_EVENT_TYPE_ERR: DOM Events Exception 0. However, this
exception type is outdated and initializing Event.type to an empty
string is legal.
No new tests, already covered by existing tests that were rebaselined.
* dom/Event.cpp:
(WebCore::Event::Event):
(WebCore::Event::initEvent):
* dom/Event.h:
(WebCore::Event::isInitialized):
* dom/EventTarget.cpp:
(WebCore::EventTarget::dispatchEvent):
LayoutTests:
* dom/html/level2/events/dispatchEvent02-expected.txt:
* dom/html/level2/events/dispatchEvent03-expected.txt:
* dom/html/level2/events/dispatchEvent04-expected.txt:
* dom/html/level2/events/dispatchEvent05-expected.txt:
* dom/html/level2/events/dispatchEvent06-expected.txt:
* dom/html/level2/events/dispatchEvent07-expected.txt:
* dom/xhtml/level2/events/dispatchEvent02-expected.txt:
* dom/xhtml/level2/events/dispatchEvent03-expected.txt:
* dom/xhtml/level2/events/dispatchEvent04-expected.txt:
* dom/xhtml/level2/events/dispatchEvent05-expected.txt:
* dom/xhtml/level2/events/dispatchEvent06-expected.txt:
* dom/xhtml/level2/events/dispatchEvent07-expected.txt:
Rebaseline, those tests are outdated and their expected results no
longer matches the behavior of the latest DOM specification.
* fast/dom/DOMException/EventException-expected.txt: Removed.
* fast/dom/DOMException/EventException.html: Removed.
* fast/dom/DOMException/resources/EventException.js: Removed.
Drop this test we no longer throw an EventException in this case.
* fast/dom/Window/dispatchEvent-expected.txt:
Rebaseline.
* fast/events/dispatch-event-being-dispatched-expected.txt:
* fast/events/dispatch-event-being-dispatched.html:
Fix the test to expect the new exception types.
* http/tests/w3c/dom/events/Event-type-empty-expected.txt:
* http/tests/w3c/dom/events/EventTarget-dispatchEvent-expected.txt:
Rebaseline.
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@189452
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
2015-09-06 Chris Dumez <cdumez@apple.com>
+ dispatchEvent() should throw an InvalidStateError if the event's initialized flag is not set
+ https://bugs.webkit.org/show_bug.cgi?id=148800
+ <rdar://problem/22565782>
+ <rdar://problem/22565485>
+
+ Reviewed by Geoffrey Garen.
+
+ * dom/html/level2/events/dispatchEvent02-expected.txt:
+ * dom/html/level2/events/dispatchEvent03-expected.txt:
+ * dom/html/level2/events/dispatchEvent04-expected.txt:
+ * dom/html/level2/events/dispatchEvent05-expected.txt:
+ * dom/html/level2/events/dispatchEvent06-expected.txt:
+ * dom/html/level2/events/dispatchEvent07-expected.txt:
+ * dom/xhtml/level2/events/dispatchEvent02-expected.txt:
+ * dom/xhtml/level2/events/dispatchEvent03-expected.txt:
+ * dom/xhtml/level2/events/dispatchEvent04-expected.txt:
+ * dom/xhtml/level2/events/dispatchEvent05-expected.txt:
+ * dom/xhtml/level2/events/dispatchEvent06-expected.txt:
+ * dom/xhtml/level2/events/dispatchEvent07-expected.txt:
+ Rebaseline, those tests are outdated and their expected results no
+ longer matches the behavior of the latest DOM specification.
+
+ * fast/dom/DOMException/EventException-expected.txt: Removed.
+ * fast/dom/DOMException/EventException.html: Removed.
+ * fast/dom/DOMException/resources/EventException.js: Removed.
+ Drop this test we no longer throw an EventException in this case.
+
+ * fast/dom/Window/dispatchEvent-expected.txt:
+ Rebaseline.
+
+ * fast/events/dispatch-event-being-dispatched-expected.txt:
+ * fast/events/dispatch-event-being-dispatched.html:
+ Fix the test to expect the new exception types.
+
+ * http/tests/w3c/dom/events/Event-type-empty-expected.txt:
+ * http/tests/w3c/dom/events/EventTarget-dispatchEvent-expected.txt:
+ Rebaseline.
+
+2015-09-06 Chris Dumez <cdumez@apple.com>
+
Unreviewed, drop a few more newly imported W3C media tests that are flaky.
* http/tests/w3c/html/semantics/embedded-content/media-elements/loading-the-media-resource/load-events-networkState-expected.txt: Removed.
-Test: http://www.w3.org/2001/DOM-Test-Suite/level2/events/dispatchEvent02
-Status: Success
+Test: http://www.w3.org/2001/DOM-Test-Suite/level2/events/dispatchEvent02
+Status: failure
+Detail: throw_UNSPECIFIED_EVENT_TYPE_ERR: assertTrue failed
-Test: http://www.w3.org/2001/DOM-Test-Suite/level2/events/dispatchEvent03
-Status: Success
+Test: http://www.w3.org/2001/DOM-Test-Suite/level2/events/dispatchEvent03
+Status: failure
+Detail: throw_UNSPECIFIED_EVENT_TYPE_ERR: assertTrue failed
-Test: http://www.w3.org/2001/DOM-Test-Suite/level2/events/dispatchEvent04
-Status: Success
+Test: http://www.w3.org/2001/DOM-Test-Suite/level2/events/dispatchEvent04
+Status: failure
+Detail: throw_UNSPECIFIED_EVENT_TYPE_ERR: assertTrue failed
-Test: http://www.w3.org/2001/DOM-Test-Suite/level2/events/dispatchEvent05
-Status: Success
+Test: http://www.w3.org/2001/DOM-Test-Suite/level2/events/dispatchEvent05
+Status: failure
+Detail: throw_UNSPECIFIED_EVENT_TYPE_ERR: assertTrue failed
-Test: http://www.w3.org/2001/DOM-Test-Suite/level2/events/dispatchEvent06
-Status: Success
+Test: http://www.w3.org/2001/DOM-Test-Suite/level2/events/dispatchEvent06
+Status: failure
+Detail: throw_UNSPECIFIED_EVENT_TYPE_ERR: assertTrue failed
-Test: http://www.w3.org/2001/DOM-Test-Suite/level2/events/dispatchEvent07
-Status: Success
+Test: http://www.w3.org/2001/DOM-Test-Suite/level2/events/dispatchEvent07
+Status: failure
+Detail: throw_UNSPECIFIED_EVENT_TYPE_ERR: assertTrue failed
Test http://www.w3.org/2001/DOM-Test-Suite/level2/events/dispatchEvent02
-Status Success
+Status failure
+Message throw_UNSPECIFIED_EVENT_TYPE_ERR: assertTrue failed
Test http://www.w3.org/2001/DOM-Test-Suite/level2/events/dispatchEvent03
-Status Success
+Status failure
+Message throw_UNSPECIFIED_EVENT_TYPE_ERR: assertTrue failed
Test http://www.w3.org/2001/DOM-Test-Suite/level2/events/dispatchEvent04
-Status Success
+Status failure
+Message throw_UNSPECIFIED_EVENT_TYPE_ERR: assertTrue failed
Test http://www.w3.org/2001/DOM-Test-Suite/level2/events/dispatchEvent05
-Status Success
+Status failure
+Message throw_UNSPECIFIED_EVENT_TYPE_ERR: assertTrue failed
Test http://www.w3.org/2001/DOM-Test-Suite/level2/events/dispatchEvent06
-Status Success
+Status failure
+Message throw_UNSPECIFIED_EVENT_TYPE_ERR: assertTrue failed
Test http://www.w3.org/2001/DOM-Test-Suite/level2/events/dispatchEvent07
-Status Success
+Status failure
+Message throw_UNSPECIFIED_EVENT_TYPE_ERR: assertTrue failed
+++ /dev/null
-Tests the properties of the EventException object.
-
-On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
-
-
-PASS e.toString() is "Error: UNSPECIFIED_EVENT_TYPE_ERR: DOM Events Exception 0"
-PASS Object.prototype.toString.call(e) is "[object EventException]"
-PASS Object.prototype.toString.call(e.__proto__) is "[object EventExceptionPrototype]"
-PASS e.constructor.toString() is "[object EventExceptionConstructor]"
-PASS e.constructor is window.EventException
-PASS e.UNSPECIFIED_EVENT_TYPE_ERR is e.constructor.UNSPECIFIED_EVENT_TYPE_ERR
-PASS e.UNSPECIFIED_EVENT_TYPE_ERR is 0
-PASS successfullyParsed is true
-
-TEST COMPLETE
-
+++ /dev/null
-<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
-<html>
-<head>
-<script src="../../../resources/js-test-pre.js"></script>
-</head>
-<body>
-<script src="resources/EventException.js"></script>
-<script src="../../../resources/js-test-post.js"></script>
-</body>
-</html>
+++ /dev/null
-description("Tests the properties of the EventException object.")
-
-var e;
-try {
- document.dispatchEvent(null);
- // raises a UNSPECIFIED_EVENT_TYPE_ERR
-} catch (err) {
- e = err;
-}
-
-shouldBeEqualToString("e.toString()", "Error: UNSPECIFIED_EVENT_TYPE_ERR: DOM Events Exception 0");
-shouldBeEqualToString("Object.prototype.toString.call(e)", "[object EventException]");
-shouldBeEqualToString("Object.prototype.toString.call(e.__proto__)", "[object EventExceptionPrototype]");
-shouldBeEqualToString("e.constructor.toString()", "[object EventExceptionConstructor]");
-shouldBe("e.constructor", "window.EventException");
-shouldBe("e.UNSPECIFIED_EVENT_TYPE_ERR", "e.constructor.UNSPECIFIED_EVENT_TYPE_ERR");
-shouldBe("e.UNSPECIFIED_EVENT_TYPE_ERR", "0");
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
-PASS window.dispatchEvent(event) threw exception Error: UNSPECIFIED_EVENT_TYPE_ERR: DOM Events Exception 0.
-PASS window.dispatchEvent(event) threw exception Error: UNSPECIFIED_EVENT_TYPE_ERR: DOM Events Exception 0.
+PASS window.dispatchEvent(event) threw exception TypeError: Type error.
+PASS window.dispatchEvent(event) threw exception Error: InvalidStateError: DOM Exception 11.
PASS myEventDispatched is true
PASS target is window
PASS currentTarget is window
-Tests that dispatchEvent raises DISPATCH_REQUEST_ERR if the event being dispatched is already being dispatched.
+Tests that dispatchEvent raises INVALID_STATE_ERR if the event being dispatched is already being dispatched.
-PASS should have got DISPATCH_REQUEST_ERR EventException
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS window.dispatchEvent(event) threw exception Error: InvalidStateError: DOM Exception 11.
PASS redispatchCustom.wasInvoked is true
-PASS should have got DISPATCH_REQUEST_ERR EventException
+PASS window.dispatchEvent(event) threw exception Error: InvalidStateError: DOM Exception 11.
PASS checkCustom.wasInvoked is true
-PASS should have got DISPATCH_REQUEST_ERR EventException
+PASS document.dispatchEvent(event) threw exception Error: InvalidStateError: DOM Exception 11.
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE html>
<html>
-<head>
-<script src="../../resources/js-test-pre.js"></script>
-</head>
<body>
-<p class="description">
-Tests that dispatchEvent raises DISPATCH_REQUEST_ERR if the event
-being dispatched is already being dispatched.
-</p>
-<pre id="console">
-</pre>
+<script src="../../resources/js-test-pre.js"></script>
+<div class="testDiv"></div>
<script>
-if (window.testRunner)
- testRunner.dumpAsText();
+description("Tests that dispatchEvent raises INVALID_STATE_ERR if the event being dispatched is already being dispatched.");
jsTestIsAsync = true;
-function shouldBeDispatchRequestErr(exception) {
- var ok = EventException.prototype.isPrototypeOf(exception) && exception.code == EventException.DISPATCH_REQUEST_ERR;
- (ok ? testPassed : testFailed)("should have got DISPATCH_REQUEST_ERR EventException");
-}
-
-// try redispatching an event in the process of being dispatched with
-// dispatchEvent
+// try redispatching an event in the process of being dispatched with dispatchEvent
function redispatchCustom(event) {
- try {
- window.dispatchEvent(event);
- testFailed('dispatchEvent of an event being dispatched should throw an exception');
- } catch (ex) {
- shouldBeDispatchRequestErr(ex);
- }
+ shouldThrow("window.dispatchEvent(event)", "'Error: InvalidStateError: DOM Exception 11'");
redispatchCustom.wasInvoked = true;
}
var customEvent = document.createEvent('CustomEvent');
customEvent.initCustomEvent('foo', true, true, null);
-var p = document.querySelector('.description');
+var p = document.querySelector('.testDiv');
p.addEventListener('foo', redispatchCustom);
p.dispatchEvent(customEvent);
shouldBeTrue('redispatchCustom.wasInvoked');
return;
}
- try {
- redispatchLoad.dispatching = true;
- document.dispatchEvent(event);
- testFailed('dispatchEvent of an event being dispatched should throw an exception');
- } catch (ex) {
- shouldBeDispatchRequestErr(ex);
- } finally {
- delete redispatchLoad.dispatching;
- }
+ redispatchLoad.dispatching = true;
+ shouldThrow("document.dispatchEvent(event)", "'Error: InvalidStateError: DOM Exception 11'");
+ delete redispatchLoad.dispatching;
finishJSTest();
}
-FAIL initEvent UNSPECIFIED_EVENT_TYPE_ERR: DOM Events Exception 0
-FAIL Constructor UNSPECIFIED_EVENT_TYPE_ERR: DOM Events Exception 0
+PASS initEvent
+PASS Constructor
CONSOLE MESSAGE: line 60: Error
-FAIL Calling dispatchEvent(null). assert_throws: function "function () { document.dispatchEvent(null) }" threw object "Error: UNSPECIFIED_EVENT_TYPE_ERR: DOM Events Exception 0" ("UNSPECIFIED_EVENT_TYPE_ERR") expected object "TypeError" ("TypeError")
-FAIL If the event's initialized flag is not set, an InvalidStateError must be thrown (CustomEvent). assert_throws: function "function () { document.dispatchEvent(e) }" threw object "Error: UNSPECIFIED_EVENT_TYPE_ERR: DOM Events Exception 0" that is not a DOMException InvalidStateError: property "code" is equal to 0, expected 11
-FAIL If the event's initialized flag is not set, an InvalidStateError must be thrown (Event). assert_throws: function "function () { document.dispatchEvent(e) }" threw object "Error: UNSPECIFIED_EVENT_TYPE_ERR: DOM Events Exception 0" that is not a DOMException InvalidStateError: property "code" is equal to 0, expected 11
-FAIL If the event's initialized flag is not set, an InvalidStateError must be thrown (Events). assert_throws: function "function () { document.dispatchEvent(e) }" threw object "Error: UNSPECIFIED_EVENT_TYPE_ERR: DOM Events Exception 0" that is not a DOMException InvalidStateError: property "code" is equal to 0, expected 11
-FAIL If the event's initialized flag is not set, an InvalidStateError must be thrown (HTMLEvents). assert_throws: function "function () { document.dispatchEvent(e) }" threw object "Error: UNSPECIFIED_EVENT_TYPE_ERR: DOM Events Exception 0" that is not a DOMException InvalidStateError: property "code" is equal to 0, expected 11
-FAIL If the event's initialized flag is not set, an InvalidStateError must be thrown (KeyboardEvent). assert_throws: function "function () { document.dispatchEvent(e) }" threw object "Error: UNSPECIFIED_EVENT_TYPE_ERR: DOM Events Exception 0" that is not a DOMException InvalidStateError: property "code" is equal to 0, expected 11
+PASS Calling dispatchEvent(null).
+PASS If the event's initialized flag is not set, an InvalidStateError must be thrown (CustomEvent).
+PASS If the event's initialized flag is not set, an InvalidStateError must be thrown (Event).
+PASS If the event's initialized flag is not set, an InvalidStateError must be thrown (Events).
+PASS If the event's initialized flag is not set, an InvalidStateError must be thrown (HTMLEvents).
+PASS If the event's initialized flag is not set, an InvalidStateError must be thrown (KeyboardEvent).
FAIL If the event's initialized flag is not set, an InvalidStateError must be thrown (KeyEvents). NotSupportedError: DOM Exception 9
-FAIL If the event's initialized flag is not set, an InvalidStateError must be thrown (MessageEvent). assert_throws: function "function () { document.dispatchEvent(e) }" threw object "Error: UNSPECIFIED_EVENT_TYPE_ERR: DOM Events Exception 0" that is not a DOMException InvalidStateError: property "code" is equal to 0, expected 11
-FAIL If the event's initialized flag is not set, an InvalidStateError must be thrown (MouseEvent). assert_throws: function "function () { document.dispatchEvent(e) }" threw object "Error: UNSPECIFIED_EVENT_TYPE_ERR: DOM Events Exception 0" that is not a DOMException InvalidStateError: property "code" is equal to 0, expected 11
-FAIL If the event's initialized flag is not set, an InvalidStateError must be thrown (MouseEvents). assert_throws: function "function () { document.dispatchEvent(e) }" threw object "Error: UNSPECIFIED_EVENT_TYPE_ERR: DOM Events Exception 0" that is not a DOMException InvalidStateError: property "code" is equal to 0, expected 11
+PASS If the event's initialized flag is not set, an InvalidStateError must be thrown (MessageEvent).
+PASS If the event's initialized flag is not set, an InvalidStateError must be thrown (MouseEvent).
+PASS If the event's initialized flag is not set, an InvalidStateError must be thrown (MouseEvents).
FAIL If the event's initialized flag is not set, an InvalidStateError must be thrown (TouchEvent). NotSupportedError: DOM Exception 9
-FAIL If the event's initialized flag is not set, an InvalidStateError must be thrown (UIEvent). assert_throws: function "function () { document.dispatchEvent(e) }" threw object "Error: UNSPECIFIED_EVENT_TYPE_ERR: DOM Events Exception 0" that is not a DOMException InvalidStateError: property "code" is equal to 0, expected 11
-FAIL If the event's initialized flag is not set, an InvalidStateError must be thrown (UIEvents). assert_throws: function "function () { document.dispatchEvent(e) }" threw object "Error: UNSPECIFIED_EVENT_TYPE_ERR: DOM Events Exception 0" that is not a DOMException InvalidStateError: property "code" is equal to 0, expected 11
-FAIL If the event's dispatch flag is set, an InvalidStateError must be thrown. assert_throws: function "function () {
- target.dispatchEvent(e)
- }" threw object "Error: DISPATCH_REQUEST_ERR: DOM Events Exception 1" that is not a DOMException InvalidStateError: property "code" is equal to 1, expected 11
+PASS If the event's initialized flag is not set, an InvalidStateError must be thrown (UIEvent).
+PASS If the event's initialized flag is not set, an InvalidStateError must be thrown (UIEvents).
+PASS If the event's dispatch flag is set, an InvalidStateError must be thrown.
PASS Exceptions from event listeners must not be propagated.
FAIL Event listeners added during dispatch should be called assert_array_equals: lengths differ, expected 2 got 0
PASS Event listeners should be called in order of addition
+2015-09-06 Chris Dumez <cdumez@apple.com>
+
+ dispatchEvent() should throw an InvalidStateError if the event's initialized flag is not set
+ https://bugs.webkit.org/show_bug.cgi?id=148800
+ <rdar://problem/22565782>
+ <rdar://problem/22565485>
+
+ Reviewed by Geoffrey Garen.
+
+ dispatchEvent() should throw an InvalidStateError if the event's
+ initialized flag is not set or its dispatch flag is set, and should
+ allow dispatching events with an empty type as long as it is
+ initialized:
+ https://dom.spec.whatwg.org/#dom-eventtarget-dispatchevent (step 1)
+
+ Previously, WebKit relied on the event type being empty to throw a
+ UNSPECIFIED_EVENT_TYPE_ERR: DOM Events Exception 0. However, this
+ exception type is outdated and initializing Event.type to an empty
+ string is legal.
+
+ No new tests, already covered by existing tests that were rebaselined.
+
+ * dom/Event.cpp:
+ (WebCore::Event::Event):
+ (WebCore::Event::initEvent):
+ * dom/Event.h:
+ (WebCore::Event::isInitialized):
+ * dom/EventTarget.cpp:
+ (WebCore::EventTarget::dispatchEvent):
+
2015-09-06 Youenn Fablet <youenn.fablet@crf.canon.fr>
XHR2 timeout property should allow late updates
}
Event::Event(const AtomicString& eventType, bool canBubbleArg, bool cancelableArg)
- : m_type(eventType)
+ : m_isInitialized(true)
+ , m_type(eventType)
, m_canBubble(canBubbleArg)
, m_cancelable(cancelableArg)
, m_propagationStopped(false)
}
Event::Event(const AtomicString& eventType, bool canBubbleArg, bool cancelableArg, double timestamp)
- : m_type(eventType)
+ : m_isInitialized(true)
+ , m_type(eventType)
, m_canBubble(canBubbleArg)
, m_cancelable(cancelableArg)
, m_propagationStopped(false)
}
Event::Event(const AtomicString& eventType, const EventInit& initializer)
- : m_type(eventType)
+ : m_isInitialized(true)
+ , m_type(eventType)
, m_canBubble(initializer.bubbles)
, m_cancelable(initializer.cancelable)
, m_propagationStopped(false)
if (dispatched())
return;
+ m_isInitialized = true;
m_propagationStopped = false;
m_immediatePropagationStopped = false;
m_defaultPrevented = false;
virtual ~Event();
void initEvent(const AtomicString& type, bool canBubble, bool cancelable);
+ bool isInitialized() const { return m_isInitialized; }
const AtomicString& type() const { return m_type; }
void setType(const AtomicString& type) { m_type = type; }
bool dispatched() const { return m_target; }
private:
+ bool m_isInitialized { false };
AtomicString m_type;
bool m_canBubble;
bool m_cancelable;
bool EventTarget::dispatchEvent(PassRefPtr<Event> event, ExceptionCode& ec)
{
- if (!event || event->type().isEmpty()) {
- ec = EventException::UNSPECIFIED_EVENT_TYPE_ERR;
+ if (!event) {
+ ec = TypeError;
return false;
}
- if (event->isBeingDispatched()) {
- ec = EventException::DISPATCH_REQUEST_ERR;
+ if (!event->isInitialized() || event->isBeingDispatched()) {
+ ec = INVALID_STATE_ERR;
return false;
}
bool EventTarget::fireEventListeners(Event* event)
{
ASSERT_WITH_SECURITY_IMPLICATION(!NoEventDispatchAssertion::isEventDispatchForbidden());
- ASSERT(event && !event->type().isEmpty());
+ ASSERT(event && event->isInitialized());
EventTargetData* d = eventTargetData();
if (!d)