cordova-js icon indicating copy to clipboard operation
cordova-js copied to clipboard

Handle event listener functions more gracefully

Open jpike88 opened this issue 3 years ago • 2 comments

Related issues: https://github.com/mapbox/mapbox-gl-js/issues/11433 https://github.com/ionic-team/capacitor/issues/4178

Platforms affected

Motivation and Context

Description

Testing

Checklist

  • [ ] I've run the tests to see all new and existing tests pass
  • [ ] I added automated test coverage as appropriate for this change
  • [ ] Commit is prefixed with (platform) if this change only applies to one platform (e.g. (android))
  • [ ] If this Pull Request resolves an issue, I linked to the issue in the text above (and used the correct keyword to close issues using keywords)
  • [ ] I've updated the documentation if necessary

jpike88 avatar Jan 24 '22 06:01 jpike88

Good catch!

However, I think we might have to handle truthy non-string arguments as well. window.addEventListener(1, () => {}) does not throw an error either (tested in Chrome). Unfortunately, I could not find anything on input validation of the type argument in https://dom.spec.whatwg.org/#ref-for-dom-eventtarget-addeventlistener%E2%91%A2

window.addEventListener(1, 2) complains about the second arg being no object.

It would be great if we knew the spec for this. Maybe we actually have to do something like evt = String(evt); instead. Like with object keys which are always converted to strings... :man_shrugging:

raphinesse avatar Jan 24 '22 13:01 raphinesse

Have modified implementation to more closely represent behaviour of the real thing. Turns out you can pass undefined as an argument, and it's a valid event label!

jpike88 avatar Jan 25 '22 03:01 jpike88

Just wondering why this was closed and what became of this? Was a fix merged?

gianlazz avatar Aug 19 '23 17:08 gianlazz