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>
This commit is contained in:
Luigi Pinca committed 2021-07-25 16:16:26 +02:00
1 parent ee7ee6e14e
commit 5b36b8bded
2 files changed
+12

No files matched your search

+3
View File
@@ -598,6 +598,9 @@ function shouldAddListener(listener) {
function validateEventListenerOptions(options) {
if (typeof options === 'boolean')
return { capture: options };
if (options === null)
return {};
validateObject(options, 'options', {
allowArray: true, allowFunction: true,
});
+9
View File
@@ -177,6 +177,15 @@ let asyncTest = Promise.resolve();
eventTarget.dispatchEvent(event);
}
{
// The `options` argument can be `null`.
const eventTarget = new EventTarget();
const event = new Event('foo');
const fn = common.mustCall((event) => strictEqual(event.type, 'foo'));
eventTarget.addEventListener('foo', fn, null);
eventTarget.dispatchEvent(event);
}
{
const uncaughtException = common.mustCall((err, origin) => {
strictEqual(err.message, 'boom');