[whatwg/dom] EventTarget.addEventListener lacks a proper definition on how to handle invalid callback (#405)

`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:

```js
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.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/issues/405

Received on Tuesday, 31 January 2017 23:00:43 UTC