0
Fork 0
mirror of https://github.com/fastmail/Squire.git synced 2024-12-22 07:13:08 -05:00

Support add/removing listeners whilst firing event

If you removed an event listener whilst it was being fired, this would alter the
list of handlers, which would cause the fireEvent function to read past the end
of the array (and to skip the next listener). Now, we clone the array of
listeners before firing, so adding/removing listeners has no effect on an
already firing event.
This commit is contained in:
Neil Jenkins 2013-05-24 14:02:12 +10:00
parent 87c0f3fbe1
commit 946afc9a17
3 changed files with 5 additions and 1 deletions

View file

@ -1159,6 +1159,8 @@ var fireEvent = function ( type, event ) {
if ( event.type !== type ) {
event.type = type;
}
// Clone handlers array, so any handlers added/removed do not affect it.
handlers = handlers.slice();
for ( i = 0, l = handlers.length; i < l; i += 1 ) {
obj = handlers[i];
try {

File diff suppressed because one or more lines are too long

View file

@ -75,6 +75,8 @@ var fireEvent = function ( type, event ) {
if ( event.type !== type ) {
event.type = type;
}
// Clone handlers array, so any handlers added/removed do not affect it.
handlers = handlers.slice();
for ( i = 0, l = handlers.length; i < l; i += 1 ) {
obj = handlers[i];
try {