Fixing issues around XHR and event listeners.

* window.addEventListener can be called with this=null
* XMLHttpRequest.open needed to be called with apply

Fixes #213.