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

Commit 5827031

Browse files
committed
Listeners added in the current dispatch should not get called
Fixes Polymer/polymer#511
1 parent 9d2bdaa commit 5827031

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

src/wrappers/events.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@
382382
targetTable.set(event, target);
383383
currentTargetTable.set(event, currentTarget);
384384

385-
for (var i = 0; i < listeners.length; i++) {
385+
for (var i = 0, len = listeners.length; i < len; i++) {
386386
var listener = listeners[i];
387387
if (listener.removed) {
388388
anyRemoved = true;

test/js/events.js

+34
Original file line numberDiff line numberDiff line change
@@ -1404,4 +1404,38 @@ test('retarget order (multiple shadow roots)', function() {
14041404
assert.equal(errorCount, 1);
14051405
});
14061406

1407+
test('add during dispatch', function() {
1408+
var div = document.createElement('div');
1409+
var fCount = 0;
1410+
var gCount = 0;
1411+
var hCount = 0;
1412+
1413+
function f() {
1414+
fCount++;
1415+
div.addEventListener('click', g);
1416+
}
1417+
1418+
function g() {
1419+
gCount++;
1420+
div.addEventListener('click', h);
1421+
}
1422+
1423+
function h() {
1424+
hCount++;
1425+
}
1426+
1427+
div.addEventListener('click', f);
1428+
1429+
div.click();
1430+
assert.equal(fCount, 1);
1431+
1432+
div.click();
1433+
assert.equal(fCount, 2);
1434+
assert.equal(gCount, 1);
1435+
1436+
div.click();
1437+
assert.equal(fCount, 3);
1438+
assert.equal(gCount, 2);
1439+
assert.equal(hCount, 1);
1440+
});
14071441
});

0 commit comments

Comments
 (0)