Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EventTarget.addEventListener lacks a proper definition on how to handle invalid callback #405

Closed
denschub opened this issue Jan 31, 2017 · 5 comments

Comments

@denschub
Copy link

EventTarget.addEventListener specifies that browsers should terminate and ignore the call if the callback is null:

If callback is null, terminate these steps.

However, it's unclear about what should happen if the callback is not a function/not a callable.

Take the following source, which is clearly a misuse:

document.addEventListener("click", 42);

The callback is not null, so according to the spec, there is no reason to ignore the addEventListener call here. However, browsers behave different. In Chrome, the call simply gets ignored, acting as if the callback would be null. In Firefox, however, we throw an exception since a Number is not callable.

To avoid further issues and to make it easier for vendors to adjust their implementations, a note should be added to the spec, saying that the call should be terminated if the callback not callable.

@domenic
Copy link
Member

domenic commented Jan 31, 2017

That is governed by the Web IDL specification which is used to define the method.

@annevk
Copy link
Member

annevk commented Feb 1, 2017

Yeah, that would be a bug in Chrome. Could you please file one and leave a link here?

@denschub
Copy link
Author

Fill file a Chrome bug. Also, Safari Technology Preview also throws, so this is the way to go. I'll throw a link here to the Chrome report, but I'll close this issue nonetheless, since it is actually covered in the WebIDL (sorry, did miss that).

@denschub
Copy link
Author

Was already reported, see Chromium bug 676845.

@annevk
Copy link
Member

annevk commented Feb 27, 2017

Thanks @denschub!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants