mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Correct an unsound optimization in event dispatch.
This commit is contained in:
parent
6cb43f213e
commit
3eaf1c1b89
3 changed files with 12 additions and 14 deletions
|
@ -112,19 +112,23 @@ pub fn dispatch_event(target: &EventTarget,
|
||||||
assert_eq!(event.phase(), EventPhase::None);
|
assert_eq!(event.phase(), EventPhase::None);
|
||||||
assert!(event.GetCurrentTarget().is_none());
|
assert!(event.GetCurrentTarget().is_none());
|
||||||
|
|
||||||
|
// Step 1.
|
||||||
|
event.mark_as_dispatching();
|
||||||
|
|
||||||
// Step 2.
|
// Step 2.
|
||||||
event.set_target(target_override.unwrap_or(target));
|
event.set_target(target_override.unwrap_or(target));
|
||||||
|
|
||||||
if event.stop_propagation() {
|
if event.stop_propagation() {
|
||||||
// If the event's stop propagation flag is set, we can skip everything because
|
// If the event's stop propagation flag is set, we can skip everything because
|
||||||
// it prevents the calls of the invoke algorithm in the spec and we asserted
|
// it prevents the calls of the invoke algorithm in the spec.
|
||||||
// at the beginning that steps 10-12 don't need to be executed.
|
|
||||||
|
// Step 10-12.
|
||||||
|
event.clear_dispatching_flags();
|
||||||
|
|
||||||
|
// Step 14.
|
||||||
return !event.DefaultPrevented();
|
return !event.DefaultPrevented();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 1. Postponed here for the reason stated above.
|
|
||||||
event.mark_as_dispatching();
|
|
||||||
|
|
||||||
// Step 3. The "invoke" algorithm is only used on `target` separately,
|
// Step 3. The "invoke" algorithm is only used on `target` separately,
|
||||||
// so we don't put it in the path.
|
// so we don't put it in the path.
|
||||||
rooted_vec!(let mut event_path);
|
rooted_vec!(let mut event_path);
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
[Event-propagation.html]
|
|
||||||
type: testharness
|
|
||||||
[After stopPropagation()]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[After stopImmediatePropagation()]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -11,6 +11,9 @@ function testPropagationFlag(ev, expected, desc) {
|
||||||
test(function() {
|
test(function() {
|
||||||
var called = false;
|
var called = false;
|
||||||
var callback = function() { called = true };
|
var callback = function() { called = true };
|
||||||
|
this.add_cleanup(function() {
|
||||||
|
document.head.removeEventListener("foo", callback)
|
||||||
|
});
|
||||||
document.head.addEventListener("foo", callback);
|
document.head.addEventListener("foo", callback);
|
||||||
document.head.dispatchEvent(ev);
|
document.head.dispatchEvent(ev);
|
||||||
assert_equals(called, expected, "Propagation flag");
|
assert_equals(called, expected, "Propagation flag");
|
||||||
|
@ -18,7 +21,6 @@ function testPropagationFlag(ev, expected, desc) {
|
||||||
// the event the second time around.
|
// the event the second time around.
|
||||||
document.head.dispatchEvent(ev);
|
document.head.dispatchEvent(ev);
|
||||||
assert_equals(called, true, "Propagation flag after first dispatch");
|
assert_equals(called, true, "Propagation flag after first dispatch");
|
||||||
document.head.removeEventListener("foo", callback);
|
|
||||||
}, desc);
|
}, desc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue