Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Commit

Permalink
Merge pull request #440 from arv/listener-add-during-dispatch
Browse files Browse the repository at this point in the history
Listeners added in the current dispatch should not get called
  • Loading branch information
dfreedm committed May 23, 2014
2 parents 41b5434 + 5827031 commit d110a12
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/wrappers/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@
targetTable.set(event, target);
currentTargetTable.set(event, currentTarget);

for (var i = 0; i < listeners.length; i++) {
for (var i = 0, len = listeners.length; i < len; i++) {
var listener = listeners[i];
if (listener.removed) {
anyRemoved = true;
Expand Down
34 changes: 34 additions & 0 deletions test/js/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -1404,4 +1404,38 @@ test('retarget order (multiple shadow roots)', function() {
assert.equal(errorCount, 1);
});

test('add during dispatch', function() {
var div = document.createElement('div');
var fCount = 0;
var gCount = 0;
var hCount = 0;

function f() {
fCount++;
div.addEventListener('click', g);
}

function g() {
gCount++;
div.addEventListener('click', h);
}

function h() {
hCount++;
}

div.addEventListener('click', f);

div.click();
assert.equal(fCount, 1);

div.click();
assert.equal(fCount, 2);
assert.equal(gCount, 1);

div.click();
assert.equal(fCount, 3);
assert.equal(gCount, 2);
assert.equal(hCount, 1);
});
});

0 comments on commit d110a12

Please sign in to comment.