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 dispatchEvent cannot be called with an object, contrary to what is stated in the docs #39125

Closed
aral opened this issue Jun 23, 2021 · 3 comments · Fixed by #39127
Closed
Labels
doc Issues and PRs related to the documentations. events Issues and PRs related to the events subsystem / EventEmitter. good first issue Issues that are suitable for first-time contributors.

Comments

@aral
Copy link

aral commented Jun 23, 2021

  • Version: 16.4.0
  • Platform: Linux
  • Subsystem: n/a

What steps will reproduce the bug?

const e = new EventTarget()
e.dispatchEvent({type: 'something'})

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

Always.

What is the expected behavior?

According to the docs, it should work.

event <Object> | <Event>

Dispatches the event to the list of handlers for event.type. The event may be an Event object or any object with a type property whose value is a string.

https://nodejs.org/api/events.html#events_eventtarget_dispatchevent_event

What do you see instead?

TypeError [ERR_INVALID_ARG_TYPE]: The "event" argument must be an instance of Event. Received an instance of Object
    at new NodeError (node:internal/errors:363:5)
    at EventTarget.dispatchEvent (node:internal/event_target:401:13)
    at REPL16:1:3
    at Script.runInThisContext (node:vm:129:12)
    at REPLServer.defaultEval (node:repl:522:29)
    at bound (node:domain:416:15)
    at REPLServer.runBound [as eval] (node:domain:427:12)
    at REPLServer.onLine (node:repl:849:10)
    at REPLServer.emit (node:events:406:35)
    at REPLServer.emit (node:domain:470:12) {
  code: 'ERR_INVALID_ARG_TYPE'
}

Additional information

n/a

@Ayase-252 Ayase-252 added the events Issues and PRs related to the events subsystem / EventEmitter. label Jun 23, 2021
@Ayase-252
Copy link
Member

May the doc need amend?

cc @jasnell

@aduh95
Copy link
Contributor

aduh95 commented Jun 23, 2021

The code snippet produces the following behavior in other JS runtimes:

  • Firefox: Uncaught TypeError: EventTarget.dispatchEvent: Argument 1 does not implement interface Event.
  • Safari: TypeError: Argument 1 ('event') to EventTarget.dispatchEvent must be an instance of Event
  • Chromium: Uncaught TypeError: Failed to execute 'dispatchEvent' on 'EventTarget': parameter 1 is not of type 'Event'.
  • Deno: Uncaught TypeError: Cannot set property 'target' of undefined

The behavior is consistent, we should align the doc with the actual behavior.

@aduh95 aduh95 added doc Issues and PRs related to the documentations. good first issue Issues that are suitable for first-time contributors. labels Jun 23, 2021
@RhnSharma
Copy link
Contributor

I would like to take this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Issues and PRs related to the documentations. events Issues and PRs related to the events subsystem / EventEmitter. good first issue Issues that are suitable for first-time contributors.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants