Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixup! arguments
  • Loading branch information
benjamingr committed Jun 4, 2020
commit a1a43261afe7a3d000bd421db9825cc62aa96e6d
10 changes: 5 additions & 5 deletions doc/api/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -908,11 +908,6 @@ Encoding provided to `TextDecoder()` API was not one of the

Thrown when an attempt is made to recursively dispatch an event on `EventTarget`.

<a id="ERR_EVENT_NAME_REQUIRED"></a>
### `ERR_EVENT_NAME_REQUIRED`

Thrown when an Event is created without passing its constructor a valid `type`.

<a id="ERR_EXECUTION_ENVIRONMENT_NOT_AVAILABLE"></a>
### `ERR_EXECUTION_ENVIRONMENT_NOT_AVAILABLE`

Expand Down Expand Up @@ -1290,6 +1285,11 @@ the worker thread.

The provided address family is not understood by the Node.js API.

<a id="ERR_INVALID_ARG_COUNT"></a>
### `ERR_INVALID_ARGUMENT_COUNT`

Thrown when an invalid number of arguments is passed to a function.

<a id="ERR_INVALID_ARG_TYPE"></a>
### `ERR_INVALID_ARG_TYPE`

Expand Down
3 changes: 1 addition & 2 deletions lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -831,8 +831,6 @@ E('ERR_ENCODING_NOT_SUPPORTED', 'The "%s" encoding is not supported',
RangeError);
E('ERR_EVAL_ESM_CANNOT_PRINT', '--print cannot be used with ESM input', Error);
E('ERR_EVENT_RECURSION', 'The event "%s" is already being dispatched', Error);
E('ERR_EVENT_NAME_REQUIRED', 'The event constructor must be called with at' +
'least 1 argument.', TypeError);
E('ERR_FALSY_VALUE_REJECTION', function(reason) {
this.reason = reason;
return 'Promise was rejected with falsy value';
Expand Down Expand Up @@ -974,6 +972,7 @@ E('ERR_INVALID_ADDRESS_FAMILY', function(addressType, host, port) {
this.port = port;
return `Invalid address family: ${addressType} ${host}:${port}`;
}, RangeError);
E('ERR_INVALID_ARG_COUNT', 'Required %d arguments but got %d', TypeError);
E('ERR_INVALID_ARG_TYPE',
(name, expected, actual) => {
assert(typeof name === 'string', "'name' must be a string");
Expand Down
4 changes: 2 additions & 2 deletions lib/internal/event_target.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const {
ERR_INVALID_ARG_TYPE,
ERR_EVENT_RECURSION,
ERR_OUT_OF_RANGE,
ERR_EVENT_NAME_REQUIRED
ERR_INVALID_ARG_COUNT
}
} = require('internal/errors');

Expand Down Expand Up @@ -47,7 +47,7 @@ class Event {

constructor(type, options) {
if (arguments.length === 0) {
throw new ERR_EVENT_NAME_REQUIRED();
throw new ERR_INVALID_ARG_COUNT(1, arguments.length);
}
if (options != null && typeof options !== 'object')
throw new ERR_INVALID_ARG_TYPE('options', 'object', options);
Expand Down
13 changes: 8 additions & 5 deletions test/parallel/test-eventtarget.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ ok(EventTarget);
strictEqual(ev.defaultPrevented, false);
strictEqual(typeof ev.timeStamp, 'number');

// no argument behavior
throws(() => {
new Event();
}, TypeError);

// compatibility properties with the DOM
deepStrictEqual(ev.composedPath(), []);
strictEqual(ev.returnValue, true);
Expand Down Expand Up @@ -66,6 +61,14 @@ ok(EventTarget);
strictEqual(ev.cancelBubble, true);
}

// no argument behavior - throw TypeError
throws(() => {
new Event();
}, TypeError);
// too many arguments passed behavior - ignore additional arguments
const ev = new Event('foo', {}, {});
strictEqual(ev.type, 'foo');
}
{
const ev = new Event('foo', { cancelable: true });
strictEqual(ev.type, 'foo');
Expand Down