Closed Bug 1072477 Opened 7 years ago Closed 7 years ago

EventTarget shim doesn't work if event listeners are removed while they are running

Categories

(Firefox :: Extension Compatibility, defect)

34 Branch
x86_64
Linux
defect
Not set
normal

Tracking

()

RESOLVED FIXED
Firefox 35

People

(Reporter: billm, Assigned: billm)

Details

Attachments

(1 file)

I found this bug while writing the tests in bug 1072467. When the EventTarget shim is running listeners, it just iterates over them. This can break if one of the listeners calls removeEventListener. Here's what happens:

listeners = [#1, #2]
start running listener #1 at index 0
listener #1 removes itself
listeners = [#2]
in the next loop iteration, we try to run index 1 but it doesn't exist, so we stop, missing listener #2

The obvious fix is to copy the list before running the listeners.
Attachment #8494697 - Flags: review?(wmccloskey)
Comment on attachment 8494697 [details] [diff] [review]
fix-shim-listener-removal

Not sure how I did that.
Attachment #8494697 - Flags: review?(wmccloskey) → review?(mconley)
Comment on attachment 8494697 [details] [diff] [review]
fix-shim-listener-removal

Review of attachment 8494697 [details] [diff] [review]:
-----------------------------------------------------------------

LGTM - thanks billm.
Attachment #8494697 - Flags: review?(mconley) → review+
https://hg.mozilla.org/mozilla-central/rev/34a233a0e4ff
Status: NEW → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 35
You need to log in before you can comment on or make changes to this bug.