Skip to content

Commit

Permalink
Listeners added in the current dispatch should not get called
Browse files Browse the repository at this point in the history
  • Loading branch information
arv committed May 21, 2014
1 parent 9d2bdaa commit 5827031
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 5827031

Please sign in to comment.