Fix emit events on 'window' and 'document' objects

This pull request fixes [#17332](https://bugs.dojotoolkit.org/ticket/17332).