Apache Cordova
  1. Apache Cordova
  2. CB-514

Do we need to monkey patch addEventListener()?

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Won't Fix
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: CordovaJS
    • Labels:
      None

      Description

      discussion here: http://markmail.org/message/mghdkbumdyjhmaye

      I noticed in cordova.js we override the following messages on window/document:

      document.addEventListener = function(evt, handler, capture) {...}
      window.addEventListener = function(evt, handler, capture) {...}
      document.removeEventListener = function(evt, handler, capture) {...}
      window.removeEventListener = function(evt, handler, capture) {...}
      

      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:

      event = document.createEvent('Events')
      event.initEvent(blah)
      
      window.dispatchEvent(event)
      // or document.dispatchEvent(event)
      

      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.

        Activity

        Filip Maj made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Won't Fix [ 2 ]
        Filip Maj made changes -
        Link This issue is related to CB-491 [ CB-491 ]
        Filip Maj made changes -
        Field Original Value New Value
        Link This issue is related to CB-491 [ CB-491 ]
        Patrick Mueller created issue -

          People

          • Assignee:
            Filip Maj
            Reporter:
            Patrick Mueller
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development