Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the handleEvent implementation doesn't seem to work #1182

Closed
GianlucaGuarini opened this issue Dec 22, 2023 · 0 comments · Fixed by #1270
Closed

the handleEvent implementation doesn't seem to work #1182

GianlucaGuarini opened this issue Dec 22, 2023 · 0 comments · Fixed by #1270
Labels
bug Something isn't working

Comments

@GianlucaGuarini
Copy link

Describe the bug
The handleEvent DOM implementation doesn't work properly. In the following example the simple click log gets called 100 times while the object handler implementation none.

To Reproduce
Run this code or check it online

const { GlobalRegistrator } = require('@happy-dom/global-registrator')

const log = console.log.bind(console)

GlobalRegistrator.register()

const handler = {
  handleEvent(event) {
    this[event.type](event);
  }
}

const div = document.createElement('div')

div.addEventListener('click', handler)
div.addEventListener('mouseup', handler)


div.addEventListener('click', () => log('simple click'))
div.addEventListener('mouseup', () => log('simple mouseup'))

handler.click = () => log('click from handler')
handler.mouseup = () => log('mouse up from handler')

div.dispatchEvent(new Event('click'))
div.dispatchEvent(new Event('mouseup'))

log('end')

Expected behavior
The DOM events should be properly fired only once

Device:

  • OS: Linux and Mac
  • Version 12.10.3
@GianlucaGuarini GianlucaGuarini added the bug Something isn't working label Dec 22, 2023
titouanmathis added a commit to titouanmathis/happy-dom that referenced this issue Feb 22, 2024
capricorn86 added a commit that referenced this issue Feb 26, 2024
fix: [#1182] The handleEvent method should be called with the listener scope
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant