cordova-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Patrick Mueller (JIRA)" <>
Subject [jira] [Commented] (CB-514) Do we need to monkey patch addEventListener()?
Date Wed, 02 May 2012 22:16:50 GMT


Patrick Mueller commented on CB-514:

That's unfortunate.  Thanks for the links.

Not really clear to me if we *need* to do all this counting in all the cases, but it seems
likely that even if we could fix them *all* now, we'd find another one next week.

We should at least add a comment in the source where we're monkey patching, as to why.

There is a bit of silver lining.  When you wrap handlers like this, you can provide extra
behavior, like logging, catching/reporting exceptions, etc.
> Do we need to monkey patch addEventListener()?
> ----------------------------------------------
>                 Key: CB-514
>                 URL:
>             Project: Apache Callback
>          Issue Type: Bug
>          Components: CordovaJS
>            Reporter: Patrick Mueller
>            Assignee: Filip Maj
> discussion here:
> I noticed in cordova.js we override the following messages on window/document:
> {noformat}
> document.addEventListener = function(evt, handler, capture) {...}
> window.addEventListener = function(evt, handler, capture) {...}
> document.removeEventListener = function(evt, handler, capture) {...}
> window.removeEventListener = function(evt, handler, capture) {...}
> {noformat}
> aka as "monkey patching".  
> Apparently, we aren't sure why we're doing this.  My guess is that we've done this in
the past when dispatching user-land events wasn't possible, and so trapping listeners was
the only way to get the listeners so you could send them events.
> It would be nice to remove this monkey patching, if we can, by using:
> {noformat}
> event = document.createEvent('Events')
> event.initEvent(blah)
> window.dispatchEvent(event)
> // or document.dispatchEvent(event)
> {noformat}
> We'll need to figure out if this works on all our platforms.  Even if it doesn't work
on all of them, I think we should only use monkey patching on platforms that we have to.

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:!default.jspa
For more information on JIRA, see:


View raw message