[dom] removeEventListener doesn't handle currently dispatching events (#84)

It seems like browsers remove an event listener even from the currently dispatched event listener list. Explaining it is kinda complicated, but here's a test which fails with an implementation that is (I hope) according to spec:
```js
    var es = [];
    var ls = [];
    var EventListener1 = function() { ls.push(this); }
    var EventListener2 = function() { ls.push(this); }
    EventListener1.prototype.handleEvent = function(event) { _handleEvent(event); }
    EventListener2.prototype.handleEvent = function(event) { _handleEvent(event); }
    var _handleEvent = function(event) {
      es.push(event);
      ls.forEach(function(l){
        event.currentTarget.removeEventListener("foo", l.handleEvent, false);
      })
    }
    // test
    var listener1 = new EventListener1();
    var listener2 = new EventListener2();
    document.addEventListener("foo", listener1.handleEvent, false);
    document.addEventListener("foo", listener2.handleEvent, false);
    var event = document.createEvent("Events");
    event.initEvent("foo",true,false);
    document.dispatchEvent(event);
    console.log(es.length); // returns 1 in Chrome + FF
```

So, both listeners remove themselves + the other listener, which seems to cause the currently dispatched event to only get to 1 listener since the other one is removed.

In [event listener invoke](https://dom.spec.whatwg.org/#concept-event-listener-invoke) the spec says to copy the event listener list, which should cause it to not be impacted by changes from removeEventListener (I'd assume).

---
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/issues/84

Received on Sunday, 27 September 2015 08:53:48 UTC