GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — lib: check number of arguments in `EventTarget`'s function · nodejs/node@1284789

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal
    • event_target.js
  • test/parallel
    • test-eventtarget.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/event_target.js‎

Copy file name to clipboardExpand all lines: lib/internal/event_target.js
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,8 @@ class EventTarget {
633633
removeEventListener(type, listener, options = kEmptyObject) {
634634
if (!isEventTarget(this))
635635
throw new ERR_INVALID_THIS('EventTarget');
636+
if (arguments.length < 2)
637+
throw new ERR_MISSING_ARGS('type', 'listener');
636638
if (!validateEventListener(listener))
637639
return;
638640

@@ -663,6 +665,8 @@ class EventTarget {
663665
dispatchEvent(event) {
664666
if (!isEventTarget(this))
665667
throw new ERR_INVALID_THIS('EventTarget');
668+
if (arguments.length < 1)
669+
throw new ERR_MISSING_ARGS('event');
666670

667671
if (!(event instanceof Event))
668672
throw new ERR_INVALID_ARG_TYPE('event', 'Event', event);
Collapse file

‎test/parallel/test-eventtarget.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-eventtarget.js
+29Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,3 +676,32 @@ let asyncTest = Promise.resolve();
676676
et.dispatchEvent(new Event('foo'));
677677
});
678678
}
679+
680+
{
681+
const et = new EventTarget();
682+
683+
throws(() => et.addEventListener(), {
684+
code: 'ERR_MISSING_ARGS',
685+
name: 'TypeError',
686+
});
687+
688+
throws(() => et.addEventListener('foo'), {
689+
code: 'ERR_MISSING_ARGS',
690+
name: 'TypeError',
691+
});
692+
693+
throws(() => et.removeEventListener(), {
694+
code: 'ERR_MISSING_ARGS',
695+
name: 'TypeError',
696+
});
697+
698+
throws(() => et.removeEventListener('foo'), {
699+
code: 'ERR_MISSING_ARGS',
700+
name: 'TypeError',
701+
});
702+
703+
throws(() => et.dispatchEvent(), {
704+
code: 'ERR_MISSING_ARGS',
705+
name: 'TypeError',
706+
});
707+
}

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.