Fix step 10 of eventdispatcher::dispatch_event (fixes #11609)

We consolidate steps 10-12 in a single function to expose less general-purpose
mutating methods on Event.
This commit is contained in:
Anthony Ramine 2016-08-24 13:45:34 +02:00
parent 9d32088116
commit 540fe15f17
3 changed files with 19 additions and 21 deletions

View file

@ -153,11 +153,6 @@ impl Event {
self.cancelable.set(cancelable);
}
#[inline]
pub fn clear_current_target(&self) {
self.current_target.set(None);
}
#[inline]
pub fn set_current_target(&self, val: &EventTarget) {
self.current_target.set(Some(val));
@ -199,8 +194,22 @@ impl Event {
}
#[inline]
pub fn set_dispatching(&self, val: bool) {
self.dispatching.set(val)
// https://dom.spec.whatwg.org/#concept-event-dispatch Step 1.
pub fn mark_as_dispatching(&self) {
assert!(!self.dispatching.get());
self.dispatching.set(true);
}
#[inline]
// https://dom.spec.whatwg.org/#concept-event-dispatch Steps 10-12.
pub fn clear_dispatching_flags(&self) {
assert!(self.dispatching.get());
self.dispatching.set(false);
self.stop_propagation.set(false);
self.stop_immediate.set(false);
self.set_phase(EventPhase::None);
self.current_target.set(None);
}
#[inline]

View file

@ -123,7 +123,7 @@ pub fn dispatch_event(target: &EventTarget,
}
// Step 1. Postponed here for the reason stated above.
event.set_dispatching(true);
event.mark_as_dispatching();
// Step 3. The "invoke" algorithm is only used on `target` separately,
// so we don't put it in the path.
@ -158,14 +158,8 @@ pub fn dispatch_event(target: &EventTarget,
None => {}
}
// Step 10.
event.set_dispatching(false);
// Step 11.
event.set_phase(EventPhase::None);
// Step 12.
event.clear_current_target();
// Step 10-12.
event.clear_dispatching_flags();
// Step 13.
!event.DefaultPrevented()

View file

@ -1,5 +0,0 @@
[Event-dispatch-multiple-stopPropagation.html]
type: testharness
[ Multiple dispatchEvent() and stopPropagation() ]
expected: FAIL