diff --git a/lib/internal/event_target.js b/lib/internal/event_target.js index c0347d79d6cd3e..863c1c6ea8bd01 100644 --- a/lib/internal/event_target.js +++ b/lib/internal/event_target.js @@ -636,6 +636,8 @@ class EventTarget { removeEventListener(type, listener, options = kEmptyObject) { if (!isEventTarget(this)) throw new ERR_INVALID_THIS('EventTarget'); + if (arguments.length < 2) + throw new ERR_MISSING_ARGS('type', 'listener'); if (!validateEventListener(listener)) return; @@ -666,6 +668,8 @@ class EventTarget { dispatchEvent(event) { if (!isEventTarget(this)) throw new ERR_INVALID_THIS('EventTarget'); + if (arguments.length < 1) + throw new ERR_MISSING_ARGS('event'); if (!(event instanceof Event)) throw new ERR_INVALID_ARG_TYPE('event', 'Event', event); diff --git a/test/parallel/test-eventtarget.js b/test/parallel/test-eventtarget.js index b7898391a793b5..f6208a3b8b8844 100644 --- a/test/parallel/test-eventtarget.js +++ b/test/parallel/test-eventtarget.js @@ -685,3 +685,32 @@ let asyncTest = Promise.resolve(); et.dispatchEvent(new Event('foo')); }); } + +{ + const et = new EventTarget(); + + throws(() => et.addEventListener(), { + code: 'ERR_MISSING_ARGS', + name: 'TypeError', + }); + + throws(() => et.addEventListener('foo'), { + code: 'ERR_MISSING_ARGS', + name: 'TypeError', + }); + + throws(() => et.removeEventListener(), { + code: 'ERR_MISSING_ARGS', + name: 'TypeError', + }); + + throws(() => et.removeEventListener('foo'), { + code: 'ERR_MISSING_ARGS', + name: 'TypeError', + }); + + throws(() => et.dispatchEvent(), { + code: 'ERR_MISSING_ARGS', + name: 'TypeError', + }); +}