robnyman / domassistant

Automatically exported from code.google.com/p/domassistant
1 stars 0 forks source link

handleEvent fails if an eventHandler adds/removes eventHandlers to the same object #7

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Attach two click-handler to e.g. document.body
2. the first click-handler removes itself after it has been executed by calling 
$(this).removeEvent(argument.callee)
3. the second click-handler is never executed and an error is thrown: 
eventColl[i] is undefined.

What is the expected output? What do you see instead?
The second click-handler should be executed.

What version of the product are you using? On what operating system?
2.7, OS X

Please provide any additional information below.

The solution is quite easy: in the function handleEvent on line 1215 in file 
DOMAssistantComplete-2.7.js instead of

var eventColl = this.events[eventType];

you need to make a copy the event-handler array and run through the copy 
instead. Like so:

var eventColl = this.events[eventType].slice();

Running through a copy makes sure, if an event-handler removes itself, that it 
does not mix up 
with the index in the for-loop when executing all event-handlers.

Original issue reported on code.google.com by wif...@gmail.com on 16 May 2008 at 1:09

GoogleCodeExporter commented 9 years ago
The fix for this bug has now been committed and will show up in the next 
release of
DOMAssistant.

Thanks for reporting it!

Original comment by VoxPe...@gmail.com on 17 May 2008 at 9:07