Open Bug 1478710 Opened 6 years ago Updated 2 years ago

Firefox should warn when adding an object with no handleEvent function as an EventListener from JavaScript

Categories

(Core :: DOM: Core & HTML, defect, P3)

61 Branch
defect

Tracking

()

UNCONFIRMED

People

(Reporter: jason.bekolay, Unassigned)

Details

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36

Steps to reproduce:

Call addEventListener passing the an object with no handleEvent function as a the handler. Simple example - https://jsfiddle.net/rh162f8b/18/

In our actual application, we were passing undefined as the handler and a library we used was wrapping that in in an object and passing the wrapped object to addEventListener.


Actual results:

A TypeError with description "Property 'handleEvent' is not callable" is thrown when the event is triggered. However, nothing is logged the event listener is added. The error is not helpful as it gives no clue which event is triggering this and where the event listener was added.


Expected results:

Noting which element & event triggered the error in the description would be helpful.

Even better would be logging some type of warning when calling addEventListener with an object without handleEvent.
Component: Untriaged → Event Handling
Product: Firefox → Core
Component: Event Handling → DOM
Product: Core → DevTools

Hello @Honza

I am an Outreachy applicant and would like to try to solve this issue as my first contribution. Could you please assign me this bug? Thanks.

Thanks for the report!

This report is related to platform API and so I am changing the component.

Honza

Component: DOM → DOM: Events
Product: DevTools → Core

(In reply to ecarr3344 from comment #1)

Hello @Honza

I am an Outreachy applicant and would like to try to solve this issue as my first contribution. Could you please assign me this bug? Thanks.

I don't think this is good-first-bug related to my project, sorry.

Honza

I wonder if this is something we need to tackle in dom/binding ...
Can we please get some ideas/suggestions about how to resolve this for :E_Carr?

Flags: needinfo?(bugs)

Problem is that one can add handleEvent property to the object passed to addEventListener later, it doesn't need to be when listener is registered.

This is really bindings layer issue, if we want to improve error messages. We could get element localName/id or something like that to console when error is thrown.

Component: DOM: Events → DOM
Flags: needinfo?(bugs)
Priority: -- → P3
Component: DOM → DOM: Core & HTML
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.