tmpvar/jsdom — pull request #893 by eventualbuddha (2014-09-30 03:27:59+00:00)
Title: Correct the return value of EventTarget#dispatchEvent.

It appears that the return value of EventTarget#dispatchEvent is intended to be `true` if the default was *not* prevented. That is, `canceled = !target.dispatchEvent(event)`. In every browser I ran the following test and got the same thing, which is the opposite of what jsdom returned before this commit.

```js
> e = document.createEvent('UIEvents')
> e.initEvent('keydown', true, true)
> document.body.dispatchEvent(e)
true
> document.body.addEventListener('keydown', function(e){ e.preventDefault() })
> e = document.createEvent('UIEvents')
> e.initEvent('keydown', true, true)
> document.body.dispatchEvent(e)
false
```

Looking at the specs, I find evidence for this in the [spec for `dispatchEvent`][1], specifically 4.7.13:

> Return false if event's canceled flag is set, and true otherwise

The `canceled` flag is set by `preventDefault()` if `cancelable` is `true`.

Additionally, the web-platform-tests project has a [test for `dispatchEvent` that asserts that the return value is `true` when the event is not cancelable][2].

[1]: https://dom.spec.whatwg.org/#dom-eventtarget-dispatchevent
[2]: https://github.com/w3c/web-platform-tests/blob/04be7dd98aa106989948ac4e5d9cb7398e6a0d4d/dom/events/EventTarget-dispatchEvent.html#L36