Commit Graph

33 Commits

Author SHA1 Message Date
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
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
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