René
9c2500295e
events: repurpose events.listenerCount() to accept EventTargets
...
PR-URL: https://github.com/nodejs/node/pull/60214
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
2025-11-26 11:09:07 +00:00
Antoine du Hamel
17fba608ae
test: ensure assertions are reached on more tests
...
PR-URL: https://github.com/nodejs/node/pull/60726
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
2025-11-17 22:10:40 +01:00
James M Snell
97a3a8204c
test: replace more uses of global with globalThis
...
PR-URL: https://github.com/nodejs/node/pull/56712
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com >
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
2025-01-25 07:23:11 +00:00
Khafra
a9081b5391
events: allow null/undefined eventInitDict
...
PR-URL: https://github.com/nodejs/node/pull/54643
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com >
Reviewed-By: LiviaMedeiros <livia@cirno.name >
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2024-09-21 09:08:39 -07:00
Mickael Meausoone
04cf8c2130
events: add stop propagation flag to Event.stopImmediatePropagation
...
Spec mention stopImmediatePropagation should set both flags:
"stop propagation" and "stop immediate propagation".
So the second is not supported by Node.js as there is no
hierarchy and bubbling,
but the flags are both present as well as stopPropagation.
It would makes sense to follow specs on that.
Refs: https://dom.spec.whatwg.org/#dom-event-stopimmediatepropagation
PR-URL: https://github.com/nodejs/node/pull/39463
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
2024-05-12 09:18:03 +02:00
mert.altin
399654faf2
events: no stopPropagation call in cancelBubble
...
PR-URL: https://github.com/nodejs/node/pull/50405
Reviewed-By: Matthew Aitken <maitken033380023@gmail.com >
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
Reviewed-By: Deokjin Kim <deokjin81.kim@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Michael Dawson <midawson@redhat.com >
2024-02-26 16:56:26 -05:00
Raz Luvaton
c39f04c141
events: remove weak listener for event target
...
Fixes: https://github.com/nodejs/node/issues/48951
PR-URL: https://github.com/nodejs/node/pull/48952
Reviewed-By: Chemi Atlow <chemi@atlow.co.il >
2023-08-12 18:20:54 +00:00
Chemi Atlow
bcd35c334e
lib: add option to force handling stopped events
...
PR-URL: https://github.com/nodejs/node/pull/48301
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
Reviewed-By: Moshe Atlow <moshe@atlow.co.il >
2023-06-22 13:38:02 +00:00
Khafra
41b8872cbd
lib: use webidl DOMString converter in EventTarget
...
PR-URL: https://github.com/nodejs/node/pull/47514
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com >
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
2023-04-14 10:12:28 +00:00
Santiago Gimeno
74b9cf2ee1
lib: define Event.isTrusted in the prototype
...
Don't conform to the spec with isTrusted. The spec defines it as
`LegacyUnforgeable` but defining it in the constructor has a big
performance impact and the property doesn't seem to be useful outside of
browsers.
Refs: https://github.com/nodejs/performance/issues/32
PR-URL: https://github.com/nodejs/node/pull/46974
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com >
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl >
Reviewed-By: James M Snell <jasnell@gmail.com >
2023-04-03 17:02:26 +00:00
Deokjin Kim
c776324f0a
lib: check number of arguments in EventTarget's function
...
For now, addEventListener() only checks number of arguments.
removeEventListener() and dispatchEvent() also need checking
number of arguments.
PR-URL: https://github.com/nodejs/node/pull/45668
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com >
Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com >
2022-12-09 06:07:20 +00:00
Rich Trott
d5d7a416c7
test: add trailing commas in event tests
...
As much as I would like to do this everywhere and then modify the lint
rule to enforce it, the churn would be too big. However if we're going
to have relatively frequent nits for this sort of thing (as we do), I'd
prefer we migrate a few files at a time to never actually getting around
to doing it.
Ref: https://github.com/nodejs/node/pull/45448#pullrequestreview-1179370442
PR-URL: https://github.com/nodejs/node/pull/45466
Reviewed-By: James M Snell <jasnell@gmail.com >
2022-11-22 23:03:33 +00:00
James M Snell
1f7e8d609a
lib: add ability to add separate event name to defineEventHandler
...
Adds an optional third argument to `defineEventHandler()` to specify
an event name that is separate from the name used for the property.
This will be used, for instance, by the quic implementation to support
generating the `on...` events where the event name itself is hyphenated.
For instance `defineEventHandler(target, 'streamreset', 'stream-reset')`
Separated out from https://github.com/nodejs/node/pull/44325
Signed-off-by: James M Snell <jasnell@gmail.com >
PR-URL: https://github.com/nodejs/node/pull/45032
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com >
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com >
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
2022-10-19 00:43:11 +00:00
Daeyeon Jeong
ed1e9ae402
events: improve EventListener validation
...
This fixes validating `EventListener` given to `add/removeEventListener`
to improve the Web API compatibility.
According to the WPT test failure with the current validation,
`addEventListener` should not require `handleEvent` to be defined on
an `EventListener`". IIUC, the same can be applied to
`removeEventListener` also.
Signed-off-by: Daeyeon Jeong daeyeon.dev@gmail.com
PR-URL: https://github.com/nodejs/node/pull/43491
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2022-06-29 12:26:18 +01:00
Benjamin Gruenbaum
0a722973cb
events: set default handler value
...
Event handler like BroadcastChannel.onmessage and AbortSignal.onabort
have a default value of `null` but we return `undefined`.
Return `null` and add a test.
PR-URL: https://github.com/nodejs/node/pull/41970
Reviewed-By: Tobias Nießen <tniessen@tnie.de >
Reviewed-By: Michaël Zasso <targos@protonmail.com >
Reviewed-By: Mestery <mestery@protonmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
2022-02-16 19:36:20 +00:00
MrBBot
b381bed10c
events: allow dispatch many times without listener
...
Fast path for EventTarget dispatch with no listeners didn't reset
kIsBeingDispatched flag, meaning same event couldn't be dispatched
multiple times.
PR-URL: https://github.com/nodejs/node/pull/39772
Refs: https://github.com/nodejs/node/pull/39395
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
2021-09-26 21:09:06 +02:00
Luigi Pinca
5c4e673a96
events: allow an event to be dispatched multiple times
...
Use a different flag to prevent recursive dispatching.
PR-URL: https://github.com/nodejs/node/pull/39395
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2021-07-25 16:17:41 +02:00
Luigi Pinca
5b36b8bded
events: allow the options argument to be null
...
Make `EventTarget.prototype.addEventListener()` accept `null` as a valid
value for the `options` argument.
PR-URL: https://github.com/nodejs/node/pull/39486
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Robert Nagy <ronagy@icloud.com >
2021-07-25 16:16:26 +02:00
Rich Trott
330f25ef82
test: prepare for consistent comma-dangle lint rule
...
Make changes so that tests will pass when the comma-dangle settings
applied to the rest of the code base are also applied to tests.
PR-URL: https://github.com/nodejs/node/pull/37930
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Derek Lewis <DerekNonGeneric@inf.is >
2021-04-01 23:14:29 -07:00
himself65
42ff00e4b5
test: remove duplicated test for eventtarget
...
PR-URL: https://github.com/nodejs/node/pull/37853
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Darshan Sen <raisinten@gmail.com >
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2021-03-22 08:42:50 -07:00
Nitzan Uziely
83d6e63aee
events: change EventTarget handler exception behavior
...
Change the behavior of EventTarget, instead of emitting
'error' on handler exception, emit 'uncaughtException'.
Fixes: https://github.com/nodejs/node/issues/36770
PR-URL: https://github.com/nodejs/node/pull/37237
Fixes: https://github.com/nodejs/node/issues/36770
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
Reviewed-By: Rich Trott <rtrott@gmail.com >
2021-02-15 20:10:07 +02:00
ExE Boss
beee53884d
lib: fix WebIDL object and dictionary type conversion
...
PR-URL: https://github.com/nodejs/node/pull/37047
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com >
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com >
Reviewed-By: Rich Trott <rtrott@gmail.com >
2021-02-08 17:02:16 -08:00
Benjamin Gruenbaum
5ef4c64e5b
lib: add weak event handlers
...
PR-URL: https://github.com/nodejs/node/pull/36607
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Gus Caplan <me@gus.host >
2021-02-06 19:01:53 +02:00
ZiJian Liu
7c767622bf
test: increase coverage for events
...
1. test EventEmitter.setMaxListeners with invalid listener count
https://coverage.nodejs.org/coverage-0b6d3070a176d437/lib/events.js.html#L171
2. test EventEmitter.setMaxListeners with invalid emitter
https://coverage.nodejs.org/coverage-0b6d3070a176d437/lib/events.js.html#L186
3. test getEventListeners with invalid emiiter
Refs: https://coverage.nodejs.org/coverage-0b6d3070a176d437/lib/events.js.html#L706
4. test events.once with options: null
Refs: https://coverage.nodejs.org/coverage-0b6d3070a176d437/lib/events.js.html#L712
5. add test case for inspect new Event()
Refs: https://coverage.nodejs.org/coverage-0b6d3070a176d437/lib/internal/event_target.js.html#L111
6. add test case for insepct new EventTarget()
Refs: https://coverage.nodejs.org/coverage-0b6d3070a176d437/lib/internal/event_target.js.html#L446
7. add test case for Event and EventTarget constructor name
PR-URL: https://github.com/nodejs/node/pull/36668
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Rich Trott <rtrott@gmail.com >
2021-01-04 19:01:59 +00:00
Benjamin Gruenbaum
ef8d0e9798
events: support signal in EventTarget
...
PR-URL: https://github.com/nodejs/node/pull/36258
Fixes: https://github.com/nodejs/node/issues/36073
Reviewed-By: James M Snell <jasnell@gmail.com >
2020-12-02 14:55:08 +00:00
Antoine du Hamel
36fbbe0b86
test: use global.EventTarget instead of internals
...
`EventTarget` is exposed on the global scope, there is no need to use
`--expose-internals` flag in the tests.
Refs: https://github.com/nodejs/node/pull/35496
PR-URL: https://github.com/nodejs/node/pull/36002
Reviewed-By: Michaël Zasso <targos@protonmail.com >
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
2020-11-09 19:25:15 +01:00
Benjamin Gruenbaum
d3969003b5
events: fire handlers in correct oder
...
PR-URL: https://github.com/nodejs/node/pull/35931
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com >
Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com >
Reviewed-By: Rich Trott <rtrott@gmail.com >
2020-11-07 18:12:30 +02:00
Benjamin Gruenbaum
8e87efb849
events: define event handler as enumerable
...
PR-URL: https://github.com/nodejs/node/pull/35931
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com >
Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com >
Reviewed-By: Rich Trott <rtrott@gmail.com >
2020-11-07 18:12:24 +02:00
Benjamin Gruenbaum
ee749ba2c6
events: add a few tests
...
PR-URL: https://github.com/nodejs/node/pull/35806
Reviewed-By: Rich Trott <rtrott@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com >
2020-11-03 17:16:55 +00:00
Daijiro Wachi
2351e2cffe
test: integrate abort_controller tests from wpt
...
Refs: https://github.com/web-platform-tests/wpt/pull/9361
PR-URL: https://github.com/nodejs/node/pull/35869
Refs: https://github.com/web-platform-tests/wpt/blob/master/dom/abort/event.any.js
Reviewed-By: Rich Trott <rtrott@gmail.com >
Reviewed-By: Michaël Zasso <targos@protonmail.com >
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
2020-11-01 10:16:56 +09:00
Juan José Arboleda
fb2f3cc828
test: improve test coverage for eventtarget
...
PR-URL: https://github.com/nodejs/node/pull/33733
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
2020-10-06 05:39:02 -05:00
James M Snell and Benjamin Gruenbaum
4629e96c20
events: improve argument handling, start passive
...
Co-authored-by: Benjamin Gruenbaum <benjamingr@gmail.com >
PR-URL: https://github.com/nodejs/node/pull/34015
Reviewed-By: Denys Otrishko <shishugi@gmail.com >
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
2020-06-23 17:08:13 -07:00
James M Snell and Benjamin Gruenbaum
ef91096565
events: support dispatching event from event
...
Co-authored-by: Benjamin Gruenbaum <benjamingr@gmail.com >
PR-URL: https://github.com/nodejs/node/pull/34015
Reviewed-By: Denys Otrishko <shishugi@gmail.com >
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
2020-06-23 17:08:12 -07:00
James M Snell
4bbd389d12
events: add event-target tests
...
PR-URL: https://github.com/nodejs/node/pull/34015
Reviewed-By: Denys Otrishko <shishugi@gmail.com >
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
2020-06-23 17:08:12 -07:00
Benjamin Gruenbaum
f3935b811a
event: cancelBubble is a property
...
Event#cancelBubble is property (and not a function). Change
Event#cancelBubble to a property and add a test.
PR-URL: https://github.com/nodejs/node/pull/33613
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Michaël Zasso <targos@protonmail.com >
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de >
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com >
PR-URL: https://github.com/nodejs/node/pull/34015
Reviewed-By: Denys Otrishko <shishugi@gmail.com >
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
2020-06-23 17:08:11 -07:00
Benjamin Gruenbaum
e8f4ac7dad
events: support event handlers
...
PR-URL: https://github.com/nodejs/node/pull/34015
Reviewed-By: Denys Otrishko <shishugi@gmail.com >
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
2020-06-23 17:08:10 -07:00
Benjamin Gruenbaum
9d324f0441
events: expose Event statics
...
PR-URL: https://github.com/nodejs/node/pull/34015
Reviewed-By: Denys Otrishko <shishugi@gmail.com >
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
2020-06-23 17:08:10 -07:00
Zirak
a30babf672
events: Handle a range of this values for dispatchEvent
...
On the web, dispatchEvent is finicky about its `this` value. An exception is
thrown for `this` values which are not an EventTarget.
PR-URL: https://github.com/nodejs/node/pull/34015
Reviewed-By: Denys Otrishko <shishugi@gmail.com >
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
2020-06-23 17:08:09 -07:00
Benjamin Gruenbaum
bf33b61be0
events: support useCapture boolean
...
PR-URL: https://github.com/nodejs/node/pull/33618
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de >
Reviewed-By: Michaël Zasso <targos@protonmail.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
2020-06-05 16:55:26 -07:00
Benjamin Gruenbaum
1969ada982
events: set target property to null
...
PR-URL: https://github.com/nodejs/node/pull/33615
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de >
Reviewed-By: Zeyu Yang <himself65@outlook.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com >
2020-06-05 16:27:04 -07:00
Benjamin Gruenbaum
236237829b
events: deal with no argument case
...
PR-URL: https://github.com/nodejs/node/pull/33611
Reviewed-By: Michaël Zasso <targos@protonmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de >
2020-06-05 14:41:43 -07:00
Benjamin Gruenbaum
3128915c57
event: cancelBubble is a property
...
Event#cancelBubble is property (and not a function). Change
Event#cancelBubble to a property and add a test.
PR-URL: https://github.com/nodejs/node/pull/33613
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Michaël Zasso <targos@protonmail.com >
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de >
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com >
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com >
Reviewed-By: Denys Otrishko <shishugi@gmail.com >
2020-06-04 10:36:41 -07:00
Benjamin Gruenbaum
3a7a5d7e62
events: deal with Symbol() passed to event constructor
...
PR-URL: https://github.com/nodejs/node/pull/33612
Reviewed-By: Michaël Zasso <targos@protonmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de >
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
2020-06-03 14:19:25 -07:00
Benjamin Gruenbaum
2d071e767d
events: fix event-target enumerable keys
...
PR-URL: https://github.com/nodejs/node/pull/33616
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
2020-05-30 04:38:46 +02:00
Benjamin Gruenbaum
56e44601d2
events: add tests, better toString
...
PR-URL: https://github.com/nodejs/node/pull/33622
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
2020-05-30 04:38:10 +02:00
James M Snell
785842a053
events: initial implementation of experimental EventTarget
...
See documentation changes for details
Signed-off-by: James M Snell <jasnell@gmail.com >
PR-URL: https://github.com/nodejs/node/pull/33556
Refs: https://github.com/nodejs/node/pull/33527
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
Reviewed-By: Bradley Farias <bradley.meck@gmail.com >
2020-05-28 06:31:58 -07:00