Skip to content

Dispatch event always set the event.target to the global object after dispatch #697

@pmdartus

Description

@pmdartus

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

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions