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.

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: http://svn.webkit.org/repository/webkit/trunk@189452 268f45cc-cd09-0410-ab3c-d52691b4dbfc
25 files changed