Closed Bug 563487 Opened 15 years ago Closed 15 years ago

removeEventListener fails when called before addEventListener

Categories

(Core :: DOM: Events, defect)

x86
Windows Vista
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla1.9.3a5

People

(Reporter: blakeyrat, Assigned: bzbarsky)

References

()

Details

Attachments

(1 file)

User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.19) Gecko/2010031422 Firefox/3.0.19 ( .NET CLR 3.5.30729) Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729) A call to removeEventListener during page load throws an exception if made before a call to addEventListener on the same object. Reproducible: Always Steps to Reproduce: 1. Write a Javascript that attempts to use removeEventListener before a cooresponding addEventListener 2. Add exception handling around the removeEventListener call 3. Load the page (see referenced URL) Actual Results: Firefox returns the following exception: [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIDOMEventTarget.removeEventListener]" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: http://schend.net/pages/removeEventHandler_bug.html :: :: line 18" data: no] Expected Results: No exception The specification (URL below) says nothing about requiring that addEventListener be called first. Therefore, I believe this is a bug in Firefox. http://www.w3.org/2003/01/dom2-javadoc/org/w3c/dom/events/EventTarget.html#removeEventListener_java.lang.String__org.w3c.dom.events.EventListener__boolean_ Workaround: When not certain whether addEventListener has been called before or not, wrap calls to removeEventListener in a try/catch block.
doesn't give an answer either way, so I would assume it's up to the implementor to deal with it how they see fit.
cancel previous comment, I'm a dumbass <Remco> <censored>: From the spec: "Calling removeEventListener with arguments which do not identify any currently registered EventListener on the EventTarget has no effect." <Remco> So it shouldn't throw an exception
Component: General → DOM: Events
Product: Firefox → Core
QA Contact: general → events
Attached patch FixSplinter Review
James, thank you very much for the clear bug report and the testcase!
Assignee: nobody → bzbarsky
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true
Attachment #443263 - Flags: review?(Olli.Pettay)
Attachment #443263 - Flags: review?(Olli.Pettay) → review+
Status: ASSIGNED → RESOLVED
Closed: 15 years ago
Flags: in-testsuite+
Resolution: --- → FIXED
Target Milestone: --- → mozilla1.9.3a5
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: