| Differences between
and this patch
- a/LayoutTests/ChangeLog +10 lines
Lines 1-3 a/LayoutTests/ChangeLog_sec1
1
2011-07-07  Dominic Cooney  <dominicc@chromium.org>
2
3
        Raise if dispatchEvent dispatches an event that is being dispatched
4
        https://bugs.webkit.org/show_bug.cgi?id=64150
5
6
        Reviewed by NOBODY (OOPS!).
7
8
        * fast/events/dispatch-event-being-dispatched.html: Added.
9
        * fast/events/dispatch-event-being-dispatched-expected.txt: Added.
10
1
2011-07-07  Kent Tamura  <tkent@chromium.org>
11
2011-07-07  Kent Tamura  <tkent@chromium.org>
2
12
3
        [Chromium] Update baseline files for input-appearance-range.html.
13
        [Chromium] Update baseline files for input-appearance-range.html.
- a/LayoutTests/fast/events/dispatch-event-being-dispatched-expected.txt +11 lines
Line 0 a/LayoutTests/fast/events/dispatch-event-being-dispatched-expected.txt_sec1
1
Tests that dispatchEvent raises DISPATCH_REQUEST_ERR if the event being dispatched is already being dispatched.
2
3
PASS should have got DISPATCH_REQUEST_ERR EventException
4
PASS redispatchCustom.wasInvoked is true
5
PASS should have got DISPATCH_REQUEST_ERR EventException
6
PASS checkCustom.wasInvoked is true
7
PASS should have got DISPATCH_REQUEST_ERR EventException
8
PASS successfullyParsed is true
9
10
TEST COMPLETE
11
- a/LayoutTests/fast/events/dispatch-event-being-dispatched.html +84 lines
Line 0 a/LayoutTests/fast/events/dispatch-event-being-dispatched.html_sec1
1
<!DOCTYPE html>
2
<html>
3
<head>
4
<script src="../js/resources/js-test-pre.js"></script>
5
</head>
6
<body>
7
<p class="description">
8
Tests that dispatchEvent raises DISPATCH_REQUEST_ERR if the event
9
being dispatched is already being dispatched.
10
</p>
11
<pre id="console">
12
</pre>
13
<script>
14
if (window.layoutTestController)
15
    layoutTestController.dumpAsText();
16
17
jsTestIsAsync = true;
18
19
function shouldBeDispatchRequestErr(exception) {
20
    var ok = EventException.prototype.isPrototypeOf(exception) && exception.code == EventException.DISPATCH_REQUEST_ERR;
21
    (ok ? testPassed : testFailed)("should have got DISPATCH_REQUEST_ERR EventException");
22
}
23
24
// try redispatching an event in the process of being dispatched with
25
// dispatchEvent
26
27
function redispatchCustom(event) {
28
    try {
29
        window.dispatchEvent(event);
30
        testFailed('dispatchEvent of an event being dispatched should throw an exception');
31
    } catch (ex) {
32
        shouldBeDispatchRequestErr(ex);
33
    }
34
35
    redispatchCustom.wasInvoked = true;
36
}
37
38
var customEvent = document.createEvent('CustomEvent');
39
customEvent.initCustomEvent('foo', true, true, null);
40
var p = document.querySelector('.description');
41
p.addEventListener('foo', redispatchCustom);
42
p.dispatchEvent(customEvent);
43
shouldBeTrue('redispatchCustom.wasInvoked');
44
45
// try redispatching an event that has already finished being dispatched
46
47
function checkCustom(event) {
48
    checkCustom.wasInvoked = true;
49
}
50
51
p.removeEventListener('foo', redispatchCustom, true);
52
p.addEventListener('foo', checkCustom, true);
53
p.dispatchEvent(customEvent);
54
shouldBeTrue('checkCustom.wasInvoked');
55
56
// try redispatching an event in the process of being dispatched by
57
// the browser
58
59
function redispatchLoad(event) {
60
    if (redispatchLoad.dispatching) {
61
        testFailed('dispatchEvent of an event being dispatched should not dispatch the event again');
62
        return;
63
    }
64
65
    try {
66
        redispatchLoad.dispatching = true;
67
        document.dispatchEvent(event);
68
        testFailed('dispatchEvent of an event being dispatched should throw an exception');
69
    } catch (ex) {
70
        shouldBeDispatchRequestErr(ex);
71
    } finally {
72
        delete redispatchLoad.dispatching;
73
    }
74
75
    finishJSTest();
76
}
77
78
window.addEventListener('load', redispatchLoad, true);
79
80
var successfullyParsed = true;
81
</script>
82
<script src="../js/resources/js-test-post.js"></script>
83
</body>
84
</html>
- a/Source/WebCore/ChangeLog +23 lines
Lines 1-3 a/Source/WebCore/ChangeLog_sec1
1
2011-07-07  Dominic Cooney  <dominicc@chromium.org>
2
3
        Raise if dispatchEvent dispatches an event that is being dispatched
4
        https://bugs.webkit.org/show_bug.cgi?id=64150
5
6
        Reviewed by NOBODY (OOPS!).
7
8
        Test: fast/events/dispatch-event-being-dispatched.html
9
10
        * dom/Event.cpp:
11
        (WebCore::Event::Event): Flag whether dispatch is in progress.
12
        * dom/Event.h:
13
        (WebCore::Event::isBeingDispatched): Added.
14
        (WebCore::EventDispatchScope::EventDispatchScope): Set/clear flag.
15
        (WebCore::EventDispatchScope::~EventDispatchScope):
16
        * dom/EventDispatcher.cpp:
17
        (WebCore::EventDispatcher::dispatchEvent): Use an event dispatch scope.
18
        * dom/EventException.h:
19
        * dom/EventException.idl:
20
        * dom/EventTarget.cpp:
21
        (WebCore::EventTarget::dispatchEvent): Raise if dispatch under way.
22
        * dom/ExceptionCode.cpp:
23
1
2011-07-07  Emil A Eklund  <eae@chromium.org>
24
2011-07-07  Emil A Eklund  <eae@chromium.org>
2
25
3
        Switch HitTestResult to to new layout types
26
        Switch HitTestResult to to new layout types
- a/Source/WebCore/dom/Event.cpp +1 lines
Lines 42-47 Event::Event() a/Source/WebCore/dom/Event.cpp_sec1
42
    , m_eventPhase(0)
42
    , m_eventPhase(0)
43
    , m_currentTarget(0)
43
    , m_currentTarget(0)
44
    , m_createTime(convertSecondsToDOMTimeStamp(currentTime()))
44
    , m_createTime(convertSecondsToDOMTimeStamp(currentTime()))
45
    , m_dispatchDepth(0)
45
{
46
{
46
}
47
}
47
48
- a/Source/WebCore/dom/Event.h +22 lines
Lines 171-176 namespace WebCore { a/Source/WebCore/dom/Event.h_sec1
171
171
172
        virtual Clipboard* clipboard() const { return 0; }
172
        virtual Clipboard* clipboard() const { return 0; }
173
173
174
        bool isBeingDispatched() const { return m_dispatchDepth > 0; }
174
175
175
    protected:
176
    protected:
176
        Event();
177
        Event();
Lines 194-201 namespace WebCore { a/Source/WebCore/dom/Event.h_sec2
194
        EventTarget* m_currentTarget;
195
        EventTarget* m_currentTarget;
195
        RefPtr<EventTarget> m_target;
196
        RefPtr<EventTarget> m_target;
196
        DOMTimeStamp m_createTime;
197
        DOMTimeStamp m_createTime;
198
        int m_dispatchDepth;
197
199
198
        RefPtr<Event> m_underlyingEvent;
200
        RefPtr<Event> m_underlyingEvent;
201
202
        friend class EventDispatchScope;
199
    };
203
    };
200
204
201
class EventDispatchMediator {
205
class EventDispatchMediator {
Lines 229-234 inline void EventDispatchMediator::setEvent(PassRefPtr<Event> event) a/Source/WebCore/dom/Event.h_sec3
229
    m_event = event;
233
    m_event = event;
230
}
234
}
231
235
236
class EventDispatchScope {
237
public:
238
    explicit EventDispatchScope(Event* event) : m_event(event)
239
    {
240
        m_event->m_dispatchDepth++;
241
    }
242
243
    ~EventDispatchScope()
244
    {
245
        m_event->m_dispatchDepth--;
246
    }
247
248
private:
249
    EventDispatchScope(const EventDispatchScope&);
250
251
    Event* m_event;
252
};
253
232
} // namespace WebCore
254
} // namespace WebCore
233
255
234
#endif // Event_h
256
#endif // Event_h
- a/Source/WebCore/dom/EventDispatcher.cpp +1 lines
Lines 280-285 void EventDispatcher::ensureEventAncestors(Event* event) a/Source/WebCore/dom/EventDispatcher.cpp_sec1
280
280
281
bool EventDispatcher::dispatchEvent(PassRefPtr<Event> event)
281
bool EventDispatcher::dispatchEvent(PassRefPtr<Event> event)
282
{
282
{
283
    EventDispatchScope dispatchScope(event.get());
283
    event->setTarget(eventTargetRespectingSVGTargetRules(m_node.get()));
284
    event->setTarget(eventTargetRespectingSVGTargetRules(m_node.get()));
284
285
285
    ASSERT(!eventDispatchForbidden());
286
    ASSERT(!eventDispatchForbidden());
- a/Source/WebCore/dom/EventException.h -1 / +2 lines
Lines 44-50 namespace WebCore { a/Source/WebCore/dom/EventException.h_sec1
44
        static const int EventExceptionMax = 199;
44
        static const int EventExceptionMax = 199;
45
45
46
        enum EventExceptionCode {
46
        enum EventExceptionCode {
47
            UNSPECIFIED_EVENT_TYPE_ERR = EventExceptionOffset
47
            UNSPECIFIED_EVENT_TYPE_ERR = EventExceptionOffset,
48
            DISPATCH_REQUEST_ERR
48
        };
49
        };
49
50
50
    private:
51
    private:
- a/Source/WebCore/dom/EventException.idl -1 / +1 lines
Lines 45-51 module events { a/Source/WebCore/dom/EventException.idl_sec1
45
45
46
        // EventExceptionCode
46
        // EventExceptionCode
47
        const unsigned short UNSPECIFIED_EVENT_TYPE_ERR = 0;
47
        const unsigned short UNSPECIFIED_EVENT_TYPE_ERR = 0;
48
48
        const unsigned short DISPATCH_REQUEST_ERR = 1;
49
    };
49
    };
50
50
51
}
51
}
- a/Source/WebCore/dom/EventTarget.cpp -1 / +5 lines
Lines 326-331 bool EventTarget::dispatchEvent(PassRefPtr<Event> event, ExceptionCode& ec) a/Source/WebCore/dom/EventTarget.cpp_sec1
326
        return false;
326
        return false;
327
    }
327
    }
328
328
329
    if (event->isBeingDispatched()) {
330
        ec = EventException::DISPATCH_REQUEST_ERR;
331
        return false;
332
    }
333
329
    if (!scriptExecutionContext())
334
    if (!scriptExecutionContext())
330
        return false;
335
        return false;
331
336
Lines 447-450 EventListener* EventListenerIterator::nextListener() a/Source/WebCore/dom/EventTarget.cpp_sec2
447
}
452
}
448
453
449
} // namespace WebCore
454
} // namespace WebCore
450
- a/Source/WebCore/dom/ExceptionCode.cpp -2 / +4 lines
Lines 112-122 static const char* const rangeExceptionDescriptions[] = { a/Source/WebCore/dom/ExceptionCode.cpp_sec1
112
};
112
};
113
113
114
static const char* const eventExceptionNames[] = {
114
static const char* const eventExceptionNames[] = {
115
    "UNSPECIFIED_EVENT_TYPE_ERR"
115
    "UNSPECIFIED_EVENT_TYPE_ERR",
116
    "DISPATCH_REQUEST_ERR"
116
};
117
};
117
118
118
static const char* const eventExceptionDescriptions[] = {
119
static const char* const eventExceptionDescriptions[] = {
119
    "The Event's type was not specified by initializing the event before the method was called."
120
    "The Event's type was not specified by initializing the event before the method was called.",
121
    "The Event object is already being dispatched."
120
};
122
};
121
123
122
static const char* const xmlHttpRequestExceptionNames[] = {
124
static const char* const xmlHttpRequestExceptionNames[] = {

Return to Bug 64150