mirror of
https://github.com/nodejs/node.git
synced 2026-11-09 15:11:11 -05:00
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:
1 parent
ee7ee6e14e
commit
5b36b8bded
2 files changed
+12
No files matched your search
@@ -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,
|
||||
});
|
||||
|
||||
@@ -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');
|
||||
|
||||
Reference in new issue
Block a user