[whatwg/dom] Dispatch event always set the event.target to the global object after dispatch (#697)

https://dom.spec.whatwg.org/commit-snapshots/42d2485c4f84fb210452ca53e07503229716b147/#dispatching-events


> If parent is a node and target’s root is a shadow\-including inclusive ancestor of parent, then:​

When walking up the parent chain and *parent* is the global object, instead of going through the (5.9.6) branch of the algorithm it goes through the (5.9.8) branch. The last tuple of all the event path, would always have it's `target` set to the global object. Because of this, after being dispatched the `event.target` is always the global object.

The following test fails: [Event-defaultPrevented-after-dispatch.html](https://github.com/web-platform-tests/wpt/blob/master/dom/events/Event-defaultPrevented-after-dispatch.html)

```js
test(function() {
    var EVENT = "foo";
    var TARGET = document.getElementById("target");
    var evt = document.createEvent("Event");
    evt.initEvent(EVENT, true, true);

    TARGET.addEventListener(EVENT, this.step_func(function(e) {
  // <-- OK: event.target === TARGET
        e.preventDefault();
        assert_true(e.defaultPrevented, "during dispatch");
    }), true);
    TARGET.dispatchEvent(evt);

    assert_true(evt.defaultPrevented, "after dispatch");
    assert_equals(evt.target, TARGET); // <-- FAILS: event.target === window
    assert_equals(evt.srcElement, TARGET);
}, "Default prevention via preventDefault");
```

In order to get around this issue the 5.9.6 should also check if *parent* is the *global object*.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/issues/697

Received on Saturday, 15 September 2018 16:18:49 UTC