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

EventTarget listener exception handling appears to deviate from the WHATWG spec #38122

Closed
rs70 opened this issue Apr 7, 2021 · 1 comment
Closed
Labels
events Issues and PRs related to the events subsystem / EventEmitter.

Comments

@rs70
Copy link

rs70 commented Apr 7, 2021

  • Version:v15.14.0
  • Platform:Linux elara 5.4.0-70-generic Mani #78-Ubuntu SMP Fri Mar 19 13:29:52 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
  • Subsystem:events

What steps will reproduce the bug?

let t = new EventTarget();
t.addEventListener('foo', evt => { throw new Error("Error thrown by first listener"); });
t.addEventListener('foo', evt => console.log("Second listener received event:", evt));
t.dispatchEvent(new Event('foo'));
console.log("After dispatch");

How often does it reproduce? Is there a required condition?

Always.

What is the expected behavior?

Unless I'm missing something, both calls to console.log should execute. This is what happens in Chrome, Safari, and Firefox (while also calling out the unhandled exception, of course).

What do you see instead?

Node does not print either log message and appears to be allowing the exception to propagate all the way out of dispatchEvent.

Additional information

@Ayase-252 Ayase-252 added the events Issues and PRs related to the events subsystem / EventEmitter. label Apr 7, 2021
@aduh95
Copy link
Contributor

aduh95 commented Apr 7, 2021

This was fixed by #37237. Here's the output on Node.js 16.0.0-pre:

Second listener received event: Event {
  type: 'foo',
  defaultPrevented: false,
  cancelable: false,
  timeStamp: 179.45869708061218
}
After dispatch
node:internal/event_target:639
  process.nextTick(() => { throw err; });
                           ^

Error: Error thrown by first listener
    at EventTarget.<anonymous> (file://…/f.mjs:2:42)
    at EventTarget.[nodejs.internal.kHybridDispatch] (node:internal/event_target:459:20)
    at EventTarget.dispatchEvent (node:internal/event_target:407:26)
    at file://…/f.mjs:4:3
    at ModuleJob.run (node:internal/modules/esm/module_job:154:23)
    at async Loader.import (node:internal/modules/esm/loader:177:24)
    at async Object.loadESM (node:internal/process/esm_loader:68:5)

I'm closing as I think the problem is already fixed, don't hesitate to re-open if I missed something or if the behaviour is still not spec-compliant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
events Issues and PRs related to the events subsystem / EventEmitter.
Projects
None yet
Development

No branches or pull requests

3 participants