Diff
Modified: trunk/LayoutTests/ChangeLog (90971 => 90972)
--- trunk/LayoutTests/ChangeLog 2011-07-14 02:16:54 UTC (rev 90971)
+++ trunk/LayoutTests/ChangeLog 2011-07-14 02:25:55 UTC (rev 90972)
@@ -1,3 +1,19 @@
+2011-07-12 Dominic Cooney <[email protected]>
+
+ Raise if dispatchEvent dispatches an event that is being dispatched
+ https://bugs.webkit.org/show_bug.cgi?id=64150
+
+ Reviewed by Dimitri Glazkov.
+
+ * fast/dom/Window/window-properties-expected.txt: Added DISPATCH_REQUEST_ERR.
+ * fast/events/dispatch-event-being-dispatched-expected.txt: Added.
+ * fast/events/dispatch-event-being-dispatched.html: Added.
+ * fast/workers/resources/worker-event-listener.js:
+ (onmessage): Redispatching the MessageEvent throws an exception now.
+ * platform/gtk/fast/dom/Window/window-properties-expected.txt:
+ * platform/qt-wk2/fast/dom/Window/window-properties-expected.txt:
+ * platform/qt/fast/dom/Window/window-properties-expected.txt:
+
2011-07-13 Kent Tamura <[email protected]>
Implement text field placeholders using shadow DOM
Modified: trunk/LayoutTests/fast/dom/Window/window-properties-expected.txt (90971 => 90972)
--- trunk/LayoutTests/fast/dom/Window/window-properties-expected.txt 2011-07-14 02:16:54 UTC (rev 90971)
+++ trunk/LayoutTests/fast/dom/Window/window-properties-expected.txt 2011-07-14 02:25:55 UTC (rev 90972)
@@ -935,8 +935,10 @@
window.Event.prototype.stopImmediatePropagation [function]
window.Event.prototype.stopPropagation [function]
window.EventException [object EventExceptionConstructor]
+window.EventException.DISPATCH_REQUEST_ERR [number]
window.EventException.UNSPECIFIED_EVENT_TYPE_ERR [number]
window.EventException.prototype [object EventExceptionPrototype]
+window.EventException.prototype.DISPATCH_REQUEST_ERR [number]
window.EventException.prototype.UNSPECIFIED_EVENT_TYPE_ERR [number]
window.EventException.prototype.toString [function]
window.EventSource [object EventSourceConstructor]
Added: trunk/LayoutTests/fast/events/dispatch-event-being-dispatched-expected.txt (0 => 90972)
--- trunk/LayoutTests/fast/events/dispatch-event-being-dispatched-expected.txt (rev 0)
+++ trunk/LayoutTests/fast/events/dispatch-event-being-dispatched-expected.txt 2011-07-14 02:25:55 UTC (rev 90972)
@@ -0,0 +1,11 @@
+Tests that dispatchEvent raises DISPATCH_REQUEST_ERR if the event being dispatched is already being dispatched.
+
+PASS should have got DISPATCH_REQUEST_ERR EventException
+PASS redispatchCustom.wasInvoked is true
+PASS should have got DISPATCH_REQUEST_ERR EventException
+PASS checkCustom.wasInvoked is true
+PASS should have got DISPATCH_REQUEST_ERR EventException
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/fast/events/dispatch-event-being-dispatched.html (0 => 90972)
--- trunk/LayoutTests/fast/events/dispatch-event-being-dispatched.html (rev 0)
+++ trunk/LayoutTests/fast/events/dispatch-event-being-dispatched.html 2011-07-14 02:25:55 UTC (rev 90972)
@@ -0,0 +1,84 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+</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>
+if (window.layoutTestController)
+ layoutTestController.dumpAsText();
+
+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
+
+function redispatchCustom(event) {
+ try {
+ window.dispatchEvent(event);
+ testFailed('dispatchEvent of an event being dispatched should throw an exception');
+ } catch (ex) {
+ shouldBeDispatchRequestErr(ex);
+ }
+
+ redispatchCustom.wasInvoked = true;
+}
+
+var customEvent = document.createEvent('CustomEvent');
+customEvent.initCustomEvent('foo', true, true, null);
+var p = document.querySelector('.description');
+p.addEventListener('foo', redispatchCustom);
+p.dispatchEvent(customEvent);
+shouldBeTrue('redispatchCustom.wasInvoked');
+
+// try redispatching an event that has already finished being dispatched
+
+function checkCustom(event) {
+ checkCustom.wasInvoked = true;
+}
+
+p.removeEventListener('foo', redispatchCustom, true);
+p.addEventListener('foo', checkCustom, true);
+p.dispatchEvent(customEvent);
+shouldBeTrue('checkCustom.wasInvoked');
+
+// try redispatching an event in the process of being dispatched by
+// the browser
+
+function redispatchLoad(event) {
+ if (redispatchLoad.dispatching) {
+ testFailed('dispatchEvent of an event being dispatched should not dispatch the event again');
+ 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;
+ }
+
+ finishJSTest();
+}
+
+window.addEventListener('load', redispatchLoad, true);
+
+var successfullyParsed = true;
+</script>
+<script src=""
+</body>
+</html>
Modified: trunk/LayoutTests/fast/workers/resources/worker-event-listener.js (90971 => 90972)
--- trunk/LayoutTests/fast/workers/resources/worker-event-listener.js 2011-07-14 02:16:54 UTC (rev 90971)
+++ trunk/LayoutTests/fast/workers/resources/worker-event-listener.js 2011-07-14 02:25:55 UTC (rev 90972)
@@ -7,14 +7,7 @@
function onmessage(evt)
{
- try {
- removeEventListener("message", onmessage, true);
- addEventListener("message", function(e) { e.foo = "bar" }, true);
- dispatchEvent(evt);
- postMessage((evt.foo == "bar") ? "SUCCESS" : "FAIL");
- } catch (ex) {
- postMessage(ex);
- }
+ postMessage("SUCCESS");
}
addEventListener("message", onmessage, true);
Modified: trunk/LayoutTests/platform/gtk/fast/dom/Window/window-properties-expected.txt (90971 => 90972)
--- trunk/LayoutTests/platform/gtk/fast/dom/Window/window-properties-expected.txt 2011-07-14 02:16:54 UTC (rev 90971)
+++ trunk/LayoutTests/platform/gtk/fast/dom/Window/window-properties-expected.txt 2011-07-14 02:25:55 UTC (rev 90972)
@@ -935,8 +935,10 @@
window.Event.prototype.stopImmediatePropagation [function]
window.Event.prototype.stopPropagation [function]
window.EventException [object EventExceptionConstructor]
+window.EventException.DISPATCH_REQUEST_ERR [number]
window.EventException.UNSPECIFIED_EVENT_TYPE_ERR [number]
window.EventException.prototype [object EventExceptionPrototype]
+window.EventException.prototype.DISPATCH_REQUEST_ERR [number]
window.EventException.prototype.UNSPECIFIED_EVENT_TYPE_ERR [number]
window.EventException.prototype.toString [function]
window.EventSource [object EventSourceConstructor]
Modified: trunk/LayoutTests/platform/qt/fast/dom/Window/window-properties-expected.txt (90971 => 90972)
--- trunk/LayoutTests/platform/qt/fast/dom/Window/window-properties-expected.txt 2011-07-14 02:16:54 UTC (rev 90971)
+++ trunk/LayoutTests/platform/qt/fast/dom/Window/window-properties-expected.txt 2011-07-14 02:25:55 UTC (rev 90972)
@@ -931,8 +931,10 @@
window.Event.prototype.stopImmediatePropagation [function]
window.Event.prototype.stopPropagation [function]
window.EventException [object EventExceptionConstructor]
+window.EventException.DISPATCH_REQUEST_ERR [number]
window.EventException.UNSPECIFIED_EVENT_TYPE_ERR [number]
window.EventException.prototype [object EventExceptionPrototype]
+window.EventException.prototype.DISPATCH_REQUEST_ERR [number]
window.EventException.prototype.UNSPECIFIED_EVENT_TYPE_ERR [number]
window.EventException.prototype.toString [function]
window.EventSource [object EventSourceConstructor]
Modified: trunk/LayoutTests/platform/qt-wk2/fast/dom/Window/window-properties-expected.txt (90971 => 90972)
--- trunk/LayoutTests/platform/qt-wk2/fast/dom/Window/window-properties-expected.txt 2011-07-14 02:16:54 UTC (rev 90971)
+++ trunk/LayoutTests/platform/qt-wk2/fast/dom/Window/window-properties-expected.txt 2011-07-14 02:25:55 UTC (rev 90972)
@@ -931,8 +931,10 @@
window.Event.prototype.stopImmediatePropagation [function]
window.Event.prototype.stopPropagation [function]
window.EventException [object EventExceptionConstructor]
+window.EventException.DISPATCH_REQUEST_ERR [number]
window.EventException.UNSPECIFIED_EVENT_TYPE_ERR [number]
window.EventException.prototype [object EventExceptionPrototype]
+window.EventException.prototype.DISPATCH_REQUEST_ERR [number]
window.EventException.prototype.UNSPECIFIED_EVENT_TYPE_ERR [number]
window.EventException.prototype.toString [function]
window.EventSource [object EventSourceConstructor]
Modified: trunk/Source/WebCore/ChangeLog (90971 => 90972)
--- trunk/Source/WebCore/ChangeLog 2011-07-14 02:16:54 UTC (rev 90971)
+++ trunk/Source/WebCore/ChangeLog 2011-07-14 02:25:55 UTC (rev 90972)
@@ -1,3 +1,22 @@
+2011-07-12 Dominic Cooney <[email protected]>
+
+ Raise if dispatchEvent dispatches an event that is being dispatched
+ https://bugs.webkit.org/show_bug.cgi?id=64150
+
+ Reviewed by Dimitri Glazkov.
+
+ Spec: http://www.w3.org/TR/DOM-Level-3-Events/#events-EventTarget-dispatchEvent
+
+ Test: fast/events/dispatch-event-being-dispatched.html
+
+ * dom/Event.h:
+ (WebCore::Event::isBeingDispatched): Added.
+ * dom/EventException.h:
+ * dom/EventException.idl: Add DISPATCH_REQUEST_ERR.
+ * dom/EventTarget.cpp:
+ (WebCore::EventTarget::dispatchEvent): Raise if being dispatched.
+ * dom/ExceptionCode.cpp: Add gunk for DISPATCH_REQUEST_ERR.
+
2011-07-13 Kent Tamura <[email protected]>
Implement text field placeholders using shadow DOM
Modified: trunk/Source/WebCore/dom/Event.h (90971 => 90972)
--- trunk/Source/WebCore/dom/Event.h 2011-07-14 02:16:54 UTC (rev 90971)
+++ trunk/Source/WebCore/dom/Event.h 2011-07-14 02:25:55 UTC (rev 90972)
@@ -171,6 +171,7 @@
virtual Clipboard* clipboard() const { return 0; }
+ bool isBeingDispatched() const { return eventPhase(); }
protected:
Event();
Modified: trunk/Source/WebCore/dom/EventException.h (90971 => 90972)
--- trunk/Source/WebCore/dom/EventException.h 2011-07-14 02:16:54 UTC (rev 90971)
+++ trunk/Source/WebCore/dom/EventException.h 2011-07-14 02:25:55 UTC (rev 90972)
@@ -44,7 +44,8 @@
static const int EventExceptionMax = 199;
enum EventExceptionCode {
- UNSPECIFIED_EVENT_TYPE_ERR = EventExceptionOffset
+ UNSPECIFIED_EVENT_TYPE_ERR = EventExceptionOffset,
+ DISPATCH_REQUEST_ERR
};
private:
Modified: trunk/Source/WebCore/dom/EventException.idl (90971 => 90972)
--- trunk/Source/WebCore/dom/EventException.idl 2011-07-14 02:16:54 UTC (rev 90971)
+++ trunk/Source/WebCore/dom/EventException.idl 2011-07-14 02:25:55 UTC (rev 90972)
@@ -45,7 +45,7 @@
// EventExceptionCode
const unsigned short UNSPECIFIED_EVENT_TYPE_ERR = 0;
-
+ const unsigned short DISPATCH_REQUEST_ERR = 1;
};
}
Modified: trunk/Source/WebCore/dom/EventTarget.cpp (90971 => 90972)
--- trunk/Source/WebCore/dom/EventTarget.cpp 2011-07-14 02:16:54 UTC (rev 90971)
+++ trunk/Source/WebCore/dom/EventTarget.cpp 2011-07-14 02:25:55 UTC (rev 90972)
@@ -326,6 +326,11 @@
return false;
}
+ if (event->isBeingDispatched()) {
+ ec = EventException::DISPATCH_REQUEST_ERR;
+ return false;
+ }
+
if (!scriptExecutionContext())
return false;
@@ -337,7 +342,9 @@
event->setTarget(this);
event->setCurrentTarget(this);
event->setEventPhase(Event::AT_TARGET);
- return fireEventListeners(event.get());
+ bool defaultPrevented = fireEventListeners(event.get());
+ event->setEventPhase(0);
+ return defaultPrevented;
}
void EventTarget::uncaughtExceptionInEventHandler()
@@ -447,4 +454,3 @@
}
} // namespace WebCore
-
Modified: trunk/Source/WebCore/dom/ExceptionCode.cpp (90971 => 90972)
--- trunk/Source/WebCore/dom/ExceptionCode.cpp 2011-07-14 02:16:54 UTC (rev 90971)
+++ trunk/Source/WebCore/dom/ExceptionCode.cpp 2011-07-14 02:25:55 UTC (rev 90972)
@@ -112,11 +112,13 @@
};
static const char* const eventExceptionNames[] = {
- "UNSPECIFIED_EVENT_TYPE_ERR"
+ "UNSPECIFIED_EVENT_TYPE_ERR",
+ "DISPATCH_REQUEST_ERR"
};
static const char* const eventExceptionDescriptions[] = {
- "The Event's type was not specified by initializing the event before the method was called."
+ "The Event's type was not specified by initializing the event before the method was called.",
+ "The Event object is already being dispatched."
};
static const char* const xmlHttpRequestExceptionNames[] = {